using System; using System.IO; using System.Reflection; using System.Text; using Yahoo.Yui.Compressor; namespace WMS.Util { /// /// 描 述:js,css,文件压缩和下载 /// public class JsCssUtil { private static JavaScriptCompressor javaScriptCompressor = new JavaScriptCompressor(); private static CssCompressor cssCompressor = new CssCompressor(); /// /// 读取js文件内容并压缩 /// /// /// public static string ReadJSFile(string[] filePathlist, bool IsJsCompressor) { StringBuilder jsStr = new StringBuilder(); try { string rootPath = ConfigHelper.GetValue("baseDir");//+ "/wwwroot"; foreach (var filePath in filePathlist) { string path = rootPath + filePath; if (File.Exists(path)) { string content = File.ReadAllText(path, Encoding.UTF8); if (IsJsCompressor) { content = javaScriptCompressor.Compress(content); } jsStr.Append(content); } } return jsStr.ToString(); } catch { return ""; } } /// /// 读取css 文件内容并压缩 /// /// /// public static string ReadCssFile(string[] filePathlist, bool IsCssCompressor) { StringBuilder cssStr = new StringBuilder(); try { string rootPath = ConfigHelper.GetValue("baseDir");//+ "/wwwroot"; foreach (var filePath in filePathlist) { string path = rootPath + filePath; if (File.Exists(path)) { string content = File.ReadAllText(path, Encoding.UTF8); if (IsCssCompressor) { content = cssCompressor.Compress(content); } cssStr.Append(content); } } return cssStr.ToString(); } catch { return cssStr.ToString(); } } } }