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


C# Provider.Get方法代码示例

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


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

示例1: OrphanTest

        private static void OrphanTest()
        {
            CoincidentalConfiguration config = Provider.Configure
                .Connection("test.yap")
                .ActivationDepth(1)
                .Debugging;

            using (Provider db = new Provider())
            {
                if (File.Exists("test.yap")) File.Delete("test.yap");
                db.Initialise(config);

                UnTracked untracked = db.Store(new UnTracked { Name = "UnTracked" });
                UnTracked other		= db.Store(new UnTracked { Name = "Other" });
                Tracked tracked		= db.Store(new Tracked { Name = "Tracked", ReferenceCount = 10 });

                Console.WriteLine("Initial reference count = {0}", tracked.ReferenceCount);

                try
                {
                    using (db.Lock(tracked)) tracked.ReferenceCount = 10;
                }
                catch(Exception e)
                {
                    Console.WriteLine("Exception caught: {0}", e.Message);
                }

                using (db.Lock(untracked)) untracked.Item = tracked;
                Console.WriteLine("Single reference added, count = {0}", tracked.ReferenceCount);

                using (db.Lock(other)) other.Item = tracked;
                Console.WriteLine("Single reference added to other, count = {0}", tracked.ReferenceCount);

                using (db.Lock(untracked.ItemList)) untracked.ItemList.Add(tracked);
                Console.WriteLine("Added to list, count = {0}", tracked.ReferenceCount);

                using (db.Lock(untracked)) untracked.Item = null;
                Console.WriteLine("Single reference removed, count = {0}", tracked.ReferenceCount);
            }

            using (Provider db = new Provider())
            {
                db.Initialise(config);

                UnTracked untracked = db.Get<UnTracked>(u => u.Name == "UnTracked");
                Tracked tracked		= db.Get<Tracked>(t => t.Name == "Tracked");

                Console.WriteLine("Closed and opened new provider, count = {0}", tracked.ReferenceCount);

                using (db.Lock(untracked.ItemList)) untracked.ItemList.Remove(tracked);
                Console.WriteLine("Removed from list, count = {0}", tracked.ReferenceCount);

                using (db.Lock(untracked)) untracked.Item = tracked;
                Console.WriteLine("Single reference added, count = {0}", tracked.ReferenceCount);
            }

            config = config.AutomaticOrphanPurge;

            using (Provider db = new Provider())
            {
                db.Initialise(config);

                UnTracked untracked = db.Get<UnTracked>(u => u.Name == "UnTracked");
                UnTracked other		= db.Get<UnTracked>(u => u.Name == "Other");
                Tracked tracked		= db.Get<Tracked>(t => t.Name == "Tracked");

                Console.WriteLine("Closed and opened new provider with automatic orphan purge enabled, count = {0}", tracked.ReferenceCount);

                db.Delete(other);
                Console.WriteLine("Deleted other, count = {0}", tracked.ReferenceCount);

                using (db.Lock(untracked)) untracked.Item = null;
                Console.WriteLine("Single reference removed, count = {0}", tracked.ReferenceCount);

                db.Flush();

                tracked = db.Get<Tracked>(t => t.Name == "Tracked");

                if (tracked == null) 	Console.WriteLine("Attempted to re-acquire tracked item, but it was successfully purged");
                else 					Console.WriteLine("Managed to re-acquire tracked item, automatic purging failed!");
            }
        }
开发者ID:parnham,项目名称:coincidental,代码行数:82,代码来源:Main.cs

示例2: StressTest

        private static void StressTest()
        {
            CoincidentalConfiguration config = Provider.Configure
                .Connection("test.yap")
                .ActivationDepth(1)
                .Indexing(i => i.Add<Entity>());

            using (Provider db = new Provider())
            {
                // Create new DB
                if (File.Exists("test.yap")) File.Delete("test.yap");
                db.Initialise(config);

                // Initialise DB
                Entity entity = MainClass.GetInitialData();
                db.Store(entity);

                MainClass.RunTests("First pass", 0, db);
            }

            using (Provider db = new Provider())
            {
                // Open DB
                db.Initialise(config);

                MainClass.RunTests("Second pass", 1, db);
            }

            using (Provider db = new Provider())
            {
                // Open DB
                db.Initialise(config);

                // Read results
                Entity entity = db.Get<Entity>(e => e.Name == "Test");

                Console.WriteLine("\nEntity: ");
                MainClass.PrintEntity(entity, 2);
            }
        }
开发者ID:parnham,项目名称:coincidental,代码行数:40,代码来源:Main.cs

示例3: IndexingTest

        private static void IndexingTest()
        {
            CoincidentalConfiguration config = Provider.Configure
                .Connection("test.yap")
                .ActivationDepth(1)
                .Debugging
                .Indexing(i => i.AssemblyOf<Location>());

            using (Provider db = new Provider())
            {
                if (File.Exists("test.yap")) File.Delete("test.yap");
                db.Initialise(config);

                Console.WriteLine("Preparing data...");

                for (int y = 0; y<200; y++)
                {
                    for (int x = 0; x<200; x++)
                    {
                        db.Store(new Location { X = x, Y = y, Index = ((ulong)x << 32) | (ulong)y,  Name = string.Format("{0}, {1}", x, y) });
                    }
                }
            }

            using (Provider db = new Provider())
            {
                Random random = new Random();
                db.Initialise(config);

                Stopwatch stopwatch = new Stopwatch();
                Console.WriteLine("Beginning query...");

                for (int i=0; i<10; i++)
                {
                    stopwatch.Reset();
                    stopwatch.Start();

                    Location loc = db.Get<Location>(l => l.X == random.Next(199) && l.Y == random.Next(199));

                    stopwatch.Stop();
                    Console.WriteLine("Query found: {0} ({1} ms) {2}", loc.Name, stopwatch.ElapsedMilliseconds, loc is IPersistence);
                }

                Console.WriteLine("Beginning query with index...");

                for (int i=0; i<10; i++)
                {
                    stopwatch.Reset();
                    stopwatch.Start();

                    ulong index = ((ulong)random.Next(199) << 32) | (ulong)random.Next(199);

                    Location loc = db.Get<Location>(l => l.Index == index);

                    stopwatch.Stop();
                    Console.WriteLine("Query found: {0} ({1} ms) {2}", loc.Name, stopwatch.ElapsedMilliseconds, loc is IPersistence);
                }
            }
        }
开发者ID:parnham,项目名称:coincidental,代码行数:59,代码来源:Main.cs


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