mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-15 10:43:30 +01:00
brace multiline if statements
This commit is contained in:
@@ -114,9 +114,13 @@ namespace Rssdp.Infrastructure
|
||||
var headersToAddTo = IsContentHeader(headerName) ? contentHeaders : headers;
|
||||
|
||||
if (values.Count > 1)
|
||||
{
|
||||
headersToAddTo.TryAddWithoutValidation(headerName, values);
|
||||
}
|
||||
else
|
||||
{
|
||||
headersToAddTo.TryAddWithoutValidation(headerName, values.First());
|
||||
}
|
||||
}
|
||||
|
||||
private int ParseHeaders(System.Net.Http.Headers.HttpHeaders headers, System.Net.Http.Headers.HttpHeaders contentHeaders, string[] lines)
|
||||
@@ -160,7 +164,9 @@ namespace Rssdp.Infrastructure
|
||||
|
||||
var indexOfSeparator = headerValue.IndexOfAny(SeparatorCharacters);
|
||||
if (indexOfSeparator <= 0)
|
||||
{
|
||||
values.Add(headerValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
var segments = headerValue.Split(SeparatorCharacters);
|
||||
@@ -170,7 +176,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
var segment = segments[segmentIndex];
|
||||
if (segment.Trim().StartsWith("\"", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
segment = CombineQuotedSegments(segments, ref segmentIndex, segment);
|
||||
}
|
||||
|
||||
values.Add(segment);
|
||||
}
|
||||
@@ -199,12 +207,16 @@ namespace Rssdp.Infrastructure
|
||||
}
|
||||
|
||||
if (index + 1 < segments.Length)
|
||||
{
|
||||
trimmedSegment += "," + segments[index + 1].TrimEnd();
|
||||
}
|
||||
}
|
||||
|
||||
segmentIndex = segments.Length;
|
||||
if (trimmedSegment.StartsWith("\"", StringComparison.OrdinalIgnoreCase) && trimmedSegment.EndsWith("\"", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return trimmedSegment.Substring(1, trimmedSegment.Length - 2);
|
||||
}
|
||||
else
|
||||
return trimmedSegment;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ namespace Rssdp.Infrastructure
|
||||
finally
|
||||
{
|
||||
if (retVal != null)
|
||||
{
|
||||
retVal.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +66,9 @@ namespace Rssdp.Infrastructure
|
||||
message.Method = new HttpMethod(parts[0].Trim());
|
||||
Uri requestUri;
|
||||
if (Uri.TryCreate(parts[1].Trim(), UriKind.RelativeOrAbsolute, out requestUri))
|
||||
{
|
||||
message.RequestUri = requestUri;
|
||||
}
|
||||
else
|
||||
System.Diagnostics.Debug.WriteLine(parts[1]);
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@ namespace Rssdp.Infrastructure
|
||||
catch
|
||||
{
|
||||
if (retVal != null)
|
||||
{
|
||||
retVal.Dispose();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
@@ -77,7 +79,9 @@ namespace Rssdp.Infrastructure
|
||||
|
||||
int statusCode = -1;
|
||||
if (!Int32.TryParse(parts[1].Trim(), out statusCode))
|
||||
{
|
||||
throw new ArgumentException("data status line is invalid. Status code is not a valid integer.", nameof(data));
|
||||
}
|
||||
|
||||
message.StatusCode = (HttpStatusCode)statusCode;
|
||||
|
||||
|
||||
@@ -480,17 +480,21 @@ namespace Rssdp.Infrastructure
|
||||
|
||||
var handlers = this.RequestReceived;
|
||||
if (handlers != null)
|
||||
{
|
||||
handlers(this, new RequestReceivedEventArgs(data, remoteEndPoint, receivedOnLocalIpAddress));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnResponseReceived(HttpResponseMessage data, IPEndPoint endPoint, IPAddress localIpAddress)
|
||||
{
|
||||
var handlers = this.ResponseReceived;
|
||||
if (handlers != null)
|
||||
{
|
||||
handlers(this, new ResponseReceivedEventArgs(data, endPoint)
|
||||
{
|
||||
LocalIpAddress = localIpAddress
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,9 @@ namespace Rssdp
|
||||
|
||||
var rootDevice = device as SsdpRootDevice;
|
||||
if (rootDevice == null)
|
||||
{
|
||||
rootDevice = ((SsdpEmbeddedDevice)device).RootDevice;
|
||||
}
|
||||
|
||||
return rootDevice;
|
||||
}
|
||||
@@ -163,7 +165,9 @@ namespace Rssdp
|
||||
get
|
||||
{
|
||||
if (String.IsNullOrEmpty(_Udn) && !String.IsNullOrEmpty(this.Uuid))
|
||||
{
|
||||
return "uuid:" + this.Uuid;
|
||||
}
|
||||
else
|
||||
return _Udn;
|
||||
}
|
||||
@@ -283,7 +287,9 @@ namespace Rssdp
|
||||
}
|
||||
|
||||
if (wasAdded)
|
||||
{
|
||||
OnDeviceAdded(device);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -314,7 +320,9 @@ namespace Rssdp
|
||||
}
|
||||
|
||||
if (wasRemoved)
|
||||
{
|
||||
OnDeviceRemoved(device);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -327,7 +335,9 @@ namespace Rssdp
|
||||
{
|
||||
var handlers = this.DeviceAdded;
|
||||
if (handlers != null)
|
||||
{
|
||||
handlers(this, new DeviceEventArgs(device));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -340,7 +350,9 @@ namespace Rssdp
|
||||
{
|
||||
var handlers = this.DeviceRemoved;
|
||||
if (handlers != null)
|
||||
{
|
||||
handlers(this, new DeviceEventArgs(device));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,10 +217,12 @@ namespace Rssdp.Infrastructure
|
||||
|
||||
var handlers = this.DeviceAvailable;
|
||||
if (handlers != null)
|
||||
{
|
||||
handlers(this, new DeviceAvailableEventArgs(device, isNewDevice)
|
||||
{
|
||||
LocalIpAddress = localIpAddress
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -426,7 +428,9 @@ namespace Rssdp.Infrastructure
|
||||
};
|
||||
|
||||
if (NotificationTypeMatchesFilter(deadDevice))
|
||||
{
|
||||
OnDeviceUnavailable(deadDevice, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -439,7 +443,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
message.Headers.TryGetValues(headerName, out values);
|
||||
if (values != null)
|
||||
{
|
||||
retVal = values.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
@@ -453,7 +459,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
message.Headers.TryGetValues(headerName, out values);
|
||||
if (values != null)
|
||||
{
|
||||
retVal = values.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
@@ -467,7 +475,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
request.Headers.TryGetValues(headerName, out values);
|
||||
if (values != null)
|
||||
{
|
||||
value = values.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
Uri retVal;
|
||||
@@ -483,7 +493,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
response.Headers.TryGetValues(headerName, out values);
|
||||
if (values != null)
|
||||
{
|
||||
value = values.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
Uri retVal;
|
||||
@@ -560,7 +572,9 @@ namespace Rssdp.Infrastructure
|
||||
foreach (var removedDevice in existingDevices)
|
||||
{
|
||||
if (NotificationTypeMatchesFilter(removedDevice))
|
||||
{
|
||||
OnDeviceUnavailable(removedDevice, expired);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -572,7 +586,9 @@ namespace Rssdp.Infrastructure
|
||||
private TimeSpan SearchTimeToMXValue(TimeSpan searchWaitTime)
|
||||
{
|
||||
if (searchWaitTime.TotalSeconds < 2 || searchWaitTime == TimeSpan.Zero)
|
||||
{
|
||||
return OneSecond;
|
||||
}
|
||||
else
|
||||
return searchWaitTime.Subtract(OneSecond);
|
||||
}
|
||||
|
||||
@@ -215,7 +215,9 @@ namespace Rssdp.Infrastructure
|
||||
if (commsServer != null)
|
||||
{
|
||||
if (!commsServer.IsShared)
|
||||
{
|
||||
commsServer.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
_RecentSearchRequests = null;
|
||||
@@ -328,7 +330,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
SendSearchResponse(SsdpConstants.UpnpDeviceTypeRootDevice, device, GetUsn(device.Udn, SsdpConstants.UpnpDeviceTypeRootDevice), endPoint, receivedOnlocalIpAddress, cancellationToken);
|
||||
if (this.SupportPnpRootDevice)
|
||||
{
|
||||
SendSearchResponse(SsdpConstants.PnpDeviceTypeRootDevice, device, GetUsn(device.Udn, SsdpConstants.PnpDeviceTypeRootDevice), endPoint, receivedOnlocalIpAddress, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
SendSearchResponse(device.Udn, device, device.Udn, endPoint, receivedOnlocalIpAddress, cancellationToken);
|
||||
@@ -394,7 +398,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
var lastRequest = _RecentSearchRequests[newRequest.Key];
|
||||
if (lastRequest.IsOld())
|
||||
{
|
||||
_RecentSearchRequests[newRequest.Key] = newRequest;
|
||||
}
|
||||
else
|
||||
isDuplicateRequest = true;
|
||||
}
|
||||
@@ -402,7 +408,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
_RecentSearchRequests.Add(newRequest.Key, newRequest);
|
||||
if (_RecentSearchRequests.Count > 10)
|
||||
{
|
||||
CleanUpRecentSearchRequestsAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,7 +470,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
SendAliveNotification(device, SsdpConstants.UpnpDeviceTypeRootDevice, GetUsn(device.Udn, SsdpConstants.UpnpDeviceTypeRootDevice), cancellationToken);
|
||||
if (this.SupportPnpRootDevice)
|
||||
{
|
||||
SendAliveNotification(device, SsdpConstants.PnpDeviceTypeRootDevice, GetUsn(device.Udn, SsdpConstants.PnpDeviceTypeRootDevice), cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
SendAliveNotification(device, device.Udn, device.Udn, cancellationToken);
|
||||
@@ -506,7 +516,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
tasks.Add(SendByeByeNotification(device, SsdpConstants.UpnpDeviceTypeRootDevice, GetUsn(device.Udn, SsdpConstants.UpnpDeviceTypeRootDevice), cancellationToken));
|
||||
if (this.SupportPnpRootDevice)
|
||||
{
|
||||
tasks.Add(SendByeByeNotification(device, "pnp:rootdevice", GetUsn(device.Udn, "pnp:rootdevice"), cancellationToken));
|
||||
}
|
||||
}
|
||||
|
||||
tasks.Add(SendByeByeNotification(device, device.Udn, device.Udn, cancellationToken));
|
||||
@@ -547,20 +559,27 @@ namespace Rssdp.Infrastructure
|
||||
var timer = _RebroadcastAliveNotificationsTimer;
|
||||
_RebroadcastAliveNotificationsTimer = null;
|
||||
if (timer != null)
|
||||
{
|
||||
timer.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private TimeSpan GetMinimumNonZeroCacheLifetime()
|
||||
{
|
||||
var nonzeroCacheLifetimesQuery = (from device
|
||||
in _Devices
|
||||
where device.CacheLifetime != TimeSpan.Zero
|
||||
select device.CacheLifetime).ToList();
|
||||
var nonzeroCacheLifetimesQuery = (
|
||||
from device
|
||||
in _Devices
|
||||
where device.CacheLifetime != TimeSpan.Zero
|
||||
select device.CacheLifetime).ToList();
|
||||
|
||||
if (nonzeroCacheLifetimesQuery.Any())
|
||||
{
|
||||
return nonzeroCacheLifetimesQuery.Min();
|
||||
}
|
||||
else
|
||||
{
|
||||
return TimeSpan.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetFirstHeaderValue(System.Net.Http.Headers.HttpRequestHeaders httpRequestHeaders, string headerName)
|
||||
@@ -568,7 +587,9 @@ namespace Rssdp.Infrastructure
|
||||
string retVal = null;
|
||||
IEnumerable<String> values = null;
|
||||
if (httpRequestHeaders.TryGetValues(headerName, out values) && values != null)
|
||||
{
|
||||
retVal = values.FirstOrDefault();
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
@@ -588,7 +609,9 @@ namespace Rssdp.Infrastructure
|
||||
{
|
||||
var rootDevice = device as SsdpRootDevice;
|
||||
if (rootDevice != null)
|
||||
{
|
||||
WriteTrace(text + " " + device.DeviceType + " - " + device.Uuid + " - " + rootDevice.Location);
|
||||
}
|
||||
else
|
||||
WriteTrace(text + " " + device.DeviceType + " - " + device.Uuid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user