brace multiline if statements

This commit is contained in:
telans 2020-06-20 21:12:36 +12:00
parent 98db8f72e0
commit 7f307f9082
No known key found for this signature in database
GPG Key ID: 195444EE92DBCB20
20 changed files with 280 additions and 5 deletions

View File

@ -140,55 +140,73 @@ namespace Emby.Dlna
if (!string.IsNullOrEmpty(profileInfo.DeviceDescription))
{
if (deviceInfo.DeviceDescription == null || !IsRegexMatch(deviceInfo.DeviceDescription, profileInfo.DeviceDescription))
{
return false;
}
}
if (!string.IsNullOrEmpty(profileInfo.FriendlyName))
{
if (deviceInfo.FriendlyName == null || !IsRegexMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName))
{
return false;
}
}
if (!string.IsNullOrEmpty(profileInfo.Manufacturer))
{
if (deviceInfo.Manufacturer == null || !IsRegexMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer))
{
return false;
}
}
if (!string.IsNullOrEmpty(profileInfo.ManufacturerUrl))
{
if (deviceInfo.ManufacturerUrl == null || !IsRegexMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl))
{
return false;
}
}
if (!string.IsNullOrEmpty(profileInfo.ModelDescription))
{
if (deviceInfo.ModelDescription == null || !IsRegexMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription))
{
return false;
}
}
if (!string.IsNullOrEmpty(profileInfo.ModelName))
{
if (deviceInfo.ModelName == null || !IsRegexMatch(deviceInfo.ModelName, profileInfo.ModelName))
{
return false;
}
}
if (!string.IsNullOrEmpty(profileInfo.ModelNumber))
{
if (deviceInfo.ModelNumber == null || !IsRegexMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber))
{
return false;
}
}
if (!string.IsNullOrEmpty(profileInfo.ModelUrl))
{
if (deviceInfo.ModelUrl == null || !IsRegexMatch(deviceInfo.ModelUrl, profileInfo.ModelUrl))
{
return false;
}
}
if (!string.IsNullOrEmpty(profileInfo.SerialNumber))
{
if (deviceInfo.SerialNumber == null || !IsRegexMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber))
{
return false;
}
}
return true;

View File

