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


C# Database.Flush方法代码示例

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


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

示例1: SubscriberInititializes

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

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

                using (var pdb = new Database<int, MockClassA>(_testName + ".publisher" + ".database", "Id")
                    .WithPublishing("Test", new FilePublisher<int, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName))))
                {
                    pdb.Load();

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

                    using (var sdb = new Database<int, MockClassA>(_testName + ".subscriber" + ".database", "Id")
                        .WithSubscription("Test", new FileSubscriber<int, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName), new TimeSpan(0, 0, 0, 0, 500))))
                    {
                        sdb.Load();

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

                        sdb.Flush();
                    }

                    pdb.Flush();
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:29,代码来源:SubscriberTests.cs

示例2: PublisherInititializes

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

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

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

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

示例3: TcpListenerRecivesPublisher

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

            var random = new Random((int)(DateTime.Now.Ticks / 7335));

            var port = random.Next(8355, 10000);

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

                using (var pdb = new Database<int, MockClassA>(_testName + ".database", "Id")
                    .WithPublishing("Test", new TcpTransactionPublisher<int, MockClassA>(IPAddress.Parse("127.0.0.1"), port, 1, new TcpSettings())))
                {
                    pdb.Load();

                    using (var sdb = new Database<int, MockClassA>(_testName + ".subscriber" + ".database", "Id")
                        .WithSubscription("Test", new TcpTransactionSubscriber<int, MockClassA>(port)))
                    {
                        sdb.Load();

                        var obj = TestResourceFactory.CreateRandom();

                        using (var t = pdb.BeginTransaction())
                        {
                            obj.Id = pdb.Add(obj);

                            t.Commit();
                        }

                        var sw = new Stopwatch();
                        sw.Start();

                        while (sdb.Fetch(obj.Id) == null && sw.ElapsedMilliseconds < 2000)
                            Thread.Sleep(100);

                        Assert.IsNotNull(sdb.Fetch(obj.Id));

                        sdb.Flush();
                    }

                    pdb.Flush();
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:46,代码来源:TcpTests.cs

示例4: DatabaseSavesOneHundredThousandRecords

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

            decimal avgTime = 0;
            var stopWatch = new Stopwatch();

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

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

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

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds);

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

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

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds) / 2;

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

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

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds) / 2;

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

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

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds) / 2;

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    Console.WriteLine("Avg Commit time for trans with 25000 entities {0} seconds", avgTime / 1000m);

                    stopWatch.Reset();
                    stopWatch.Start();
                    Assert.AreEqual(20000, db.Select(o => o.Value<int>("Id") > 80000).Count());
                    stopWatch.Stop();

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

                    db.Flush();
                }

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

                    Assert.AreEqual(100000, len);

                    stopWatch.Reset();
                    stopWatch.Start();
                    Assert.AreEqual(20000, db.Select(o => o.Value<int>("Id") > 80000).Count());
                    stopWatch.Stop();

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

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

示例5: ApplyMigration

        /// <summary>
        /// Applies the specified <paramref name="migration"/> within the
        /// specified <paramref name="context"/>.
        /// </summary>
        /// <param name="migration">The migration to apply.</param>
        /// <param name="direction">The migration direction.</param>
        /// <param name="context">The context.</param>
        protected virtual void ApplyMigration(IMigration migration, MigrationDirection direction, MigrationContext context)
        {
            //
            // Notify environment
            //
            var beforeArgs = new BeforeMigrationEventArgs(migration.GetVersion(), migration, direction);
            OnBeforeMigration(beforeArgs);
            if (beforeArgs.Cancel) throw new Exception("environment cancelled migration");

            //
            // Generate model
            //
            Database model = new Database(context);

            //
            // Send SQL statements on flush notification
            //
            model.FlushChanges += delegate(object sender, EventArgs e)
            {
                foreach (string sql in context.SqlProvider.GenerateSqlCommands(model))
                {
                    // Notify environment
                    var beforeSqlArgs = new BeforeSqlEventArgs(sql);
                    OnBeforeSql(beforeSqlArgs);
                    if (beforeSqlArgs.Cancel) throw new Exception("environment cancelled migration");

                    // Execute
                    SqlProcessor.ProcessMigrationStatement(context, sql);

                    // Notify environment
                    var afterSqlArgs = new AfterSqlEventArgs(sql, true);
                    OnAfterSql(afterSqlArgs);
                }
            };

            //
            // Run migration
            //
            if (direction == MigrationDirection.Up)
                migration.Up(model);
            else
                migration.Down(model);

            //
            // Flush changes
            //
            model.Flush();

            //
            // Memorize migration
            //
            HistoryRepository.AddItem(context,
                new MigrationHistoryItem()
                {
                    Date = DateTime.Now,
                    Direction = direction,
                    Version = migration.GetVersion()
                }
            );

            //
            // Notify enviroment
            //
            var afterArgs = new AfterMigrationEventArgs(migration.GetVersion(), migration, direction, true);
            OnAfterMigration(afterArgs);
        }
