Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Bond-009 committed Aug 19, 2020
1 parent 634ee2d commit 2b400c9
Show file tree
Hide file tree
Showing 46 changed files with 366 additions and 302 deletions.
12 changes: 6 additions & 6 deletions Emby.Dlna/DlnaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ public DlnaManager(
_appHost = appHost;
}

private string UserProfilesPath => Path.Combine(_appPaths.ConfigurationDirectoryPath, "dlna", "user");

private string SystemProfilesPath => Path.Combine(_appPaths.ConfigurationDirectoryPath, "dlna", "system");

public async Task InitProfilesAsync()
{
try
{
await ExtractSystemProfilesAsync();
await ExtractSystemProfilesAsync().ConfigureAwait(false);
LoadProfiles();
}
catch (Exception ex)
Expand Down Expand Up @@ -240,7 +244,7 @@ public DeviceProfile GetProfile(IHeaderDictionary headers)
}
else
{
var headerString = string.Join(", ", headers.Select(i => string.Format("{0}={1}", i.Key, i.Value)).ToArray());
var headerString = string.Join(", ", headers.Select(i => string.Format(CultureInfo.InvariantCulture, "{0}={1}", i.Key, i.Value)));
_logger.LogDebug("No matching device profile found. {0}", headerString);
}

Expand Down Expand Up @@ -280,10 +284,6 @@ private bool IsMatch(IHeaderDictionary headers, HttpHeaderInfo header)
return false;
}

private string UserProfilesPath => Path.Combine(_appPaths.ConfigurationDirectoryPath, "dlna", "user");

private string SystemProfilesPath => Path.Combine(_appPaths.ConfigurationDirectoryPath, "dlna", "system");

private IEnumerable<DeviceProfile> GetProfiles(string path, DeviceProfileType type)
{
try
Expand Down
36 changes: 17 additions & 19 deletions Emby.Dlna/PlayTo/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Emby.Dlna.PlayTo
{
public class Device : IDisposable
{
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");

private Timer _timer;

public DeviceInfo Properties { get; set; }
Expand Down Expand Up @@ -55,16 +57,13 @@ public int Volume

private readonly ILogger _logger;

private readonly IServerConfigurationManager _config;

public Action OnDeviceUnavailable { get; set; }

public Device(DeviceInfo deviceProperties, IHttpClient httpClient, ILogger logger, IServerConfigurationManager config)
public Device(DeviceInfo deviceProperties, IHttpClient httpClient, ILogger logger)
{
Properties = deviceProperties;
_httpClient = httpClient;
_logger = logger;
_config = config;
}

public void Start()
Expand Down Expand Up @@ -275,7 +274,7 @@ public async Task Seek(TimeSpan value, CancellationToken cancellationToken)
throw new InvalidOperationException("Unable to find service");
}

await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, avCommands.BuildPost(command, service.ServiceType, string.Format("{0:hh}:{0:mm}:{0:ss}", value), "REL_TIME"))
await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, avCommands.BuildPost(command, service.ServiceType, string.Format(CultureInfo.InvariantCulture, "{0:hh}:{0:mm}:{0:ss}", value), "REL_TIME"))
.ConfigureAwait(false);

