当前位置: 首页>>代码示例>>C#>>正文


C# Database.FlushAll方法代码示例

本文整理汇总了C#中Database.FlushAll方法的典型用法代码示例。如果您正苦于以下问题:C# Database.FlushAll方法的具体用法?C# Database.FlushAll怎么用?C# Database.FlushAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Database的用法示例。


在下文中一共展示了Database.FlushAll方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PublisherQueuesTransactionsOnPause

        public void PublisherQueuesTransactionsOnPause()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    db.Add(TestResourceFactory.CreateRandom());

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database")
                    .WithPublishing("Test", new FilePublisher<int, MockClassA>(_testName)))
                {
                    db.Load();

                    Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));

                    using (var fs = File.Create(Path.Combine(Environment.CurrentDirectory, _testName, "test.pause")))
                    {
                        fs.Flush();
                    }

                    using (var tran = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25).ToList().ForEach(m => db.Add(m));

                        tran.Commit();
                    }

                    Thread.Sleep(100);

                    Assert.AreEqual(0, Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, _testName), "*.trans").Count());

                    File.Delete(Path.Combine(Environment.CurrentDirectory, _testName, "test.pause"));

                    Thread.Sleep(3000);

                    Assert.Greater(Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, _testName), "*.trans").Count(), 0);

                    db.FlushAll();
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:50,代码来源:PublisherTests.cs

示例2: AddOrUpdateWithoutIdAddsWithIdZeroAndUpdatesWithNonZeroId

        public void AddOrUpdateWithoutIdAddsWithIdZeroAndUpdatesWithNonZeroId()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    objs.ToList().ForEach(o => o.Id = db.AddOrUpdate(o));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);

                    Assert.IsNotNull(last);

                    last.Name = "last";

                    db.AddOrUpdate(last);

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);

                    Assert.IsNotNull(last);
                    Assert.AreEqual("last", last.Name);

                    Assert.IsNotNull(db.Fetch(objs.First().Id));

                    db.FlushAll();
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:48,代码来源:DatabaseCRUDTests.cs

示例3: DatabaseAddsUpdatesAndQueriesActiveTransaction

        public void DatabaseAddsUpdatesAndQueriesActiveTransaction()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var objects = TestResourceFactory.GetMockClassAObjects(12);

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
            {
                db.Load();

                db.BeginTransaction();

                foreach (var obj in objects)
                    db.AddOrUpdate(obj, 0);

                var update = db.Fetch(3);

                update.Name = "Updated " + update.Id;

                db.AddOrUpdate(update, update.Id);

                db.FlushAll();
            }

            using (var db = new Database<int, MockClassA>(_testName + ".database"))
            {
                db.Load();

                db.Update<MockClassA>(u => !u.Value<string>("Name").Contains("Updated"), m => m.Name = "batch " + m.Id);

                db.FlushAll();

                var old = db.Select(s => s.Value<string>("Name").Contains("Updated"));

                Assert.AreEqual(1, old.Count);
                Assert.AreEqual("Updated 3", old.Single().Name);

                var updates = db.SelectFirst(s => s.Value<string>("Name").Contains("batch"), 11);

                Assert.AreEqual(11, updates.Count);
                Assert.AreEqual(1, updates.First().Id);
                Assert.AreEqual(12, updates.Last().Id);
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:45,代码来源:DatabaseTransactionTests.cs

示例4: SelectFirstQuerySelectsFirst10Matches

        public void SelectFirstQuerySelectsFirst10Matches()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var core = new FileCore<int, long>(new Seed32(999));
            var formatter = TestResourceFactory.CreateJsonFormatterWithoutArrayFormatting();

            var stopWatch = new Stopwatch();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", core))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25000).ToList().ForEach(a => db.Add(a));

                        t.Commit();
                    }

                    stopWatch.Reset();
                    stopWatch.Start();
                    var gets = db.SelectFirst(o => o.Value<int>("Id") > 24000, 10);
                    stopWatch.Stop();

                    Console.WriteLine("query with 10 first records retreived in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    Assert.AreEqual(10, gets.Count());

                    foreach (var item in gets)
                        Assert.Greater(item.Id, 23999);

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    var len = db.Load();

                    stopWatch.Reset();
                    stopWatch.Start();
                    var gets = db.SelectFirst(o => o.Value<int>("Id") > 24000, 10);
                    stopWatch.Stop();

                    Console.WriteLine("query with 10 first records retreived in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    Assert.AreEqual(10, gets.Count());

                    foreach (var item in gets)
                        Assert.Greater(item.Id, 23999);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:57,代码来源:DatabaseQueryTests.cs

示例5: DatabaseFetchesUpdatesAndDeletesWithQueries

        public void DatabaseFetchesUpdatesAndDeletesWithQueries()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new JSONFormatter()))
                {
                    db.Load();

                    objs.ToList().ForEach(o => ids.Add(db.Add(o)));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", new JSONFormatter()))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        var last = db.SelectLast(s => true, 1).LastOrDefault();

                        Assert.IsNotNull(last);

                        db.Update(s => s.Value<string>("Name") == last.Name
                            , new System.Action<MockClassA>(a => a.Name = "last"));

                        db.Delete(s => true);

                        t.Commit();
                    }

                    var selected = db.Select(s => true);

                    Assert.AreEqual(0, selected.Count);
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", new JSONFormatter()))
                {
                    db.Load();

                    var selected = db.Select(s => true);

                    Assert.AreEqual(0, selected.Count);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:53,代码来源:DatabaseQueryTests.cs

示例6: DatabaseFetchesUpdatesAndDeletesWithSecondaryIndex

        public void DatabaseFetchesUpdatesAndDeletesWithSecondaryIndex()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var seed = new Seed32();
            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var ids = new List<int>();

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
                .WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
            {
                db.Load();

                objs.ToList().ForEach(o => ids.Add(db.Add(o)));

                db.FlushAll();
            }

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id")
                .WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
            {
                db.Load();

                var last = db.Fetch(objs.Last().Id);

                Assert.IsNotNull(last);

                last.Name = "last";

                db.Update(last, last.Id);

                db.FlushAll();
            }

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
                .WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
            {
                db.Load();

                var last = db.Fetch(objs.Last().Id);

                Assert.IsNotNull(last);
                Assert.AreEqual("last", last.Name);

                Assert.IsNotNull(db.Fetch(objs.First().Id));

                db.Delete(objs.First().Id);

                Assert.IsNull(db.Fetch(objs.First().Id));

                db.FlushAll();
            }

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
                .WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
            {
                db.Load();

                Assert.IsNull(db.Fetch(objs.First().Id));

                db.Clear();
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:64,代码来源:SecondaryIndexTests.cs

示例7: SecondaryIndexRebuldsOnLateCreate

        public void SecondaryIndexRebuldsOnLateCreate()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var objs = TestResourceFactory.GetMockClassAObjects(2500);

            objs[0].Name = "Booger";
            objs[1].Name = "Pluckers";
            objs[2].Name = "Pluckers";

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>()))
            {
                db.Load();

                using (var t = db.BeginTransaction())
                {
                    foreach (var o in objs)
                        o.Id = db.Add(o);

                    t.Commit();
                }

                db.FlushAll();
            }

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id")
                .WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
            {
                db.Load();

                var check = db.FetchFromIndex<string>("catIndex", objs.First().CatalogName);

                Assert.IsNotNull(check);
                Assert.AreEqual(1, check.Count);
                Assert.AreEqual(objs.First().Id, check[0].Id);

                check = db.FetchFromIndex<string>("catIndex", "P");

                Assert.IsNotNull(check);
                Assert.AreEqual(2, check.Count);

                //check = db.FetchRangeFromIndexInclusive<string>("catIndex", "A", "C");

                //Assert.IsNotNull(check);
                //Assert.AreEqual(2498, check.Count);
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:48,代码来源:SecondaryIndexTests.cs

示例8: DatabaseUpdatesIdFieldAndIndexes

        public void DatabaseUpdatesIdFieldAndIndexes()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    objs.ToList().ForEach(o => ids.Add(db.Add(o)));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);

                    Assert.IsNotNull(last);

                    var oldId = last.Id;
                    last.Name = "last";
                    last.Id = 1024;

                    db.Update(last, oldId);

                    last = db.Fetch(last.Id);

                    Assert.AreEqual(1024, last.Id);

                    var old = db.Fetch(oldId);

                    Assert.IsNull(old);

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);
                    Assert.IsNull(last);

                    last = db.Fetch(1024);
                    Assert.IsNotNull(last);

                    Assert.AreEqual("last", last.Name);

                    Assert.IsNotNull(db.Fetch(objs.First().Id));

                    db.Delete(new int[] { objs.First().Id, objs.Last().Id });

                    Assert.IsNull(db.Fetch(objs.First().Id));
                    Assert.IsNull(db.Fetch(objs.Last().Id));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    Assert.IsNull(db.Fetch(objs.First().Id));

                    db.Clear();
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:76,代码来源:DatabaseCRUDTests.cs

