コード例 #1
0
        public IEnumerable <CommitPointViewModel> GetCommitPoints(Store store, DateTime latest, DateTime earliest, int skip, int take)
        {
            var client = BrightstarService.GetClient(ConnectionString);

            return
                (client.GetCommitPoints(store.Location, latest, earliest, skip, take).Select(
                     x => new CommitPointViewModel(x)));
        }
コード例 #2
0
 /// <summary>
 /// Create a new bootstrapper from the specified configuration and root path configuration
 /// </summary>
 /// <param name="configuration">The service configuration</param>
 /// <param name="rootPath">The root path</param>
 public BrightstarBootstrapper(BrightstarServiceConfiguration configuration, string rootPath = null)
     : this(BrightstarService.GetClient(configuration.ConnectionString),
            configuration.AuthenticationProviders,
            configuration.StorePermissionsProvider,
            configuration.SystemPermissionsProvider,
            rootPath)
 {
 }
コード例 #3
0
 public ClientTestBase()
     : this(new BrightstarBootstrapper(
                BrightstarService.GetClient(),
                new IAuthenticationProvider[] { new NullAuthenticationProvider() },
                new FallbackStorePermissionsProvider(StorePermissions.All, StorePermissions.All),
                new FallbackSystemPermissionsProvider(SystemPermissions.All, SystemPermissions.All)))
 {
 }
コード例 #4
0
        private void StartExport()
        {
            var client = BrightstarService.GetClient(Store.Source.ConnectionString);

            _transactionJob = client.StartExport(Store.Location, ExportFileName, exportFormat: ExportFileFormat.Format);
            _dispatcher.BeginInvoke(DispatcherPriority.SystemIdle,
                                    new TransactionViewModel.JobMonitorDelegate(CheckJobStatus));
        }
コード例 #5
0
        public SparqlUpdateTests()
        {
#if WINDOWS_PHONE
            _client = BrightstarService.GetEmbeddedClient("brightstar");
#else
            _client = BrightstarService.GetClient("type=embedded;storesDirectory=c:\\brightstar");
#endif
        }
