public static T CreateService <T>(string name) where T : WebService, new() { JObj web = Config.GetValue("WEB"); if (web == null) { throw new FrameworkException("Missing 'WEB' in " + WEPAPP_JSON); } JObj cfg = web.GetValue(name); if (cfg == null) { throw new FrameworkException("missing '" + name + "' service in " + WEPAPP_JSON); } var svc = new T { Name = name, Config = cfg }; services.Add(name, svc); svc.OnInitialize(); return(svc); }
static Framework() { // load configuration // byte[] bytes = File.ReadAllBytes(WEPAPP_JSON); JsonParser parser = new JsonParser(bytes, bytes.Length); Config = (JObj)parser.Parse(); logging = Config.GetValue(nameof(logging)); sign = Config.GetValue(nameof(sign)); // setup logger first // string file = DateTime.Now.ToString("yyyyMM") + ".log"; Logger = new FrameworkLogger(file) { Level = logging }; if (!File.Exists(WEPAPP_JSON)) { Logger.Log(LogLevel.Error, WEPAPP_JSON + " not found"); return; } Web = Config.GetValue("WEB"); Db = Config.GetValue("DB"); Net = Config.GetValue("NET"); Ext = Config.GetValue("EXT"); // references if (Net != null) { for (var i = 0; i < Net.Count; i++) { var e = Net.EntryAt(i); peers.Add(new NetPeer(e.Key, e.Value) { Clustered = true }); } } if (Db != null) { for (var i = 0; i < Db.Count; i++) { var e = Db.EntryAt(i); sources.Add(new DbSource(e.Value) { Name = e.Key }); } } // create and start the scheduler thead if (polls != null) { // to repeatedly check and initiate event polling activities. scheduler = new Thread(() => { while (true) { // interval Thread.Sleep(1000); // a schedule cycle int tick = Environment.TickCount; for (int i = 0; i < polls.Count; i++) { var cli = polls[i]; cli.TryPollAsync(tick); } } }); scheduler.Start(); } }