public void CreatePonoInSpace() { Console.WriteLine("Connecting to data grid..."); ISpaceProxy spaceProxy = new SpaceProxyFactory("myDataGrid").Create(); Console.WriteLine("Write (store) a couple of entries in the data grid:"); spaceProxy.Write(new Person { Ssn = 1, FirstName = "Vincent", LastName = "Chase" }); spaceProxy.Write(new Person { Ssn = 2, FirstName = "Johnny", LastName = "Drama" }); Console.WriteLine("Read (retrieve) an entry from the grid by its id:"); Person person1 = spaceProxy.ReadById <Person>(1); person1.Should().NotBeNull(); person1.FirstName.Should().BeEquivalentTo("Vincent"); person1.LastName.Should().BeEquivalentTo("Chase"); Console.WriteLine("Result: " + person1); Console.WriteLine("Read an entry from the grid using LINQ:"); var query = from p in spaceProxy.Query <Person>() where p.FirstName == "Johnny" select p; var spaceQuery = query.ToSpaceQuery(); Person person2 = spaceProxy.Read <Person>(spaceQuery); person2.LastName.Should().BeEquivalentTo("Drama"); Console.WriteLine("Result: " + person2); Console.WriteLine("Read all entries of type Person from the grid:"); Person[] results = spaceProxy.ReadMultiple(new Person()); results.Count().Should().Be(2); Console.WriteLine("Result: " + String.Join <Person>(",", results)); }
public void CreateSpaceDocument() { using (var spaceProxy = new SpaceProxyFactory(SpaceName).Create()) { var document = CreateDocumemt(); RegisterProductTypeAt(spaceProxy); spaceProxy.Write(document); SpaceDocument template = new SpaceDocument(SpaceDocument_Product); template[Product.Properties.CatalogNumber] = "av-9876"; var readDocumentFromSpace = spaceProxy.Read(template); readDocumentFromSpace.Should().NotBeNull(); Assert.IsTrue(Equals(readDocumentFromSpace[Product.Properties.Name], "Jet Propelled Pogo Stick")); var price = readDocumentFromSpace[Product.Properties.Price]; price.Should().Be(19.99); } // Local Helpers SpaceDocument CreateDocumemt() { DocumentProperties properties = new DocumentProperties(); properties[Product.Properties.CatalogNumber] = "av-9876"; properties[Product.Properties.Category] = "Aviation"; properties[Product.Properties.Name] = "Jet Propelled Pogo Stick"; properties[Product.Properties.Price] = 19.99; properties[Product.Properties.Tags] = new String[4] { "New", "Cool", "Pogo", "Jet" }; DocumentProperties p2 = new DocumentProperties(); p2[Product.Feature.Properties.Manufacturer] = "Acme"; p2[Product.Feature.Properties.RequiresAssembly] = true; p2[Product.Feature.Properties.NumberOfParts] = 42; properties[Product.Feature.ClassName] = p2; SpaceDocument document = new SpaceDocument(Product.ClassName, properties); return(document); } void RegisterProductTypeAt(ISpaceProxy proxy) { // Create type Document descriptor: SpaceTypeDescriptorBuilder typeBuilder = new SpaceTypeDescriptorBuilder(Product.ClassName); typeBuilder.SetIdProperty(Product.Properties.CatalogNumber); typeBuilder.SetRoutingProperty(Product.Properties.Category); typeBuilder.AddPathIndex(Product.Properties.Name); typeBuilder.AddPathIndex(Product.Properties.Price, SpaceIndexType.Extended); ISpaceTypeDescriptor typeDescriptor = typeBuilder.Create(); // Register type: proxy.TypeManager.RegisterTypeDescriptor(typeDescriptor); } }