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


C# Database.Load方法代码示例

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


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

示例1: DatabaseErrosWithetId

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

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

            var stopWatch = new Stopwatch();

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

                using (var t = db.BeginTransaction())
                {
                    var a = TestResourceFactory.CreateRandom();
                    a.Id = 5;

                    var obj = JObject.FromObject(a, formatter.Serializer);

                    db.AddJObj(obj);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:25,代码来源:DatabaseServerTests.cs

示例2: SelectExpressionReturnsItems

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

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var first = objs.FirstOrDefault() as MockClassC;

            var select = new WhereExpression(
                new CompareToken("ReferenceCode", CompareEnum.Like, first.ReferenceCode),
                new CompareToken("Location.X", CompareEnum.Equals, first.Location.X),
                new CompareToken("Name", CompareEnum.Like, first.Name.Substring(1, first.Name.Length - 2)));

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

                db.Load();

                using (var t = db.BeginTransaction())
                {
                    objs.ToList().ForEach(o => o.Id = db.Add(o));

                    t.Commit();

                    var results = eval.ExecuteSelect(select);

                    Assert.AreEqual(1, results.Count);

                    MockClassC.Validate(results[0].ToObject<MockClassC>(), objs.FirstOrDefault() as MockClassC);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:33,代码来源:ExpressionResolverSelectTests.cs

示例3: 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

示例4: SelectExpressionReturnsFirstItems

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

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var max = objs.Cast<MockClassC>().Max(o => o.Location.X);
            var min = objs.Cast<MockClassC>().Min(o => o.Location.X);

            var first = objs.FirstOrDefault() as MockClassC;

            var select = new WhereExpression(10, true, new CompareToken("Location.X", CompareEnum.Greater, max - min));

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

                db.Load();

                using (var t = db.BeginTransaction())
                {
                    objs.ToList().ForEach(o => o.Id = db.Add(o));

                    t.Commit();

                    var results = eval.ExecuteSelect(select);

                    Assert.LessOrEqual(results.Count, 10);

                    foreach (var result in results)
                        MockClassC.Validate(result.ToObject<MockClassC>(), objs.FirstOrDefault(o => o.Id == result.Value<int>("Id")) as MockClassC);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:34,代码来源:ExpressionResolverSelectTests.cs

示例5: DatabasedisallowsDuplicateIndexName

 public void DatabasedisallowsDuplicateIndexName()
 {
     using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
         .WithIndex<string>("catIndex", "CatalogName", new BinConverterString())
         .WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
     {
         db.Load();
     }
 }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:9,代码来源:SecondaryIndexTests.cs

示例6: UpdateFromQuery

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

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            objs.OfType<MockClassC>().ToList().ForEach(o => o.ReferenceCode = null);

            var first = objs.FirstOrDefault() as MockClassC;
            var refCode =  "R " + new Random().Next();

            var select = new ScalarSelectExpression(
                new string[] { "Location.Y" },
                new CompareToken("Id", CompareEnum.Equals, 1),
                new CompareToken("Location.X", CompareEnum.Equals, first.Location.X),
                new CompareToken("Name", CompareEnum.Like, first.Name.Substring(1, first.Name.Length - 2)));

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

                db.Load();

                using (var t = db.BeginTransaction())
                {
                    objs.ToList().ForEach(o => o.Id = db.Add(o));

                    t.Commit();
                }

                using (var t = db.BeginTransaction())
                {
                    var count = eval.ExecuteUpdate(
                        new UpdateExpression(
                            typeof(MockClassC).AssemblyQualifiedName,
                            select,
                            new UpdateToken("Location.Y", 133.33, ValueEnum.Float),
                            new UpdateToken("Location.Z", 222.11, ValueEnum.Float),
                            new UpdateToken("ReferenceCode", refCode)));

                    Assert.AreEqual(1, count);

                    t.Commit();

                    var results = eval.ExecuteScaler(select);

                    Assert.AreEqual(1, results.Count);

                    Assert.AreEqual(133.33f, ((MockClassC)db.Fetch(1)).Location.Y);
                    Assert.AreEqual(222.11f, ((MockClassC)db.Fetch(1)).Location.Z);
                    Assert.AreEqual(refCode, ((MockClassC)db.Fetch(1)).ReferenceCode);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:54,代码来源:ExpressionResolverUpdateScalarTests.cs

示例7: DatabaseDeletesFirstLastWithActiveTransactions

        public void DatabaseDeletesFirstLastWithActiveTransactions()
        {
            _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();

                    var t = db.BeginTransaction();

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

                    var last = db.SelectLast(s => true, 1).LastOrDefault();

                    Assert.IsNotNull(last);

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

                    Assert.AreEqual(1, count);

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

                    Assert.AreEqual(100, selected.Count);

                    count = db.DeleteFirst(s => true, 10);

                    Assert.AreEqual(10, count);

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

                    Assert.AreEqual(90, selected.Count);

                    count = db.DeleteLast(s => true, 10);

                    Assert.AreEqual(10, count);

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

                    Assert.AreEqual(80, selected.Count);

                    t.Rollback();

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

示例8: 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

示例9: 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

示例10: Main

 private static void Main()
 {
     var dataDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data");
     //Directory.Delete(dataDirectory, true);
     using (var db = new Database(dataDirectory,
                                  x =>
                                  {
                                      x.AddProjectionsFromAssemblyContaining<Program>();
                                      x.AddQueriesFromAssemblyContaining<Program>();
                                  }))
     {
         //CreateData(db);
         var player = db.Load<Player>(1);
     }
 }
开发者ID:JonasSamuelsson,项目名称:DocuDB,代码行数:15,代码来源:Program.cs

示例11: 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

示例12: SubscriberPicksUpTransaction

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

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

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

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

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

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

                        var objects = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();
                        //objects.ForEach(o => o.ReplicationID = Guid.Empty);

                        using (var tran = pdb.BeginTransaction())
                        {
                            objects.ForEach(o => o.ReplicationID = pdb.Add(o));

                            tran.Commit();
                        }

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

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

                        Assert.IsNotNull(sdb.Fetch(objects.First().ReplicationID));

                        sdb.Flush();
                    }

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

示例13: 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

示例14: 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

示例15: DeletesFromQuery

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

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var first = objs.FirstOrDefault() as MockClassC;

            var delete = new DeleteExpression(
                new CompareToken("ReferenceCode", CompareEnum.Like, first.ReferenceCode.Substring(1, first.ReferenceCode.Length - 2)),
                new CompareToken("ReferenceCode", CompareEnum.Equals, first.ReferenceCode),
                new CompareToken("ReferenceCode", CompareEnum.NotEquals, first.Name),
                new CompareToken("ReferenceCode", CompareEnum.NotEquals, null),
                new CompareToken("Name", CompareEnum.Greater, "Z" + first.Name),
                new CompareToken("Name", CompareEnum.GreaterOrEqual, first.Name),
                new CompareToken("Name", CompareEnum.Lesser, "A" + first.Name.Substring(1, first.Name.Length - 1)),
                new CompareToken("Name", CompareEnum.LesserOrEqual, "A" + first.Name));

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

                db.Load();

                using (var t = db.BeginTransaction())
                {
                    objs.ToList().ForEach(o => o.Id = db.Add(o));

                    t.Commit();
                }

                using (var t = db.BeginTransaction())
                {
                    var results = eval.ExecuteDelete(delete);

                    Assert.AreEqual(1, results);

                    t.Commit();

                    Assert.IsNull(db.Fetch(first.Id));
                }

                Assert.IsNull(db.Fetch(first.Id));
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:45,代码来源:ExpressionResolverDeleteTests.cs


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