123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System;
- using System.IO;
- using System.Reflection;
- using System.Text;
- using Yahoo.Yui.Compressor;
- namespace WMS.Util
- {
- /// <summary>
- /// 描 述:js,css,文件压缩和下载
- /// </summary>
- public class JsCssUtil
- {
- private static JavaScriptCompressor javaScriptCompressor = new JavaScriptCompressor();
- private static CssCompressor cssCompressor = new CssCompressor();
- /// <summary>
- /// 读取js文件内容并压缩
- /// </summary>
- /// <param name="filePathlist"></param>
- /// <returns></returns>
- public static string ReadJSFile(string[] filePathlist, bool IsJsCompressor)
- {
- StringBuilder jsStr = new StringBuilder();
- try
- {
- string rootPath = ConfigHelper.GetValue<string>("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 "";
- }
- }
- /// <summary>
- /// 读取css 文件内容并压缩
- /// </summary>
- /// <param name="filePathlist"></param>
- /// <returns></returns>
- public static string ReadCssFile(string[] filePathlist, bool IsCssCompressor)
- {
- StringBuilder cssStr = new StringBuilder();
- try
- {
- string rootPath = ConfigHelper.GetValue<string>("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();
- }
- }
- }
- }
|