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); }
public static P Decrypt <P>(string token) where P : IData, new() { int mask = sign; int[] masks = { (mask >> 24) & 0xff, (mask >> 16) & 0xff, (mask >> 8) & 0xff, mask & 0xff }; int len = token.Length / 2; var str = new Text(1024); int p = 0; for (int i = 0; i < len; i++) { // TODO reordering // transform to byte int b = (byte)(Dv(token[p++]) << 4 | Dv(token[p++])); // masking str.Accept((byte)(b ^ masks[i % 4])); } // deserialize try { JObj jo = (JObj) new JsonParser(str.ToString()).Parse(); P prin = new P(); prin.Read(jo, 0xff); return(prin); } catch { return(default);
public JMbr(JObj v, string name = null) { this.name = name; type = JType.Object; refv = v; numv = default; }
public void Put(string name, JObj v) { if (counts[level]++ > 0) { Add(','); } if (name != null) { Add('"'); Add(name); Add('"'); Add(':'); } if (v == null) { Add("null"); } else { counts[++level] = 0; // enter Add('{'); v.Write(this); Add('}'); level--; // exit } }
public bool Get(string name, ref JObj v) { if (TryGetValue(name, out var mbr)) { v = mbr; return(true); } return(false); }
public bool Get <D>(string name, ref D v, byte proj = 0x0f) where D : IData, new() { if (TryGetValue(name, out var mbr)) { JObj jobj = mbr; if (jobj != null) { v = new D(); v.Read(jobj); } return(true); } return(false); }
public static D FileToObject <D>(string file, byte proj = 0x0f) where D : IData, new() { try { byte[] bytes = File.ReadAllBytes(file); JObj jo = (JObj) new JsonParser(bytes, bytes.Length).Parse(); if (jo != null) { return(jo.ToObject <D>(proj)); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(default);
public bool Get <D>(string name, ref D[] v, byte proj = 0x0f) where D : IData, new() { if (TryGetValue(name, out var mbr)) { JArr ja = mbr; if (ja != null) { v = new D[ja.Count]; for (int i = 0; i < ja.Count; i++) { JObj jo = ja[i]; D dat = new D(); dat.Read(jo); v[i] = dat; } } return(true); } return(false); }
public bool Get(string name, ref JObj v) { throw new NotImplementedException(); }
public void Put(string name, JObj v) { throw new NotImplementedException(); }
public bool Get(string name, ref long v) { JObj jo = elements[current]; return(jo != null && jo.Get(name, ref v)); }
public void Add(JObj elem) { Add(new JMbr(elem)); }
public bool Get <D>(string name, ref D[] v, byte proj = 0x0f) where D : IData, new() { JObj jo = elements[current]; return(jo != null && jo.Get(name, ref v)); }
public bool Get(string name, ref JObj v) { return(false); }
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(); } }
public void Put(string name, JObj v) { }
public void Add(string name, JObj v) { Add <JMbr>(new JMbr(v, name)); }