public override string MinifyFile(Stream fileStream, ClientDependencyType type) { Func <Stream, string> streamToString = stream => { if (!stream.CanRead) { throw new InvalidOperationException("Cannot read input stream"); } if (stream.CanSeek) { stream.Position = 0; } var reader = new StreamReader(stream); return(reader.ReadToEnd()); }; switch (type) { case ClientDependencyType.Css: return(this.MinifyCss ? CssHelper.MinifyCss(fileStream) : streamToString(fileStream)); case ClientDependencyType.Javascript: return(this.MinifyJs ? JSMin.CompressJS(fileStream) : streamToString(fileStream)); default: return(streamToString(fileStream)); } }
public override string MinifyFile(string fileContents, ClientDependencyType type) { switch (type) { case ClientDependencyType.Css: return(this.MinifyCss ? CssHelper.MinifyCss(fileContents) : fileContents); case ClientDependencyType.Javascript: { if (!this.MinifyJs) { return(fileContents); } using (var ms = new MemoryStream()) using (var writer = new StreamWriter(ms)) { writer.Write(fileContents); writer.Flush(); return(JSMin.CompressJS(ms)); } } default: return(fileContents); } }
/// <summary> /// Minifies the file /// </summary> /// <param name="fileStream"></param> /// <param name="type"></param> /// <returns></returns> public virtual string MinifyFile(Stream fileStream, ClientDependencyType type) { switch (type) { case ClientDependencyType.Css: return(EnableCssMinify ? CssHelper.MinifyCss(fileStream) : StreamToString(fileStream)); case ClientDependencyType.Javascript: return(EnableJsMinify ? JSMin.CompressJS(fileStream) : StreamToString(fileStream)); default: return(StreamToString(fileStream)); } }
protected override string MinifyFile(string fileContents, ClientDependencyType type) { switch (type) { case ClientDependencyType.Css: return(MinifyCss ? CssMin.CompressCSS(fileContents) : fileContents); case ClientDependencyType.Javascript: return(MinifyJs ? JSMin.CompressJS(fileContents) : fileContents); default: return(fileContents); } }
/// <summary> /// Minifies the file /// </summary> /// <param name="fileStream"></param> /// <param name="type"></param> /// <returns></returns> public virtual string MinifyFile(Stream fileStream, ClientDependencyType type) { Func <Stream, string> streamToString = stream => { var reader = new StreamReader(stream); return(reader.ReadToEnd()); }; switch (type) { case ClientDependencyType.Css: return(EnableCssMinify ? CssHelper.MinifyCss(fileStream) : streamToString(fileStream)); case ClientDependencyType.Javascript: return(EnableJsMinify ? JSMin.CompressJS(fileStream) : streamToString(fileStream)); default: return(streamToString(fileStream)); } }