示例9: DatabaseFetchesSavedValues

        public void DatabaseFetchesSavedValues()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs= TestResourceFactory.GetMockClassAObjects(3).ToList();
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    objs.ToList().ForEach(o => ids.Add(db.Add(o)));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    db.Load();

                    foreach (var obj in objs)
                    {
                        var orig = obj as MockClassC;
                        var item = db.Fetch(obj.Id) as MockClassC;

                        Assert.AreEqual(item.Id, orig.Id);
                        Assert.AreEqual(item.Name, orig.Name);
                        Assert.AreEqual(item.GetSomeCheckSum[0], orig.GetSomeCheckSum[0]);
                        Assert.AreEqual(item.Location.X, orig.Location.X);
                        Assert.AreEqual(item.Location.Y, orig.Location.Y);
                        Assert.AreEqual(item.Location.Z, orig.Location.Z);
                        Assert.AreEqual(item.Location.W, orig.Location.W);
                        Assert.AreEqual(item.ReferenceCode, orig.ReferenceCode);
                        Assert.AreEqual(item.ReplicationID, orig.ReplicationID);
                    }
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:42,代码来源:DatabaseCRUDTests.cs

示例10: DatabaseRebuildsWithNewSeedSize

        public void DatabaseRebuildsWithNewSeedSize()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var objects = TestResourceFactory.GetMockClassAObjects(10000);

            using (var fLock = new ManagedFileLock(_testName + ".database"))
            {

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>() { InitialDbSize = 9000 }))
                {
                    db.Load();

                    using (var tran = db.BeginTransaction())
                    {

                        foreach (var obj in objects)
                            obj.Id = db.AddOrUpdate(obj, 0);

                        var update = db.Fetch(3);

                        update.Name = "Updated " + update.Id;

                        db.AddOrUpdate(update, update.Id);

                        tran.Commit();
                    }

                    db.FlushAll();
                }

                var deletes = objects.Skip(5000).Take(2500);
                var queryDeletes = objects.Skip(7500);

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    db.Load();

                    var check = db.Fetch(10000);

                    using (var tran = db.BeginTransaction())
                    {
                        deletes.ToList().ForEach(d => db.Delete(d.Id));

                        db.Delete(s => s.Value<int>("Id") >= objects.First().Id);

                        tran.Commit();
                    }
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:52,代码来源:DatabaseTransactionTests.cs


注:本文中的Database.FlushAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。