| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 | 
							- using CP.Business;
 
- using CP.Cache;
 
- using Newtonsoft.Json;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Web;
 
- namespace CP.Web
 
- {
 
-     public class Statics
 
-     {
 
-         #region 返回静态文件输出
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public static string GetStatics(string name, string type = "")
 
-         {
 
-             if (string.IsNullOrEmpty(name))
 
-                 return "";
 
-             StringBuilder sb = new StringBuilder();
 
-             var names = name.Split(':');
 
-             if (names != null && names.Length > 0)
 
-             {
 
-                 string br = "\r\n";
 
-                 for (int i = 0; i < names.Length; i++)
 
-                 {
 
-                     if (i == names.Length - 1)
 
-                         br = "";
 
-                     var item = StaticFile.GetStaticFile(names[i], type);
 
-                     if (item != null && !string.IsNullOrEmpty(item.url))
 
-                     {
 
-                         switch (item.type)
 
-                         {
 
-                             case "js":
 
-                                 sb.Append("<script type=\"text/javascript\" src=\"" + item.url + "?v=" + item.ver + "\"></script>" + br);
 
-                                 break;
 
-                             case "css":
 
-                                 sb.Append("<link href=\"" + item.url + "?v=" + item.ver + "\" rel=\"stylesheet\" type=\"text/css\" />" + br);
 
-                                 break;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             return sb.ToString();
 
-         }
 
-         #endregion
 
-     }
 
-     public class StaticFile
 
-     {
 
-         
 
-         
 
-         
 
-         static WMCache cache = WMCache.GetCacheService();
 
-         
 
-         
 
-         
 
-         
 
-         public static List<StaticFileInfo> GetStaticFileList()
 
-         {
 
-             string key = CacheKeys.Static_File;
 
-             List<StaticFileInfo> list = cache.GetObject<List<StaticFileInfo>>(key) as List<StaticFileInfo>;
 
-             if (list == null)
 
-             {
 
-                 list = StaticFileData.GetStaticFileList();
 
-                 cache.AddObject(key, list, (int)CacheTime.System);
 
-             }
 
-             return list;
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public static StaticFileInfo GetStaticFile(string name, string type)
 
-         {
 
-             StaticFileInfo info = new StaticFileInfo();
 
-             var list = GetStaticFileList();
 
-             foreach (var item in list)
 
-             {
 
-                 if (!string.IsNullOrWhiteSpace(type))
 
-                 {
 
-                     if (item.name.Trim().Equals(name, StringComparison.CurrentCultureIgnoreCase)
 
-                          && item.type.Equals(type, StringComparison.CurrentCultureIgnoreCase))
 
-                         return item;
 
-                 }
 
-                 else
 
-                 {
 
-                     if (item.name.Trim().Equals(name, StringComparison.CurrentCultureIgnoreCase))
 
-                         return item;
 
-                 }
 
-             }
 
-             return info;
 
-         }
 
-     }
 
-     public class StaticFileInfo
 
-     {
 
-         
 
-         
 
-         
 
-         public string name { get; set; }
 
-         
 
-         
 
-         
 
-         public string url { get; set; }
 
-         
 
-         
 
-         
 
-         public string ver { get; set; }
 
-         
 
-         
 
-         
 
-         public string type { get; set; }
 
-     }
 
-     public class StaticFileData
 
-     {
 
-         
 
-         
 
-         
 
-         
 
-         public static List<StaticFileInfo> GetStaticFileList()
 
-         {
 
-             List<StaticFileInfo> list = new List<StaticFileInfo>();
 
-             string result = string.Empty;
 
-             try
 
-             {
 
-                 string path = System.Web.HttpContext.Current.Server.MapPath("/") + "Config/data/static.config";
 
-                 result = File.ReadAllText(path);
 
-             }
 
-             catch (Exception ex)
 
-             {
 
-                 throw new Exception("static.config配置错误:" + ex.Message);
 
-             }
 
-             if (!string.IsNullOrEmpty(result))
 
-             {
 
-                 try
 
-                 {
 
-                     list = JsonConvert.DeserializeObject<List<StaticFileInfo>>(result);
 
-                 }
 
-                 catch (Exception ex)
 
-                 {
 
-                     throw new Exception("反序列化static.config出错:" + ex.Message);
 
-                 }
 
-             }
 
-             return list;
 
-         }
 
-     }
 
- }
 
 
  |