Fix multiple mistakes and warnings

pull/1775/head
Bond_009 5 years ago
parent b8fd6a7ec3
commit c9820d30ed

@ -212,7 +212,6 @@ namespace BDInfo
public void Scan()
{
var errorStreamClipFiles = new List<TSStreamClipFile>();
foreach (var streamClipFile in StreamClipFiles.Values)
{
try
@ -221,7 +220,6 @@ namespace BDInfo
}
catch (Exception ex)
{
errorStreamClipFiles.Add(streamClipFile);
if (StreamClipFileScanError != null)
{
if (StreamClipFileScanError(streamClipFile, ex))
@ -250,7 +248,6 @@ namespace BDInfo
StreamFiles.Values.CopyTo(streamFiles, 0);
Array.Sort(streamFiles, CompareStreamFiles);
var errorPlaylistFiles = new List<TSPlaylistFile>();
foreach (var playlistFile in PlaylistFiles.Values)
{
try
@ -259,7 +256,6 @@ namespace BDInfo
}
catch (Exception ex)
{
errorPlaylistFiles.Add(playlistFile);
if (PlaylistFileScanError != null)
{
if (PlaylistFileScanError(playlistFile, ex))
@ -275,7 +271,6 @@ namespace BDInfo
}
}
var errorStreamFiles = new List<TSStreamFile>();
foreach (var streamFile in streamFiles)
{
try
@ -296,7 +291,6 @@ namespace BDInfo
}
catch (Exception ex)
{
errorStreamFiles.Add(streamFile);
if (StreamFileScanError != null)
{
if (StreamFileScanError(streamFile, ex))
@ -431,7 +425,7 @@ namespace BDInfo
{
return 1;
}
else if ((x != null || x.FileInfo != null) && (y == null || y.FileInfo == null))
else if ((x != null && x.FileInfo != null) && (y == null || y.FileInfo == null))
{
return -1;
}
@ -451,6 +445,5 @@ namespace BDInfo
}
}
}
}
}

@ -218,14 +218,12 @@ namespace Emby.Server.Implementations.Dto
AttachUserSpecificInfo(dto, item, user, options);
}
if (item is IHasMediaSources hasMediaSources)
if (item is IHasMediaSources
&& options.ContainsField(ItemFields.MediaSources))
{
if (options.ContainsField(ItemFields.MediaSources))
{
dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(item, true, user).ToArray();
dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(item, true, user).ToArray();
NormalizeMediaSourceContainers(dto);
}
NormalizeMediaSourceContainers(dto);
}
if (options.ContainsField(ItemFields.Studios))

@ -51,7 +51,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
var user = auth.User;
if (user == null & !auth.UserId.Equals(Guid.Empty))
if (user == null && auth.UserId != Guid.Empty)
{
throw new SecurityException("User with Id " + auth.UserId + " not found");
}

