public void DropAndReCreateCollections()
        {
            _liteDatabase.DropCollection(UserAuthCol);
            _liteDatabase.DropCollection(UserOAuthProviderCol);

            CreateMissingCollections();
        }
Example #2
0
        public void CreateDB()
        {
            Directory.CreateDirectory(DirectoryConstants.DatabaseDirectory);

            using (var db = new LiteDatabase(DirectoryConstants.DatabaseString))
            {
                if (db.CollectionExists(m_CreaturesCollectionName))
                {
                    db.DropCollection(m_CreaturesCollectionName);
                }
                if (db.CollectionExists(m_SavedCreaturesCollectionName))
                {
                    db.DropCollection(m_SavedCreaturesCollectionName);
                }

                var collection = db.GetCollection <Creature>(m_CreaturesCollectionName);
                CreateCreatures(collection);

                // Setup indexes
                // May not need if not querying to filter
                // These caused a 3GB spike in memory usage
                //collection.EnsureIndex(x => x.Rank);
                //collection.EnsureIndex(x => x.Abilities);
            }
        }
Example #3
0
 public void DropDatabase()
 {
     using (var testDatabase = new LiteDatabase(AppDomain.CurrentDomain.BaseDirectory + "TestStorage.db"))
     {
         testDatabase.DropCollection("matches");
         testDatabase.DropCollection("servers");
     }
 }
Example #4
0
        public LiteDBTests()
        {
            db = new LiteDatabase(".\\SimpleTodoList.data");
            db.DropCollection("items");
            db.DropCollection("lists");

            lists = db.GetCollection <TodoList>("lists");
        }
Example #5
0
 public virtual void TearDown()
 {
     using (var db = new LiteDatabase("tests.db"))
     {
         db.DropCollection(typeof(GameServer).Name);
         db.DropCollection(typeof(GameMatch).Name);
     }
 }
Example #6
0
        static void Main(string[] args)
        {
            // Produts and Customer are other collections (not embedded document)
            // you can use [BsonRef("colname")] attribute

            using (var db = new LiteDatabase("LiteDB"))
            {
                db.DropCollection("customers");
                db.DropCollection("orders");
                db.DropCollection("products");
                //var mapper = BsonMapper.Global;
                //mapper.Entity<Order>()
                // .DbRef(x => x.Customer, "customers")   // 1 to 1/0 reference
                // .DbRef(x => x.Products, "products");

                var customers = db.GetCollection <Customer>("customers");
                var products  = db.GetCollection <Product>("products");
                var orders    = db.GetCollection <Order>("orders");

                var john = new Customer {
                    Name = "John Doe"
                };
                var tv = new Product {
                    Id = 1, Description = "TV Sony 44\"", Price = 799
                };
                var iphone = new Product {
                    Id = 2, Description = "iPhone X", Price = 999
                };
                List <Product> p = new List <Product>().ToList();
                p.Add(tv);
                var order1 = new Order {
                    OrderDate = new DateTime(2017, 1, 1), Customer = john, Products = p
                };
                var order2 = new Order {
                    OrderDate = new DateTime(2017, 10, 1), Customer = john
                };
                customers.Insert(john);
                products.Insert(new Product[] { tv, iphone });
                orders.Insert(order1);
                // products.Delete(1);
                var result = orders
                             .Include(x => x.Customer)
                             .Include(x => x.Products).FindAll();


                foreach (var o in result)
                {
                    Console.WriteLine("name:{0}", o.Customer.Name.ToString());

                    foreach (Product p1 in o.Products)
                    {
                        Console.WriteLine(String.Format("{0},{1:0.00}", p1.Description, p1.Price));
                    }

                    Console.ReadLine();
                }
            }
        }
Example #7
0
 public void Delete()
 {
     if (!disposed)
     {
         connection.DropCollection(typeof(Artist).Name);
         connection.DropCollection(typeof(Album).Name);
         connection.DropCollection(typeof(Song).Name);
     }
 }
        public void BeforeEachTest()
        {
            Database = new LiteDatabase("test.db");
            Users    = Database.GetCollection <IdentityUser>("users");
            Roles    = Database.GetCollection <IdentityRole>("roles");

            Database.DropCollection("users");
            Database.DropCollection("roles");
        }
