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); }
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 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(); }
private bool ValidateForm() { bool isTextFieldsFilled = true; this.Height = 255; if (tbFilePath.Text.Equals("")) { lblFilePath.ForeColor = Color.Red; isTextFieldsFilled = false; lblStatus.Text = "Please fill in the required information."; } else lblFilePath.ForeColor = Color.Black; if (tbClusterSize.Text.Equals("")) { lblClusterSize.ForeColor = Color.Red; isTextFieldsFilled = false; lblStatus.Text = "Please fill in the required information."; } else lblClusterSize.ForeColor = Color.Black; if (!isTextFieldsFilled) return false; int clusterSize; if (!Int32.TryParse(tbClusterSize.Text, out clusterSize)) { lblClusterSize.ForeColor = Color.Red; lblStatus.Text = "Cluster size must be an integer."; return false; } try { if(tbHeader.Text.Equals("")) using ( FileStream file = new FileStream(tbFilePath.Text, FileMode.Open)) using (var storage = new IndexedFileStorage(file, clusterSize, checkSafeWrite.Checked)) { } else using (FileStream file = new FileStream(tbFilePath.Text, FileMode.Open)) using (var storage = new IndexedFileStorage(file, clusterSize, checkSafeWrite.Checked, tbHeader.Text)) { } } catch (Exception e) { ExceptionDialog exDialog = new ExceptionDialog("An exception occured. \nPlease check the inputed parameters.", e); exDialog.ShowDialog(); return false; } if(tbHeader.Text.Equals("")) parent.setStorageInformation(tbFilePath.Text, clusterSize, checkSafeWrite.Checked); else parent.setStorageInformation(tbFilePath.Text, clusterSize, checkSafeWrite.Checked, tbHeader.Text); return true; }
private void btnCreateGVFile_Click(object sender, EventArgs e) { disableControls(); this.Cursor = Cursors.WaitCursor; Application.DoEvents(); try { string gvContent = null; string chosenTypeName = null; //Opening the storage using (FileStream file = new FileStream(filePath, FileMode.Open)) using (var storage = new IndexedFileStorage(file, clusterSize, safeWrite, header)) { TypesVisualisationService typesVisualisationService = new TypesVisualisationService(storage); string rootTypeName = typesVisualisationService.getRootTypeName(); if (rbRootType.Checked) { chosenTypeName = rootTypeName; gvContent = typesVisualisationService.GetGraphVizContentFromStorage(storage); } else { //Opening the dialog for choosing a type. ChooseTypeForm chooseTypeForm = new ChooseTypeForm(typesVisualisationService.GetTypeVisualUnits(typesVisualisationService.GetRootTypeId()), rootTypeName); if (chooseTypeForm.ShowDialog() == DialogResult.OK) { chosenTypeName = chooseTypeForm.CurrentType.Name; gvContent = typesVisualisationService.GetGraphVizContentFromStorage(chosenTypeName, storage); } } } if (gvContent != null) { this.Cursor = Cursors.WaitCursor; Application.DoEvents(); //creating the filename for the image. string fileLocation = filePath.Substring(0, filePath.LastIndexOf("\\") + 1); string fileName = Path.GetFileNameWithoutExtension(filePath) + "_" + chosenTypeName; string pngExtension = ".png"; string newFilePathPng = fileLocation + fileName + pngExtension; int occurance = 0; while (File.Exists(newFilePathPng)) { occurance++; newFilePathPng = fileLocation + fileName + occurance + pngExtension; } //Calling dot.exe to generate the image. var getStartProcessQuery = new GetStartProcessQuery(); var getProcessStartInfoQuery = new GetProcessStartInfoQuery(); var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery); var wrapper = new GraphVizWrapper.GraphVizWrapper(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand); byte[] output = wrapper.GenerateGraph(gvContent, Enums.GraphReturnType.Png); File.WriteAllBytes(newFilePathPng, output); panStatus.Visible = true; tbStatus.Text = newFilePathPng; } } catch (FileNotFoundException ex) { String message = "File Path is invalid! The file has probably been moved or removed since opening it.\n Please check the file location."; ExceptionDialog exDialog = new ExceptionDialog(message, ex); exDialog.ShowDialog(); } catch (Exception ex) { String message = "An exception has occured. Please consult the exception log below."; ExceptionDialog exDialog = new ExceptionDialog(message, ex); exDialog.ShowDialog(); } enableControls(); this.Cursor = Cursors.Default; Application.DoEvents(); }
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); } }
private void btnCreateGVFile_Click(object sender, EventArgs e) { disableControls(); this.Cursor = Cursors.WaitCursor; Application.DoEvents(); try { string gvContent = null; string chosenTypeName = null; //Opening the storage using (FileStream file = new FileStream(filePath, FileMode.Open)) using (var storage = new IndexedFileStorage(file, clusterSize, safeWrite, header)) { TypesVisualisationService typesVisualisationService = new TypesVisualisationService(storage); string rootTypeName = typesVisualisationService.getRootTypeName(); if (rbRootType.Checked) { chosenTypeName = rootTypeName; gvContent = typesVisualisationService.GetGraphVizContentFromStorage(storage); } else { //Opening the dialog for choosing a type. ChooseTypeForm chooseTypeForm = new ChooseTypeForm(typesVisualisationService.GetTypeVisualUnits(typesVisualisationService.GetRootTypeId()), rootTypeName); if (chooseTypeForm.ShowDialog() == DialogResult.OK) { chosenTypeName = chooseTypeForm.CurrentType.Name; gvContent = typesVisualisationService.GetGraphVizContentFromStorage(chosenTypeName, storage); } } } if (gvContent != null) { this.Cursor = Cursors.WaitCursor; Application.DoEvents(); //creating the filename for the image. string fileLocation = filePath.Substring(0, filePath.LastIndexOf("\\") + 1); string fileName = Path.GetFileNameWithoutExtension(filePath) + "_" + chosenTypeName; string pngExtension = ".png"; string newFilePathPng = fileLocation + fileName + pngExtension; int occurance = 0; while (File.Exists(newFilePathPng)) { occurance++; newFilePathPng = fileLocation + fileName + occurance + pngExtension; } //Calling dot.exe to generate the image. var getStartProcessQuery = new GetStartProcessQuery(); var getProcessStartInfoQuery = new GetProcessStartInfoQuery(); var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery,getStartProcessQuery); var wrapper = new GraphVizWrapper.GraphVizWrapper(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand); byte[] output = wrapper.GenerateGraph(gvContent, Enums.GraphReturnType.Png); File.WriteAllBytes(newFilePathPng, output); panStatus.Visible = true; tbStatus.Text = newFilePathPng; } } catch (FileNotFoundException ex) { String message = "File Path is invalid! The file has probably been moved or removed since opening it.\n Please check the file location."; ExceptionDialog exDialog = new ExceptionDialog(message, ex); exDialog.ShowDialog(); } catch (Exception ex) { String message = "An exception has occured. Please consult the exception log below."; ExceptionDialog exDialog = new ExceptionDialog(message, ex); exDialog.ShowDialog(); } enableControls(); this.Cursor = Cursors.Default; Application.DoEvents(); }
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); } }
static void Main(string[] args) { Console.WriteLine("Initializing local context data"); var file = new FileStream("data.dat", FileMode.OpenOrCreate); using (var storage = new IndexedFileStorage(file, 256, true)) { using (var ctxLocal = new Context(typeof(IDataModel), null, storage)) { using (var ws = ctxLocal.OpenWorkspace <IDataModel>(IsolationLevel.Exclusive)) { ws.Data.Users = ws.New <ICollection <IUser> >(); for (int i = 0; i < 10; i++) { var user = ws.New <IUser>(); user.Username = "******" + i; user.Age = i; ws.Data.Users.Add(user); } ws.Commit(); } var ctxServer = new ServerContext(ctxLocal); Console.WriteLine("Starting server..."); BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider(); serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider(); IDictionary props = new Hashtable(); props["port"] = 5656; props["name"] = "serverChannelName"; HttpChannel channel = new HttpChannel(props, clientProv, serverProv); ChannelServices.RegisterChannel(channel, false); try { RemotingServices.Marshal(ctxServer, "ctxServer"); do { while (!Console.KeyAvailable) { Console.Clear(); Console.WriteLine("Press ESC to stop the server."); using (var ws = ctxLocal.OpenWorkspace <Execom.IOG.Distributed.Model.IDataModel>(IsolationLevel.ReadOnly)) { Console.WriteLine(ws.Data.Users.Count + " USERS "); } Thread.Sleep(5000); } }while (Console.ReadKey().Key != ConsoleKey.Escape); } finally { RemotingServices.Disconnect(ctxServer); ChannelServices.UnregisterChannel(channel); } } } }
static void Main(string[] args) { Console.WriteLine("Initializing local context data"); var file = new FileStream("data.dat", FileMode.OpenOrCreate); using (var storage = new IndexedFileStorage(file, 256, true)) { using (var ctxLocal = new Context(typeof(IDataModel), null, storage)) { using (var ws = ctxLocal.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive)) { ws.Data.Users = ws.New<ICollection<IUser>>(); for (int i = 0; i < 10; i++) { var user = ws.New<IUser>(); user.Username = "******" + i; user.Age = i; ws.Data.Users.Add(user); } ws.Commit(); } var ctxServer = new ServerContext(ctxLocal); Console.WriteLine("Starting server..."); BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider(); serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider(); IDictionary props = new Hashtable(); props["port"] = 5656; props["name"] = "serverChannelName"; HttpChannel channel = new HttpChannel(props, clientProv, serverProv); ChannelServices.RegisterChannel(channel, false); try { RemotingServices.Marshal(ctxServer, "ctxServer"); do { while (!Console.KeyAvailable) { Console.Clear(); Console.WriteLine("Press ESC to stop the server."); using (var ws = ctxLocal.OpenWorkspace<Execom.IOG.Distributed.Model.IDataModel>(IsolationLevel.ReadOnly)) { Console.WriteLine(ws.Data.Users.Count + " USERS "); } Thread.Sleep(5000); } } while (Console.ReadKey().Key != ConsoleKey.Escape); } finally { RemotingServices.Disconnect(ctxServer); ChannelServices.UnregisterChannel(channel); } } } }
private void InitializeServices(Type rootEntityType, Type[] entityTypes, UpgradeConfiguration upgradeConfiguration) { this.rootEntityType = rootEntityType; this.entityTypes = entityTypes; typesService = new TypesService(provider); objectSerializationService.TypesService = typesService; var interfaceToTypeIdMapping = typesService.InitializeTypeSystem(entityTypes); var completeTypesList = interfaceToTypeIdMapping.Keys; generationService = new GenerationService(typesService); // TODO (nsabo) Optional loading of proxy types from the given assembly (we dont want always to generate on small devices, Silverlight...) // Note: Collection/Dictionary types are not saved in the assembly var interfaceToGeneratedMapping = generationService.GenerateProxyTypes(completeTypesList, Properties.Settings.Default.SaveGeneratedAssemblyToDisk, Properties.Settings.Default.GeneratedAssemblyFileName); proxyCreatorService = new ProxyCreatorService(completeTypesList, interfaceToTypeIdMapping, interfaceToGeneratedMapping); snapshotsService = new SnapshotsService(provider); #region Parent map provider setup if (Properties.Settings.Default.ParentMappingFileStorageUsed) { // Usage of file for caching parent information var indexedFile = new IndexedFileStorage(new FileStream(this.parentMappingFileName, FileMode.Create), Properties.Settings.Default.ParentMappingFileBlockSize, false); indexedFile.Serializer = this.objectSerializationService; disposables.Add(indexedFile); var parentProviderStorage = new CachedWriteNodeProviderUnsafe <Guid, object, EdgeData>( new DirectNodeProviderUnsafe <Guid, object, EdgeData>(indexedFile, true), new LimitedDirectNodeProviderUnsafe <Guid, object, EdgeData>( new LimitedMemoryStorageUnsafe <Guid, object>(Properties.Settings.Default.ParentMappingMemoryMinimumCount, Properties.Settings.Default.ParentMappingMemoryMaximumCount), false) ); disposables.Add(parentProviderStorage); mutableParentProvider = new ParentMapProvider(parentProviderStorage, provider, null, true); } else { // Default parent information is stored in memory and has only the last snapshot available mutableParentProvider = new ParentMapProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false), provider, null, true); } #endregion #region Merge rule provider setup IMergeRuleProvider mergeRuleProvider = null; if (SnapshotIsolationEnabled) { if (Properties.Settings.Default.ConcurrencyAutoOverrideResolution) { mergeRuleProvider = new AutoOverrideMergeRuleProvider(); } else { if (Properties.Settings.Default.ConcurrencyAttributesEnabled) { mergeRuleProvider = new AttributeBasedMergeRuleProvider(typesService); } else { throw new ArgumentException("No selected provider for merge rules in snapshot isolation conflicts. Check configuration of merge rule providers."); } } } #endregion #region Setup change set provider // TODO (nsabo) Provide option for change set safety when context goes offline, OfflineWorkspaces should enable commits when context is back online if (Properties.Settings.Default.ChangeSetHistoryFileStorageUsed) { var indexedFile = new IndexedFileStorage(new FileStream(Properties.Settings.Default.ChangeSetHistoryFileStorageFileName, FileMode.Create), 256, false); indexedFile.Serializer = this.objectSerializationService; disposables.Add(indexedFile); var changeSetProviderStorage = new CachedWriteNodeProviderUnsafe <Guid, object, EdgeData>( new DirectNodeProviderUnsafe <Guid, object, EdgeData>(indexedFile, true), new LimitedDirectNodeProviderUnsafe <Guid, object, EdgeData>( new LimitedMemoryStorageUnsafe <Guid, object>(Properties.Settings.Default.ChangeSetHistoryWriteCacheMinimumCount, Properties.Settings.Default.ChangeSetHistoryWriteCacheMaximumCount), false) ); disposables.Add(changeSetProviderStorage); changeSetProvider = new TrackingChangeSetProvider(changeSetProviderStorage); } else { changeSetProvider = new TrackingChangeSetProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false)); } #endregion var immutableParentProvider = new ParentMapProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false), provider, null, false); collectedNodesProvider = new CollectedNodesProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false), provider); commitDataService = new CommitDataService(provider, typesService, snapshotsService, mutableParentProvider, immutableParentProvider, changeSetProvider, new NodeMergeExecutor(mergeRuleProvider, typesService), collectedNodesProvider); workspaceExclusiveLockProvider = new WorkspaceExclusiveLockProvider(); disposables.Add(workspaceExclusiveLockProvider); trackingWorkspaceStateProvider = new TrackingWorkspaceStateProvider(workspaceExclusiveLockProvider); objectInstancesService = new ObjectInstancesService(provider, typesService); subscriptionManagerService = new SubscriptionManagerService(typesService, objectInstancesService); workspaceFacade = new WorkspaceFacade(commitDataService, trackingWorkspaceStateProvider, subscriptionManagerService, snapshotsService, workspaceExclusiveLockProvider); backupService = new BackupService(); bool firstRun = snapshotsService.InitializeSnapshots(); if (firstRun) { InitializeDefaultSnapshot(); } else { OptimizeData(); } StaticProxyFacade.Initialize(typesService); }
private bool ValidateForm() { bool isTextFieldsFilled = true; this.Height = 255; if (tbFilePath.Text.Equals("")) { lblFilePath.ForeColor = Color.Red; isTextFieldsFilled = false; lblStatus.Text = "Please fill in the required information."; } else { lblFilePath.ForeColor = Color.Black; } if (tbClusterSize.Text.Equals("")) { lblClusterSize.ForeColor = Color.Red; isTextFieldsFilled = false; lblStatus.Text = "Please fill in the required information."; } else { lblClusterSize.ForeColor = Color.Black; } if (!isTextFieldsFilled) { return(false); } int clusterSize; if (!Int32.TryParse(tbClusterSize.Text, out clusterSize)) { lblClusterSize.ForeColor = Color.Red; lblStatus.Text = "Cluster size must be an integer."; return(false); } try { if (tbHeader.Text.Equals("")) { using (FileStream file = new FileStream(tbFilePath.Text, FileMode.Open)) using (var storage = new IndexedFileStorage(file, clusterSize, checkSafeWrite.Checked)) { } } else { using (FileStream file = new FileStream(tbFilePath.Text, FileMode.Open)) using (var storage = new IndexedFileStorage(file, clusterSize, checkSafeWrite.Checked, tbHeader.Text)) { } } } catch (Exception e) { ExceptionDialog exDialog = new ExceptionDialog("An exception occured. \nPlease check the inputed parameters.", e); exDialog.ShowDialog(); return(false); } if (tbHeader.Text.Equals("")) { parent.setStorageInformation(tbFilePath.Text, clusterSize, checkSafeWrite.Checked); } else { parent.setStorageInformation(tbFilePath.Text, clusterSize, checkSafeWrite.Checked, tbHeader.Text); } return(true); }