public void TestGetHttpDataContextOpenStore()
        {
            var connectionString = "Type=rest;endpoint=http://localhost:8090/brightstar;StoreName=DataObjectTests" + Guid.NewGuid();
            var cs      = new ConnectionString(connectionString);
            var context = BrightstarService.GetDataObjectContext(cs);

            Assert.IsNotNull(context);
            var store = context.CreateStore(cs.StoreName);

            Assert.IsNotNull(store);
            store = context.OpenStore(cs.StoreName);
            Assert.IsNotNull(store);
        }
        public void TestReadWriteConnection()
        {
            var doContext =
                BrightstarService.GetDataObjectContext(
                    "type=sparql;query=http://example.org/sparql;update=http://example.org/update");

            Assert.IsNotNull(doContext);
            Assert.That(doContext.DoesStoreExist("sparql"));
            var store = doContext.OpenStore("sparql");

            Assert.That(store, Is.Not.Null);
            Assert.That(store.IsReadOnly, Is.False);
        }
        private IDataObjectContext GetContext(string type)
        {
            switch (type)
            {
            case "http":
                return(BrightstarService.GetDataObjectContext(
                           "Type=http;endpoint=http://localhost:8090/brightstar;StoreName=DynamicObjectTests" + Guid.NewGuid()));

            case "embedded":
                return(BrightstarService.GetDataObjectContext(
                           "Type=embedded;StoresDirectory=c:\\brightstar;StoreName=DynamicObjectTests-" + Guid.NewGuid()));
            }
            return(null);
        }
Beispiel #4
0
        public void InitializeDb()
        {
            var dataObjectContext = BrightstarService.GetDataObjectContext(Properties.Properties.BaseConnectionString);

            if (!dataObjectContext.DoesStoreExist(Properties.Properties.StoreName))
            {
                dataObjectContext.CreateStore(Properties.Properties.StoreName, persistenceType: PersistenceType.Rewrite);

                using (var context = DbContext.Create())
                {
                    Tools.InitDatabase.Fill(context);
                }
            }
        }
Beispiel #5
0
        public void TestConfigurationWithMultipleStores()
        {
            var doContext = BrightstarService.GetDataObjectContext(
                "type=dotNetRdf;configuration=" + Configuration.DataLocation +
                "multipleObjectStoreConfiguration.ttl");

            Assert.IsTrue(doContext.DoesStoreExist("#emptyStore"));
            Assert.IsTrue(doContext.DoesStoreExist("anotherStore"));
            Assert.IsTrue(doContext.DoesStoreExist("#yetAnotherStore"));

            // Check we can open these stores without an exception
            Assert.That(doContext.OpenStore("#emptyStore"), Is.Not.Null);
            Assert.That(doContext.OpenStore("anotherStore"), Is.Not.Null);
            Assert.That(doContext.OpenStore("#yetAnotherStore"), Is.Not.Null);
        }
Beispiel #6
0
        public void TestBasicConfigurationDoesStoreExist()
        {
            var doContext =
                BrightstarService.GetDataObjectContext("type=dotNetRdf;configuration=" + Configuration.DataLocation +
                                                       "dataObjectStoreConfig.ttl");

            // Configuration contains a single store
            Assert.IsTrue(doContext.DoesStoreExist("http://www.brightstardb.com/tests#people"));

            // Check that the other resources in the file have not been resolved to a store.
            Assert.IsFalse(doContext.DoesStoreExist("http://www.brightstardb.com/tests#peopleGraph"));       // is a graph configuration
            Assert.IsFalse(doContext.DoesStoreExist("http://www.brightstardb.com/tests#addGraph"));          // is a graph configuration
            Assert.IsFalse(doContext.DoesStoreExist("http://www.brightstardb.com/tests#peopleStoreQuery"));  // is a sparql query processor
            Assert.IsFalse(doContext.DoesStoreExist("http://www.brightstardb.com/tests#peopleStoreUpdate")); // is a sparql update processor
        }
