Simplify/remove/clean code
* Remove useless runtime check (we only support one) * Remove unused args * Remove a global constant And ofc fix some warnings ;)
This commit is contained in:
parent
5024c52c60
commit
b44a70ff36
|
@ -200,7 +200,7 @@ namespace Emby.Server.Implementations
|
|||
/// <summary>
|
||||
/// The disposable parts
|
||||
/// </summary>
|
||||
protected readonly List<IDisposable> _disposableParts = new List<IDisposable>();
|
||||
private readonly List<IDisposable> _disposableParts = new List<IDisposable>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the configuration manager.
|
||||
|
@ -216,8 +216,9 @@ namespace Emby.Server.Implementations
|
|||
{
|
||||
#if BETA
|
||||
return PackageVersionClass.Beta;
|
||||
#endif
|
||||
#else
|
||||
return PackageVersionClass.Release;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -340,7 +341,6 @@ namespace Emby.Server.Implementations
|
|||
|
||||
protected IProcessFactory ProcessFactory { get; private set; }
|
||||
|
||||
protected ICryptoProvider CryptographyProvider = new CryptographyProvider();
|
||||
protected readonly IXmlSerializer XmlSerializer;
|
||||
|
||||
protected ISocketFactory SocketFactory { get; private set; }
|
||||
|
@ -369,9 +369,6 @@ namespace Emby.Server.Implementations
|
|||
{
|
||||
_configuration = configuration;
|
||||
|
||||
// hack alert, until common can target .net core
|
||||
BaseExtensions.CryptographyProvider = CryptographyProvider;
|
||||
|
||||
XmlSerializer = new MyXmlSerializer(fileSystem, loggerFactory);
|
||||
|
||||
NetworkManager = networkManager;
|
||||
|
@ -735,13 +732,12 @@ namespace Emby.Server.Implementations
|
|||
ApplicationHost.StreamHelper = new StreamHelper();
|
||||
serviceCollection.AddSingleton(StreamHelper);
|
||||
|
||||
serviceCollection.AddSingleton(CryptographyProvider);
|
||||
serviceCollection.AddSingleton(typeof(ICryptoProvider), typeof(CryptographyProvider));
|
||||
|
||||
SocketFactory = new SocketFactory();
|
||||
serviceCollection.AddSingleton(SocketFactory);
|
||||
|
||||
InstallationManager = new InstallationManager(LoggerFactory, this, ApplicationPaths, HttpClient, JsonSerializer, ServerConfigurationManager, FileSystemManager, CryptographyProvider, ZipClient, PackageRuntime);
|
||||
serviceCollection.AddSingleton(InstallationManager);
|
||||
serviceCollection.AddSingleton(typeof(IInstallationManager), typeof(InstallationManager));
|
||||
|
||||
ZipClient = new ZipClient();
|
||||
serviceCollection.AddSingleton(ZipClient);
|
||||
|
@ -908,8 +904,6 @@ namespace Emby.Server.Implementations
|
|||
_serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
}
|
||||
|
||||
public virtual string PackageRuntime => "netcore";
|
||||
|
||||
public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths)
|
||||
{
|
||||
// Distinct these to prevent users from reporting problems that aren't actually problems
|
||||
|
@ -1049,6 +1043,8 @@ namespace Emby.Server.Implementations
|
|||
/// </summary>
|
||||
protected void FindParts()
|
||||
{
|
||||
InstallationManager = _serviceProvider.GetService<IInstallationManager>();
|
||||
|
||||
if (!ServerConfigurationManager.Configuration.IsPortAuthorized)
|
||||
{
|
||||
ServerConfigurationManager.Configuration.IsPortAuthorized = true;
|
||||
|
|
|
@ -4,7 +4,6 @@ using System.Globalization;
|
|||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Model.Cryptography;
|
||||
|
||||
namespace Emby.Server.Implementations.Cryptography
|
||||
|
|
|
@ -90,9 +90,10 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
throw new ArgumentNullException(nameof(displayPreferences));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(displayPreferences.Id))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(displayPreferences.Id));
|
||||
throw new ArgumentException("Display preferences has an invalid Id", nameof(displayPreferences));
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
|
|
@ -388,7 +388,7 @@ namespace Emby.Server.Implementations.EntryPoints
|
|||
|
||||
FoldersRemovedFrom = foldersRemovedFrom.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToArray(),
|
||||
|
||||
CollectionFolders = GetTopParentIds(newAndRemoved, user, allUserRootChildren).ToArray()
|
||||
CollectionFolders = GetTopParentIds(newAndRemoved, allUserRootChildren).ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -407,7 +407,7 @@ namespace Emby.Server.Implementations.EntryPoints
|
|||
return item.SourceType == SourceType.Library;
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetTopParentIds(List<BaseItem> items, User user, List<Folder> allUserRootChildren)
|
||||
private IEnumerable<string> GetTopParentIds(List<BaseItem> items, List<Folder> allUserRootChildren)
|
||||
{
|
||||
var list = new List<string>();
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
|||
// This code is executed before the service
|
||||
var auth = AuthorizationContext.GetAuthorizationInfo(request);
|
||||
|
||||
if (!IsExemptFromAuthenticationToken(auth, authAttribtues, request))
|
||||
if (!IsExemptFromAuthenticationToken(authAttribtues, request))
|
||||
{
|
||||
ValidateSecurityToken(request, auth.Token);
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
|||
}
|
||||
}
|
||||
|
||||
private bool IsExemptFromAuthenticationToken(AuthorizationInfo auth, IAuthenticationAttributes authAttribtues, IRequest request)
|
||||
private bool IsExemptFromAuthenticationToken(IAuthenticationAttributes authAttribtues, IRequest request)
|
||||
{
|
||||
if (!_config.Configuration.IsStartupWizardCompleted && authAttribtues.AllowBeforeStartupWizard)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -14,8 +13,6 @@ namespace Emby.Server.Implementations.HttpServer
|
|||
/// </summary>
|
||||
public class StreamWriter : IAsyncStreamWriter, IHasHeaders
|
||||
{
|
||||
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the source stream.
|
||||
/// </summary>
|
||||
|
|
|
@ -261,7 +261,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
|||
|
||||
public string HomePageUrl => "https://github.com/jellyfin/jellyfin";
|
||||
|
||||
public async Task RefreshSeriesTimers(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
public async Task RefreshSeriesTimers(CancellationToken cancellationToken)
|
||||
{
|
||||
var seriesTimers = await GetSeriesTimersAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
|
@ -271,7 +271,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
|||
}
|
||||
}
|
||||
|
||||
public async Task RefreshTimers(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
public async Task RefreshTimers(CancellationToken cancellationToken)
|
||||
{
|
||||
var timers = await GetTimersAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
|
|
|
@ -1087,8 +1087,8 @@ namespace Emby.Server.Implementations.LiveTv
|
|||
|
||||
if (coreService != null)
|
||||
{
|
||||
await coreService.RefreshSeriesTimers(cancellationToken, new SimpleProgress<double>()).ConfigureAwait(false);
|
||||
await coreService.RefreshTimers(cancellationToken, new SimpleProgress<double>()).ConfigureAwait(false);
|
||||
await coreService.RefreshSeriesTimers(cancellationToken).ConfigureAwait(false);
|
||||
await coreService.RefreshTimers(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// Load these now which will prefetch metadata
|
||||
|
|
|
@ -10,14 +10,12 @@ using MediaBrowser.Controller;
|
|||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.LiveTv;
|
||||
using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.LiveTv;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Model.System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
|
@ -52,9 +50,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
{
|
||||
var channelIdPrefix = GetFullChannelIdPrefix(info);
|
||||
|
||||
var result = await new M3uParser(Logger, _httpClient, _appHost).Parse(info.Url, channelIdPrefix, info.Id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return result.Cast<ChannelInfo>().ToList();
|
||||
return await new M3uParser(Logger, _httpClient, _appHost).Parse(info.Url, channelIdPrefix, info.Id, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken)
|
||||
|
@ -73,7 +69,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
return Task.FromResult(list);
|
||||
}
|
||||
|
||||
private string[] _disallowedSharedStreamExtensions = new string[]
|
||||
private static readonly string[] _disallowedSharedStreamExtensions = new string[]
|
||||
{
|
||||
".mkv",
|
||||
".mp4",
|
||||
|
@ -88,9 +84,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
if (tunerCount > 0)
|
||||
{
|
||||
var tunerHostId = info.Id;
|
||||
var liveStreams = currentLiveStreams.Where(i => string.Equals(i.TunerHostId, tunerHostId, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
var liveStreams = currentLiveStreams.Where(i => string.Equals(i.TunerHostId, tunerHostId, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (liveStreams.Count >= tunerCount)
|
||||
if (liveStreams.Count() >= tunerCount)
|
||||
{
|
||||
throw new LiveTvConflictException("M3U simultaneous stream limit has been reached.");
|
||||
}
|
||||
|
@ -98,7 +94,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
|
||||
var sources = await GetChannelStreamMediaSources(info, channelInfo, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var mediaSource = sources.First();
|
||||
var mediaSource = sources[0];
|
||||
|
||||
if (mediaSource.Protocol == MediaProtocol.Http && !mediaSource.RequiresLooping)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,6 @@ using MediaBrowser.Common.Net;
|
|||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.LiveTv;
|
||||
using MediaBrowser.Model.Extensions;
|
||||
using MediaBrowser.Model.IO;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
||||
|
@ -62,12 +61,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
return Task.FromResult((Stream)File.OpenRead(url));
|
||||
}
|
||||
|
||||
const string ExtInfPrefix = "#EXTINF:";
|
||||
private const string ExtInfPrefix = "#EXTINF:";
|
||||
|
||||
private List<ChannelInfo> GetChannels(TextReader reader, string channelIdPrefix, string tunerHostId)
|
||||
{
|
||||
var channels = new List<ChannelInfo>();
|
||||
string line;
|
||||
string extInf = "";
|
||||
string extInf = string.Empty;
|
||||
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
|
||||
channel.Path = line;
|
||||
channels.Add(channel);
|
||||
extInf = "";
|
||||
extInf = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,8 +110,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
|
||||
private ChannelInfo GetChannelnfo(string extInf, string tunerHostId, string mediaUrl)
|
||||
{
|
||||
var channel = new ChannelInfo();
|
||||
channel.TunerHostId = tunerHostId;
|
||||
var channel = new ChannelInfo()
|
||||
{
|
||||
TunerHostId = tunerHostId
|
||||
};
|
||||
|
||||
extInf = extInf.Trim();
|
||||
|
||||
|
@ -137,13 +139,15 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
{
|
||||
channelIdValues.Add(channelId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(tvgId))
|
||||
{
|
||||
channelIdValues.Add(tvgId);
|
||||
}
|
||||
|
||||
if (channelIdValues.Count > 0)
|
||||
{
|
||||
channel.Id = string.Join("_", channelIdValues.ToArray());
|
||||
channel.Id = string.Join("_", channelIdValues);
|
||||
}
|
||||
|
||||
return channel;
|
||||
|
@ -152,7 +156,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
private string GetChannelNumber(string extInf, Dictionary<string, string> attributes, string mediaUrl)
|
||||
{
|
||||
var nameParts = extInf.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var nameInExtInf = nameParts.Length > 1 ? nameParts.Last().Trim() : null;
|
||||
var nameInExtInf = nameParts.Length > 1 ? nameParts[nameParts.Length - 1].Trim() : null;
|
||||
|
||||
string numberString = null;
|
||||
string attributeValue;
|
||||
|
|
|
@ -12,7 +12,6 @@ using MediaBrowser.Common.Plugins;
|
|||
using MediaBrowser.Common.Progress;
|
||||
using MediaBrowser.Common.Updates;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Model.Cryptography;
|
||||
using MediaBrowser.Model.Events;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
@ -39,11 +38,10 @@ namespace Emby.Server.Implementations.Updates
|
|||
/// <summary>
|
||||
/// The completed installations
|
||||
/// </summary>
|
||||
private ConcurrentBag<InstallationInfo> CompletedInstallationsInternal { get; set; }
|
||||
private ConcurrentBag<InstallationInfo> _completedInstallationsInternal;
|
||||
|
||||
public IEnumerable<InstallationInfo> CompletedInstallations => CompletedInstallationsInternal;
|
||||
public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal;
|
||||
|
||||
#region PluginUninstalled Event
|
||||
/// <summary>
|
||||
/// Occurs when [plugin uninstalled].
|
||||
/// </summary>
|
||||
|
@ -57,9 +55,7 @@ namespace Emby.Server.Implementations.Updates
|
|||
{
|
||||
PluginUninstalled?.Invoke(this, new GenericEventArgs<IPlugin> { Argument = plugin });
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PluginUpdated Event
|
||||
/// <summary>
|
||||
/// Occurs when [plugin updated].
|
||||
/// </summary>
|
||||
|
@ -77,9 +73,7 @@ namespace Emby.Server.Implementations.Updates
|
|||
|
||||
_applicationHost.NotifyPendingRestart();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PluginInstalled Event
|
||||
/// <summary>
|
||||
/// Occurs when [plugin updated].
|
||||
/// </summary>
|
||||
|
@ -96,7 +90,6 @@ namespace Emby.Server.Implementations.Updates
|
|||
|
||||
_applicationHost.NotifyPendingRestart();
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The _logger
|
||||
|
@ -115,12 +108,8 @@ namespace Emby.Server.Implementations.Updates
|
|||
/// <value>The application host.</value>
|
||||
private readonly IApplicationHost _applicationHost;
|
||||
|
||||
private readonly ICryptoProvider _cryptographyProvider;
|
||||
private readonly IZipClient _zipClient;
|
||||
|
||||
// netframework or netcore
|
||||
private readonly string _packageRuntime;
|
||||
|
||||
public InstallationManager(
|
||||
ILoggerFactory loggerFactory,
|
||||
IApplicationHost appHost,
|
||||
|
@ -129,9 +118,7 @@ namespace Emby.Server.Implementations.Updates
|
|||
IJsonSerializer jsonSerializer,
|
||||
IServerConfigurationManager config,
|
||||
IFileSystem fileSystem,
|
||||
ICryptoProvider cryptographyProvider,
|
||||
IZipClient zipClient,
|
||||
string packageRuntime)
|
||||
IZipClient zipClient)
|
||||
{
|
||||
if (loggerFactory == null)
|
||||
{
|
||||
|
@ -139,18 +126,16 @@ namespace Emby.Server.Implementations.Updates
|
|||
}
|
||||
|
||||
CurrentInstallations = new List<Tuple<InstallationInfo, CancellationTokenSource>>();
|
||||
CompletedInstallationsInternal = new ConcurrentBag<InstallationInfo>();
|
||||
_completedInstallationsInternal = new ConcurrentBag<InstallationInfo>();
|
||||
|
||||
_logger = loggerFactory.CreateLogger(nameof(InstallationManager));
|
||||
_applicationHost = appHost;
|
||||
_appPaths = appPaths;
|
||||
_httpClient = httpClient;
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_config = config;
|
||||
_fileSystem = fileSystem;
|
||||
_cryptographyProvider = cryptographyProvider;
|
||||
_zipClient = zipClient;
|
||||
_packageRuntime = packageRuntime;
|
||||
_logger = loggerFactory.CreateLogger(nameof(InstallationManager));
|
||||
}
|
||||
|
||||
private static Version GetPackageVersion(PackageVersionInfo version)
|
||||
|
@ -222,11 +207,6 @@ namespace Emby.Server.Implementations.Updates
|
|||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(version.runtimes) || version.runtimes.IndexOf(_packageRuntime, StringComparison.OrdinalIgnoreCase) == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
versions.Add(version);
|
||||
}
|
||||
|
||||
|
@ -448,7 +428,7 @@ namespace Emby.Server.Implementations.Updates
|
|||
CurrentInstallations.Remove(tuple);
|
||||
}
|
||||
|
||||
CompletedInstallationsInternal.Add(installationInfo);
|
||||
_completedInstallationsInternal.Add(installationInfo);
|
||||
|
||||
PackageInstallationCompleted?.Invoke(this, installationEventArgs);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ using MediaBrowser.Common.Configuration;
|
|||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.IO;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using MediaBrowser.Model.Cryptography;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace MediaBrowser.Common.Extensions
|
||||
{
|
||||
|
@ -9,8 +10,6 @@ namespace MediaBrowser.Common.Extensions
|
|||
/// </summary>
|
||||
public static class BaseExtensions
|
||||
{
|
||||
public static ICryptoProvider CryptographyProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Strips the HTML.
|
||||
/// </summary>
|
||||
|
@ -31,7 +30,10 @@ namespace MediaBrowser.Common.Extensions
|
|||
/// <returns>Guid.</returns>
|
||||
public static Guid GetMD5(this string str)
|
||||
{
|
||||
return CryptographyProvider.GetMD5(str);
|
||||
using (var provider = MD5.Create())
|
||||
{
|
||||
return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
<Rule Id="SA1633" Action="None" />
|
||||
</Rules>
|
||||
<Rules AnalyzerId="Microsoft.CodeAnalysis.FxCopAnalyzers" RuleNamespace="Microsoft.Design">
|
||||
<!-- disable warning CA1822: Member does not access instance data and can be marked as static -->
|
||||
<Rule Id="CA1822" Action="Info" />
|
||||
|
||||
<!-- disable warning CA1054: Change the type of parameter url from string to System.Uri -->
|
||||
<Rule Id="CA1054" Action="None" />
|
||||
</Rules>
|
||||
|
|
Loading…
Reference in New Issue
Block a user