add using block

pull/1154/head
Luke Pulverenti 8 years ago
parent 495d06a970
commit 047d383cda

@ -67,45 +67,33 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
return; return;
} }
var tcpClient = _socketFactory.CreateTcpSocket(_remoteIp, HdHomeRunPort); using (var tcpClient = _socketFactory.CreateTcpSocket(_remoteIp, HdHomeRunPort))
if (!_lockkey.HasValue)
{ {
var rand = new Random(); if (!_lockkey.HasValue)
_lockkey = (uint)rand.Next();
}
var ipEndPoint = new IpEndPointInfo(_remoteIp, HdHomeRunPort);
for (int i = 0; i < numTuners; ++i)
{
if (!await CheckTunerAvailability(tcpClient, _remoteIp, i, cancellationToken).ConfigureAwait(false))
continue;
_activeTuner = i;
var lockKeyString = String.Format("{0:d}", _lockkey.Value);
var lockkeyMsg = CreateSetMessage(i, "lockkey", lockKeyString, null);
await tcpClient.SendAsync(lockkeyMsg, lockkeyMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false);
var response = await tcpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false);
string returnVal;
// parse response to make sure it worked
if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal))
continue;
var channelMsg = CreateSetMessage(i, "channel", frequency, _lockkey.Value);
await tcpClient.SendAsync(channelMsg, channelMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false);
await tcpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false);
// parse response to make sure it worked
if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal))
{ {
await ReleaseLockkey(tcpClient).ConfigureAwait(false); var rand = new Random();
continue; _lockkey = (uint)rand.Next();
} }
if (program != String.Empty) var ipEndPoint = new IpEndPointInfo(_remoteIp, HdHomeRunPort);
for (int i = 0; i < numTuners; ++i)
{ {
var programMsg = CreateSetMessage(i, "program", program, _lockkey.Value); if (!await CheckTunerAvailability(tcpClient, _remoteIp, i, cancellationToken).ConfigureAwait(false))
await tcpClient.SendAsync(programMsg, programMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false); continue;
_activeTuner = i;
var lockKeyString = String.Format("{0:d}", _lockkey.Value);
var lockkeyMsg = CreateSetMessage(i, "lockkey", lockKeyString, null);
await tcpClient.SendAsync(lockkeyMsg, lockkeyMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false);
var response = await tcpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false);
string returnVal;
// parse response to make sure it worked
if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal))
continue;
var channelMsg = CreateSetMessage(i, "channel", frequency, _lockkey.Value);
await tcpClient.SendAsync(channelMsg, channelMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false);
await tcpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false); await tcpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false);
// parse response to make sure it worked // parse response to make sure it worked
if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal)) if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal))
@ -113,21 +101,34 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
await ReleaseLockkey(tcpClient).ConfigureAwait(false); await ReleaseLockkey(tcpClient).ConfigureAwait(false);
continue; continue;
} }
}
var targetValue = String.Format("rtp://{0}:{1}", localIp, localPort); if (program != String.Empty)
var targetMsg = CreateSetMessage(i, "target", targetValue, _lockkey.Value); {
var programMsg = CreateSetMessage(i, "program", program, _lockkey.Value);
await tcpClient.SendAsync(programMsg, programMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false);
await tcpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false);
// parse response to make sure it worked
if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal))
{
await ReleaseLockkey(tcpClient).ConfigureAwait(false);
continue;
}
}
await tcpClient.SendAsync(targetMsg, targetMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false); var targetValue = String.Format("rtp://{0}:{1}", localIp, localPort);
response = await tcpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false); var targetMsg = CreateSetMessage(i, "target", targetValue, _lockkey.Value);
// parse response to make sure it worked
if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal))
{
await ReleaseLockkey(tcpClient).ConfigureAwait(false);
continue;
}
break; await tcpClient.SendAsync(targetMsg, targetMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false);
response = await tcpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false);
// parse response to make sure it worked
if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal))
{
await ReleaseLockkey(tcpClient).ConfigureAwait(false);
continue;
}
break;
}
} }
} }

Loading…
Cancel
Save