@ -208,7 +208,9 @@ namespace Emby.Dlna.PlayTo
var command = rendererCommands.ServiceActions.FirstOrDefault(c => c.Name == "SetMute");
if (command == null)
{
return false;
}
var service = GetServiceRenderingControl();
@ -237,7 +239,9 @@ namespace Emby.Dlna.PlayTo
var command = rendererCommands.ServiceActions.FirstOrDefault(c => c.Name == "SetVolume");
if (command == null)
{
return;
}
var service = GetServiceRenderingControl();
@ -260,7 +264,9 @@ namespace Emby.Dlna.PlayTo
var command = avCommands.ServiceActions.FirstOrDefault(c => c.Name == "Seek");
if (command == null)
{
return;
}
var service = GetAvTransportService();
@ -285,7 +291,9 @@ namespace Emby.Dlna.PlayTo
var command = avCommands.ServiceActions.FirstOrDefault(c => c.Name == "SetAVTransportURI");
if (command == null)
{
return;
}
var dictionary = new Dictionary<string, string>
{
@ -452,7 +460,9 @@ namespace Emby.Dlna.PlayTo
_connectFailureCount = 0;
if (_disposed)
{
return;
}
// If we're not playing anything make sure we don't get data more often than neccessry to keep the Session alive
if (transportState.Value == TRANSPORTSTATE.STOPPED)
@ -472,7 +482,9 @@ namespace Emby.Dlna.PlayTo
catch (Exception ex)
{
if (_disposed)
{
return;
}
_logger.LogError(ex, "Error updating device info for {DeviceName}", Properties.Name);
@ -573,7 +585,9 @@ namespace Emby.Dlna.PlayTo
cancellationToken: cancellationToken).ConfigureAwait(false);
if (result == null || result.Document == null)
{
return;
}
var valueNode = result.Document.Descendants(uPnpNamespaces.RenderingControl + "GetMuteResponse")
.Select(i => i.Element("CurrentMute"))

View File

@ -19,7 +19,9 @@ namespace Emby.Server.Implementations.Library.Resolvers.Books
// Only process items that are in a collection folder containing books
if (!string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
{
return null;
}
if (args.IsDirectory)
{
@ -55,7 +57,9 @@ namespace Emby.Server.Implementations.Library.Resolvers.Books
// Don't return a Book if there is more (or less) than one document in the directory
if (bookFiles.Count != 1)
{
return null;
}
return new Book
{

View File

@ -40,7 +40,9 @@ namespace Emby.Server.Implementations.Services
if (httpResult != null)
{
if (httpResult.RequestContext == null)
{
httpResult.RequestContext = request;
}
response.StatusCode = httpResult.Status;
}

View File

@ -42,11 +42,15 @@ namespace Emby.Server.Implementations.Services
}
if (mi.GetParameters().Length != 1)
{
continue;
}
var actionName = mi.Name;
if (!AllVerbs.Contains(actionName, StringComparer.OrdinalIgnoreCase))
{
continue;
}
list.Add(mi);
}

View File

@ -445,12 +445,14 @@ namespace Emby.Server.Implementations.Services
&& requestComponents.Length >= this.TotalComponentsCount - this.wildcardCount;
if (!isValidWildCardPath)
{
throw new ArgumentException(
string.Format(
CultureInfo.InvariantCulture,
"Path Mismatch: Request Path '{0}' has invalid number of components compared to: '{1}'",
pathInfo,
this.restPath));
}
}
var requestKeyValuesMap = new Dictionary<string, string>();

View File

@ -19,10 +19,14 @@ namespace Emby.Server.Implementations.Sorting
public int Compare(BaseItem x, BaseItem y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
return DateTime.Compare(x.DateCreated, y.DateCreated);
}

View File

@ -19,10 +19,14 @@ namespace Emby.Server.Implementations.Sorting
public int Compare(BaseItem x, BaseItem y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
return (x.RunTimeTicks ?? 0).CompareTo(y.RunTimeTicks ?? 0);
}

View File

@ -19,10 +19,14 @@ namespace Emby.Server.Implementations.Sorting
public int Compare(BaseItem x, BaseItem y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase);
}

View File

@ -2951,7 +2951,9 @@ namespace MediaBrowser.Controller.Entities
public IEnumerable<BaseItem> GetTrailers()
{
if (this is IHasTrailers)
{
return ((IHasTrailers)this).LocalTrailerIds.Select(LibraryManager.GetItemById).Where(i => i != null).OrderBy(i => i.SortName);
}
else
return Array.Empty<BaseItem>();
}

View File

@ -58,7 +58,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var endTime = time[1];
var idx = endTime.IndexOf(" ", StringComparison.Ordinal);
if (idx > 0)
{
endTime = endTime.Substring(0, idx);
}
subEvent.EndPositionTicks = GetTicks(endTime);
var multiline = new List<string>();
while ((line = reader.ReadLine()) != null)

View File

