public Map <K, D> ToMap <K, D>(byte proj = 0x0f, Func <D, K> keyer = null, Predicate <K> toper = null) where D : IData, new() { Map <K, D> map = new Map <K, D>(); for (int i = 0; i < count; i++) { D obj = new D(); obj.Read((JObj)elements[i], proj); K key = default; if (keyer != null) { key = keyer(obj); } else if (obj is IKeyable <K> mappable) { key = mappable.Key; } map.Add(key, obj); } return(map); }
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(); } }