public ICssMinifier CreateMinifier(string minifierName) { #if DNXCORE50 ICssMinifier minifier = new KristensenCssMinifier(); #else ICssMinifier minifier; switch (minifierName) { case "KristensenCssMinifier": minifier = new KristensenCssMinifier(); break; case "MsAjaxCssMinifier": minifier = new MsAjaxCssMinifier(); break; case "YuiCssMinifier": minifier = new YuiCssMinifier(); break; default: throw new NotSupportedException(); } #endif return minifier; }
public ICssMinifier CreateMinifier(string minifierName) { ICssMinifier minifier; switch (minifierName) { case "KristensenCssMinifier": minifier = new KristensenCssMinifier(); break; #if !NETSTANDARD1_6 case "MsAjaxCssMinifier": minifier = new MsAjaxCssMinifier(); break; case "YuiCssMinifier": minifier = new YuiCssMinifier(); break; #endif case "NUglifyCssMinifier": minifier = new NUglifyCssMinifier(); break; default: throw new NotSupportedException(); } return minifier; }
/// <summary> /// Gets all CSS. /// </summary> /// <returns>Task{Stream}.</returns> private async Task<Stream> GetAllCss(bool enableMinification) { var memoryStream = new MemoryStream(); var files = new[] { "css/site.css", "css/librarymenu.css", "css/librarybrowser.css", "thirdparty/paper-button-style.css" }; var builder = new StringBuilder(); foreach (var file in files) { var path = GetDashboardResourcePath(file); using (var fs = _fileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true)) { using (var streamReader = new StreamReader(fs)) { var text = await streamReader.ReadToEndAsync().ConfigureAwait(false); builder.Append(text); builder.Append(Environment.NewLine); } } } var css = builder.ToString(); if (enableMinification) { try { var result = new KristensenCssMinifier().Minify(builder.ToString(), false, Encoding.UTF8); if (result.Errors.Count > 0) { _logger.Error("Error minifying css: " + result.Errors[0].Message); } else { css = result.MinifiedContent; } } catch (Exception ex) { _logger.ErrorException("Error minifying css", ex); } } var bytes = Encoding.UTF8.GetBytes(css); memoryStream.Write(bytes, 0, bytes.Length); memoryStream.Position = 0; return memoryStream; }
public async Task<Stream> ModifyCss(Stream sourceStream, bool enableMinification) { using (sourceStream) { string content; using (var memoryStream = new MemoryStream()) { await sourceStream.CopyToAsync(memoryStream).ConfigureAwait(false); content = Encoding.UTF8.GetString(memoryStream.ToArray()); if (enableMinification) { try { var result = new KristensenCssMinifier().Minify(content, false, Encoding.UTF8); if (result.Errors.Count > 0) { _logger.Error("Error minifying css: " + result.Errors[0].Message); } else { content = result.MinifiedContent; } } catch (Exception ex) { _logger.ErrorException("Error minifying css", ex); } } } var bytes = Encoding.UTF8.GetBytes(content); return new MemoryStream(bytes); } }
/// <summary> /// Gets all CSS. /// </summary> /// <returns>Task{Stream}.</returns> private async Task<Stream> GetAllCss(bool enableMinification) { var memoryStream = new MemoryStream(); var newLineBytes = Encoding.UTF8.GetBytes(Environment.NewLine); await AppendResource(memoryStream, "thirdparty/jquerymobile-1.4.5/jquery.mobile.custom.theme.min.css", newLineBytes).ConfigureAwait(false); await AppendResource(memoryStream, "thirdparty/jquerymobile-1.4.5/jquery.mobile.custom.structure.min.css", newLineBytes).ConfigureAwait(false); var files = new[] { "css/site.css", "css/chromecast.css", "css/nowplayingbar.css", "css/mediaplayer.css", "css/mediaplayer-video.css", "css/librarymenu.css", "css/librarybrowser.css", "css/card.css", "css/notifications.css", "css/search.css", "css/pluginupdates.css", "css/remotecontrol.css", "css/userimage.css", "css/nowplaying.css", "css/materialize.css", "thirdparty/paper-button-style.css" }; var builder = new StringBuilder(); foreach (var file in files) { var path = GetDashboardResourcePath(file); using (var fs = _fileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true)) { using (var streamReader = new StreamReader(fs)) { var text = await streamReader.ReadToEndAsync().ConfigureAwait(false); builder.Append(text); builder.Append(Environment.NewLine); } } } var css = builder.ToString(); if (enableMinification) { try { var result = new KristensenCssMinifier().Minify(builder.ToString(), false, Encoding.UTF8); if (result.Errors.Count > 0) { _logger.Error("Error minifying css: " + result.Errors[0].Message); } else { css = result.MinifiedContent; } } catch (Exception ex) { _logger.ErrorException("Error minifying css", ex); } } var bytes = Encoding.UTF8.GetBytes(css); memoryStream.Write(bytes, 0, bytes.Length); memoryStream.Position = 0; return memoryStream; }
/// <summary> /// Gets all CSS. /// </summary> /// <returns>Task{Stream}.</returns> private async Task<Stream> GetAllCss(bool enableMinification) { var files = new[] { "site.css", "chromecast.css", "mediaplayer.css", "mediaplayer-video.css", "librarymenu.css", "librarybrowser.css", "detailtable.css", "card.css", "tileitem.css", "metadataeditor.css", "notifications.css", "search.css", "pluginupdates.css", "remotecontrol.css", "userimage.css", "livetv.css", "nowplaying.css", "icons.css", "materialize.css" }; var builder = new StringBuilder(); foreach (var file in files) { var path = GetDashboardResourcePath("css/" + file); using (var fs = _fileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true)) { using (var streamReader = new StreamReader(fs)) { var text = await streamReader.ReadToEndAsync().ConfigureAwait(false); builder.Append(text); builder.Append(Environment.NewLine); } } } var css = builder.ToString(); if (enableMinification) { try { var result = new KristensenCssMinifier().Minify(builder.ToString(), false, Encoding.UTF8); if (result.Errors.Count > 0) { _logger.Error("Error minifying css: " + result.Errors[0].Message); } else { css = result.MinifiedContent; } } catch (Exception ex) { _logger.ErrorException("Error minifying css", ex); } } var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(css)); memoryStream.Position = 0; return memoryStream; }