using Sy
stem; using Sy
stem.Collections.Generic; using Sy
stem.Linq; using Sy
stem.Text; using Sy
stem.IO ; using Sy
stem.Xml ; using Sy
stem.Web.Caching ; using Sy
stem.Threading ; namespace BasicCompent { public class PageC
ssprovider { static Sy
stem.Web.HttpContext cxt; static ManualResetEvent mr = new ManualResetEvent(true); static ManualResetEvent mw = new ManualResetEvent(true); static XmlDocument _doc; private PageC
ssprovider() { } static PageC
ssprovider() { cxt = Sy
stem.Web.HttpContext.Current; Init(); } public static string PageCss(string pageName) { if (string.IsNullOrEmpty(pageName)) return string.Empty; string xmpath = string.Format("/pages/page[@name=/"{0}/"]",pageName); mw.WaitOne(); mr.Reset(); try { if(_doc ==null ) return string.Empty ; XmlNode node = _doc.SelectSingleNode(xmpath); return node.InnerXml; } finally { mr.Set(); } } static void Init() { mr.WaitOne(); mw.Reset(); try { string realPath = cxt.Server.MapPath("~/Css.xml"); if (!File.Exists(realPath)) return; _doc = new XmlDocument(); _doc.Load(realPath); CacheDependency cd = new CacheDependency(realPath); cxt.Cache.Insert("pageCss",realPath,cd,Cache.NoAbsoluteExpiration,Cache.NoSlidingExpiration,CacheItemPriority.NotRemovable,reportRemovedCallback); } finally { mw.Set(); } } static void reportRemovedCallback(String key,object value,CacheItemRemovedReason reason) { Init(); } } }