Beispiel #7
0
        public void SetUp()
        {
            var storeName = "BasicDataObjectTests_" + DateTime.Now.Ticks;

            if (_isPersistent)
            {
                var client = BrightstarService.GetClient(_connectionString);
                if (client.DoesStoreExist(storeName))
                {
                    client.DeleteStore(storeName);
                    Thread.Sleep(500);
                }
                client.CreateStore(storeName);
            }
            _context = BrightstarService.GetDataObjectContext(_connectionString);
            _store   = _context.OpenStore(storeName, NamespaceMappings);
        }
        public void TestReadOnlyConnection()
        {
            var doContext = BrightstarService.GetDataObjectContext("type=sparql;query=http://dbpedia.org/sparql");

            Assert.IsNotNull(doContext);
            var sparqlDoContext = doContext as SparqlDataObjectContext;

            Assert.That(sparqlDoContext, Is.Not.Null);
            Assert.That(sparqlDoContext.UpdateProcessor, Is.Null);
            Assert.That(sparqlDoContext.QueryProcessor, Is.Not.Null);
            Assert.That(sparqlDoContext.OptimisticLockingEnabled, Is.False);

            // Check that the default store name has been applied
            Assert.That(doContext.DoesStoreExist("sparql"));
            var store = doContext.OpenStore("sparql");

            Assert.That(store, Is.Not.Null);
            Assert.That(store.IsReadOnly, Is.True);
        }
Beispiel #9
0
        public void TestInitializeFromInMemoryStore()
        {
            var configFilePath    = Path.GetFullPath(Configuration.DataLocation + "dataObjectStoreConfig.ttl");
            var connectionString  = "type=dotNetRdf;configuration=" + configFilePath;
            var namespaceMappings = new Dictionary <string, string>
            {
                { "npp", "http://www.networkedplanet.com/people/" },
                { "foaf", "http://xmlns.com/foaf/0.1/" }
            };
            var doContext = BrightstarService.GetDataObjectContext(connectionString);

            Assert.That(doContext, Is.Not.Null);
            Assert.That(doContext.DoesStoreExist("http://www.brightstardb.com/tests#people"));
            var doStore = doContext.OpenStore("http://www.brightstardb.com/tests#people", namespaceMappings, updateGraph: "http://example.org/people");
            var alice   = doStore.GetDataObject("npp:alice");

            Assert.That(alice, Is.Not.Null);
            var email = alice.GetPropertyValue("foaf:mbox");

            Assert.That(email, Is.Not.Null);
        }
        public void SetUp()
        {
            var storeName        = "BasicDataObjectTests_" + DateTime.Now.Ticks;
            var connectionString = new ConnectionString(String.Format(_connectionString,
                                                                      Path.GetFullPath(Configuration.DataLocation),
                                                                      Path.GetFullPath(Configuration.StoreLocation),
                                                                      storeName));

            if (_isPersistent)
            {
                var client = BrightstarService.GetClient(connectionString);
                if (client.DoesStoreExist(connectionString.StoreName))
                {
                    client.DeleteStore(connectionString.StoreName);
                    Thread.Sleep(500);
                }
                client.CreateStore(connectionString.StoreName);
            }
            _context = BrightstarService.GetDataObjectContext(connectionString);
            _store   = _context.OpenStore(connectionString.StoreName, NamespaceMappings);
        }
        public DynamicObjectSystem(string connectionString, string storeId)
        {
            _connectionString = connectionString;
            _storeId          = storeId;
            var dataObjectContext = BrightstarService.GetDataObjectContext(_connectionString);
            var dynamicContext    = new BrightstarDynamicContext(dataObjectContext);

            if (dynamicContext.DoesStoreExist(_storeId))
            {
                _dynamicStore = dynamicContext.OpenStore(_storeId, new Dictionary <string, string>()
                {
                    { "ds", UriPrefix }
                });
            }
            else
            {
                _dynamicStore = dynamicContext.CreateStore(_storeId, new Dictionary <string, string>()
                {
                    { "ds", UriPrefix }
                });
            }
        }
Beispiel #12
0
 public void TestDnrConnectionRequiresConfigurationProperty()
 {
     BrightstarService.GetDataObjectContext("type=dotnetrdf;storename=foo");
 }
