Beispiel #1
0
        /// <summary>
        /// Dump database converting to most recent version syntax
        /// </summary>
        public void Dump(TextWriter writer)
        {
            // do not include this collections now
            var specials = new string[] { "_master", "_files", "_chunks" };

            foreach (var name in _db.GetCollections().Where(x => !specials.Contains(x)))
            {
                var col     = _db.GetCollection(name);
                var indexes = col.GetIndexes().Where(x => x["field"] != "_id");

                writer.WriteLine("-- Collection '{0}'", name);

                foreach (var index in indexes)
                {
                    writer.WriteLine("db.{0}.ensureIndex {1} {2}",
                                     name,
                                     index["field"].AsString,
                                     JsonEx.Serialize(index));
                }

                foreach (var doc in col.Find(Query.All()))
                {
                    writer.WriteLine("db.{0}.insert {1}", name, JsonEx.Serialize(doc));
                }
            }

            // convert FileStorage to new format
            var files  = _db.GetCollection("_files");
            var chunks = _db.GetCollection("_chunks");

            if (files.Count() == 0)
            {
                return;
            }

            writer.WriteLine("-- FileStorage: _files");

            foreach (var file in files.Find(Query.All()))
            {
                // adding missing values
                file["chunks"] = chunks.Count(Query.StartsWith("_id", file.Id + @"\"));

                writer.WriteLine("db._files.insert {0}", JsonEx.Serialize(file));
            }

            writer.WriteLine("-- FileStorage: _chunks");

            foreach (var chunk in chunks.Find(Query.All()))
            {
                // adding _id format 00000
                chunk.Id = string.Format("{0}\\{1:00000}",
                                         chunk.Id.ToString().Substring(0, chunk.Id.ToString().IndexOf('\\')),
                                         Convert.ToInt32(chunk.Id.ToString().Substring(chunk.Id.ToString().IndexOf('\\') + 1)));

                writer.WriteLine("db._chunks.insert {0}", JsonEx.Serialize(chunk));
            }
        }
Beispiel #2
0
 public void Store(string key, object value)
 {
     try
     {
         _database.StringSet(key, JsonEx.Serialize(value));
     }
     catch (Exception ex)
     {
         //log here exception
     }
 }
Beispiel #3
0
 public void Store(string key, object value)
 {
     try
     {
         _client.Store(StoreMode.Set, key, JsonEx.Serialize(value));
     }
     catch (Exception ex)
     {
         //log here exception
     }
 }
Beispiel #4
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);
        }
Beispiel #5
0
 public void WriteBson(BsonValue result)
 {
     this.WriteLine(ConsoleColor.DarkCyan, JsonEx.Serialize(result, this.Pretty, false));
 }