开发者ID:stevencasey,项目名称:NMigrations,代码行数:73,代码来源:Engine.cs

示例6: PublisherUnInititializes

        public void PublisherUnInititializes()
        {
            _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")
                    .WithPublishing("Test", new FilePublisher<int, MockClassA>(_testName)))
                {
                    db.Load();

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

                    db.Flush();
                }

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

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

                    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), "*.tLock").Count());
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:38,代码来源:PublisherTests.cs

示例7: PublisherWritesTransactionOnCommit

        public void PublisherWritesTransactionOnCommit()
        {
            _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")
                    .WithPublishing("Test", new FilePublisher<int, MockClassA>(_testName)))
                {
                    db.Load();

                    Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));
                    db.Add(TestResourceFactory.CreateRandom());
                    db.Flush();
                }

                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 tran = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25).ToList().ForEach(m => db.Add(m));

                        tran.Commit();
                    }

                    while (db.FileFlushQueueActive)
                        Thread.Sleep(100);

                    Assert.Greater(Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, _testName), "*.trans").Count(), 0);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:39,代码来源:PublisherTests.cs

示例8: PubSubPicksUpOtherTransactions

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

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

                using (var pdb1 = new Database<Guid, MockClassA>(_testName + ".publisher" + ".database", "ReplicationID", new FileCore<Guid, long>())
                    .WithPublishing("Test", new FilePublisher<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName)))
                    .WithSubscription("Test", new FileSubscriber<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName), new TimeSpan(0, 0, 0, 0, 500))))
                {
                    pdb1.Load();

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

                    using (var pdb2 = new Database<Guid, MockClassA>(_testName + ".subscriber" + ".database", "ReplicationID", new FileCore<Guid, long>())
                        .WithPublishing("Test", new FilePublisher<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName)))
                        .WithSubscription("Test", new FileSubscriber<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName), new TimeSpan(0, 0, 0, 0, 500))))
                    {
                        pdb2.Load();

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

                        var objects1 = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();

                        var objects2 = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();

                        using (var tran = pdb1.BeginTransaction())
                        {
                            objects1.ForEach(o => o.ReplicationID = pdb1.Add(o));

                            tran.Commit();
                        }

                        using (var tran = pdb2.BeginTransaction())
                        {
                            objects2.ForEach(o => o.ReplicationID = pdb2.Add(o));

                            tran.Commit();
                        }

                        var sw = new Stopwatch();
                        sw.Start();

                        while (pdb2.Fetch(objects1.First().ReplicationID) == null && sw.ElapsedMilliseconds < 6000)
                            Thread.Sleep(750);

                        Assert.IsNotNull(pdb2.Fetch(objects1.First().ReplicationID));

                        sw.Reset();

                        while (pdb1.Fetch(objects2.First().ReplicationID) == null && sw.ElapsedMilliseconds < 6000)
                            Thread.Sleep(750);

                        Assert.IsNotNull(pdb1.Fetch(objects2.First().ReplicationID));

                        sw.Stop();

                        pdb2.Flush();
                    }

                    pdb1.Flush();
                }

            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:67,代码来源:MultiplePublisherSubscriberTests.cs

示例9: SecondaryIndexDeletesByIdAndByQuery

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

            var objs = TestResourceFactory.GetMockClassAObjects(2500);

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

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

                    t.Commit();
                }

                db.Flush();
            }

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

                var delete1 = objs.Skip(500).Take(500);
                var delete2 = objs.Skip(1000).Take(500);

                using (var t = db.BeginTransaction())
                {
                    foreach (var o in delete1)
                        db.Delete(o.Id);

                    t.Commit();
                }

                while (db.FileFlushQueueActive)
                    Thread.Sleep(100);

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

                using (var t = db.BeginTransaction())
                {
                    Assert.AreEqual(500, db.Delete(f => delete2.Any(a => a.Id == f.Value<int>("Id"))));

                    t.Commit();
                }

                while (db.FileFlushQueueActive)
                    Thread.Sleep(100);

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

                Assert.AreEqual(1500, db.Select(s => true).Count());
            }

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

                db.Reorganize();

                Assert.AreEqual(1500, db.Select(s => true).Count());
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:69,代码来源:SecondaryIndexTests.cs

示例10: TransactionFailsWhenUpdatingDeletedRecord

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

            var objects = TestResourceFactory.GetMockClassAObjects(12);

            using (var fLock = new ManagedFileLock(_testName + ".database"))
            {
                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.Flush();
                }

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

                    db.BeginTransaction();

                    db.Delete(d => d.Value<string>("Name").Contains("Updated"));

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

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


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