Beispiel #13
0
        static void Main(string[] args)
        {
            SamplesConfiguration.Register();

            // Create a new service context using a connection string.
            var context = BrightstarService.GetDataObjectContext(@"Type=embedded;storesDirectory=" + SamplesConfiguration.StoresDirectory);

            // create a new store
            string storeName = "DataObjectLayerSample_" + Guid.NewGuid();
            var    store     = context.CreateStore(storeName);

            //In order to use simpler identities, we set up some namespace mappings to pass through when we open a store
            _namespaceMappings = new Dictionary <string, string>()
            {
                { "people", "http://example.org/people/" },
                { "skills", "http://example.org/skills/" },
                { "schema", "http://example.org/schema/" }
            };

            //Open a Data Object Store passing through the namespace mappings
            store = context.OpenStore(storeName, _namespaceMappings);

            var skillType = store.MakeDataObject("schema:skill");
            //use namespace mappings to create a number of skills
            var csharp = store.MakeDataObject("skills:csharp");

            csharp.SetType(skillType);
            var html = store.MakeDataObject("skills:html");

            html.SetType(skillType);
            var css = store.MakeDataObject("skills:css");

            css.SetType(skillType);
            var javascript = store.MakeDataObject("skills:javascript");

            javascript.SetType(skillType);

            //create a data objects for people
            var personType = store.MakeDataObject("schema:person");
            var fred       = store.MakeDataObject("people:fred");

            fred.SetType(personType);
            var william = store.MakeDataObject("people:william");

            william.SetType(personType);

            //create objects for property types for name and category
            var fullname = store.MakeDataObject("schema:person/fullName");
            var skill    = store.MakeDataObject("schema:person/skill");

            //Set the name property
            fred.SetProperty(fullname, "Fred Evans");
            //Add the skills
            fred.AddProperty(skill, csharp);
            fred.AddProperty(skill, html);
            fred.AddProperty(skill, css);

            //Set the name property
            william.SetProperty(fullname, "William Turner");
            //Add the skills
            william.AddProperty(skill, html);
            william.AddProperty(skill, css);
            william.AddProperty(skill, javascript);

            //save the changes to the store
            store.SaveChanges();

            Console.WriteLine("Added 2 data objects to store.");
            Console.WriteLine("Identity: {0}", fred.Identity);
            Console.WriteLine("Name: {0}", fred.GetPropertyValue(fullname));
            Console.WriteLine("Identity: {0}", william.Identity);
            Console.WriteLine("Name: {0}", william.GetPropertyValue(fullname));
            Console.WriteLine();

            var employeeNumber = store.MakeDataObject("schema:person/employeeNumber");
            var dateOfBirth    = store.MakeDataObject("schema:person/dateOfBirth");
            var salary         = store.MakeDataObject("schema:person/salary");

            //adding literal properties to a data object
            fred = store.GetDataObject("people:fred");
            //the datatypes are auto detected
            Console.WriteLine("Adding literal data to the person data object");
            fred.SetProperty(employeeNumber, 123);
            fred.SetProperty(dateOfBirth, DateTime.Now.AddYears(-30));
            fred.SetProperty(salary, 18000.00);

            store.SaveChanges();

            store = context.OpenStore(storeName, _namespaceMappings);

            fred = store.GetDataObject("people:fred");
            Console.WriteLine("Name: {0}", fred.GetPropertyValue(fullname));
            Console.WriteLine("Employee Number: {0}", fred.GetPropertyValue(employeeNumber));
            Console.WriteLine("Date of Birth: {0}", fred.GetPropertyValue(dateOfBirth));
            Console.WriteLine("Salary: {0:C}", fred.GetPropertyValue(salary));
            Console.WriteLine();

            // SPARQL query for all the categories connected to BrightstarDB
            const string getPersonSkillsQuery = "SELECT ?skill WHERE { <http://example.org/people/fred> <http://example.org/schema/person/skill> ?skill }";

            Console.WriteLine("Executing SPARQL query to return Fred's skills:");
            Console.WriteLine(getPersonSkillsQuery);
            var sparqlResult = store.ExecuteSparql(getPersonSkillsQuery);

            var result = sparqlResult.ResultSet;

            foreach (var sparqlResultRow in result)
            {
                var val = sparqlResultRow["skill"];
                Console.WriteLine("Skill is " + val);
            }

            Console.WriteLine();

            //connect to the store again to make sure cache is flushed
            store = context.OpenStore(storeName, _namespaceMappings);

            // SPARQL query to return URIs of all objects of the 'category' type
            const string skillsQuery = "SELECT ?skill WHERE {?skill a <http://example.org/schema/skill>}";
            //Use the BindDataObjectsWithSparql Method to pull a collection of data objects from the store that match the SPARQL query supplied
            var allSkills = store.BindDataObjectsWithSparql(skillsQuery).ToList();

            Console.WriteLine("Binding data objects with query for all skills in the store:");
            Console.WriteLine(skillsQuery);
            foreach (var s in allSkills)
            {
                Console.WriteLine("Skill is " + s.Identity);
            }

            //Delete all categories found
            Console.WriteLine();
            Console.WriteLine("Deleting all skill data objects");
            foreach (var s in allSkills)
            {
                s.Delete();
            }
            store.SaveChanges();

            //connect to the store again to make sure cache is flushed
            store     = context.OpenStore(storeName, _namespaceMappings);
            allSkills = store.BindDataObjectsWithSparql(skillsQuery).ToList();
            var skillCount = allSkills.Count;

            Console.WriteLine("Skill count after delete is " + skillCount);

            // Shutdown Brightstar processing threads.
            BrightstarService.Shutdown();

            Console.WriteLine();
            Console.WriteLine("Finished. Press Return key to exit.");
            Console.ReadLine();
        }
 private IDataObjectContext GetContext()
 {
     return(BrightstarService.GetDataObjectContext(
                "Type=rest;endpoint=http://localhost:8090/brightstar;StoreName=DataObjectTests" + Guid.NewGuid()));
 }