@ -41,7 +41,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles
lineNumber++;
if (!eventsStarted)
{
header.AppendLine(line);
}
if (line.Trim().ToLowerInvariant() == "[events]")
{
@ -62,17 +64,29 @@ namespace MediaBrowser.MediaEncoding.Subtitles
for (int i = 0; i < format.Length; i++)
{
if (format[i].Trim().ToLowerInvariant() == "layer")
{
indexLayer = i;
}
else if (format[i].Trim().ToLowerInvariant() == "start")
{
indexStart = i;
}
else if (format[i].Trim().ToLowerInvariant() == "end")
{
indexEnd = i;
}
else if (format[i].Trim().ToLowerInvariant() == "text")
{
indexText = i;
}
else if (format[i].Trim().ToLowerInvariant() == "effect")
{
indexEffect = i;
}
else if (format[i].Trim().ToLowerInvariant() == "style")
{
indexStyle = i;
}
}
}
}
@ -89,28 +103,48 @@ namespace MediaBrowser.MediaEncoding.Subtitles
string[] splittedLine;
if (s.StartsWith("dialogue:"))
{
splittedLine = line.Substring(10).Split(',');
}
else
{
splittedLine = line.Split(',');
}
for (int i = 0; i < splittedLine.Length; i++)
{
if (i == indexStart)
{
start = splittedLine[i].Trim();
}
else if (i == indexEnd)
{
end = splittedLine[i].Trim();
}
else if (i == indexLayer)
{
layer = splittedLine[i];
}
else if (i == indexEffect)
{
effect = splittedLine[i];
}
else if (i == indexText)
{
text = splittedLine[i];
}
else if (i == indexStyle)
{
style = splittedLine[i];
}
else if (i == indexName)
{
name = splittedLine[i];
}
else if (i > indexText)
{
text += "," + splittedLine[i];
}
}
try
@ -169,13 +203,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles
CheckAndAddSubTags(ref fontName, ref extraTags, out italic);
text = text.Remove(start, end - start + 1);
if (italic)
{
text = text.Insert(start, "<font face=\"" + fontName + "\"" + extraTags + "><i>");
}
else
text = text.Insert(start, "<font face=\"" + fontName + "\"" + extraTags + ">");
int indexOfEndTag = text.IndexOf("{\\fn}", start);
if (indexOfEndTag > 0)
{
text = text.Remove(indexOfEndTag, "{\\fn}".Length).Insert(indexOfEndTag, "</font>");
}
else
text += "</font>";
}
@ -194,13 +232,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
text = text.Remove(start, end - start + 1);
if (italic)
{
text = text.Insert(start, "<font size=\"" + fontSize + "\"" + extraTags + "><i>");
}
else
text = text.Insert(start, "<font size=\"" + fontSize + "\"" + extraTags + ">");
int indexOfEndTag = text.IndexOf("{\\fs}", start);
if (indexOfEndTag > 0)
{
text = text.Remove(indexOfEndTag, "{\\fs}".Length).Insert(indexOfEndTag, "</font>");
}
else
text += "</font>";
}
@ -226,12 +268,16 @@ namespace MediaBrowser.MediaEncoding.Subtitles
text = text.Remove(start, end - start + 1);
if (italic)
{
text = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + "><i>");
}
else
text = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + ">");
int indexOfEndTag = text.IndexOf("{\\c}", start);
if (indexOfEndTag > 0)
{
text = text.Remove(indexOfEndTag, "{\\c}".Length).Insert(indexOfEndTag, "</font>");
}
else
text += "</font>";
}
@ -256,7 +302,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles
text = text.Remove(start, end - start + 1);
if (italic)
{
text = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + "><i>");
}
else
text = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + ">");
text += "</font>";
@ -268,19 +316,25 @@ namespace MediaBrowser.MediaEncoding.Subtitles
text = text.Replace(@"{\i0}", "</i>");
text = text.Replace(@"{\i}", "</i>");
if (CountTagInText(text, "<i>") > CountTagInText(text, "</i>"))
{
text += "</i>";
}
text = text.Replace(@"{\u1}", "<u>");
text = text.Replace(@"{\u0}", "</u>");
text = text.Replace(@"{\u}", "</u>");
if (CountTagInText(text, "<u>") > CountTagInText(text, "</u>"))
{
text += "</u>";
}
text = text.Replace(@"{\b1}", "<b>");
text = text.Replace(@"{\b0}", "</b>");
text = text.Replace(@"{\b}", "</b>");
if (CountTagInText(text, "<b>") > CountTagInText(text, "</b>"))
{
text += "</b>";
}
return text;
}
@ -288,7 +342,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles
private static bool IsInteger(string s)
{
if (int.TryParse(s, out var i))
{
return true;
}
return false;
}
@ -300,7 +356,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
count++;
if (index == text.Length)
{
return count;
}
index = text.IndexOf(tag, index + 1);
}

