1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Reflection; 6 using System.Text; 7 using System.Threading.Tasks; 8 using System.Web; 9 10 namespace JCBJ.Route 11 { 12 /// <summary>获取相应域名下静态资源文件管理</summary> 13 public class RouteManage 14 { 15 private static DebugFlag debugOnline; 16 17 /// <summary> 18 /// 开关,是否开启本地调试online资源 19 /// </summary> 20 public static bool DebugSwitch { get; set; } 21 22 23 private static DebugFlag checkDebugFlag() 24 { 25 if (!DebugSwitch) 26 DebugSwitch = HttpContext.Current.Request.Url.Host != "localhost"; 27 28 switch (DebugSwitch) 29 { 30 case true: 31 debugOnline = DebugFlag.online; 32 break; 33 case false: 34 debugOnline = DebugFlag.local; 35 break; 36 } 37 38 return debugOnline; 39 40 } 41 42 /// <summary> 获取相应域名下的样式文件 </summary> 43 /// <param name="domainName">当前域名(DomainFlag枚举)</param> 44 /// <param name="CSSName">样式文件名称,支持多个文件用逗号分隔,不用扩展名</param> 45 /// <returns></returns> 46 public static Dictionary<string, string> CSS(DomainFlag domainName, string CSSName) 47 { 48 string[] _CSSName = CSSName.Split(','); 49 Dictionary<string, string> cssUrl = new Dictionary<string, string>(); 50 for (int i = 0; i < _CSSName.Length; i++) 51 { 52 cssUrl.Add(_CSSName[i], DomainAddress.Static + "/" + checkDebugFlag() + "/" + domainName.ToString() + "/css/" + _CSSName[i] + ".css"); 53 } 54 return cssUrl; 55 } 56 57 /// <summary>获取相应域名下的JS文件</summary> 58 /// <param name="domainName">当前域名(DomainFlag枚举)</param> 59 /// <param name="JSName">JS文件名称,支持多个文件用逗号分隔,不用扩展名</param> 60 /// <returns></returns> 61 public static Dictionary<string, string> Script(DomainFlag domainName, string JSName) 62 { 63 string[] _JSName = JSName.Split(','); 64 Dictionary<string, string> JSUrl = new Dictionary<string, string>(); 65 for (int i = 0; i < _JSName.Length; i++) 66 { 67 JSUrl.Add(_JSName[i], DomainAddress.Static + "/" + checkDebugFlag() + "/" + domainName.ToString() + "/scripts/" + _JSName[i] + ".js"); 68 } 69 return JSUrl; 70 } 71 72 /// <summary>获取公共JS文件</summary> 73 /// <param name="JSName">JS文件名称,支持多个文件用逗号分隔,不用扩展名</param> 74 /// <returns></returns> 75 public static Dictionary<string, string> PubScript(string JSName) 76 { 77 string[] _JSName = JSName.Split(','); 78 Dictionary<string, string> JSUrl = new Dictionary<string, string>(); 79 for (int i = 0; i < _JSName.Length; i++) 80 { 81 JSUrl.Add(_JSName[i], DomainAddress.Static + "/scripts/" + _JSName[i] + ".js"); 82 } 83 return JSUrl; 84 } 85 86 /// <summary>获取公共资源文件</summary> 87 /// <param name="filePath">文件路径</param> 88 /// <param name="fileName">要引用的文件,带后缀</param> 89 /// <returns></returns> 90 public static Dictionary<string, string> PubScript(string filePath, string fileName) 91 { 92 // filePath: /Scripts/Arale/artDialog/css/ 93 // fileName: ui-dialog.css 94 string[] _FileName = fileName.Split(','); 95 Dictionary<string, string> fileUrl = new Dictionary<string, string>(); 96 for (int i = 0; i < _FileName.Length; i++) 97 { 98 fileUrl.Add(_FileName[i], DomainAddress.Static + filePath + _FileName[i]); 99 } 100 return fileUrl; 101 } 102 103 /// <summary> 获取相应域名下的图片文件</summary> 104 /// <param name="domainName">当前域名(DomainFlag枚举)</param> 105 /// <param name="imgName">图片文件名且带扩展名,支持多个文件用逗号分隔</param> 106 /// <returns></returns> 107 public static Dictionary<string, string> Image(DomainFlag domainName, string imgName) 108 { 109 string[] _imgName = imgName.Split(','); 110 111 Dictionary<string, string> imgUrl = new Dictionary<string, string>(); 112 for (int i = 0; i < _imgName.Length; i++) 113 { 114 imgUrl.Add(_imgName[i], DomainAddress.Static + "/" + checkDebugFlag() + "/" + domainName.ToString() + "/Images/" + _imgName[i]); 115 } 116 return imgUrl; 117 } 118 119 /// <summary> 获取相应域名下的静态页面 </summary> 120 /// <param name="domainName">当前域名(DomainFlag枚举)</param> 121 /// <param name="htmlName">页面文件名且带扩展名</param> 122 /// <returns></returns> 123 public static Dictionary<string, string> Html(DomainFlag domainName, string htmlName) 124 { 125 string[] _htmlName = htmlName.Split(','); 126 Dictionary<string, string> htmlUrl = new Dictionary<string, string>(); 127 for (int i = 0; i < _htmlName.Length; i++) 128 { 129 htmlUrl.Add(_htmlName[i], DomainAddress.Static + "/" + checkDebugFlag() + "/" + domainName.ToString() + "/html/" + _htmlName[i]); 130 } 131 return htmlUrl; 132 } 133 134 /// <summary>根据文件类型获取upload资源文件</summary> 135 /// <param name="imgUrl">文件路径</param> 136 /// <param name="imgType">文件类型</param> 137 /// <returns></returns> 138 public static string UploadFile(string imgUrl, ImgTypeFlag imgType) 139 { 140 string[] imgName = imgUrl.Split('/'); 141 string _imgUrl = DomainAddress.Static + "/UploadFile"; 142 string imgname = "default.jpg"; 143 if (imgName[imgName.Length - 1] != null && !imgName[imgName.Length - 1].Equals("")) 144 { 145 imgname = imgName[imgName.Length - 1]; 146 } 147 switch (imgType) 148 { 149 case ImgTypeFlag.license: 150 _imgUrl += "/license"; 151 break; 152 case ImgTypeFlag.logo: 153 _imgUrl += "/logo"; 154 break; 155 case ImgTypeFlag.pic: 156 _imgUrl += "/pic"; 157 break; 158 } 159 _imgUrl += "/" + imgname; 160 161 return _imgUrl; 162 163 } 164 } 165}