Beispiel #15
0
        private static void Main(string[] args)
        {
            SamplesConfiguration.Register();
            Console.WriteLine("BrightstarDB Dynamic Objects Example");
            Console.WriteLine("Creating and populating store using dynamic objects");
            // gets a new BrightstarDB DataObjectContext
            var dataObjectContext =
                BrightstarService.GetDataObjectContext("type=embedded;storesDirectory=" +
                                                       SamplesConfiguration.StoresDirectory);

            // create a dynamic context
            var dynaContext = new BrightstarDynamicContext(dataObjectContext);

            // open a new store
            var storeId   = "DynamicSample" + Guid.NewGuid().ToString();
            var dynaStore = dynaContext.CreateStore(storeId);

            // create some dynamic objects.
            dynamic brightstar = dynaStore.MakeNewObject();
            dynamic product    = dynaStore.MakeNewObject();

            // set some properties
            brightstar.name     = "BrightstarDB";
            product.rdfs__label = "Product";
            var id = brightstar.Identity;

            // use namespace mapping (RDF and RDFS are defined by default)
            // Assigning a list creates repeated RDF properties.
            brightstar.rdfs__label = new[] { "BrightstarDB", "NoSQL Database" };

            // objects are connected together in the same way
            brightstar.rdfs__type = product;

            dynaStore.SaveChanges();

            Console.WriteLine("Reading dynamic object from BrightstarDB");
            // open store and read some data
            dynaStore  = dynaContext.OpenStore(storeId);
            brightstar = dynaStore.GetDataObject(brightstar.Identity);

            Console.WriteLine("Got item with identity: {0}", brightstar.Identity);
            // property values are ALWAYS collections.
            var name = brightstar.name.FirstOrDefault();

            Console.WriteLine("\tName = {0}", name);

            // property can also be accessed by index
            var nameByIndex = brightstar.name[0];

            Console.WriteLine("\tName (using indexed property) = {0}", nameByIndex);

            // they can be enumerated without a cast
            Console.WriteLine("Enumerating rdfs:label values");
            foreach (var l in brightstar.rdfs__label)
            {
                Console.WriteLine("\tLabel = {0}", l);
            }

            // object relationships are navigated in the same way
            Console.WriteLine("Retrieving rdfs:type relationship");
            var p = brightstar.rdfs__type.FirstOrDefault();

            Console.WriteLine("\tType object ID = {0}", p.Identity);
            Console.WriteLine("\tType object label = {0}", p.rdfs__label.FirstOrDefault());

            // dynamic objects can also be loaded via sparql
            dynaStore = dynaContext.OpenStore(storeId);
            Console.WriteLine("Binding SPARQL query to dynamic objects");
            var objects = dynaStore.BindObjectsWithSparql("select distinct ?dy where { ?dy ?p ?o }");

            foreach (var obj in objects)
            {
                Console.WriteLine("\tItem Label: {0}", obj.rdfs__label[0]);
            }

            // Shutdown Brightstar processing threads.
            BrightstarService.Shutdown();

            Console.WriteLine();
            Console.WriteLine("Example complete. Press return to exit.");
            Console.ReadLine();
        }
Beispiel #16
0
 public void TestInitializeFromDnrStorageProvider()
 {
     var configFilePath   = Path.GetFullPath(Configuration.DataLocation + "dataObjectStoreConfig.ttl");
     var connectionString = "type=dotNetRdf;configuration=" + configFilePath + ";storeName=example;store=http://www.brightstardb.com/tests#fuseki";
     var doContext        = BrightstarService.GetDataObjectContext(connectionString);
 }