View File

@ -32,18 +32,25 @@ namespace MediaBrowser.Model.Dlna
}
if (string.Equals(container, "avi", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { MediaFormatProfile.AVI };
}
if (string.Equals(container, "mkv", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { MediaFormatProfile.MATROSKA };
}
if (string.Equals(container, "mpeg2ps", StringComparison.OrdinalIgnoreCase) ||
string.Equals(container, "ts", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { MediaFormatProfile.MPEG_PS_NTSC, MediaFormatProfile.MPEG_PS_PAL };
}
if (string.Equals(container, "mpeg1video", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { MediaFormatProfile.MPEG1 };
}
if (string.Equals(container, "mpeg2ts", StringComparison.OrdinalIgnoreCase) ||
string.Equals(container, "mpegts", StringComparison.OrdinalIgnoreCase) ||
@ -54,10 +61,14 @@ namespace MediaBrowser.Model.Dlna
}
if (string.Equals(container, "flv", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { MediaFormatProfile.FLV };
}
if (string.Equals(container, "wtv", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { MediaFormatProfile.WTV };
}
if (string.Equals(container, "3gp", StringComparison.OrdinalIgnoreCase))
{
@ -66,7 +77,9 @@ namespace MediaBrowser.Model.Dlna
}
if (string.Equals(container, "ogv", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "ogg", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { MediaFormatProfile.OGV };
}
return Array.Empty<MediaFormatProfile>();
}
@ -111,7 +124,9 @@ namespace MediaBrowser.Model.Dlna
if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase))
{
if (string.Equals(audioCodec, "lpcm", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_50_LPCM_T };
}
if (string.Equals(audioCodec, "dts", StringComparison.OrdinalIgnoreCase))
{
@ -134,14 +149,20 @@ namespace MediaBrowser.Model.Dlna
}
if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_AAC_MULT5{1}", resolution, suffix)) };
}
if (string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_MPEG1_L3{1}", resolution, suffix)) };
}
if (string.IsNullOrEmpty(audioCodec) ||
string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_AC3{1}", resolution, suffix)) };
}
}
else if (string.Equals(videoCodec, "vc1", StringComparison.OrdinalIgnoreCase))
{
@ -165,13 +186,24 @@ namespace MediaBrowser.Model.Dlna
else if (string.Equals(videoCodec, "mpeg4", StringComparison.OrdinalIgnoreCase) || string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase))
{
if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_AAC{0}", suffix)) };
}
if (string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_MPEG1_L3{0}", suffix)) };
}
if (string.Equals(audioCodec, "mp2", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_MPEG2_L2{0}", suffix)) };
}
if (string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase))
{
return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_AC3{0}", suffix)) };
}
}
return new MediaFormatProfile[] { };
@ -187,7 +219,9 @@ namespace MediaBrowser.Model.Dlna
if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase))
{
if (string.Equals(audioCodec, "lpcm", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.AVC_MP4_LPCM;
}
if (string.IsNullOrEmpty(audioCodec) ||
string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase))
{
@ -204,12 +238,16 @@ namespace MediaBrowser.Model.Dlna
if ((width.Value <= 720) && (height.Value <= 576))
{
if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.AVC_MP4_MP_SD_AAC_MULT5;
}
}
else if ((width.Value <= 1280) && (height.Value <= 720))
{
if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.AVC_MP4_MP_HD_720p_AAC;
}
}
else if ((width.Value <= 1920) && (height.Value <= 1080))
{
@ -226,7 +264,9 @@ namespace MediaBrowser.Model.Dlna
if (width.HasValue && height.HasValue && width.Value <= 720 && height.Value <= 576)
{
if (string.IsNullOrEmpty(audioCodec) || string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.MPEG4_P2_MP4_ASP_AAC;
}
if (string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase) || string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.MPEG4_P2_MP4_NDSD;
@ -250,15 +290,22 @@ namespace MediaBrowser.Model.Dlna
if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(audioCodec) || string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.AVC_3GPP_BL_QCIF15_AAC;
}
}
else if (string.Equals(videoCodec, "mpeg4", StringComparison.OrdinalIgnoreCase) ||
string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(audioCodec) || string.Equals(audioCodec, "wma", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.MPEG4_P2_3GPP_SP_L0B_AAC;
}
if (string.Equals(audioCodec, "amrnb", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.MPEG4_P2_3GPP_SP_L0B_AMR;
}
}
else if (string.Equals(videoCodec, "h263", StringComparison.OrdinalIgnoreCase) && string.Equals(audioCodec, "amrnb", StringComparison.OrdinalIgnoreCase))
{
@ -300,11 +347,19 @@ namespace MediaBrowser.Model.Dlna
if (width.HasValue && height.HasValue)
{
if ((width.Value <= 720) && (height.Value <= 576))
{
return MediaFormatProfile.VC1_ASF_AP_L1_WMA;
}
if ((width.Value <= 1280) && (height.Value <= 720))
{
return MediaFormatProfile.VC1_ASF_AP_L2_WMA;
}
if ((width.Value <= 1920) && (height.Value <= 1080))
{
return MediaFormatProfile.VC1_ASF_AP_L3_WMA;
}
}
}
else if (string.Equals(videoCodec, "mpeg2video", StringComparison.OrdinalIgnoreCase))
@ -318,27 +373,41 @@ namespace MediaBrowser.Model.Dlna
public MediaFormatProfile? ResolveAudioFormat(string container, int? bitrate, int? frequency, int? channels)
{
if (string.Equals(container, "asf", StringComparison.OrdinalIgnoreCase))
{
return ResolveAudioASFFormat(bitrate);
}
if (string.Equals(container, "mp3", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.MP3;
}
if (string.Equals(container, "lpcm", StringComparison.OrdinalIgnoreCase))
{
return ResolveAudioLPCMFormat(frequency, channels);
}
if (string.Equals(container, "mp4", StringComparison.OrdinalIgnoreCase) ||
string.Equals(container, "aac", StringComparison.OrdinalIgnoreCase))
{
return ResolveAudioMP4Format(bitrate);
}
if (string.Equals(container, "adts", StringComparison.OrdinalIgnoreCase))
{
return ResolveAudioADTSFormat(bitrate);
}
if (string.Equals(container, "flac", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.FLAC;
}
if (string.Equals(container, "oga", StringComparison.OrdinalIgnoreCase) ||
string.Equals(container, "ogg", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.OGG;
}
return null;
}
@ -410,13 +479,19 @@ namespace MediaBrowser.Model.Dlna
return ResolveImageJPGFormat(width, height);
if (string.Equals(container, "png", StringComparison.OrdinalIgnoreCase))
{
return ResolveImagePNGFormat(width, height);
}
if (string.Equals(container, "gif", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.GIF_LRG;
}
if (string.Equals(container, "raw", StringComparison.OrdinalIgnoreCase))
{
return MediaFormatProfile.RAW;
}
return null;
}
@ -426,10 +501,14 @@ namespace MediaBrowser.Model.Dlna
if (width.HasValue && height.HasValue)
{
if ((width.Value <= 160) && (height.Value <= 160))
{
return MediaFormatProfile.JPEG_TN;
}
if ((width.Value <= 640) && (height.Value <= 480))
{
return MediaFormatProfile.JPEG_SM;
}
if ((width.Value <= 1024) && (height.Value <= 768))
{
@ -447,7 +526,9 @@ namespace MediaBrowser.Model.Dlna
if (width.HasValue && height.HasValue)
{
if ((width.Value <= 160) && (height.Value <= 160))
{
return MediaFormatProfile.PNG_TN;
}
}
return MediaFormatProfile.PNG_LRG;

View File

@ -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;
}

View File

@ -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]);

View File

@ -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;

View File

@ -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
});
}
}
}
}

View File

@ -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));
}
}
}
}

View File

@ -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);
}

View File

@ -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);
}