@ -57,7 +57,6 @@ namespace Emby.Server.Implementations.Library
}
var filename = fileInfo.Name;
var path = fileInfo.FullName;
// Ignore hidden files on UNIX
if (Environment.OSVersion.Platform != PlatformID.Win32NT

@ -273,14 +273,12 @@ namespace Emby.Server.Implementations.Library
var user = Users.FirstOrDefault(i => string.Equals(username, i.Name, StringComparison.OrdinalIgnoreCase));
var success = false;
string updatedUsername = null;
IAuthenticationProvider authenticationProvider = null;
if (user != null)
{
var authResult = await AuthenticateLocalUser(username, password, hashedPassword, user, remoteEndPoint).ConfigureAwait(false);
authenticationProvider = authResult.authenticationProvider;
updatedUsername = authResult.username;
success = authResult.success;
}
else
@ -288,7 +286,7 @@ namespace Emby.Server.Implementations.Library
// user is null
var authResult = await AuthenticateLocalUser(username, password, hashedPassword, null, remoteEndPoint).ConfigureAwait(false);
authenticationProvider = authResult.authenticationProvider;
updatedUsername = authResult.username;
string updatedUsername = authResult.username;
success = authResult.success;
if (success

@ -236,7 +236,7 @@ namespace Emby.Server.Implementations.Library
if (!parentId.Equals(Guid.Empty))
{
var parentItem = _libraryManager.GetItemById(parentId);
if (parentItem is Channel parentItemChannel)
if (parentItem is Channel)
{
return _channelManager.GetLatestChannelItemsInternal(
new InternalItemsQuery(user)
@ -248,7 +248,7 @@ namespace Emby.Server.Implementations.Library
IncludeItemTypes = request.IncludeItemTypes,
EnableTotalRecordCount = false
},
CancellationToken.None).Result.Items;
CancellationToken.None).GetAwaiter().GetResult().Items;
}
if (parentItem is Folder parent)

@ -208,9 +208,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
private static string GetAudioArgs(MediaSourceInfo mediaSource)
{
var mediaStreams = mediaSource.MediaStreams ?? new List<MediaStream>();
var inputAudioCodec = mediaStreams.Where(i => i.Type == MediaStreamType.Audio).Select(i => i.Codec).FirstOrDefault() ?? string.Empty;
return "-codec:a:0 copy";
//var audioChannels = 2;

@ -17,7 +17,6 @@ using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
namespace Emby.Server.Implementations.LiveTv.Listings
{
@ -41,6 +40,12 @@ namespace Emby.Server.Implementations.LiveTv.Listings
private string UserAgent => _appHost.ApplicationUserAgent;
/// <inheritdoc />
public string Name => "Schedules Direct";
/// <inheritdoc />
public string Type => nameof(SchedulesDirect);
private static List<string> GetScheduleRequestDates(DateTime startDateUtc, DateTime endDateUtc)
{
var dates = new List<string>();
@ -103,7 +108,6 @@ namespace Emby.Server.Implementations.LiveTv.Listings
httpOptions.RequestHeaders["token"] = token;
using (var response = await Post(httpOptions, true, info).ConfigureAwait(false))
using (var reader = new StreamReader(response.Content))
{
var dailySchedules = await _jsonSerializer.DeserializeFromStreamAsync<List<ScheduleDirect.Day>>(response.Content).ConfigureAwait(false);
_logger.LogDebug("Found {ScheduleCount} programs on {ChannelID} ScheduleDirect", dailySchedules.Count, channelId);
@ -122,7 +126,6 @@ namespace Emby.Server.Implementations.LiveTv.Listings
httpOptions.RequestContent = "[\"" + string.Join("\", \"", programsID) + "\"]";
using (var innerResponse = await Post(httpOptions, true, info).ConfigureAwait(false))
using (var innerReader = new StreamReader(innerResponse.Content))
{
var programDetails = await _jsonSerializer.DeserializeFromStreamAsync<List<ScheduleDirect.ProgramDetails>>(innerResponse.Content).ConfigureAwait(false);
var programDict = programDetails.ToDictionary(p => p.programID, y => y);
@ -152,14 +155,14 @@ namespace Emby.Server.Implementations.LiveTv.Listings
var imagesWithText = allImages.Where(i => string.Equals(i.text, "yes", StringComparison.OrdinalIgnoreCase));
var imagesWithoutText = allImages.Where(i => string.Equals(i.text, "no", StringComparison.OrdinalIgnoreCase));
const double desiredAspect = 0.666666667;
const double DesiredAspect = 2.0 / 3;
programEntry.primaryImage = GetProgramImage(ApiUrl, imagesWithText, true, desiredAspect) ??
GetProgramImage(ApiUrl, allImages, true, desiredAspect);
programEntry.primaryImage = GetProgramImage(ApiUrl, imagesWithText, true, DesiredAspect) ??
GetProgramImage(ApiUrl, allImages, true, DesiredAspect);
const double wideAspect = 1.77777778;
const double WideAspect = 16.0 / 9;
programEntry.thumbImage = GetProgramImage(ApiUrl, imagesWithText, true, wideAspect);
programEntry.thumbImage = GetProgramImage(ApiUrl, imagesWithText, true, WideAspect);
// Don't supply the same image twice
if (string.Equals(programEntry.primaryImage, programEntry.thumbImage, StringComparison.Ordinal))
@ -167,7 +170,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
programEntry.thumbImage = null;
}
programEntry.backdropImage = GetProgramImage(ApiUrl, imagesWithoutText, true, wideAspect);
programEntry.backdropImage = GetProgramImage(ApiUrl, imagesWithoutText, true, WideAspect);
//programEntry.bannerImage = GetProgramImage(ApiUrl, data, "Banner", false) ??
// GetProgramImage(ApiUrl, data, "Banner-L1", false) ??
@ -178,6 +181,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
programsInfo.Add(GetProgram(channelId, schedule, programDict[schedule.programID]));
}
return programsInfo;
}
}
@ -185,12 +189,10 @@ namespace Emby.Server.Implementations.LiveTv.Listings
private static int GetSizeOrder(ScheduleDirect.ImageData image)
{
if (!string.IsNullOrWhiteSpace(image.height))
if (!string.IsNullOrWhiteSpace(image.height)
&& int.TryParse(image.height, out int value))
{
if (int.TryParse(image.height, out int value))
{
return value;
}
return value;
}
return 0;
@ -736,16 +738,11 @@ namespace Emby.Server.Implementations.LiveTv.Listings
httpOptions.RequestHeaders["token"] = token;
using (var response = await _httpClient.SendAsync(httpOptions, "PUT"))
using (await _httpClient.SendAsync(httpOptions, "PUT"))
{
}
}
public string Name => "Schedules Direct";
public static string TypeName = "SchedulesDirect";
public string Type => TypeName;
private async Task<bool> HasLineup(ListingsProviderInfo info, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(info.ListingsId))

@ -60,16 +60,6 @@ namespace Emby.Server.Implementations.LiveTv
private IListingsProvider[] _listingProviders = Array.Empty<IListingsProvider>();
private readonly IFileSystem _fileSystem;
public event EventHandler<GenericEventArgs<TimerEventInfo>> SeriesTimerCancelled;
public event EventHandler<GenericEventArgs<TimerEventInfo>> TimerCancelled;
public event EventHandler<GenericEventArgs<TimerEventInfo>> TimerCreated;
public event EventHandler<GenericEventArgs<TimerEventInfo>> SeriesTimerCreated;
public string GetEmbyTvActiveRecordingPath(string id)
{
return EmbyTV.EmbyTV.Current.GetActiveRecordingPath(id);
}
public LiveTvManager(
IServerApplicationHost appHost,
IServerConfigurationManager config,
@ -102,17 +92,34 @@ namespace Emby.Server.Implementations.LiveTv
_tvDtoService = new LiveTvDtoService(dtoService, imageProcessor, loggerFactory, appHost, _libraryManager);
}
public event EventHandler<GenericEventArgs<TimerEventInfo>> SeriesTimerCancelled;
public event EventHandler<GenericEventArgs<TimerEventInfo>> TimerCancelled;
public event EventHandler<GenericEventArgs<TimerEventInfo>> TimerCreated;
public event EventHandler<GenericEventArgs<TimerEventInfo>> SeriesTimerCreated;
/// <summary>
/// Gets the services.
/// </summary>
/// <value>The services.</value>
public IReadOnlyList<ILiveTvService> Services => _services;
public ITunerHost[] TunerHosts => _tunerHosts;
public IListingsProvider[] ListingProviders => _listingProviders;
private LiveTvOptions GetConfiguration()
{
return _config.GetConfiguration<LiveTvOptions>("livetv");
}
public string GetEmbyTvActiveRecordingPath(string id)
{
return EmbyTV.EmbyTV.Current.GetActiveRecordingPath(id);
}
/// <summary>
/// Adds the parts.
/// </summary>
@ -130,13 +137,13 @@ namespace Emby.Server.Implementations.LiveTv
{
if (service is EmbyTV.EmbyTV embyTv)
{
embyTv.TimerCreated += EmbyTv_TimerCreated;
embyTv.TimerCancelled += EmbyTv_TimerCancelled;
embyTv.TimerCreated += OnEmbyTvTimerCreated;
embyTv.TimerCancelled += OnEmbyTvTimerCancelled;
}
}
}
private void EmbyTv_TimerCancelled(object sender, GenericEventArgs<string> e)
private void OnEmbyTvTimerCancelled(object sender, GenericEventArgs<string> e)
{
var timerId = e.Argument;
@ -149,10 +156,9 @@ namespace Emby.Server.Implementations.LiveTv
});
}
private void EmbyTv_TimerCreated(object sender, GenericEventArgs<TimerInfo> e)
private void OnEmbyTvTimerCreated(object sender, GenericEventArgs<TimerInfo> e)
{
var timer = e.Argument;
var service = sender as ILiveTvService;
TimerCreated?.Invoke(this, new GenericEventArgs<TimerEventInfo>
{
@ -164,10 +170,6 @@ namespace Emby.Server.Implementations.LiveTv
});
}
public ITunerHost[] TunerHosts => _tunerHosts;
public IListingsProvider[] ListingProviders => _listingProviders;
public List<NameIdPair> GetTunerHostTypes()
{
return _tunerHosts.OrderBy(i => i.Name).Select(i => new NameIdPair
@ -966,9 +968,6 @@ namespace Emby.Server.Implementations.LiveTv
private async Task AddRecordingInfo(IEnumerable<Tuple<BaseItemDto, string, string>> programs, CancellationToken cancellationToken)
{
var timers = new Dictionary<string, List<TimerInfo>>();
var seriesTimers = new Dictionary<string, List<SeriesTimerInfo>>();
IReadOnlyList<TimerInfo> timerList = null;
IReadOnlyList<SeriesTimerInfo> seriesTimerList = null;
@ -1601,8 +1600,6 @@ namespace Emby.Server.Implementations.LiveTv
if (!string.IsNullOrEmpty(query.Id))
{
var guid = new Guid(query.Id);
timers = timers
.Where(i => string.Equals(_tvDtoService.GetInternalTimerId(i.Item1.Id), query.Id, StringComparison.OrdinalIgnoreCase));
}

@ -424,14 +424,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
return false;
}
var nameTag = buf[offset++];
offset++; // Name Tag
var nameLength = buf[offset++];
// skip the name field to get to value for return
offset += nameLength;
var valueTag = buf[offset++];
offset++; // Value Tag
var valueLength = buf[offset++];

@ -15,7 +15,7 @@ namespace Emby.Server.Implementations.Services
{
PropertySetFn = propertySetFn;
PropertyParseStringFn = propertyParseStringFn;
PropertyType = PropertyType;
PropertyType = propertyType;
}
public Action<object, object> PropertySetFn { get; private set; }

@ -22,7 +22,7 @@
<EmbeddedResource Include="Resources/Configuration/*" />
</ItemGroup>
<!-- Code analysers-->
<!-- Code analyzers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />

@ -455,9 +455,7 @@ namespace MediaBrowser.Api.UserLibrary
IncludeItemTypes = new[] { typeof(MusicAlbum).Name },
Name = i,
Limit = 1
}).Select(albumId => albumId);
});
}).ToArray();
}

