Beispiel #1
0
        public IDataInput Let <D>(out D v, int proj = 0x00ff) where D : IData, new()
        {
            try
            {
                int ord = ordinal++;
                if (!reader.IsDBNull(ord))
                {
                    string    str = reader.GetString(ord);
                    JsonParse p   = new JsonParse(str);
                    JObj      jo  = (JObj)p.Parse();
                    v = new D();
                    v.Read(jo, proj);

                    // add shard if any
                    IShardable sharded = v as IShardable;
                    if (sharded != null)
                    {
                        sharded.Shard = service.Shard;
                    }
                    return(this);
                }
            }
            catch
            {
            }
            v = default(D);
            return(this);
        }
Beispiel #2
0
        public bool Get <D>(string name, ref D[] v, int proj = 0x00ff) where D : IData, new()
        {
            try
            {
                int ord = reader.GetOrdinal(name);
                if (!reader.IsDBNull(ord))
                {
                    string    str   = reader.GetString(ord);
                    JsonParse parse = new JsonParse(str);
                    JArr      ja    = (JArr)parse.Parse();
                    int       len   = ja.Count;
                    v = new D[len];
                    for (int i = 0; i < len; i++)
                    {
                        JObj jo  = ja[i];
                        D    obj = new D();
                        obj.Read(jo, proj);

                        // add shard if any
                        IShardable sharded = obj as IShardable;
                        if (sharded != null)
                        {
                            sharded.Shard = service.Shard;
                        }

                        v[i] = obj;
                    }
                    return(true);
                }
            }
            catch
            {
            }
            return(false);
        }
Beispiel #3
0
        public bool Get <D>(string name, ref D v, int proj = 0x00ff) where D : IData, new()
        {
            try
            {
                int ord = reader.GetOrdinal(name);
                if (!reader.IsDBNull(ord))
                {
                    string    str = reader.GetString(ord);
                    JsonParse p   = new JsonParse(str);
                    JObj      jo  = (JObj)p.Parse();
                    v = new D();
                    v.Read(jo, proj);

                    // add shard if any
                    IShardable sharded = v as IShardable;
                    if (sharded != null)
                    {
                        sharded.Shard = service.Shard;
                    }
                    return(true);
                }
            }
            catch
            {
            }
            return(false);
        }
Beispiel #4
0
 public bool Get(string name, ref JArr v)
 {
     try
     {
         int ord = reader.GetOrdinal(name);
         if (!reader.IsDBNull(ord))
         {
             string    str   = reader.GetString(ord);
             JsonParse parse = new JsonParse(str);
             v = (JArr)parse.Parse();
             return(true);
         }
     }
     catch
     {
     }
     return(false);
 }
Beispiel #5
0
        public static bool TryCreate <S>(ServiceContext sc, bool load, object attachment = null) where S : Service
        {
            // initialize work context
            sc.Attach    = attachment;
            sc.Parent    = null;
            sc.Level     = 0;
            sc.Directory = sc.Name;

            if (load) // need to load configuration file
            {
                string file = sc.GetFilePath(CONFIG_FILE);
                if (File.Exists(file))
                {
                    byte[]    bytes = File.ReadAllBytes(file);
                    JsonParse p     = new JsonParse(bytes, bytes.Length);
                    JObj      jo    = (JObj)p.Parse();

                    // this will override values
                    sc.Read(jo, 0xffff);
                }
                else
                {
                    return(false);
                }
            }

            // create instance by reflection
            Type            typ = typeof(S);
            ConstructorInfo ci  = typ.GetConstructor(new[] { typeof(ServiceContext) });

            if (ci == null)
            {
                throw new ServiceException(typ + " missing ServiceContext");
            }

            S service = (S)ci.Invoke(new object[] { sc });

            Services.Add(service);
            return(true);
        }