public JMbr(string name, JObj v) { this.name = name; type = JType.Object; refv = v; numv = default(JNumber); }
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); }
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); }
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); }
public bool Get <D>(string name, ref D v, int proj = 0x00ff) where D : IData, new() { JMbr mbr; if (TryGet(name, out mbr)) { JObj jobj = mbr; if (jobj != null) { v = new D(); v.Read(jobj); } return(true); } return(false); }
public static D FileToObject <D>(string file, int proj = 0x00ff) where D : IData, new() { try { byte[] bytes = File.ReadAllBytes(file); JObj jo = (JObj) new JsonParse(bytes, bytes.Length).Parse(); if (jo != null) { return(jo.ToObject <D>(proj)); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(default(D)); }
public bool Get(string name, ref JObj v) { try { int ord = reader.GetOrdinal(name); if (!reader.IsDBNull(ord)) { string str = reader.GetString(ord); JsonParse p = new JsonParse(str); v = (JObj)p.Parse(); return(true); } } catch { } return(false); }
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); }
public DbParameters Put(string name, JObj v) { if (name == null) { name = Defaults[position++]; } if (v == null) { coll.Add(new NpgsqlParameter(name, NpgsqlDbType.Jsonb) { Value = DBNull.Value }); } else { coll.Add(new NpgsqlParameter(name, NpgsqlDbType.Jsonb) { Value = v.ToString() }); } return(this); }
public bool Get <D>(string name, ref D[] v, int proj = 0x00ff) where D : IData, new() { JMbr mbr; if (TryGet(name, out 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 Dictionary <string, string> v) { JMbr mbr; if (TryGet(name, out mbr)) { if (mbr.type == JType.Object) { JObj jo = mbr; int count = jo.Count; Dictionary <string, string> dict = new Dictionary <string, string>(count); for (int i = 0; i < count; i++) { JMbr e = jo[i]; dict.Add(e.Name, e); } v = dict; return(true); } } return(false); }
public static D StringToObject <D>(string v, int proj = 0x00ff) where D : IData, new() { JObj jo = (JObj) new JsonParse(v).Parse(); return(jo.ToObject <D>(proj)); }
internal void Add(string name, JObj v) { Add(new JMbr(name, v)); }
public bool Get(string name, ref DateTime v) { JObj jo = elements[current]; return(jo != null && jo.Get(name, ref v)); }
public bool Get <D>(string name, ref D[] v, int proj = 0x00ff) where D : IData, new() { JObj jo = elements[current]; return(jo != null && jo.Get(name, ref v)); }
public bool Get(string name, ref ArraySegment <byte> v) { JObj jo = elements[current]; return(jo != null && jo.Get(name, ref v)); }