public void TestEnumInRoot() { FileStream file = new FileStream("data.dat", FileMode.Create); IndexedFileStorage storage = new IndexedFileStorage(file, 256, true); Context ctx = new Context(typeof(IDataEnumModel), null, storage); using (var ws = ctx.OpenWorkspace <IDataEnumModel>(IsolationLevel.Exclusive)) { IDataEnumModel database = ws.Data; ws.Data.firstEnum = EnumsEnglish.FirstValue; ws.Data.secondEnum = EnumsSrpski.DrugaVrednost; ws.Data.intNumber = 100; ws.Commit(); } ctx.Dispose(); storage.Dispose(); file.Close(); file = new FileStream("data.dat", FileMode.Open); storage = new IndexedFileStorage(file, 256, true); TypesVisualisationService service = new TypesVisualisationService(storage); string content = service.GetGraphVizContentFromStorage(storage); System.IO.File.WriteAllText("TestEnumInRoot.gv", content); storage.Dispose(); file.Close(); }
static void Main(string[] args) { startMemory = GC.GetTotalMemory(false); var storage = new IndexedFileStorage(new FileStream("data.dat", FileMode.OpenOrCreate), 256, true); storage.Serializer = new ObjectSerializationService(); TestStorage(storage, maxElements); storage.Dispose(); //TestStorage(new MemoryStorage<Guid, object>(), maxElements); }
static void Main(string[] args) { startMemory = GC.GetTotalMemory(false); var storage = new IndexedFileStorage(new FileStream("data.dat", FileMode.OpenOrCreate), 256, true); storage.Serializer = new ObjectSerializationService(); TestStorage(storage, maxElements); storage.Dispose(); //TestStorage(new MemoryStorage<Guid, object>(), maxElements); }
public void TestTextTemplateGenerationRemotely() { CreateDatFile(); FileStream file = new FileStream("data.dat", FileMode.Open); IndexedFileStorage storage = new IndexedFileStorage(file, 256, true); TypesVisualisationService service = new TypesVisualisationService(storage); string content = service.GetGraphVizContentFromStorage(storage); System.IO.File.WriteAllText("templateOutputRemote.gv", content); Assert.IsTrue(true); storage.Dispose(); file.Close(); }
private void CreateDatFile() { FileStream file = new FileStream("data.dat", FileMode.Create); IndexedFileStorage storage = new IndexedFileStorage(file, 256, true); Context ctx = new Context(typeof(IDataModel), null, storage); using (var ws = ctx.OpenWorkspace <IDataModel>(IsolationLevel.Exclusive)) { IDataModel database = ws.Data; ws.Commit(); } ctx.Dispose(); storage.Dispose(); file.Close(); }
static void Main(string[] args) { // Open or create new file stream to use as storage var file = new FileStream("data.dat", FileMode.OpenOrCreate); // Initialize IOG storage in the flat file using var storage = new IndexedFileStorage(file, 256, true); // Create an IOG context in memory which has the data model of IDataModel type // Use the created storage for the context data Context ctx = new Context(typeof(IDataModel), null, storage); // Open workspace for writing using (var workspace = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive)) { // Access the data model via the current workspace IDataModel data = workspace.Data; // Write out the current data: // When running for the first time, data will be empty string // When running for the second time, data will be loaded from file Console.WriteLine(data.StringValue); // Set the value in data model data.StringValue = "Hello world!"; // Commit the change workspace.Commit(); } // Dispose the IOG storage making a clean shutdown storage.Dispose(); // Dipose the context ctx.Dispose(); }
static void Main(string[] args) { // Open or create new file stream to use as storage var file = new FileStream("data.dat", FileMode.OpenOrCreate); // Initialize IOG storage in the flat file using var storage = new IndexedFileStorage(file, 256, true); // Create an IOG context in memory which has the data model of IDataModel type // Use the created storage for the context data Context ctx = new Context(typeof(IDataModel), null, storage); // Open workspace for writing using (var workspace = ctx.OpenWorkspace <IDataModel>(IsolationLevel.Exclusive)) { // Access the data model via the current workspace IDataModel data = workspace.Data; // Write out the current data: // When running for the first time, data will be empty string // When running for the second time, data will be loaded from file Console.WriteLine(data.StringValue); // Set the value in data model data.StringValue = "Hello world!"; // Commit the change workspace.Commit(); } // Dispose the IOG storage making a clean shutdown storage.Dispose(); // Dipose the context ctx.Dispose(); }
private void CreateDatFile() { FileStream file = new FileStream("data.dat", FileMode.Create); IndexedFileStorage storage = new IndexedFileStorage(file, 256, true); Context ctx = new Context(typeof(IDataModel), null, storage); using (var ws = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive)) { IDataModel database = ws.Data; ws.Commit(); } ctx.Dispose(); storage.Dispose(); file.Close(); }
public void TestTextTemplateGenerationRemotely() { CreateDatFile(); FileStream file = new FileStream("data.dat", FileMode.Open); IndexedFileStorage storage = new IndexedFileStorage(file, 256, true); TypesVisualisationService service = new TypesVisualisationService(storage); string content = service.GetGraphVizContentFromStorage(storage); System.IO.File.WriteAllText("templateOutputRemote.gv", content); Assert.IsTrue(true); storage.Dispose(); file.Close(); }
public void TestEnumInRoot() { FileStream file = new FileStream("data.dat", FileMode.Create); IndexedFileStorage storage = new IndexedFileStorage(file, 256, true); Context ctx = new Context(typeof(IDataEnumModel), null, storage); using (var ws = ctx.OpenWorkspace<IDataEnumModel>(IsolationLevel.Exclusive)) { IDataEnumModel database = ws.Data; ws.Data.firstEnum = EnumsEnglish.FirstValue; ws.Data.secondEnum = EnumsSrpski.DrugaVrednost; ws.Data.intNumber = 100; ws.Commit(); } ctx.Dispose(); storage.Dispose(); file.Close(); file = new FileStream("data.dat", FileMode.Open); storage = new IndexedFileStorage(file, 256, true); TypesVisualisationService service = new TypesVisualisationService(storage); string content = service.GetGraphVizContentFromStorage(storage); System.IO.File.WriteAllText("TestEnumInRoot.gv", content); storage.Dispose(); file.Close(); }
static void Main(string[] args) { var file = new FileStream("data.dat", FileMode.OpenOrCreate); var storage = new IndexedFileStorage(file, 256, true); Context ctx = new Context(typeof(IDataModel), null, storage); // Initialize data for the first time creating 100 users and 100 products using (var ws = ctx.OpenWorkspace <IDataModel>(IsolationLevel.Exclusive)) { if (ws.Data.Users == null) { Console.WriteLine("Creating data for the first time"); // Create 100 users ws.Data.Users = ws.New <ICollection <IUser> >(); for (int i = 0; i < 100; i++) { IUser usr = ws.New <IUser>(); usr.Username = "******" + i; usr.Age = i; ws.Data.Users.Add(usr); } //Create 100 products ws.Data.Products = ws.New <ICollection <IProduct> >(); for (int i = 0; i < 100; i++) { IProduct prd = ws.New <IProduct>(); prd.Name = "Product" + i; prd.Price = i; ws.Data.Products.Add(prd); } // Create 100 orders ws.Data.Orders = ws.New <ICollection <IOrder> >(); for (int i = 0; i < 100; i++) { // Use LINQ to find user with appropriate age var user = ws.Data.Users.Single(u => u.Age == i); // Use LINQ to find product with appropriate price var product = ws.Data.Products.Single(p => p.Price.Equals(i)); var order = ws.New <IOrder>(); order.Date = DateTime.UtcNow; order.Product = product; order.User = user; ws.Data.Orders.Add(order); } ws.Commit(); } else { Console.WriteLine("Using data from file"); } } // We set all product prices to zero to test if orders are still ok using (var ws = ctx.OpenWorkspace <IDataModel>(IsolationLevel.Exclusive)) { foreach (var product in ws.Data.Products) { product.Price = 0; } ws.Commit(); } // List all orders which have been made by users of age greater than 75 using (var ws = ctx.OpenWorkspace <IDataModel>(IsolationLevel.Exclusive)) { // We list all products with prices Console.WriteLine("Product\tPrice"); foreach (var item in ws.Data.Products) { Console.WriteLine("{0}\t{1}", item.Name, item.Price); } var orders = ws.Data.Orders.Where(o => o.User.Age > 75); Console.WriteLine("Date\tProduct\tUser\tPrice"); foreach (var item in orders) { Console.WriteLine("{0}\t{1}\t{2}\t{3}", item.Date, item.Product.Name, item.User.Username, item.Product.Price); } } // Dispose the IOG storage making a clean shutdown storage.Dispose(); // Dispose the context ctx.Dispose(); }
static void Main(string[] args) { var file = new FileStream("data.dat", FileMode.OpenOrCreate); var storage = new IndexedFileStorage(file, 256, true); Context ctx = new Context(typeof(IDataModel), null, storage); // Initialize data for the first time creating 100 users and 100 products using (var ws = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive)) { if (ws.Data.Users == null) { Console.WriteLine("Creating data for the first time"); // Create 100 users ws.Data.Users = ws.New<ICollection<IUser>>(); for (int i = 0; i < 100; i++) { IUser usr = ws.New<IUser>(); usr.Username = "******" + i; usr.Age = i; ws.Data.Users.Add(usr); } //Create 100 products ws.Data.Products = ws.New<ICollection<IProduct>>(); for (int i = 0; i < 100; i++) { IProduct prd = ws.New<IProduct>(); prd.Name = "Product" + i; prd.Price = i; ws.Data.Products.Add(prd); } // Create 100 orders ws.Data.Orders = ws.New<ICollection<IOrder>>(); for (int i = 0; i < 100; i++) { // Use LINQ to find user with appropriate age var user = ws.Data.Users.Single(u => u.Age == i); // Use LINQ to find product with appropriate price var product = ws.Data.Products.Single(p => p.Price.Equals(i)); var order = ws.New<IOrder>(); order.Date = DateTime.UtcNow; order.Product = product; order.User = user; ws.Data.Orders.Add(order); } ws.Commit(); } else { Console.WriteLine("Using data from file"); } } // We set all product prices to zero to test if orders are still ok using (var ws = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive)) { foreach (var product in ws.Data.Products) { product.Price = 0; } ws.Commit(); } // List all orders which have been made by users of age greater than 75 using (var ws = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive)) { // We list all products with prices Console.WriteLine("Product\tPrice"); foreach (var item in ws.Data.Products) { Console.WriteLine("{0}\t{1}", item.Name, item.Price); } var orders = ws.Data.Orders.Where(o => o.User.Age > 75); Console.WriteLine("Date\tProduct\tUser\tPrice"); foreach (var item in orders) { Console.WriteLine("{0}\t{1}\t{2}\t{3}", item.Date, item.Product.Name, item.User.Username, item.Product.Price); } } // Dispose the IOG storage making a clean shutdown storage.Dispose(); // Dispose the context ctx.Dispose(); }
public void TestParentNodesIndexStorage() { var file = new FileStream("data.dat", FileMode.Create); var storage = new IndexedFileStorage(file, 256, true); Context ctx = new Context(typeof(IDatabase), null, storage); using (var ws = ctx.OpenWorkspace <IDatabase>(IsolationLevel.Exclusive)) { IDatabase database = ws.Data; var person = ws.New <IPerson>(); person.Name = "John Connor"; var car = ws.New <ICar>(); car.Model = "Renault"; person.Car = car; car = ws.New <ICar>(); car.Model = "Renault with parent"; person.CarWithParent = car; database.Person = person; Assert.AreEqual("John Connor", database.Person.Name); Assert.AreEqual("Renault", database.Person.Car.Model); Assert.AreEqual("Renault with parent", database.Person.CarWithParent.Model); Assert.AreEqual(0, ws.ParentNodes(database.Person.Car).Count); Assert.AreEqual(0, ws.ParentNodes(database.Person.CarWithParent).Count); ws.Commit(); } using (var ws = ctx.OpenWorkspace <IDatabase>(IsolationLevel.Exclusive)) { IDatabase database = ws.Data; Assert.AreEqual("John Connor", database.Person.Name); Assert.AreEqual("Renault", database.Person.Car.Model); Assert.AreEqual("Renault with parent", database.Person.CarWithParent.Model); Assert.AreEqual(0, ws.ParentNodes(database.Person.Car).Count); Assert.AreEqual(1, ws.ParentNodes(database.Person.CarWithParent).Count); Assert.AreEqual("John Connor", (ws.ParentNodes(database.Person.CarWithParent).ElementAt(0) as IPerson).Name); } ctx.Dispose(); storage.Dispose(); file.Close(); file = new FileStream("data.dat", FileMode.Open); storage = new IndexedFileStorage(file, 256, true); ctx = new Context(typeof(IDatabase), null, storage); using (var ws = ctx.OpenWorkspace <IDatabase>(IsolationLevel.Exclusive)) { IDatabase database = ws.Data; Assert.AreEqual("John Connor", database.Person.Name); Assert.AreEqual("Renault", database.Person.Car.Model); Assert.AreEqual("Renault with parent", database.Person.CarWithParent.Model); Assert.AreEqual(0, ws.ParentNodes(database.Person.Car).Count); Assert.AreEqual(1, ws.ParentNodes(database.Person.CarWithParent).Count); Assert.AreEqual("John Connor", (ws.ParentNodes(database.Person.CarWithParent).ElementAt(0) as IPerson).Name); } }
public void TestParentNodesIndexStorage() { var file = new FileStream("data.dat", FileMode.Create); var storage = new IndexedFileStorage(file, 256, true); Context ctx = new Context(typeof(IDatabase), null, storage); using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive)) { IDatabase database = ws.Data; var person = ws.New<IPerson>(); person.Name = "John Connor"; var car = ws.New<ICar>(); car.Model = "Renault"; person.Car = car; car = ws.New<ICar>(); car.Model = "Renault with parent"; person.CarWithParent = car; database.Person = person; Assert.AreEqual("John Connor", database.Person.Name); Assert.AreEqual("Renault", database.Person.Car.Model); Assert.AreEqual("Renault with parent", database.Person.CarWithParent.Model); Assert.AreEqual(0, ws.ParentNodes(database.Person.Car).Count); Assert.AreEqual(0, ws.ParentNodes(database.Person.CarWithParent).Count); ws.Commit(); } using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive)) { IDatabase database = ws.Data; Assert.AreEqual("John Connor", database.Person.Name); Assert.AreEqual("Renault", database.Person.Car.Model); Assert.AreEqual("Renault with parent", database.Person.CarWithParent.Model); Assert.AreEqual(0, ws.ParentNodes(database.Person.Car).Count); Assert.AreEqual(1, ws.ParentNodes(database.Person.CarWithParent).Count); Assert.AreEqual("John Connor", (ws.ParentNodes(database.Person.CarWithParent).ElementAt(0) as IPerson).Name); } ctx.Dispose(); storage.Dispose(); file.Close(); file = new FileStream("data.dat", FileMode.Open); storage = new IndexedFileStorage(file, 256, true); ctx = new Context(typeof(IDatabase), null, storage); using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive)) { IDatabase database = ws.Data; Assert.AreEqual("John Connor", database.Person.Name); Assert.AreEqual("Renault", database.Person.Car.Model); Assert.AreEqual("Renault with parent", database.Person.CarWithParent.Model); Assert.AreEqual(0, ws.ParentNodes(database.Person.Car).Count); Assert.AreEqual(1, ws.ParentNodes(database.Person.CarWithParent).Count); Assert.AreEqual("John Connor", (ws.ParentNodes(database.Person.CarWithParent).ElementAt(0) as IPerson).Name); } }
public void Dispose() { storage.Dispose(); }