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


C# Context.OpenWorkspace方法代码示例

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


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

示例1: TestRevisionId

        public void TestRevisionId()
        {
            Context ctx = new Context(typeof(IDatabase));

            Guid lastRevision = Guid.Empty;

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;
                database.Value = 1;
                lastRevision = database.Id;

                // Test for attribute in generated type also
                Assert.AreEqual(1, database.GetType().GetProperty("Id").GetCustomAttributes(typeof(RevisionIdAttribute), false).Length);

                ws.Commit();
            }

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;
                database.Value = 2;
                ws.Commit();
                Assert.AreNotEqual(lastRevision, database.Id);
            }
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:26,代码来源:RevisionIdTest.cs

示例2: Main

        static void Main(string[] args)
        {
            // Create an IOG context in memory which has the data model of IDataModel type
            Context ctx = new Context(typeof(IDataModel));

            // Open workspace for writing
            using (var workspace = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive))
            {
                // Access the data model via the current workspace
                IDataModel data = workspace.Data;
                // Set the value in data model
                data.StringValue = "Hello world!";
                // Commit the change
                workspace.Commit();
            }

            // Open workspace for reading
            using (var workspace = ctx.OpenWorkspace<IDataModel>(IsolationLevel.ReadOnly))
            {
                // Access the data model via the current workspace
                IDataModel data = workspace.Data;
                // Display the message
                Console.Write(data.StringValue);
            }

            // Dispose the context
            ctx.Dispose();
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:28,代码来源:Program.cs

示例3: TestExclusiveCounter

        public void TestExclusiveCounter()
        {
            int nrThreads = 30;

            var ctx = new Context(typeof(IDataModel));

            Collection<Thread> threads = new Collection<Thread>();

            // Start up threads in exclusive mode
            for (int i = 0; i < nrThreads; i++)
            {
                Thread t = new Thread(() => {
                    using (var ws = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive))
                    {
                        ws.Data.Counter = ws.Data.Counter + 1;
                        ws.Commit();
                    }
                });

                t.Start();

                threads.Add(t);
            }

            // Wait for completion
            foreach (var thread in threads)
            {
                thread.Join();
            }

            using (var ws = ctx.OpenWorkspace<IDataModel>(IsolationLevel.ReadOnly))
            {
                Assert.AreEqual(nrThreads, ws.Data.Counter);
            }
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:35,代码来源:ThreadingTest.cs

示例4: TestSnapshotExclusiveCanOpen2

        public void TestSnapshotExclusiveCanOpen2()
        {
            Context ctx = new Context(typeof(IDatabase));

            var workspaceSnap = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Snapshot);
            var workspaceEx = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive);

            ctx.Dispose();
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:9,代码来源:SnapshotExclusiveTest.cs

示例5: TestSnapshotExclusiveThreads

        public void TestSnapshotExclusiveThreads()
        {
            Context ctx = new Context(typeof(IDatabase));

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                ws.Data.Data = "Initial";
                ws.Commit();
            }

            var workspaceEx = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive);

            Thread t = new Thread(() =>
            {
                using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Snapshot))
                {
                    ws.Data.Data = "Snapshot";
                    ws.Commit();
                }
            });

            t.Start();

            Thread.Sleep(500);

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.ReadOnly))
            {
                Assert.AreEqual("Initial", ws.Data.Data);
            }

            workspaceEx.Data.Data = "Exclusive";
            workspaceEx.Commit();

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.ReadOnly))
            {
                Assert.AreEqual("Exclusive", ws.Data.Data);
            }

            workspaceEx.Dispose();

            Thread.Sleep(500);

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.ReadOnly))
            {
                Assert.AreEqual("Snapshot", ws.Data.Data);
            }

            ctx.Dispose();
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:49,代码来源:SnapshotExclusiveTest.cs

示例6: SetUp

        public void SetUp()
        {
            ctx = new Context(typeof(IDatabase));

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;

                database.Integers = ws.New<IScalarSet<int>>();
                for (int i = 0; i < 20; i ++)
                {
                    database.Integers.Add(i);
                }

                database.Doubles = ws.New<IScalarSet<double>>();
                for (double i = 0; i < 10; i += 0.2)
                {
                    database.Doubles.Add(i);
                }

                database.DateTimes = ws.New<IScalarSet<DateTime>>();
                database.DateTimes.Add(dateTimeNow);

                int num = database.Integers.Single(n => n == 10);

                ws.Commit();
            }
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:28,代码来源:ScalarSetCollectionDataModel.cs

