diff options
Diffstat (limited to 'MediaBrowser.WebDashboard/Api')
| -rw-r--r-- | MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs | 51 | ||||
| -rw-r--r-- | MediaBrowser.WebDashboard/Api/DashboardService.cs | 81 | ||||
| -rw-r--r-- | MediaBrowser.WebDashboard/Api/PackageCreator.cs | 23 |
3 files changed, 84 insertions, 71 deletions
diff --git a/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs b/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs index b8f9e09b5..e49a4be8a 100644 --- a/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs +++ b/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS1591 + using MediaBrowser.Common.Plugins; using MediaBrowser.Controller.Plugins; using MediaBrowser.Model.Plugins; @@ -6,29 +8,6 @@ namespace MediaBrowser.WebDashboard.Api { public class ConfigurationPageInfo { - /// <summary> - /// Gets the name. - /// </summary> - /// <value>The name.</value> - public string Name { get; set; } - public bool EnableInMainMenu { get; set; } - public string MenuSection { get; set; } - public string MenuIcon { get; set; } - - public string DisplayName { get; set; } - - /// <summary> - /// Gets the type of the configuration page. - /// </summary> - /// <value>The type of the configuration page.</value> - public ConfigurationPageType ConfigurationPageType { get; set; } - - /// <summary> - /// Gets or sets the plugin id. - /// </summary> - /// <value>The plugin id.</value> - public string PluginId { get; set; } - public ConfigurationPageInfo(IPluginConfigurationPage page) { Name = page.Name; @@ -54,5 +33,31 @@ namespace MediaBrowser.WebDashboard.Api // Don't use "N" because it needs to match Plugin.Id PluginId = plugin.Id.ToString(); } + + /// <summary> + /// Gets or sets the name. + /// </summary> + /// <value>The name.</value> + public string Name { get; set; } + + public bool EnableInMainMenu { get; set; } + + public string MenuSection { get; set; } + + public string MenuIcon { get; set; } + + public string DisplayName { get; set; } + + /// <summary> + /// Gets or sets the type of the configuration page. + /// </summary> + /// <value>The type of the configuration page.</value> + public ConfigurationPageType ConfigurationPageType { get; set; } + + /// <summary> + /// Gets or sets the plugin id. + /// </summary> + /// <value>The plugin id.</value> + public string PluginId { get; set; } } } diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 9e0aae782..99d8d044f 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -1,5 +1,10 @@ +#pragma warning disable CS1591 +#pragma warning disable SA1402 +#pragma warning disable SA1649 + using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -18,7 +23,7 @@ using Microsoft.Extensions.Logging; namespace MediaBrowser.WebDashboard.Api { /// <summary> - /// Class GetDashboardConfigurationPages + /// Class GetDashboardConfigurationPages. /// </summary> [Route("/web/ConfigurationPages", "GET")] public class GetDashboardConfigurationPages : IReturn<List<ConfigurationPageInfo>> @@ -28,11 +33,12 @@ namespace MediaBrowser.WebDashboard.Api /// </summary> /// <value>The type of the page.</value> public ConfigurationPageType? PageType { get; set; } + public bool? EnableInMainMenu { get; set; } } /// <summary> - /// Class GetDashboardConfigurationPage + /// Class GetDashboardConfigurationPage. /// </summary> [Route("/web/ConfigurationPage", "GET")] public class GetDashboardConfigurationPage @@ -56,7 +62,7 @@ namespace MediaBrowser.WebDashboard.Api } /// <summary> - /// Class GetDashboardResource + /// Class GetDashboardResource. /// </summary> [Route("/web/{ResourceName*}", "GET", IsHidden = true)] public class GetDashboardResource @@ -66,6 +72,7 @@ namespace MediaBrowser.WebDashboard.Api /// </summary> /// <value>The name.</value> public string ResourceName { get; set; } + /// <summary> /// Gets or sets the V. /// </summary> @@ -79,7 +86,7 @@ namespace MediaBrowser.WebDashboard.Api } /// <summary> - /// Class DashboardService + /// Class DashboardService. /// </summary> public class DashboardService : IService, IRequiresRequest { @@ -94,46 +101,43 @@ namespace MediaBrowser.WebDashboard.Api /// </summary> /// <value>The HTTP result factory.</value> private readonly IHttpResultFactory _resultFactory; - - /// <summary> - /// Gets or sets the request context. - /// </summary> - /// <value>The request context.</value> - public IRequest Request { get; set; } - - /// <summary> - /// The _app host - /// </summary> private readonly IServerApplicationHost _appHost; - - /// <summary> - /// The _server configuration manager - /// </summary> private readonly IServerConfigurationManager _serverConfigurationManager; - private readonly IFileSystem _fileSystem; - private IResourceFileManager _resourceFileManager; + private readonly IResourceFileManager _resourceFileManager; /// <summary> /// Initializes a new instance of the <see cref="DashboardService" /> class. /// </summary> + /// <param name="logger">The logger.</param> + /// <param name="appHost">The application host.</param> + /// <param name="resourceFileManager">The resource file manager.</param> + /// <param name="serverConfigurationManager">The server configuration manager.</param> + /// <param name="fileSystem">The file system.</param> + /// <param name="resultFactory">The result factory.</param> public DashboardService( + ILogger<DashboardService> logger, IServerApplicationHost appHost, IResourceFileManager resourceFileManager, IServerConfigurationManager serverConfigurationManager, IFileSystem fileSystem, - ILogger<DashboardService> logger, IHttpResultFactory resultFactory) { + _logger = logger; _appHost = appHost; + _resourceFileManager = resourceFileManager; _serverConfigurationManager = serverConfigurationManager; _fileSystem = fileSystem; - _logger = logger; _resultFactory = resultFactory; - _resourceFileManager = resourceFileManager; } /// <summary> + /// Gets or sets the request context. + /// </summary> + /// <value>The request context.</value> + public IRequest Request { get; set; } + + /// <summary> /// Gets the path for the web interface. /// </summary> /// <value>The path for the web interface.</value> @@ -150,6 +154,7 @@ namespace MediaBrowser.WebDashboard.Api } } + [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "request", Justification = "Required for ServiceStack")] public object Get(GetFavIcon request) { return Get(new GetDashboardResource @@ -163,6 +168,7 @@ namespace MediaBrowser.WebDashboard.Api /// </summary> /// <param name="request">The request.</param> /// <returns>System.Object.</returns> + [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "request", Justification = "Required for ServiceStack")] public Task<object> Get(GetDashboardConfigurationPage request) { IPlugin plugin = null; @@ -187,7 +193,7 @@ namespace MediaBrowser.WebDashboard.Api stream = plugin.GetType().Assembly.GetManifestResourceStream(altPage.Item1.EmbeddedResourcePath); isJs = string.Equals(Path.GetExtension(altPage.Item1.EmbeddedResourcePath), ".js", StringComparison.OrdinalIgnoreCase); - isTemplate = altPage.Item1.EmbeddedResourcePath.EndsWith(".template.html"); + isTemplate = altPage.Item1.EmbeddedResourcePath.EndsWith(".template.html", StringComparison.Ordinal); } } @@ -235,7 +241,6 @@ namespace MediaBrowser.WebDashboard.Api // Don't allow a failing plugin to fail them all var configPages = pages.Select(p => { - try { return new ConfigurationPageInfo(p); @@ -286,6 +291,7 @@ namespace MediaBrowser.WebDashboard.Api return GetPluginPages(plugin).Select(i => new ConfigurationPageInfo(plugin, i.Item1)); } + [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "request", Justification = "Required for ServiceStack")] public object Get(GetRobotsTxt request) { return Get(new GetDashboardResource @@ -348,7 +354,7 @@ namespace MediaBrowser.WebDashboard.Api return await _resultFactory.GetStaticResult(Request, cacheKey, null, cacheDuration, contentType, () => GetResourceStream(basePath, path, localizationCulture)).ConfigureAwait(false); } - return await _resultFactory.GetStaticFileResult(Request, _resourceFileManager.GetResourcePath(basePath, path)); + return await _resultFactory.GetStaticFileResult(Request, _resourceFileManager.GetResourcePath(basePath, path)).ConfigureAwait(false); } private string GetLocalizationCulture() @@ -390,9 +396,9 @@ namespace MediaBrowser.WebDashboard.Api { Directory.Delete(targetPath, true); } - catch (IOException) + catch (IOException ex) { - + _logger.LogError(ex, "Error deleting {Path}", targetPath); } CopyDirectory(inputPath, targetPath); @@ -400,9 +406,9 @@ namespace MediaBrowser.WebDashboard.Api var appVersion = _appHost.ApplicationVersionString; - await DumpHtml(packageCreator, inputPath, targetPath, mode, appVersion); + await DumpHtml(packageCreator, inputPath, targetPath, mode, appVersion).ConfigureAwait(false); - return ""; + return string.Empty; } private async Task DumpHtml(PackageCreator packageCreator, string source, string destination, string mode, string appVersion) @@ -425,7 +431,7 @@ namespace MediaBrowser.WebDashboard.Api using (var stream = await packageCreator.GetResource(resourceVirtualPath, mode, null, appVersion).ConfigureAwait(false)) using (var fs = new FileStream(destinationFilePath, FileMode.Create, FileAccess.Write, FileShare.Read)) { - await stream.CopyToAsync(fs); + await stream.CopyToAsync(fs).ConfigureAwait(false); } } @@ -433,14 +439,17 @@ namespace MediaBrowser.WebDashboard.Api { Directory.CreateDirectory(destination); - //Now Create all of the directories + // Now Create all of the directories foreach (var dirPath in _fileSystem.GetDirectories(source, true)) - Directory.CreateDirectory(dirPath.FullName.Replace(source, destination)); + { + Directory.CreateDirectory(dirPath.FullName.Replace(source, destination, StringComparison.Ordinal)); + } - //Copy all the files & Replaces any files with the same name + // Copy all the files & Replaces any files with the same name foreach (var newPath in _fileSystem.GetFiles(source, true)) - File.Copy(newPath.FullName, newPath.FullName.Replace(source, destination), true); + { + File.Copy(newPath.FullName, newPath.FullName.Replace(source, destination, StringComparison.Ordinal), true); + } } } - } diff --git a/MediaBrowser.WebDashboard/Api/PackageCreator.cs b/MediaBrowser.WebDashboard/Api/PackageCreator.cs index 133bf61e8..ad996c5a9 100644 --- a/MediaBrowser.WebDashboard/Api/PackageCreator.cs +++ b/MediaBrowser.WebDashboard/Api/PackageCreator.cs @@ -1,4 +1,7 @@ +#pragma warning disable CS1591 + using System; +using System.Globalization; using System.IO; using System.Text; using System.Threading.Tasks; @@ -44,10 +47,7 @@ namespace MediaBrowser.WebDashboard.Api return string.Equals(Path.GetExtension(path), ".html", StringComparison.OrdinalIgnoreCase); } - /// <summary> - /// Modifies the HTML by adding common meta tags, css and js. - /// </summary> - /// <returns>Task{Stream}.</returns> + // Modifies the HTML by adding common meta tags, css and js. public async Task<Stream> ModifyHtml( string path, Stream sourceStream, @@ -67,30 +67,29 @@ namespace MediaBrowser.WebDashboard.Api { var lang = localizationCulture.Split('-')[0]; - html = html.Replace("<html", "<html data-culture=\"" + localizationCulture + "\" lang=\"" + lang + "\""); + html = html.Replace("<html", "<html data-culture=\"" + localizationCulture + "\" lang=\"" + lang + "\"", StringComparison.Ordinal); } if (isMainIndexPage) { - html = html.Replace("<head>", "<head>" + GetMetaTags(mode)); + html = html.Replace("<head>", "<head>" + GetMetaTags(mode), StringComparison.Ordinal); } // Disable embedded scripts from plugins. We'll run them later once resources have loaded if (html.IndexOf("<script", StringComparison.OrdinalIgnoreCase) != -1) { - html = html.Replace("<script", "<!--<script"); - html = html.Replace("</script>", "</script>-->"); + html = html.Replace("<script", "<!--<script", StringComparison.Ordinal); + html = html.Replace("</script>", "</script>-->", StringComparison.Ordinal); } if (isMainIndexPage) { - html = html.Replace("</body>", GetCommonJavascript(mode, appVersion) + "</body>"); + html = html.Replace("</body>", GetCommonJavascript(mode, appVersion) + "</body>", StringComparison.Ordinal); } var bytes = Encoding.UTF8.GetBytes(html); return new MemoryStream(bytes); - } /// <summary> @@ -123,11 +122,11 @@ namespace MediaBrowser.WebDashboard.Api builder.Append("<script>"); if (!string.IsNullOrWhiteSpace(mode)) { - builder.AppendFormat("window.appMode='{0}';", mode); + builder.AppendFormat(CultureInfo.InvariantCulture, "window.appMode='{0}';", mode); } else { - builder.AppendFormat("window.dashboardVersion='{0}';", version); + builder.AppendFormat(CultureInfo.InvariantCulture, "window.dashboardVersion='{0}';", version); } builder.Append("</script>"); |
