Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
Esempio n. 3
0
 public JMbr(JObj v, string name = null)
 {
     this.name = name;
     type      = JType.Object;
     refv      = v;
     numv      = default;
 }
Esempio n. 4
0
 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
     }
 }
Esempio n. 5
0
        public bool Get(string name, ref JObj v)
        {
            if (TryGetValue(name, out var mbr))
            {
                v = mbr;
                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
 public bool Get(string name, ref JObj v)
 {
     throw new NotImplementedException();
 }
Esempio n. 10
0
 public void Put(string name, JObj v)
 {
     throw new NotImplementedException();
 }
Esempio n. 11
0
        public bool Get(string name, ref long v)
        {
            JObj jo = elements[current];

            return(jo != null && jo.Get(name, ref v));
        }
Esempio n. 12
0
 public void Add(JObj elem)
 {
     Add(new JMbr(elem));
 }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
 public bool Get(string name, ref JObj v)
 {
     return(false);
 }
Esempio n. 15
0
        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();
            }
        }
Esempio n. 16
0
 public void Put(string name, JObj v)
 {
 }
Esempio n. 17
0
 public void Add(string name, JObj v)
 {
     Add <JMbr>(new JMbr(v, name));
 }