Example #9
0
        public void Clear()
        {
            using (var db = new LiteDatabase(ConnectionString))
            {
                db.DropCollection(GroupsCollection);
                db.DropCollection(ContactsCollection);

                var groups = GetGroupsCollection(db);
                groups.Insert(dbDummyData.CreateDefaultGroup());
            }
        }
        /// <summary>
        /// Retrieve the wallet contract according to transaction ID from the local data store. If not found, retrieve through the blockchain API.
        /// </summary>
        /// <param name="txid">Bitcoin-compatible transaction ID</param>
        /// <returns>Return a wallet contract if found. Return null object if not found.</returns>
        public async Task <WalletContract> FindContract(string txid)
        {
            WalletContract existing = null;

            existing = collection.Find(c => c.ID == txid).FirstOrDefault();

            if (existing != null)
            {
                return(existing);
            }
            else
            {
                try
                {
                    var transaction = await insightAPI.GetTransactionInfo(txid);

                    var detectedWallet = new WalletContract();
                    detectedWallet.ID = txid;
                    detectedWallet.OwnerPublicAddress = transaction.GetOwnerAddress();
                    var op_return = transaction.GetOP_RETURN();
                    if (!op_return.StartsWith(DomainHex))
                    {
                        return(null);
                    }
                    var startBit = 32;
                    detectedWallet.NameHex = op_return.Substring(startBit, 16);
                    startBit += 16;
                    detectedWallet.TokenHex = op_return.Substring(startBit, 16);
                    startBit += 16;
                    detectedWallet.TotalSupply = BitConverterExtension.ToDecimal(op_return.Substring(startBit, 32));
                    startBit += 32;
                    detectedWallet.NoOfDecimal = ushort.Parse(op_return.Substring(startBit, 4), System.Globalization.NumberStyles.HexNumber);
                    startBit += 4;
                    detectedWallet.Conditions = op_return.Substring(startBit, 16).StringToByteArray();
                    startBit += 16;
                    detectedWallet.StartingBlock   = transaction.blockheight;
                    detectedWallet.LastSyncedBlock = transaction.blockheight;
                    byte[] myByte    = Encoding.ASCII.GetBytes(detectedWallet.ID);
                    var    encrypted = NBitcoin.Crypto.Hashes.RIPEMD160(myByte, myByte.Length);
                    var    hashID    = encrypted.ByteArrayToString();
                    db.DropCollection($"Ledger-{hashID}");
                    db.DropCollection($"Account-{hashID}");
                    UpdateContract(detectedWallet, true);
                    return(detectedWallet);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
 public override void Clear()
 {
     using (var db = new LiteDatabase(DatabaseName))
     {
         db.DropCollection(CollectionName);
     }
 }
Example #12
0
 public void RemoveAll()
 {
     using (var db = new LiteDatabase(_storageProvider.CacheDatabase))
     {
         db.DropCollection("tracks");
     }
 }
Example #13
0
 protected override void Init()
 {
     try {
         using (LiteDatabase db = new LiteDatabase(ConnString)) {
             var col = db.GetCollection <LocalMessageData>();
             foreach (var item in col.FindAll().OrderBy(a => a.Timestamp))
             {
                 if (_records.Count < NTKeyword.LocalMessageSetCapacity)
                 {
                     _records.AddFirst(item);
                 }
                 else
                 {
                     col.Delete(item.Id);
                 }
             }
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         try {
             using (LiteDatabase db = new LiteDatabase(ConnString)) {
                 db.DropCollection(nameof(LocalMessageData));
             }
         }
         catch {
         }
     }
     foreach (var item in _records.Take(50).Reverse())
     {
         LocalMessageDtoSet.Add(item.ToDto());
     }
 }
Example #14
0
 public void ResetCollection()
 {
     using (var db = new LiteDatabase(Path))
     {
         db.DropCollection(Collection);
     }
 }
Example #15
0
        public void Setup()
        {
            var collections = _db.GetCollectionNames().ToList();

            foreach (var collection in collections)
            {
                _db.DropCollection(collection);
            }

            var data = new List <BsonDocument>
            {
                new BsonDocument {
                    ["_id"] = "language", ["Value"] = "C#"
                },
                new BsonDocument {
                    ["_id"] = "cloud", ["Value"] = "Amazon"
                },
                new BsonDocument {
                    ["_id"] = "sql", ["Value"] = "Postgres"
                }
            };

            var dataCollection = _db.GetCollection(DataCollectionName);

            dataCollection.InsertBulk(data);
            dataCollection.EnsureIndex("_id", true);
        }
Example #16
0
 public void Drop()
 {
     using (LiteDatabase _liteDb = new LiteDatabase(LiteDBLocation))
     {
         _liteDb.DropCollection(CollectionName);
     }
 }
        public static void DeleteUser()
        {
            LiteDatabase db = new LiteDatabase(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "local_workin.db"));

            db.DropCollection("user");
            SecureStorageHelper.DeleteKey();
        }
Example #18
0
 //Use this with caution!
 //Kind of only suitable on reboot of the server
 public static void clearActiveUsers()
 {
     if (theDB.CollectionExists(AlbotDBDatatypes.ACTIVEUSERCOLECTION))
     {
         theDB.DropCollection(AlbotDBDatatypes.ACTIVEUSERCOLECTION);
     }
 }
Example #19
0
 public void ClearAllHistory()
 {
     using (var db = new LiteDatabase(_path))
     {
         db.DropCollection("histories");
     }
 }
Example #20
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            alarmManager = (AlarmManager)Application.Context.GetSystemService(Context.AlarmService);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            Toast.MakeText(this, "Long-press the homescreen to add the widget", ToastLength.Long).Show();
            var documentspath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            var dbpath        = Path.Combine(documentspath, "pet.db");

            Constant.dbpath = dbpath;
            using (var db = new LiteDatabase(dbpath)) {
                db.DropCollection("pet");
                var data = db.GetCollection <Pet>("pet");
                var pet  = new Pet()
                {
                    Name       = "lala",
                    Status     = (int)PetAction.Idle,
                    Hunger     = 100,
                    Thirst     = 100,
                    Happyness  = 100,
                    Sickness   = 100,
                    Sleepyness = 100,
                    Filthyness = 100
                };
                data.Insert(pet);
            }
            Finish();
        }
 public void Clear(AppSettingsType type)
 {
     using (var db = new LiteDatabase(_database))
     {
         db.DropCollection(GetTableNameFromType(type));
     }
 }
Example #22
0
 public static void DropTodos()
 {
     using (var db = new LiteDatabase(connectionString))
     {
         db.DropCollection("todos");
     }
 }
Example #23
0
 public void Cleanup()
 {
     using (var database = new LiteDatabase(ConfigurationProvider.DatabaseAddress))
     {
         database.DropCollection("Customers");
     }
 }
Example #24
0
 private void Form1_Load(object sender, EventArgs e)
 {
     _liteDatabase = new LiteDatabase(@"../../AdemOlgunerNoSQL.db");
     _liteDatabase.DropCollection("Personels");
     _personalList = GetlistPersonels(_liteDatabase);
     PersonListBindDataGrid(_personalList);
 }
        public void deleteCollection(CustomCollection collection)
        {
            var col = db.GetCollection <CustomCollection>("customCollections");

            col.Delete(Query.EQ("name", collection.name));
            db.DropCollection(collection.name);
        }
Example #26
0
 public void ClearAllMusic()
 {
     using (var db = new LiteDatabase(_path))
     {
         db.DropCollection("musics");
     }
 }
Example #27
0
        private void LoadData()
        {
            var filePath      = HttpContext.Current.Server.MapPath(string.Format("~/Data/{0}", ConfigurationHelper.DataFile));
            var list          = ReadDataHelper.Read(filePath);
            var sanityList    = list.Where(x => !string.IsNullOrEmpty(x.Documento)).ToList();
            var distinctItems = sanityList.Distinct(new DistinctItemComparer()).ToList();
            var databasePath  = HttpContext.Current.Server.MapPath(string.Format("~/Data/{0}", ConfigurationHelper.DatabaseFile));

            // Open database (or create if not exits)
            using (var db = new LiteDatabase(databasePath))
            {
                // Get customer collection
                var customers = db.GetCollection <AfiliadoModel>("customers");

                if (customers.Count() > 0)
                {
                    db.DropCollection("customers");
                    customers.DropIndex("Documento");
                }

                // Inserting a high volume of documents (Id will be auto-incremented)
                customers.InsertBulk(distinctItems);
                // Index document using a document property
                customers.EnsureIndex(x => x.Documento);
            }
        }
Example #28
0
        public void NewGame()
        {
            var settings = new EngineSettings {
                Password = "", Filename = "./Database.db"
            };
            var db = new LiteEngine(settings);

            if (db != null && liteDB == null)
            {
                liteDB = new LiteDatabase(db);
            }

            Systems = new List <SolarSystem>
            {
                NewSystem()
            };

            try
            {
                liteDB.DropCollection("systems");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            liteDB.GetCollection <SolarSystem>("systems").Insert(Systems);


            //LoadGame();

            //col.EnsureIndex(x => x.Id); //sets ID to track
        }
Example #29
0
 public void CleanCollection(string collectionName)
 {
     using (var db = new LiteDatabase(_dbPath))
     {
         db.DropCollection(collectionName);
     }
 }
Example #30
0
        public void SeedDB()
        {
            using (var db = new LiteDatabase(Constants.DB_NAME))
            {
                //clean up
                IEnumerable <string> collectionNames = db.GetCollectionNames().ToList();
                foreach (string collectionName in collectionNames)
                {
                    db.DropCollection(collectionName);
                }
            }

            //setup test data
            Employee nextMgr = new Employee()
            {
                Id = Guid.Empty
            };

            for (int i = 0; i < 99; i++)
            {
                FakeName fname                = GetAName();
                DateTime onboardDate          = DateTime.Now.AddMonths(random.Next(-100, -12));
                DateTime recentPerfReviewDate = new DateTime(DateTime.Now.Year - 1, onboardDate.Month, 1);
                Employee theNextMgr           = EmployeeFactory.CreateEmployee(fname.FirstName, fname.LastName, (Gender)GetValue(genders), fname.Email, nextMgr, (Title)GetValue(titles), (Level)GetValue(levels), random.Next(50000, 200000), random.Next(0, 10000), onboardDate);
                HistoryFactory.CreateHistory(theNextMgr, nextMgr, (Title)GetValue(titles), (Level)GetValue(levels), random.Next(50000, 200000), random.Next(0, 10000), ActionType.ANNUAL_PERFORMANCE_REVIEW, recentPerfReviewDate);
                nextMgr = theNextMgr;
            }
        }
        public void DropCollection_Test()
        {
            using (var db = new LiteDatabase(new MemoryStream()))
            {
                Assert.IsFalse(db.CollectionExists("customerCollection"));
                var collection = db.GetCollection<Customer>("customerCollection");

                collection.Insert(new Customer());
                Assert.IsTrue(db.CollectionExists("customerCollection"));

                db.DropCollection("customerCollection");
                Assert.IsFalse(db.CollectionExists("customerCollection"));
            }
        }
Example #32
0
        public void ShrinkDatabaseTest_Test()
        {
            using (var file = new TempFile())
            using (var db = new LiteDatabase(file.Filename))
            {
                var col = db.GetCollection<LargeDoc>("col");

                col.Insert(GetDocs(1, 10000));

                db.DropCollection("col");

                // full disk usage
                var size = file.Size;

                var r = db.Shrink();

                // only header page
                Assert.AreEqual(BasePage.PAGE_SIZE, size - r);
            }
        }
Example #33
0
 private void Setup()
 {
     using (var db = new LiteDatabase(_filename))
     {
         db.DropCollection("targets");
         for (var i = 0; i < 1000; i++)
         {
             db.GetCollection<Target>("targets").Insert(this.CreateTarget());
         }
     }
 }