示例7: StorageServices

        /// <summary>
        /// Storage services constructor
        /// </summary>
        /// <param name="dataFilePath">Path to data file</param>
        public StorageServices(String dataFilePath)
        {
            // Initialize in-memory context
            context = new Context(typeof(SystemData), null, ConfigureStorage(dataFilePath));
            using (var iogWorkspace = context.OpenWorkspace<SystemData>(IsolationLevel.Exclusive))
            {
                // Initialize context with dummy data
                InitilazieContextWithData(iogWorkspace);

                iogWorkspace.Commit();
            }
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:16,代码来源:StorageServices.cs

示例8: TestRespawn

        public void TestRespawn()
        {
            Context ctx = new Context(typeof(IDatabase));

            Guid initialPersonId = Guid.Empty;

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;
                var person = ws.New<IPerson>();
                var car = ws.New<ICar>();
                car.Model = "model";

                person.Name = "John Connor";
                person.Car = car;

                database.Person = person;

                initialPersonId = person.RevisionId;

                ws.Commit();
            }

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;
                var person = database.Person;
                person.Name = "changed";
                person.Car.Model = "changed";

                ws.Commit();
            }

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                var initialPerson = ws.Spawn<IPerson>(initialPersonId);

                Assert.AreEqual("John Connor", initialPerson.Name);
                Assert.AreEqual("model", initialPerson.Car.Model);

                ws.Commit();
            }

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                var person = ws.Data.Person;

                Assert.AreEqual("changed", person.Name);
                Assert.AreEqual("changed", person.Car.Model);

                ws.Commit();
            }
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:53,代码来源:SpawningTest.cs

示例9: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Items,Inserts per second,Reads per second,Updates per second, Memory(MB)");

            var fs = new FileStream("data.dat", FileMode.Create);
            Context ctx = new Context(typeof(IDataModel), null, new IndexedFileStorage(fs, 512, true));
            //Context<IDataModel> ctx = new Context<IDataModel>(new Type[] { typeof(IDataModel) });

            using (var ws = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive))
            {
                if (ws.Data.PersonCollection == null)
                {
                    ws.Data.PersonCollection = ws.New<IIndexedCollection<IPerson>>();
                    ws.Commit();
                }
            }

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

            double sumInsertMs = 0;
            double sumReadMs = 0;
            double sumUpdateMs = 0;

            for (int iter = 0; iter < maxElements / batchSize; iter++)
            {

                sumInsertMs += TestInsert(sw, ctx);
                sumReadMs += TestRead(sw, ctx);
                sumUpdateMs += TestUpdate(sw, ctx);

                long memoryStatus = GC.GetTotalMemory(false) - startMemory;

                if ((iter) % reportingFrequency == 0)
                {
                    Console.WriteLine((Program.ID).ToString()
                        + "," + (1000 / (sumInsertMs / reportingFrequency))
                        + "," + (1000 / (sumReadMs / reportingFrequency))
                        + "," + (1000 / (sumUpdateMs / reportingFrequency))
                        + "," + memoryStatus / 1024 / 1024
                        );

                    sumInsertMs = 0;
                    sumReadMs = 0;
                    sumUpdateMs = 0;

                    ctx.Cleanup();
                }
            }

            ctx.Dispose();
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:52,代码来源:Program.cs

示例10: TestAddReference

        public void TestAddReference()
        {
            Context ctx = new Context(typeof(IDatabase));
            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                ws.Data.PersonCollection = ws.New<ICollection<IPerson>>();
                ws.Data.PersonCollection.Add(ws.New<IPerson>());

                ws.Data.PersonDictionary = ws.New<IDictionary<int, IPerson>>();
                ws.Data.PersonDictionary.Add(0, ws.New<IPerson>());
                IPerson per = ws.Data.PersonDictionary[0];
                per.Name = "I'm from dictionary";

                ws.Commit();
            }
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:16,代码来源:CollectionTest.cs

示例11: TestEvent

        public void TestEvent()
        {
            Context ctx = new Context(typeof(IDatabase));

            bool eventThrown = false;

            EventHandler<Events.ObjectChangedEventArgs> del = new EventHandler<Events.ObjectChangedEventArgs>((sender, args) =>
            {
                eventThrown = true;
            });

            // Create data
            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;
                var person = ws.New<IPerson>();
                var car = ws.New<ICar>();
                car.Model = "Model";

                person.Name = "John Connor";
                person.Car = car;

                database.Person = person;

                ws.Commit();

                ws.CreateSubscription(ws.Data.Person, del);
            }

            // Make changes
            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;
                database.Person.Name = "Changed";
                ws.Commit();
            }

            Assert.IsTrue(eventThrown);
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:39,代码来源:ChangeNotificationTest.cs