RestartTimer(true);
Expand All @@ -285,7 +284,7 @@ public async Task SetAvTransport(string url, string header, string metaData, Can
{
var avCommands = await GetAVProtocolAsync(cancellationToken).ConfigureAwait(false);

url = url.Replace("&", "&amp;");
url = url.Replace("&", "&amp;", StringComparison.Ordinal);

_logger.LogDebug("{0} - SetAvTransport Uri: {1} DlnaHeaders: {2}", Properties.Name, url, header);

Expand All @@ -297,8 +296,8 @@ public async Task SetAvTransport(string url, string header, string metaData, Can

var dictionary = new Dictionary<string, string>
{
{"CurrentURI", url},
{"CurrentURIMetaData", CreateDidlMeta(metaData)}
{ "CurrentURI", url },
{ "CurrentURIMetaData", CreateDidlMeta(metaData) }
};

var service = GetAvTransportService();
Expand Down Expand Up @@ -732,10 +731,10 @@ private async Task<uBaseObject> GetMediaInfo(TransportCommands avCommands, Cance
}

var trackUriElem = result.Document.Descendants(uPnpNamespaces.AvTransport + "GetPositionInfoResponse").Select(i => i.Element("TrackURI")).FirstOrDefault(i => i != null);
var trackUri = trackUriElem == null ? null : trackUriElem.Value;
var trackUri = trackUriElem?.Value;

var durationElem = result.Document.Descendants(uPnpNamespaces.AvTransport + "GetPositionInfoResponse").Select(i => i.Element("TrackDuration")).FirstOrDefault(i => i != null);
var duration = durationElem == null ? null : durationElem.Value;
var duration = durationElem?.Value;

if (!string.IsNullOrWhiteSpace(duration)
&& !string.Equals(duration, "NOT_IMPLEMENTED", StringComparison.OrdinalIgnoreCase))
Expand All @@ -748,7 +747,7 @@ private async Task<uBaseObject> GetMediaInfo(TransportCommands avCommands, Cance
}

var positionElem = result.Document.Descendants(uPnpNamespaces.AvTransport + "GetPositionInfoResponse").Select(i => i.Element("RelTime")).FirstOrDefault(i => i != null);
var position = positionElem == null ? null : positionElem.Value;
var position = positionElem?.Value;

if (!string.IsNullOrWhiteSpace(position) && !string.Equals(position, "NOT_IMPLEMENTED", StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -819,7 +818,7 @@ private XElement ParseResponse(string xml)
// some devices send back invalid xml
try
{
return XElement.Parse(xml.Replace("&", "&amp;"));
return XElement.Parse(xml.Replace("&", "&amp;", StringComparison.Ordinal));
}
catch (XmlException)
{
Expand Down Expand Up @@ -848,7 +847,7 @@ private static uBaseObject CreateUBaseObject(XElement container, string trackUri
ParentId = container.GetAttributeValue(uPnpNamespaces.ParentId),
Title = container.GetValue(uPnpNamespaces.title),
IconUrl = container.GetValue(uPnpNamespaces.Artwork),
SecondText = "",
SecondText = string.Empty,
Url = url,
ProtocolInfo = GetProtocolInfo(container),
MetaData = container.ToString()
Expand Down Expand Up @@ -941,12 +940,12 @@ private string NormalizeUrl(string baseUrl, string url)
return url;
}

if (!url.Contains("/"))
if (!url.Contains('/', StringComparison.Ordinal))
{
url = "/dmr/" + url;
}

if (!url.StartsWith("/"))
if (!url.StartsWith("/", StringComparison.Ordinal))
{
url = "/" + url;
}
Expand Down Expand Up @@ -981,7 +980,7 @@ public static async Task<Device> CreateuPnpDeviceAsync(Uri url, IHttpClient http
var deviceProperties = new DeviceInfo()
{
Name = string.Join(" ", friendlyNames),
BaseUrl = string.Format("http://{0}:{1}", url.Host, url.Port)
BaseUrl = string.Format(CultureInfo.InvariantCulture, "http://{0}:{1}", url.Host, url.Port)
};

var model = document.Descendants(uPnpNamespaces.ud.GetName("modelName")).FirstOrDefault();
Expand Down Expand Up @@ -1068,10 +1067,9 @@ public static async Task<Device> CreateuPnpDeviceAsync(Uri url, IHttpClient http
}
}

return new Device(deviceProperties, httpClient, logger, config);
return new Device(deviceProperties, httpClient, logger);
}

private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
private static DeviceIcon CreateIcon(XElement element)
{
if (element == null)
Expand Down Expand Up @@ -1222,7 +1220,7 @@ protected virtual void Dispose(bool disposing)

public override string ToString()
{
return string.Format("{0} - {1}", Properties.Name, Properties.BaseUrl);
return string.Format(CultureInfo.InvariantCulture, "{0} - {1}", Properties.Name, Properties.BaseUrl);
}
}
}
17 changes: 9 additions & 8 deletions Emby.Dlna/PlayTo/TransportCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;
using Emby.Dlna.Common;
Expand All @@ -11,14 +12,16 @@ namespace Emby.Dlna.PlayTo
{
public class TransportCommands
{
private const string CommandBase = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<SOAP-ENV:Body>" + "<m:{0} xmlns:m=\"{1}\">" + "{2}" + "</m:{0}>" + "</SOAP-ENV:Body></SOAP-ENV:Envelope>";
private List<StateVariable> _stateVariables = new List<StateVariable>();
private List<ServiceAction> _serviceActions = new List<ServiceAction>();

public List<StateVariable> StateVariables
{
get => _stateVariables;
set => _stateVariables = value;
}

private List<ServiceAction> _serviceActions = new List<ServiceAction>();
public List<ServiceAction> ServiceActions
{
get => _serviceActions;
Expand Down Expand Up @@ -123,7 +126,7 @@ public string BuildPost(ServiceAction action, string xmlNamespace)
}
}

return string.Format(CommandBase, action.Name, xmlNamespace, stateString);
return string.Format(CultureInfo.InvariantCulture, CommandBase, action.Name, xmlNamespace, stateString);
}

public string BuildPost(ServiceAction action, string xmlNamesapce, object value, string commandParameter = "")
Expand All @@ -147,7 +150,7 @@ public string BuildPost(ServiceAction action, string xmlNamesapce, object value,
}
}

return string.Format(CommandBase, action.Name, xmlNamesapce, stateString);
return string.Format(CultureInfo.InvariantCulture, CommandBase, action.Name, xmlNamesapce, stateString);
}

public string BuildPost(ServiceAction action, string xmlNamesapce, object value, Dictionary<string, string> dictionary)
Expand All @@ -170,7 +173,7 @@ public string BuildPost(ServiceAction action, string xmlNamesapce, object value,
}
}

return string.Format(CommandBase, action.Name, xmlNamesapce, stateString);
return string.Format(CultureInfo.InvariantCulture, CommandBase, action.Name, xmlNamesapce, stateString);
}

