public void Execute(ref LiteEngine db, StringScanner s, Display display) { var col = this.ReadCollection(db, s); var filename = s.Scan(@".*"); var json = File.ReadAllText(filename, Encoding.UTF8); var docs = JsonEx.Deserialize(json); var count = 0; db.BeginTrans(); if (docs.IsArray) { foreach (var doc in docs.AsArray) { count++; col.Insert(new BsonDocument(doc)); } } else { count = 1; col.Insert(new BsonDocument(docs)); } db.Commit(); display.WriteBson(count); }
public void Json_Test() { var o = CreateDoc(); var json = JsonEx.Serialize(o, true); var d = JsonEx.Deserialize <BsonDocument>(json); Assert.AreEqual(d["Date"].AsDateTime, o["Date"].AsDateTime); Assert.AreEqual(d["CustomerId"].AsGuid, o["CustomerId"].AsGuid); Assert.AreEqual(d["Items"].AsArray.Length, o["Items"].AsArray.Length); Assert.AreEqual(d.Id, 123); Assert.AreEqual(d["_id"].AsLong, o["_id"].AsLong); }
public object Get(string key) { try { dynamic value = _client.Get(key); if (value == null) { return(null); } value = value.ToString(); return(JsonEx.Deserialize(value)); } catch (Exception ex) { //exception should be logged return(null); } }
public object Get(string key) { try { dynamic value = _database.StringGet(key); if (string.IsNullOrEmpty(value)) { return(null); } value = value.ToString(); return(JsonEx.Deserialize(value)); } catch (Exception ex) { //exception should be logged return(null); } }