示例12: TestDeep

        public void TestDeep()
        {
            Context ctx = new Context(typeof(IDatabase));

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;
                var car = ws.New<ICar>();
                car.Model = "Model1";

                var person = ws.New<IPerson>();
                person.Name = "John Connor";
                person.Car = car;

                database.PermanentPerson = person;
                database.PlainPerson = person;

                ws.SetImmutable(database, "PermanentPerson");

                ws.Commit();
            }

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;
                database.PlainPerson.Car.Model = "Changed!";
                Assert.AreEqual("Changed!", database.PlainPerson.Car.Model);
                Assert.AreEqual("Model1", database.PermanentPerson.Car.Model);
                ws.Commit();
            }

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;
                Assert.AreEqual("Changed!", database.PlainPerson.Car.Model);
                Assert.AreEqual("Model1", database.PermanentPerson.Car.Model);
            }
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:38,代码来源:DynamicPermanentTest.cs

示例13: TestProperty

        public void TestProperty()
        {
            Context ctx = new Context(typeof(IDatabase));

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                ws.Data.Person = ws.New<IPerson>();
                ws.Commit();
            }

            var ws1 = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Snapshot);
            ws1.Data.Person.Name = "Name";

            var ws2 = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Snapshot);
            ws2.Data.Person.Address = "Address";

            ws1.Commit();

            Assert.AreEqual("Name", ws1.Data.Person.Name);

            ws2.Commit();

            Assert.AreEqual("Name", ws2.Data.Person.Name);
            Assert.AreEqual("Address", ws2.Data.Person.Address);

            ws1.Dispose();
            ws2.Dispose();

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.ReadOnly))
            {
                Assert.AreEqual("Name", ws.Data.Person.Name);
                Assert.AreEqual("Address", ws.Data.Person.Address);
            }
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:34,代码来源:SnapshotIsolationTest.cs

示例14: SetUp

        public void SetUp()
        {
            ctx = new Context(typeof(IDatabase));
            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;

                var person = ws.New<IPerson>();
                person.Name = "John Connor";
                person.Address = ws.New<IAddress>();
                person.Address.Name = "1st Boulevard";

                person.City = ws.New<ICity>();
                person.City.Name = "San Francisco";
                person.Car = ws.New<ICar>();
                person.Car.Model = "Ford Mustang";

                var newEvent = ws.New<IEvent>();
                newEvent.City = person.City;
                newEvent.Organizator = person;
                newEvent.Address = ws.New<IAddress>();
                newEvent.Address.Name = "12th Boulevard";
                newEvent.Address.Number = 10;

                database.PermanentPerson = person;
                database.PlainPerson = person;
                database.Event = newEvent;

                ws.Commit();
            }
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:31,代码来源:PlainDatamodelTest.cs

示例15: SetUp

        public void SetUp()
        {
            ctx = new Context(typeof(IDatabase));

            using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;

                ICollection<ICity> tempCities = ws.New<ICollection<ICity>>();

                database.Users = ws.New<ICollection<IUser>>();
                IUser user;
                ICity city;
                for (int i = 0; i < 100; i++)
                {
                    user = ws.New<IUser>();
                    user.Username = "User" + i;
                    user.Age = i;

                    city = ws.New<ICity>();
                    city.Name = "City" + i;
                    tempCities.Add(city);
                    user.City = city;

                    database.Users.Add(user);
                }

                database.States = ws.New<ICollection<IState>>();
                IState state;
                for (int i = 0; i < 2; i++)
                {
                    state = ws.New<IState>();
                    state.Name = "State" + i;
                    state.Cities = tempCities;
                    database.States.Add(state);
                }

                database.Cities = tempCities;

                //Create 100 products
                database.Products = ws.New<ICollection<IProduct>>();
                IProduct product;
                for (int i = 0; i < 100; i++)
                {
                    product = ws.New<IProduct>();
                    product.Name = "Product" + i;
                    product.Price = i;

                    database.Products.Add(product);
                }

                // Create 100 orders
                database.Orders = ws.New<ICollection<IOrder>>();
                for (int i = 0; i < 100; i++)
                {
                    // Use LINQ to find user with appropriate age
                    user = database.Users.Single(u => u.Age == i);

                    // Use LINQ to find product with appropriate price
                    product = database.Products.Single(p => p.Price.Equals(i));

                    var order = ws.New<IOrder>();
                    order.Date = DateTime.UtcNow;
                    order.Product = product;
                    order.User = user;

                    database.Orders.Add(order);
                }

                ws.Commit();
            }
        }
开发者ID:nemanjazz,项目名称:iog,代码行数:72,代码来源:CollectionDataModelTest.cs


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