internal static CSApplication Instance() { const string key = "CSApplication"; CSApplication app = CSCache.Get(key) as CSApplication; if(app == null) { lock(sync) { app = CSCache.Get(key) as CSApplication; if(app == null) { CSConfiguration config = CSContext.Current.Config; XmlNode node = config.GetConfigSection("CommunityServer/CSModules"); app = new CSApplication(); if(node != null) { foreach(XmlNode n in node.ChildNodes) { if(n.NodeType != XmlNodeType.Comment) { switch(n.Name) { case "clear": app.modules.Clear(); break; case "remove": app.modules.Remove(n.Attributes["name"].Value); break; case "add": string name = n.Attributes["name"].Value; string itype = n.Attributes["type"].Value; Type type = Type.GetType(itype); if(type == null) throw new Exception(itype + " does not exist"); ICSModule mod = Activator.CreateInstance(type) as ICSModule; if(mod == null) throw new Exception(itype + " does not implement ICSModule or is not configured correctly"); mod.Init(app, n); app.modules.Add(name,mod); break; } } } } CacheDependency dep = new CacheDependency(null, new string[]{CSConfiguration.CacheKey}); CSCache.Max(key, app,dep); } } } return app; }
public void Init(CSApplication csa, System.Xml.XmlNode node) { csa.CSException +=new CSExceptionHandler(csa_CSException); }