@ -14,20 +14,20 @@ namespace MediaBrowser.Common.Extensions
/// Strips the HTML.
/// </summary>
/// <param name="htmlString">The HTML string.</param>
/// <returns>System.String.</returns>
/// <returns><see cref="string" />.</returns>
public static string StripHtml(this string htmlString)
{
// http://stackoverflow.com/questions/1349023/how-can-i-strip-html-from-text-in-net
const string pattern = @"<(.|\n)*?>";
const string Pattern = @"<(.|\n)*?>";
return Regex.Replace(htmlString, pattern, string.Empty).Trim();
return Regex.Replace(htmlString, Pattern, string.Empty).Trim();
}
/// <summary>
/// Gets the M d5.
/// Gets the Md5.
/// </summary>
/// <param name="str">The STR.</param>
/// <returns>Guid.</returns>
/// <param name="str">The string.</param>
/// <returns><see cref="Guid" />.</returns>
public static Guid GetMD5(this string str)
{
using (var provider = MD5.Create())

@ -5,13 +5,28 @@ namespace MediaBrowser.Common.Extensions
// The MS CollectionExtensions are only available in netcoreapp
public static class CollectionExtensions
{
public static TValue GetValueOrDefault<TKey, TValue> (this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
public static TValue GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
{
dictionary.TryGetValue(key, out var ret);
return ret;
}
// REVIEW: Inline?
/// <summary>
/// Copies all the elements of the current collection to the specified list
/// starting at the specified destination array index. The index is specified as a 32-bit integer.
/// </summary>
/// <param name="source">The current collection that is the source of the elements.</param>
/// <param name="destination">The list that is the destination of the elements copied from the current collection.</param>
/// <param name="index">A 32-bit integer that represents the index in <c>destination</c> at which copying begins.</param>
/// <typeparam name="T"></typeparam>
public static void CopyTo<T>(this IReadOnlyList<T> source, IList<T> destination, int index = 0)
{
for (int i = 0; i < source.Count; i++)
{
destination[index + i] = source[i];
}
}
/// <summary>
/// Copies all the elements of the current collection to the specified list
/// starting at the specified destination array index. The index is specified as a 32-bit integer.

@ -2045,7 +2045,7 @@ namespace MediaBrowser.Controller.Entities
if (itemByPath == null)
{
//Logger.LogWarning("Unable to find linked item at path {0}", info.Path);
Logger.LogWarning("Unable to find linked item at path {0}", info.Path);
}
return itemByPath;
@ -2057,7 +2057,7 @@ namespace MediaBrowser.Controller.Entities
if (item == null)
{
//Logger.LogWarning("Unable to find linked item at path {0}", info.Path);
Logger.LogWarning("Unable to find linked item at path {0}", info.Path);
}
return item;
@ -2085,14 +2085,17 @@ namespace MediaBrowser.Controller.Entities
if (!current.Contains(name, StringComparer.OrdinalIgnoreCase))
{
if (current.Length == 0)
int curLen = current.Length;
if (curLen == 0)
{
Studios = new[] { name };
}
else
{
var list =
Studios = current.Concat(new[] { name }).ToArray();
var newArr = new string[curLen + 1];
current.CopyTo(newArr, 0);
newArr[curLen] = name;
Studios = newArr;
}
}
}
@ -2231,8 +2234,12 @@ namespace MediaBrowser.Controller.Entities
else
{
var currentCount = ImageInfos.Length;
ImageInfos = ImageInfos.Concat(new[] { image }).ToArray();
var current = ImageInfos;
var currentCount = current.Length;
var newArr = new ItemImageInfo[currentCount + 1];
current.CopyTo(newArr, 0);
current[currentCount] = image;
ImageInfos = current;
}
}

@ -1252,9 +1252,6 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (request.AudioBitRate.HasValue)
{
// Make sure we don't request a bitrate higher than the source
var currentBitrate = audioStream == null ? request.AudioBitRate.Value : audioStream.BitRate ?? request.AudioBitRate.Value;
// Don't encode any higher than this
return Math.Min(384000, request.AudioBitRate.Value);
}

@ -158,8 +158,6 @@ namespace MediaBrowser.LocalMetadata.Savers
/// <returns>Task.</returns>
public static void AddCommonNodes(BaseItem item, XmlWriter writer, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataRepo, IFileSystem fileSystem, IServerConfigurationManager config)
{
var writtenProviderIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
if (!string.IsNullOrEmpty(item.OfficialRating))
{
writer.WriteElementString("ContentRating", item.OfficialRating);

@ -506,12 +506,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles
if (failed)
{
var msg = string.Format("ffmpeg subtitle conversion failed for {Path}", inputPath);
_logger.LogError("ffmpeg subtitle conversion failed for {Path}", inputPath);
_logger.LogError(msg);
throw new Exception(msg);
throw new Exception(
string.Format(CultureInfo.InvariantCulture, "ffmpeg subtitle conversion failed for {0}", inputPath));
}
await SetAssFont(outputPath).ConfigureAwait(false);
_logger.LogInformation("ffmpeg subtitle conversion succeeded for {Path}", inputPath);

@ -31,7 +31,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
/// <inheritdoc />
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
=> !item.SupportsLocalMetadata && item is Episode && updateType >= MinimumUpdateType;
=> item.SupportsLocalMetadata && item is Episode && updateType >= MinimumUpdateType;
/// <inheritdoc />
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)

@ -86,7 +86,6 @@ namespace Rssdp.Infrastructure
ThrowIfDisposed();
var minCacheTime = TimeSpan.Zero;
bool wasAdded = false;
lock (_Devices)
{
@ -94,7 +93,6 @@ namespace Rssdp.Infrastructure
{
_Devices.Add(device);
wasAdded = true;
minCacheTime = GetMinimumNonZeroCacheLifetime();
}
}
@ -120,14 +118,12 @@ namespace Rssdp.Infrastructure
if (device == null) throw new ArgumentNullException(nameof(device));
bool wasRemoved = false;
var minCacheTime = TimeSpan.Zero;
lock (_Devices)
{
if (_Devices.Contains(device))
{
_Devices.Remove(device);
wasRemoved = true;
minCacheTime = GetMinimumNonZeroCacheLifetime();
}
}

Loading…
Cancel
Save