using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web; namespace JCBJ.Route
{
/// <summary>获取相应域名下静态资源文件管理</summary>
public class RouteManage
{
private static DebugFlag debugOnline; /// <summary>
/// 开关,是否开启本地调试online资源
/// </summary>
public static bool DebugSwitch { get; set; } private static DebugFlag checkDebugFlag()
{
if (!DebugSwitch)
DebugSwitch = HttpContext.Current.Request.Url.Host != "localhost"; switch (DebugSwitch)
{
case true:
debugOnline = DebugFlag.online;
break;
case false:
debugOnline = DebugFlag.local;
break;
} return debugOnline; } /// <summary> 获取相应域名下的样式文件 </summary>
/// <param name="domainName">当前域名(DomainFlag枚举)</param>
/// <param name="CSSName">样式文件名称,支持多个文件用逗号分隔,不用扩展名</param>
/// <returns></returns>
public static Dictionary<string, string> CSS(DomainFlag domainName, string CSSName)
{
string[] _CSSName = CSSName.Split(',');
Dictionary<string, string> cssUrl = new Dictionary<string, string>();
for (int i = ; i < _CSSName.Length; i++)
{
cssUrl.Add(_CSSName[i], DomainAddress.Static + "/" + checkDebugFlag() + "/" + domainName.ToString() + "/css/" + _CSSName[i] + ".css");
}
return cssUrl;
} /// <summary>获取相应域名下的JS文件</summary>
/// <param name="domainName">当前域名(DomainFlag枚举)</param>
/// <param name="JSName">JS文件名称,支持多个文件用逗号分隔,不用扩展名</param>
/// <returns></returns>
public static Dictionary<string, string> Script(DomainFlag domainName, string JSName)
{
string[] _JSName = JSName.Split(',');
Dictionary<string, string> JSUrl = new Dictionary<string, string>();
for (int i = ; i < _JSName.Length; i++)
{
JSUrl.Add(_JSName[i], DomainAddress.Static + "/" + checkDebugFlag() + "/" + domainName.ToString() + "/scripts/" + _JSName[i] + ".js");
}
return JSUrl;
} /// <summary>获取公共JS文件</summary>
/// <param name="JSName">JS文件名称,支持多个文件用逗号分隔,不用扩展名</param>
/// <returns></returns>
public static Dictionary<string, string> PubScript(string JSName)
{
string[] _JSName = JSName.Split(',');
Dictionary<string, string> JSUrl = new Dictionary<string, string>();
for (int i = ; i < _JSName.Length; i++)
{
JSUrl.Add(_JSName[i], DomainAddress.Static + "/scripts/" + _JSName[i] + ".js");
}
return JSUrl;
} /// <summary>获取公共资源文件</summary>
/// <param name="filePath">文件路径</param>
/// <param name="fileName">要引用的文件,带后缀</param>
/// <returns></returns>
public static Dictionary<string, string> PubScript(string filePath, string fileName)
{
// filePath: /Scripts/Arale/artDialog/css/
// fileName: ui-dialog.css
string[] _FileName = fileName.Split(',');
Dictionary<string, string> fileUrl = new Dictionary<string, string>();
for (int i = ; i < _FileName.Length; i++)
{
fileUrl.Add(_FileName[i], DomainAddress.Static + filePath + _FileName[i]);
}
return fileUrl;
} /// <summary> 获取相应域名下的图片文件</summary>
/// <param name="domainName">当前域名(DomainFlag枚举)</param>
/// <param name="imgName">图片文件名且带扩展名,支持多个文件用逗号分隔</param>
/// <returns></returns>
public static Dictionary<string, string> Image(DomainFlag domainName, string imgName)
{
string[] _imgName = imgName.Split(','); Dictionary<string, string> imgUrl = new Dictionary<string, string>();
for (int i = ; i < _imgName.Length; i++)
{
imgUrl.Add(_imgName[i], DomainAddress.Static + "/" + checkDebugFlag() + "/" + domainName.ToString() + "/Images/" + _imgName[i]);
}
return imgUrl;
} /// <summary> 获取相应域名下的静态页面 </summary>
/// <param name="domainName">当前域名(DomainFlag枚举)</param>
/// <param name="htmlName">页面文件名且带扩展名</param>
/// <returns></returns>
public static Dictionary<string, string> Html(DomainFlag domainName, string htmlName)
{
string[] _htmlName = htmlName.Split(',');
Dictionary<string, string> htmlUrl = new Dictionary<string, string>();
for (int i = ; i < _htmlName.Length; i++)
{
htmlUrl.Add(_htmlName[i], DomainAddress.Static + "/" + checkDebugFlag() + "/" + domainName.ToString() + "/html/" + _htmlName[i]);
}
return htmlUrl;
} /// <summary>根据文件类型获取upload资源文件</summary>
/// <param name="imgUrl">文件路径</param>
/// <param name="imgType">文件类型</param>
/// <returns></returns>
public static string UploadFile(string imgUrl, ImgTypeFlag imgType)
{
string[] imgName = imgUrl.Split('/');
string _imgUrl = DomainAddress.Static + "/UploadFile";
string imgname = "default.jpg";
if (imgName[imgName.Length - ] != null && !imgName[imgName.Length - ].Equals(""))
{
imgname = imgName[imgName.Length - ];
}
switch (imgType)
{
case ImgTypeFlag.license:
_imgUrl += "/license";
break;
case ImgTypeFlag.logo:
_imgUrl += "/logo";
break;
case ImgTypeFlag.pic:
_imgUrl += "/pic";
break;
}
_imgUrl += "/" + imgname; return _imgUrl; }
}
}
04-30 09:58