예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
            }
        }