using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; namespace Bowin.Web.Controls.Mvc { public static class ControlHelper { static System.Collections.Concurrent.ConcurrentDictionary> scriptRegisterCache; static ControlHelper() { scriptRegisterCache = new System.Collections.Concurrent.ConcurrentDictionary>(); scriptRegisterCache.TryAdd(HttpContext.Current, new List()); } public static bool IsRegisterScript(this HttpContext httpContext, string scriptKey) { return GetRegisterKeyList(httpContext).Contains(scriptKey); } public static void RegisterScript(this HttpContext httpContext, string scriptKey) { if (IsRegisterScript(httpContext, scriptKey)) { throw new Exception(string.Format("当前HttpContext已经脚本key:{0}", scriptKey)); } GetRegisterKeyList(httpContext).Add(scriptKey); } public static IList GetRegisterKeyList(this HttpContext httpContext) { IList scriptKeyList = new List(); var isRegisterContext = scriptRegisterCache.TryGetValue(httpContext, out scriptKeyList); if (!isRegisterContext) { scriptRegisterCache.TryAdd(HttpContext.Current, new List()); scriptKeyList = new List(); } return scriptKeyList; } } }