コード例 #6
0
        public void TestExportGraphs()
        {
            var storeName = "TestExportGraphs_" + DateTime.Now.Ticks;
            var client    = BrightstarService.GetClient("type=embedded;storesDirectory=C:\\brightstar");

            client.CreateStore(storeName);


            var job = client.StartImport(storeName, "graph_triples.nt", "http://np.com/g2");

            while (!job.JobCompletedOk && !job.JobCompletedWithErrors)
            {
                Sleep(10);
                job = client.GetJobInfo(storeName, job.JobId);
            }

            var exportFileName = "C:\\brightstar\\import\\graph_triples_out.nt";

            EnsureFileDoesNotExist(exportFileName);

            job = client.StartExport(storeName, "graph_triples_out.nt");
            while (!job.JobCompletedOk && !job.JobCompletedWithErrors)
            {
                Sleep(10);
                job = client.GetJobInfo(storeName, job.JobId);
            }

#if PORTABLE
            using (var sr = new StreamReader(_persistenceManager.GetInputStream(exportFileName)))
#else
            using (var sr = new StreamReader(exportFileName))
#endif
            {
                var content = sr.ReadToEnd();
                Assert.AreEqual(2, content.Split(new [] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Count());
                sr.Close();
            }

            exportFileName = "C:\\brightstar\\import\\graph_triples_out_2.nt";
            EnsureFileDoesNotExist(exportFileName);
            job = client.StartExport(storeName, "graph_triples_out_2.nt", "http://np.com/g1");
            while (!job.JobCompletedOk && !job.JobCompletedWithErrors)
            {
                Sleep(10);
                job = client.GetJobInfo(storeName, job.JobId);
            }

#if PORTABLE
            using (var sr = new StreamReader(_persistenceManager.GetInputStream(exportFileName)))
#else
            using (var sr = new StreamReader(exportFileName))
#endif
            {
                var content = sr.ReadToEnd();
                Assert.AreEqual(1, content.Split(new [] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Count());
                sr.Close();
            }
        }
コード例 #7
0
        public void TestGetRestDataContextByConnectionString()
        {
            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);
            Assert.AreEqual(typeof(RestDataObjectContext), context.GetType());
        }
コード例 #8
0
        public void TestInitializeFromFusekiStorageProvider()
        {
            var configFilePath   = Path.GetFullPath(Configuration.DataLocation + "dataObjectStoreConfig.ttl");
            var connectionString = "type=dotNetRdf;configuration=" + configFilePath;
            var doContext        = BrightstarService.GetDataObjectContext(connectionString);

            Assert.That(doContext.DoesStoreExist("http://www.brightstardb.com/tests#fuseki"));
            Assert.That(doContext.OpenStore("http://www.brightstardb.com/tests#fuseki"), Is.Not.Null);
        }
コード例 #9
0
        private IDataObjectStore GetDataObjectStore()
        {
            var context = BrightstarService.GetDataObjectContext(_connectionString);

            if (!context.DoesStoreExist(_storeName))
            {
                return(context.CreateStore(_storeName));
            }
            return(context.OpenStore(_storeName));
        }
コード例 #10
0
        public void TestCanConnectToConfiguredStorageProvider()
        {
            var doContext =
                BrightstarService.GetDataObjectContext("type=dotNetRdf;configuration=" + Configuration.DataLocation +
                                                       "dataObjectStoreConfig.ttl");
            // Configuration contains a single store
            var store = doContext.OpenStore("http://www.brightstardb.com/tests#people");

            Assert.That(store, Is.Not.Null);
        }
コード例 #11
0
ファイル: Connection.cs プロジェクト: ststeiger/BrightstarDB
 /// <summary>
 /// Create a client for the connection. If credentials are available they will be used, otherwise
 /// an anonymous connection will be attempted.
 /// </summary>
 /// <returns></returns>
 private IBrightstarService MakeConnection()
 {
     if (HaveCredentials())
     {
         var connectionString = String.Format("{0};userName={1};password={2}", ConnectionString, _userName,
                                              _password);
         return(BrightstarService.GetClient(connectionString));
     }
     return(BrightstarService.GetClient(ConnectionString));
 }
コード例 #12
0
        private static IDataObjectContext MakeDataObjectContext(bool optimisticLockingEnabled = false)
        {
            var connectionString = "type=rest;endpoint=http://localhost:8090/brightstar/";

            if (optimisticLockingEnabled)
            {
                connectionString += ";optimisticLocking=true";
            }
            return(BrightstarService.GetDataObjectContext(connectionString));
        }
コード例 #13
0
        public void DeleteStore(string storeName)
        {
            var client = BrightstarService.GetClient(_connectionString);

            client.DeleteStore(storeName);
            foreach (var item in Stores.Where(s => s.Location.Equals(storeName)).ToList())
            {
                Stores.Remove(item);
            }
        }
コード例 #14
0
        private static void GetValue()
        {
            var service = BrightstarService.GetClient(GetConnectionString());

            foreach (var store in service.ListStores())
            {
                var job = service.StartExport(store, FileName(store));
                jobs.Add(store, job);
            }
        }
コード例 #15
0
        public AccountRepositoryTests()
        {
            _storeName        = "AccountRepoTests_" + DateTime.Now.Ticks;
            _connectionString = "type=embedded;storesDirectory=c:\\brightstar\\;storeName=" + _storeName;
            var client = BrightstarService.GetClient(_connectionString);

            if (client.DoesStoreExist(_storeName))
            {
                client.DeleteStore(_storeName);
            }
        }
コード例 #16
0
 static IBrightstarService TryGetClient(string connectionString)
 {
     try
     {
         return(BrightstarService.GetClient(connectionString));
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #17
0
ファイル: Program.cs プロジェクト: zhuliangbing/BrightstarDB
        private static void Main()
        {
            // Register the license we are using for BrightstarDB
            SamplesConfiguration.Register();

            // Create a client - the connection string used is configured in the App.config file.
            var client =
                BrightstarService.GetClient("type=embedded;storesDirectory=" + SamplesConfiguration.StoresDirectory);

            // Create a test store and populate it with data using several transactions
            var storeName = CreateTestStore(client);

            Console.WriteLine("Initial commit points:");
            List <ICommitPointInfo> commitPoints = ListCommitPoints(client, storeName);

            // Revert to the last-but-one commit point
            Console.WriteLine("Reverting store to commit point #1");
            client.RevertToCommitPoint(storeName, commitPoints[1]);

            Console.WriteLine("Commit points after revert:");
            ListCommitPoints(client, storeName);

            // Revert back to the commit point before the first revert
            Console.WriteLine("Re-reverting store");
            client.RevertToCommitPoint(storeName, commitPoints[0]);

            Console.WriteLine("Commit points after re-revert:");
            ListCommitPoints(client, storeName);

            Console.WriteLine("Coalescing store to single commit point");
            var consolidateJob = client.ConsolidateStore(storeName);

            while (!(consolidateJob.JobCompletedOk || consolidateJob.JobCompletedWithErrors))
            {
                System.Threading.Thread.Sleep(500);
                consolidateJob = client.GetJobInfo(storeName, consolidateJob.JobId);
            }
            if (consolidateJob.JobCompletedOk)
            {
                Console.WriteLine("Consolidate job completed. Listing commit points after consolidate:");
                ListCommitPoints(client, storeName);
            }
            else
            {
                Console.WriteLine("Consolidate job failed.");
            }

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

            Console.WriteLine();
            Console.WriteLine("Finished. Press the Return key to exit.");
            Console.ReadLine();
        }
コード例 #18
0
        public ActionResult Index(string query)
        {
            if (String.IsNullOrEmpty(query))
            {
                return(View("Error"));
            }
            var client  = BrightstarService.GetClient();
            var results = client.ExecuteQuery("NerdDinner", query);

            return(new FileStreamResult(results, "application/xml; charset=utf-8"));
        }
コード例 #19
0
        public void TestEmbeddedClient()
        {
            var storeName = Guid.NewGuid().ToString();
            var client    =
                BrightstarService.GetClient("type=embedded;storesDirectory=c:\\brightstar;storeName=" + storeName);

            var tripleData =
                "<http://www.networkedplanet.com/people/gra> <<http://www.networkedplanet.com/type/worksfor> <http://www.networkedplanet.com/companies/networkedplanet> .";

            client.ExecuteTransaction(storeName, null, null, tripleData);
        }
コード例 #20
0
        public void TestCreateStoreWithTransactionLoggingEnabled()
        {
            var client = BrightstarService.GetClient(_baseConnectionString,
                                                     new EmbeddedServiceConfiguration(enableTransactionLoggingOnNewStores: true));
            var storeName = MakeStoreName("CreateStoreWithTransactionLoggingEnabled");

            client.CreateStore(storeName);
            Assert.IsTrue(File.Exists(Path.Combine(Configuration.StoreLocation, storeName, "transactionheaders.bs")));
            Assert.IsTrue(File.Exists(Path.Combine(Configuration.StoreLocation, storeName, "transactions.bs")));
            Assert.IsFalse(client.GetTransactions(storeName, 0, 10).Any()); // Will still be false as no operations executed yet
        }
コード例 #21
0
        public void TestSampleCode()
        {
            // gets a new BrightstarDB DataObjectContext
            var dataObjectContext = BrightstarService.GetDataObjectContext();

            // 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";

            // 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();

            // open store and read some data
            dynaStore = dynaContext.OpenStore(storeId);

            var id = brightstar.Identity;

            brightstar = dynaStore.GetDataObject(id);

            // property values are ALWAYS collections.
            var name = brightstar.Name.FirstOrDefault();

            Console.WriteLine("Name = " + name);

            // they can be enumerated without a cast
            foreach (var l in brightstar.rdfs__label)
            {
                Console.WriteLine("Label = " + l);
            }

            // object relationships are navigated in the same way
            var p = brightstar.rdfs__type.FirstOrDefault();

            Console.WriteLine(p.rdfs__label.FirstOrDefault());

            Console.ReadLine();
        }
コード例 #22
0
        private static void AssertStoreFromConnectionString(ConnectionString connectionString)
        {
#if SILVERLIGHT
            var service = new EmbeddedBrightstarService(connectionString.StoresDirectory);
#else
            var service = BrightstarService.GetClient(connectionString.Value);
#endif
            if (!service.DoesStoreExist(connectionString.StoreName))
            {
                service.CreateStore(connectionString.StoreName);
            }
        }
コード例 #23
0
        private void StartRemoteImport()
        {
            var client    = BrightstarService.GetClient(Store.Source.ConnectionString);
            var importJob = client.StartImport(Store.Location, ImportFileName);

            QueuedJobs.Add(new ImportJobViewModel(ImportFileName, importJob, false));
            if (!_monitorStarted)
            {
                _dispatcher.BeginInvoke(DispatcherPriority.SystemIdle,
                                        new TransactionViewModel.JobMonitorDelegate(CheckJobStatus));
            }
        }
コード例 #24
0
        public void TestSesameServerConnector()
        {
            var doContext = BrightstarService.GetDataObjectContext(
                "type=dotNetRdf;configuration=" + Configuration.DataLocation +
                "mockStorageServerConfig.ttl;storageServer=server");

            Assert.That(doContext, Is.Not.Null);

            Assert.That(doContext.DoesStoreExist("foo"), Is.True);
            Assert.That(doContext.DoesStoreExist("bar"), Is.True);
            Assert.That(doContext.DoesStoreExist("bletch"), Is.False);
        }
コード例 #25
0
        public BrightstarBootstrapper()
        {
            var config = ConfigurationManager.GetSection("brightstarService") as BrightstarServiceConfiguration;

            if (config == null)
            {
                throw new ConfigurationErrorsException(Strings.NoServiceConfiguration);
            }

            _brightstarService         = BrightstarService.GetClient(config.ConnectionString);
            _storePermissionsProvider  = config.StorePermissionsProvider;
            _systemPermissionsProvider = config.SystemPermissionsProvider;
        }
コード例 #26
0
        private void UpdateStats(RoutedEventArgs e)
        {
            var button = e.Source as Button;

            if (button != null)
            {
                _dispatcher = button.Dispatcher;
                var client = BrightstarService.GetClient(Store.Source.ConnectionString);
                _statsUpdateJob = client.UpdateStatistics(Store.Location);
                _dispatcher.BeginInvoke(DispatcherPriority.SystemIdle,
                                        new TransactionViewModel.JobMonitorDelegate(CheckJobStatus));
            }
        }
コード例 #27
0
        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);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        public void TestSpecialCharsInIdentities()
        {
            var importDir = Path.Combine(Configuration.StoreLocation, "import");

            if (!Directory.Exists(importDir))
            {
                Directory.CreateDirectory(importDir);
            }
            var testTarget = new FileInfo(importDir + Path.DirectorySeparatorChar + "persondata_en_subset.nt");

            if (!testTarget.Exists)
            {
                var testSource = new FileInfo("persondata_en_subset.nt");
                if (!testSource.Exists)
                {
                    Assert.Inconclusive("Could not locate test source file {0}. Test will not run", testSource.FullName);
                    return;
                }
                testSource.CopyTo(importDir + Path.DirectorySeparatorChar + "persondata_en_subset.nt");
            }

            var bc        = BrightstarService.GetClient("type=http;endpoint=http://localhost:8090/brightstar");
            var storeName = Guid.NewGuid().ToString();

            bc.CreateStore(storeName);
            var jobInfo = bc.StartImport(storeName, "persondata_en_subset.nt", null);

            while (!(jobInfo.JobCompletedOk || jobInfo.JobCompletedWithErrors))
            {
                Thread.Sleep(1000);
                jobInfo = bc.GetJobInfo(storeName, jobInfo.JobId);
            }
            Assert.IsTrue(jobInfo.JobCompletedOk, "Import job failed");

            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var store = context.OpenStore(storeName);

            var test = store.BindDataObjectsWithSparql("SELECT ?p WHERE {?p a <http://xmlns.com/foaf/0.1/Person>} LIMIT 30").ToList();

            Assert.IsNotNull(test);

            foreach (var testDo in test)
            {
                Assert.IsNotNull(testDo);

                var propValues = testDo.GetPropertyValues("http://xmlns.com/foaf/0.1/name").Cast <string>();
                Assert.IsNotNull(propValues);
                Assert.IsTrue(propValues.Count() > 0);
            }
        }
コード例 #30
0
        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);
        }