private string BuildArgumentXml(Argument argument, string value, string commandParameter = "")
Expand All @@ -183,12 +186,10 @@ private string BuildArgumentXml(Argument argument, string value, string commandP
state.AllowedValues.FirstOrDefault() ??
value;

return string.Format("<{0} xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"{1}\">{2}</{0}>", argument.Name, state.DataType ?? "string", sendValue);
return string.Format(CultureInfo.InvariantCulture, "<{0} xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"{1}\">{2}</{0}>", argument.Name, state.DataType ?? "string", sendValue);
}

return string.Format("<{0}>{1}</{0}>", argument.Name, value);
return string.Format(CultureInfo.InvariantCulture, "<{0}>{1}</{0}>", argument.Name, value);
}

private const string CommandBase = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<SOAP-ENV:Body>" + "<m:{0} xmlns:m=\"{1}\">" + "{2}" + "</m:{0}>" + "</SOAP-ENV:Body></SOAP-ENV:Envelope>";
}
}
4 changes: 2 additions & 2 deletions Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4560,13 +4560,13 @@ private List<string> GetWhereClauses(InternalItemsQuery query, IStatement statem
if (query.AncestorIds.Length > 1)
{
var inClause = string.Join(",", query.AncestorIds.Select(i => "'" + i.ToString("N", CultureInfo.InvariantCulture) + "'"));
whereClauses.Add(string.Format("Guid in (select itemId from AncestorIds where AncestorIdText in ({0}))", inClause));
whereClauses.Add(string.Format(CultureInfo.InvariantCulture, "Guid in (select itemId from AncestorIds where AncestorIdText in ({0}))", inClause));
}

if (!string.IsNullOrWhiteSpace(query.AncestorWithPresentationUniqueKey))
{
var inClause = "select guid from TypedBaseItems where PresentationUniqueKey=@AncestorWithPresentationUniqueKey";
whereClauses.Add(string.Format("Guid in (select itemId from AncestorIds where AncestorId in ({0}))", inClause));
whereClauses.Add(string.Format(CultureInfo.InvariantCulture, "Guid in (select itemId from AncestorIds where AncestorId in ({0}))", inClause));
if (statement != null)
{
statement.TryBind("@AncestorWithPresentationUniqueKey", query.AncestorWithPresentationUniqueKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected string GetOutputSizeParam()

if (filters.Count > 0)
{
output += string.Format(" -vf \"{0}\"", string.Join(",", filters.ToArray()));
output += string.Format(CultureInfo.InvariantCulture, " -vf \"{0}\"", string.Join(",", filters.ToArray()));
}

return output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private static ProgramInfo GetProgramInfo(XmlTvProgram program, ListingsProvider
&& !programInfo.IsRepeat
&& (programInfo.EpisodeNumber ?? 0) == 0)
{
programInfo.ShowId = programInfo.ShowId + programInfo.StartDate.Ticks.ToString(CultureInfo.InvariantCulture);
programInfo.ShowId += programInfo.StartDate.Ticks.ToString(CultureInfo.InvariantCulture);
}
}
else
Expand All @@ -246,7 +246,7 @@ private static ProgramInfo GetProgramInfo(XmlTvProgram program, ListingsProvider
}

// Construct an id from the channel and start date
programInfo.Id = string.Format("{0}_{1:O}", program.ChannelId, program.StartDate);
programInfo.Id = string.Format(CultureInfo.InvariantCulture, "{0}_{1:O}", program.ChannelId, program.StartDate);

if (programInfo.IsMovie)
{
Expand Down Expand Up @@ -296,7 +296,6 @@ public async Task<List<ChannelInfo>> GetChannels(ListingsProviderInfo info, Canc
Name = c.DisplayName,
ImageUrl = c.Icon != null && !string.IsNullOrEmpty(c.Icon.Source) ? c.Icon.Source : null,
Number = string.IsNullOrWhiteSpace(c.Number) ? c.Id : c.Number

}).ToList();
}
}
Expand Down
Loading

0 comments on commit 2b400c9

Please sign in to comment.