Ejemplo n.º 1
0
 public static void AssertTriplePatternNotInDefaultGraph(IBrightstarService client, string storeName,
                                                       string triplePattern)
 {
     var sparql = "ASK {{" + triplePattern + "}}";
     var resultsDoc = XDocument.Load(client.ExecuteQuery(storeName, sparql));
     Assert.IsFalse(resultsDoc.SparqlBooleanResult());
 }
 /// <summary>
 /// Creates a new bootstrapper that denies all anonymous access to the specified Brightstar service
 /// but grants all authenticated users full access to the service and all of its stores.
 /// </summary>
 /// <param name="brightstarService"></param>
 public BrightstarBootstrapper(IBrightstarService brightstarService)
     : this(
         brightstarService,
         new FallbackStorePermissionsProvider(StorePermissions.All),
         new FallbackSystemPermissionsProvider(SystemPermissions.All))
 {
 }
 public SparqlResultModel(string storeName, IBrightstarService service, SparqlRequestObject sparqlRequest, SparqlResultsFormat resultsFormat)
 {
     _storeName = storeName;
     _sparqlRequest = sparqlRequest;
     _service = service;
     ResultsFormat = resultsFormat;
 }
Ejemplo n.º 4
0
        public static void AssertUpdateTransaction(IBrightstarService client, string storeName, UpdateTransactionData txnData)
        {
            var job = client.ExecuteTransaction(storeName, txnData);

            job = WaitForJob(job, client, storeName);
            Assert.IsTrue(job.JobCompletedOk, "Expected update transaction to complete successfully");
        }
 public SparqlQueryProcessingModel(string storeName, IBrightstarService service, SparqlRequestObject sparqlRequest)
 {
     _storeName = storeName;
     _service = service;
     _sparqlRequest = sparqlRequest;
     ResultModel = sparqlRequest.Query == null ? SerializableModel.None : SparqlQueryHelper.GetResultModel(sparqlRequest.Query);
 }
Ejemplo n.º 6
0
        private void CRMForm_Load(object sender, EventArgs e)
        {
            // Initialise license and stores directory location
            Configuration.Register();

            //create a unique store name
            var storeName = "CRM_Ontology";

            //connection string to the BrightstarDB service
            string connectionString =
                string.Format(@"Type=embedded;storesDirectory={0};StoreName={1};", Configuration.StoresDirectory,
                              storeName);

            dataContext = new CRMOntologyContext(connectionString);
            client      = BrightstarService.GetClient(connectionString);

            //getPredicates
            XDocument xDoc = dataContext.ExecuteQuery("SELECT DISTINCT ?predicate WHERE {  ?x ?predicate ?y.}");

            foreach (var sparqlResultRow in xDoc.SparqlResultRows())
            {
                string result = sparqlResultRow.GetColumnValue("predicate").ToString();
                //beautify
                if (result.IndexOf(URI) >= 0)
                {
                    treeViewOntology.Nodes[0].Nodes[0].Nodes.Add(result, result.Replace(URI + "/", "").Replace("#", ""));
                    treeViewOntology.Nodes[0].Nodes[1].Nodes.Add(result, result.Replace(URI + "/", "").Replace("#", ""));
                }
            }
        }
Ejemplo n.º 7
0
        public SparqlModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider permissionsProvider)
        {
            this.RequiresBrightstarStorePermission(permissionsProvider, get: StorePermissions.Read, post: StorePermissions.Read);
            _brightstar = brightstarService;

            Get["/{storeName}/sparql"] = parameters =>
            {
                try
                {
                    var requestObject = BindSparqlRequestObject();
                    return(ProcessQuery(parameters["storeName"], requestObject));
                }
                catch (RdfParseException)
                {
                    return(HttpStatusCode.BadRequest);
                }
            };
            Post["/{storeName}/sparql"] = parameters =>
            {
                try
                {
                    var requestObject = BindSparqlRequestObject();
                    return(ProcessQuery(parameters["storeName"], requestObject));
                }
                catch (RdfParseException)
                {
                    return(HttpStatusCode.BadRequest);
                }
            };
            Get["/{storeName}/commits/{commitId}/sparql"]  = ProcessCommitPointQuery;
            Post["/{storeName}/commits/{commitId}/sparql"] = ProcessCommitPointQuery;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TripleStore"/> class.
        /// </summary>
        /// <param name="storeDirectory"> Directory where the store will be located</param>
        /// <param name="storeName">Name of the store</param>
        /// <param name="clearStore">True if the store needs to be cleared when opened</param>
        public TripleStore(string storeDirectory, string storeName = null, bool clearStore = false)
        {
            Contract.Requires <ArgumentNullException>(storeDirectory != null, "Store directory cannot be null.");
            Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(storeDirectory), "Store directory cannot be empty.");

            this.storeDirectory = storeDirectory;
            this.storeName      = storeName ?? DefaultStoreName;

            this.client = BrightstarService.GetClient(this.ConnectionString);

            if (this.client.DoesStoreExist(this.storeName))
            {
                // clear store if necessary
                if (clearStore)
                {
                    this.ClearStore();
                }
            }
            else
            {
                // create store if does not exists
                Logger.Info("Creating triple store {0} at {1}", this.storeName, this.storeDirectory);
                this.client.CreateStore(this.storeName);
            }
        }
        /// <summary>
        /// Creates a new bootstrapper with store and system access goverened by the specified providers.
        /// </summary>
        /// <param name="brightstarService">The connection to the BrightstarDB stores</param>
        /// <param name="authenticationProviders">An enumeration of the authentication providers to be used by the service</param>
        /// <param name="storePermissionsProvider">The store permissions provider to be used by the service</param>
        /// <param name="systemPermissionsProvider">The system permissions provider to be used by the service</param>
        /// <param name="rootPath">The path to the directory containing the service Views and assets folder</param>
        /// <exception cref="ArgumentNullException">Raised if any of the arguments to the method other than <paramref name="rootPath"/> are Null.</exception>
        public BrightstarBootstrapper(IBrightstarService brightstarService,
                                      IEnumerable <IAuthenticationProvider> authenticationProviders,
                                      AbstractStorePermissionsProvider storePermissionsProvider,
                                      AbstractSystemPermissionsProvider systemPermissionsProvider,
                                      string rootPath = null)
        {
            if (brightstarService == null)
            {
                throw new ArgumentNullException("brightstarService");
            }
            if (authenticationProviders == null)
            {
                throw new ArgumentNullException("authenticationProviders");
            }
            if (storePermissionsProvider == null)
            {
                throw new ArgumentNullException("storePermissionsProvider");
            }
            if (systemPermissionsProvider == null)
            {
                throw new ArgumentNullException("systemPermissionsProvider");
            }

            _brightstarService         = brightstarService;
            _authenticationProviders   = authenticationProviders;
            _storePermissionsProvider  = storePermissionsProvider;
            _systemPermissionsProvider = systemPermissionsProvider;
            _rootPathProvider          = (rootPath == null
                                     ? new DefaultRootPathProvider()
                                     : new FixedRootPathProvider(rootPath) as IRootPathProvider);
        }
 public SparqlQueryProcessingModel(string storeName, IBrightstarService service, SparqlRequestObject sparqlRequest)
 {
     _storeName     = storeName;
     _service       = service;
     _sparqlRequest = sparqlRequest;
     ResultModel    = sparqlRequest.Query == null ? SerializableModel.None : SparqlQueryHelper.GetResultModel(sparqlRequest.Query);
 }
        public ServiceHost CreateServiceHost(IBrightstarService service, int httpPort, int tcpPort, string pipeName)
        {
            var serviceHost = new ServiceHost(service, new[] { new Uri(string.Format("http://localhost:{0}/brightstar", httpPort)),
                                                               new Uri(string.Format("net.tcp://localhost:{0}/brightstar", tcpPort)),
                                                               new Uri(string.Format("net.pipe://localhost/{0}", pipeName)) });

            var basicHttpBinding = new BasicHttpContextBinding {
                TransferMode = TransferMode.StreamedResponse, MaxReceivedMessageSize = int.MaxValue, SendTimeout = TimeSpan.FromMinutes(30), ReaderQuotas = XmlDictionaryReaderQuotas.Max, Namespace = "http://www.networkedplanet.com/schemas/brightstar"
            };
            var netTcpContextBinding = new NetTcpContextBinding {
                TransferMode = TransferMode.StreamedResponse, MaxReceivedMessageSize = int.MaxValue, SendTimeout = TimeSpan.FromMinutes(30), ReaderQuotas = XmlDictionaryReaderQuotas.Max, Namespace = "http://www.networkedplanet.com/schemas/brightstar"
            };
            var netNamedPipeBinding = new NetNamedPipeBinding {
                TransferMode = TransferMode.StreamedResponse, MaxReceivedMessageSize = int.MaxValue, SendTimeout = TimeSpan.FromMinutes(30), ReaderQuotas = XmlDictionaryReaderQuotas.Max, Namespace = "http://www.networkedplanet.com/schemas/brightstar"
            };

            serviceHost.AddServiceEndpoint(typeof(IBrightstarService), basicHttpBinding, "");
            serviceHost.AddServiceEndpoint(typeof(IBrightstarService), netTcpContextBinding, "");
            serviceHost.AddServiceEndpoint(typeof(IBrightstarService), netNamedPipeBinding, "");

            var throttlingBehavior = new ServiceThrottlingBehavior {
                MaxConcurrentCalls = int.MaxValue
            };

            serviceHost.Description.Behaviors.Add(new ServiceMetadataBehavior {
                HttpGetEnabled = true
            });
            serviceHost.Description.Behaviors.Add(throttlingBehavior);

            return(serviceHost);
        }
 /// <summary>
 /// Creates a new bootstrapper that denies all anonymous access to the specified Brightstar service
 /// but grants all authenticated users full access to the service and all of its stores.
 /// </summary>
 /// <param name="brightstarService"></param>
 public BrightstarBootstrapper(IBrightstarService brightstarService)
     : this(
         brightstarService, 
     new FallbackStorePermissionsProvider(StorePermissions.All),
     new FallbackSystemPermissionsProvider(SystemPermissions.All))
 {
 }
Ejemplo n.º 13
0
        public SparqlModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider permissionsProvider)
        {
            this.RequiresBrightstarStorePermission(permissionsProvider, get:StorePermissions.Read, post:StorePermissions.Read);
            _brightstar = brightstarService;

            Get["/{storeName}/sparql"] = parameters =>
                {
                    try
                    {
                        var requestObject = BindSparqlRequestObject();
                        return ProcessQuery(parameters["storeName"], requestObject);
                    }
                    catch (RdfParseException)
                    {
                        return HttpStatusCode.BadRequest;
                    }
                };
            Post["/{storeName}/sparql"] = parameters =>
                {
                    try
                    {
                        var requestObject = BindSparqlRequestObject();
                        return ProcessQuery(parameters["storeName"], requestObject);
                    }
                    catch (RdfParseException)
                    {
                        return HttpStatusCode.BadRequest;
                    }
                };
            Get["/{storeName}/commits/{commitId}/sparql"] = ProcessCommitPointQuery;
            Post["/{storeName}/commits/{commitId}/sparql"] = ProcessCommitPointQuery;
        }
Ejemplo n.º 14
0
        public TransactionsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider storePermissionsProvider)
        {
            this.RequiresBrightstarStorePermission(storePermissionsProvider, get:StorePermissions.ViewHistory);

            Get["/{storeName}/transactions"] = parameters =>
                {
                    var transactionsRequest = this.Bind<TransactionsRequestObject>();
                    ViewBag.Title = transactionsRequest.StoreName + " - Transactions";
                    if (transactionsRequest.Take <= 0) transactionsRequest.Take = DefaultPageSize;
                    var transactions = brightstarService.GetTransactions(transactionsRequest.StoreName,
                                                                                 transactionsRequest.Skip,
                                                                                 transactionsRequest.Take + 1);
                    return Negotiate.WithPagedList(transactionsRequest,
                                                   transactions.Select(MakeResponseObject),
                                                   transactionsRequest.Skip, transactionsRequest.Take, DefaultPageSize,
                                                   "transactions");
                };

            Get["/{storeName}/transactions/byjob/{jobId}"] = parameters =>
                {
                    Guid jobId;
                    if (!Guid.TryParse(parameters["jobId"], out jobId))
                    {
                        return HttpStatusCode.NotFound;
                    }
                    var storeName = parameters["storeName"];
                    ViewBag.Title = storeName + " - Transaction - Job " + jobId;
                    var txn = brightstarService.GetTransaction(parameters["storeName"], jobId);
                    return txn == null ? HttpStatusCode.NotFound : MakeResponseObject(txn);
                };
        }
Ejemplo n.º 15
0
        public StoreModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider storePermissionsProvider)
        {
            this.RequiresBrightstarStorePermission(storePermissionsProvider, get:StorePermissions.Read, delete:StorePermissions.Admin);

            Get["/{storeName}"] = parameters =>
            {
                var storeName = parameters["storeName"];
                ViewBag.Title = storeName;

                if (!brightstarService.DoesStoreExist(storeName)) return HttpStatusCode.NotFound;
                if (Request.Method.ToUpperInvariant() == "HEAD")
                {
                    IEnumerable < ICommitPointInfo > commitPoints = brightstarService.GetCommitPoints(storeName, 0, 1);
                    var commit = commitPoints.First();
                    return
                        Negotiate.WithHeader("Last-Modified", commit.CommitTime.ToUniversalTime().ToString("r"))
                            .WithStatusCode(HttpStatusCode.OK)
                            .WithModel(new StoreResponseModel(parameters["storeName"]));
                }
                return new StoreResponseModel(parameters["storeName"]);
            };

            Delete["/{storeName}"] = parameters =>
                {
                    var storeName = parameters["storeName"];
                    ViewBag.Title = "Deleted - " + storeName;
                    if (brightstarService.DoesStoreExist(storeName))
                    {
                        brightstarService.DeleteStore(storeName);
                    }
                    return Negotiate.WithMediaRangeModel(new MediaRange("text/html"), 
                                                         new StoreDeletedModel {StoreName = storeName});
                };
        }
Ejemplo n.º 16
0
        static bool RunImportJob(IBrightstarService client, string storeName, string fileName, bool logProgress, out string finalMessage)
        {
            var importJobInfo = client.StartImport(storeName, fileName);
            var lastMessage   = String.Empty;

            while (!(importJobInfo.JobCompletedOk || importJobInfo.JobCompletedWithErrors))
            {
                Thread.Sleep(1000);
                importJobInfo = client.GetJobInfo(storeName, importJobInfo.JobId);
                if (logProgress && !String.IsNullOrEmpty(importJobInfo.StatusMessage) &&
                    !importJobInfo.StatusMessage.Equals(lastMessage))
                {
                    ClearCurrentConsoleLine();
                    Console.WriteLine(importJobInfo.StatusMessage);
                    Console.SetCursorPosition(0, Console.CursorTop - 1);
                    lastMessage = importJobInfo.StatusMessage;
                }
            }
            finalMessage = importJobInfo.StatusMessage;
            if (importJobInfo.ExceptionInfo != null)
            {
                finalMessage += " Exception Detail:" + importJobInfo.ExceptionInfo;
            }
            if (logProgress && !String.IsNullOrEmpty(finalMessage))
            {
                ClearCurrentConsoleLine();
                Console.WriteLine(finalMessage);
            }
            return(importJobInfo.JobCompletedOk);
        }
Ejemplo n.º 17
0
        public StatisticsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider storePermissionsProvider)
        {
            this.RequiresBrightstarStorePermission(storePermissionsProvider, get: StorePermissions.ViewHistory);
            Get["/{storeName}/statistics"] = parameters =>
            {
                var request     = this.Bind <StatisticsRequestObject>();
                var resourceUri = "statistics" + CreateQueryString(request);

                // Set defaults
                if (!request.Latest.HasValue)
                {
                    request.Latest = DateTime.MaxValue;
                }
                if (!request.Earliest.HasValue)
                {
                    request.Earliest = DateTime.MinValue;
                }

                // Execute
                var stats = brightstarService.GetStatistics(
                    request.StoreName, request.Latest.Value, request.Earliest.Value,
                    request.Skip, DefaultPageSize + 1);

                return(Negotiate.WithPagedList(request, stats.Select(MakeResponseModel), request.Skip, DefaultPageSize,
                                               DefaultPageSize, resourceUri));
            };
        }
Ejemplo n.º 18
0
        public TransactionsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider storePermissionsProvider)
        {
            this.RequiresBrightstarStorePermission(storePermissionsProvider, get: StorePermissions.ViewHistory);

            Get["/{storeName}/transactions"] = parameters =>
            {
                var transactionsRequest = this.Bind <TransactionsRequestObject>();
                if (transactionsRequest.Take <= 0)
                {
                    transactionsRequest.Take = DefaultPageSize;
                }
                var transactions = brightstarService.GetTransactions(transactionsRequest.StoreName,
                                                                     transactionsRequest.Skip,
                                                                     transactionsRequest.Take + 1);
                return(Negotiate.WithPagedList(transactionsRequest,
                                               transactions.Select(MakeResponseObject),
                                               transactionsRequest.Skip, transactionsRequest.Take, DefaultPageSize,
                                               "transactions"));
            };

            Get["/{storeName}/transactions/byjob/{jobId}"] = parameters =>
            {
                Guid jobId;
                if (!Guid.TryParse(parameters["jobId"], out jobId))
                {
                    return(HttpStatusCode.NotFound);
                }
                var txn = brightstarService.GetTransaction(parameters["storeName"], jobId);
                return(txn == null ? HttpStatusCode.NotFound : MakeResponseObject(txn));
            };
        }
        public ServiceHost CreateServiceHost(IBrightstarService service, EventHandler onCloseEventHandler)
        {
            var httpPort = Configuration.HttPort;
            var tcpPort = Configuration.TcpPort;
            var pipeName = Configuration.NamedPipeName;

            var serviceHost = new ServiceHost(service, new[] {   new Uri(string.Format("http://localhost:{0}/brightstar", httpPort)) , 
                                                                                 new Uri(string.Format("net.tcp://localhost:{0}/brightstar", tcpPort)),
                                                                                 new Uri(string.Format("net.pipe://localhost/{0}", pipeName)) });

            var basicHttpBinding = new BasicHttpContextBinding { TransferMode = TransferMode.StreamedResponse, MaxReceivedMessageSize = int.MaxValue, SendTimeout = TimeSpan.FromMinutes(30), ReaderQuotas = XmlDictionaryReaderQuotas.Max, Namespace = "http://www.networkedplanet.com/schemas/brightstar" };
            var netTcpContextBinding = new NetTcpContextBinding { TransferMode = TransferMode.StreamedResponse, MaxReceivedMessageSize = int.MaxValue, SendTimeout = TimeSpan.FromMinutes(30), ReaderQuotas = XmlDictionaryReaderQuotas.Max, Namespace = "http://www.networkedplanet.com/schemas/brightstar" };
            var netNamedPipeBinding = new NetNamedPipeBinding { TransferMode = TransferMode.StreamedResponse, MaxReceivedMessageSize = int.MaxValue, SendTimeout = TimeSpan.FromMinutes(30), ReaderQuotas = XmlDictionaryReaderQuotas.Max, Namespace = "http://www.networkedplanet.com/schemas/brightstar" };

            serviceHost.AddServiceEndpoint(typeof(IBrightstarService), basicHttpBinding, "");
            serviceHost.AddServiceEndpoint(typeof(IBrightstarService), netTcpContextBinding, "");
            serviceHost.AddServiceEndpoint(typeof(IBrightstarService), netNamedPipeBinding, "");

            var throttlingBehavior = new ServiceThrottlingBehavior { MaxConcurrentCalls = int.MaxValue };

            serviceHost.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
            serviceHost.Description.Behaviors.Add(throttlingBehavior);

            serviceHost.Closed += onCloseEventHandler;

            return serviceHost;
        }
Ejemplo n.º 20
0
 public static void AssertTriplePatternInGraph(IBrightstarService client, string storeName, string triplePattern,
                               string graphUri)
 {
     var sparql = "ASK { GRAPH <" + graphUri + "> {" + triplePattern + "}}";
     var resultsDoc = XDocument.Load(client.ExecuteQuery(storeName, sparql));
     Assert.IsTrue(resultsDoc.SparqlBooleanResult());
 }
Ejemplo n.º 21
0
        public SparqlExtensionTests()
        {
#if WINDOWS_PHONE
            _client = BrightstarService.GetEmbeddedClient("brightstar");
#else
            _client = BrightstarService.GetClient("type=embedded;storesDirectory=c:\\brightstar");
#endif
        }
Ejemplo n.º 22
0
 public SingleThreadStressTest(ConnectionString connectionString) : base(connectionString)
 {
     _client = BrightstarService.GetClient(connectionString);
     _storeName = connectionString.StoreName;
     _importJobs = new List<string>();
     _queryTimes = new ConcurrentQueue<Tuple<long, int>>();
     _queryTasks = new List<Task>();
 }
Ejemplo n.º 23
0
 public FakeNancyBootstrapper(IBrightstarService brightstarService,
                              AbstractStorePermissionsProvider storePermissionsProvider,
     AbstractSystemPermissionsProvider systemPermissionsProvider)
 {
     _brightstarService = brightstarService;
     _storePermissionsProvider = storePermissionsProvider;
     _systemPermissionsProvider = systemPermissionsProvider;
 }
Ejemplo n.º 24
0
        public static void AssertTriplePatternNotInDefaultGraph(IBrightstarService client, string storeName,
                                                                string triplePattern)
        {
            var sparql     = "ASK {{" + triplePattern + "}}";
            var resultsDoc = XDocument.Load(client.ExecuteQuery(storeName, sparql));

            Assert.IsFalse(resultsDoc.SparqlBooleanResult());
        }
Ejemplo n.º 25
0
 public SparqlResultModel(string storeName, IBrightstarService service, SparqlRequestObject sparqlRequest, SparqlResultsFormat resultsFormat, RdfFormat graphFormat)
 {
     _storeName     = storeName;
     _sparqlRequest = sparqlRequest;
     _service       = service;
     ResultsFormat  = resultsFormat;
     GraphFormat    = graphFormat;
 }
Ejemplo n.º 26
0
        public SparqlUpdateTests()
        {
#if WINDOWS_PHONE || PORTABLE
            _client = BrightstarService.GetClient("type=embedded;storesDirectory=brightstar");
#else
            _client = BrightstarService.GetClient("type=embedded;storesDirectory=c:\\brightstar");
#endif
        }
Ejemplo n.º 27
0
        public SparqlUpdateTests()
        {
#if WINDOWS_PHONE
            _client = BrightstarService.GetEmbeddedClient("brightstar");
#else
            _client = BrightstarService.GetClient("type=embedded;storesDirectory=c:\\brightstar");
#endif
        }
Ejemplo n.º 28
0
        public static void AssertTriplePatternInGraph(IBrightstarService client, string storeName, string triplePattern,
                                                      string graphUri)
        {
            var sparql     = "ASK { GRAPH <" + graphUri + "> {" + triplePattern + "}}";
            var resultsDoc = XDocument.Load(client.ExecuteQuery(storeName, sparql));

            Assert.IsTrue(resultsDoc.SparqlBooleanResult());
        }
Ejemplo n.º 29
0
 public FakeNancyBootstrapper(IBrightstarService brightstarService,
                              AbstractStorePermissionsProvider storePermissionsProvider,
                              AbstractSystemPermissionsProvider systemPermissionsProvider)
 {
     _brightstarService         = brightstarService;
     _storePermissionsProvider  = storePermissionsProvider;
     _systemPermissionsProvider = systemPermissionsProvider;
 }
Ejemplo n.º 30
0
 public SingleThreadStressTest(ConnectionString connectionString) : base(connectionString)
 {
     _client     = BrightstarService.GetClient(connectionString);
     _storeName  = connectionString.StoreName;
     _importJobs = new List <string>();
     _queryTimes = new ConcurrentQueue <Tuple <long, int> >();
     _queryTasks = new List <Task>();
 }
 public SparqlQueryProcessingModel(string storeName, ulong commitId, IBrightstarService service,
                                   SparqlRequestObject sparqlRequest)
 {
     _storeName = storeName;
     _commitId = commitId;
     _service = service;
     _sparqlRequest = sparqlRequest;
 }
Ejemplo n.º 32
0
 public static void AssertJobCompletesSuccessfully(IBrightstarService client, string storeName, IJobInfo job)
 {
     while (!job.JobCompletedOk && !job.JobCompletedWithErrors)
     {
         Task.Delay(10).Wait();
         job = client.GetJobInfo(storeName, job.JobId);
     }
     Assert.IsTrue(job.JobCompletedOk, "Expected job to complete successfully, but it failed with message '{0}' : {1}", job.StatusMessage, job.ExceptionInfo);
 }
        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;
        }
Ejemplo n.º 34
0
 /// <summary>
 /// Creates a new bootstrapper that denies all anonymous access to the specified Brightstar service
 /// but grants all authenticated users full access to the service and all of its stores.
 /// </summary>
 /// <param name="brightstarService"></param>
 /// <param name="authenticationProviders">An enumeration of the authentication providers to be used by the service</param>
 public BrightstarBootstrapper(IBrightstarService brightstarService,
                               IEnumerable<IAuthenticationProvider> authenticationProviders)
     : this(
         brightstarService,
         authenticationProviders,
         new FallbackStorePermissionsProvider(StorePermissions.All),
         new FallbackSystemPermissionsProvider(SystemPermissions.All))
 {
 }
Ejemplo n.º 35
0
 protected void AssertJobSuccessful(IBrightstarService client, string storeName, IJobInfo job)
 {
     while (!(job.JobCompletedOk || job.JobCompletedWithErrors))
     {
         Task.Delay(3).Wait();
         job = client.GetJobInfo(storeName, job.JobId);
     }
     Assert.IsTrue(job.JobCompletedOk, "Job failed with message: {0} : {1}", job.StatusMessage, job.ExceptionInfo);
 }
Ejemplo n.º 36
0
 protected void AssertJobSuccessful(IBrightstarService client,string storeName, IJobInfo job)
 {
     while (!(job.JobCompletedOk || job.JobCompletedWithErrors))
     {
         Task.Delay(3).Wait();
         job = client.GetJobInfo(storeName, job.JobId);
     }
     Assert.IsTrue(job.JobCompletedOk, "Job failed with message: {0} : {1}", job.StatusMessage, job.ExceptionInfo);
 }
 /// <summary>
 /// Creates a new bootstrapper that denies all anonymous access to the specified Brightstar service
 /// but grants all authenticated users full access to the service and all of its stores.
 /// </summary>
 /// <param name="brightstarService"></param>
 /// <param name="authenticationProviders">An enumeration of the authentication providers to be used by the service</param>
 public BrightstarBootstrapper(IBrightstarService brightstarService,
                               IEnumerable <IAuthenticationProvider> authenticationProviders)
     : this(
         brightstarService,
         authenticationProviders,
         new FallbackStorePermissionsProvider(StorePermissions.All),
         new FallbackSystemPermissionsProvider(SystemPermissions.All))
 {
 }
        public SparqlUpdateTests()
        {
#if WINDOWS_PHONE
            Licensing.License.Validate("*****@*****.**", "MOB-PW08C-ZBX4Y-00200-0000G");
            _client = BrightstarService.GetEmbeddedClient("brightstar");
#else
            _client = BrightstarService.GetClient("type=embedded;storesDirectory=c:\\brightstar");
#endif
        }
 /// <summary>
 /// Create a new bootstrapper from the specified configuration and root path configuration
 /// with an override for the IBrightstarService instance to be used
 /// </summary>
 /// <param name="service">The IBrightstarService instance to be used</param>
 /// <param name="configuration">The service configuration</param>
 /// <param name="rootPath">The root path</param>
 public BrightstarBootstrapper(IBrightstarService service,
                               BrightstarServiceConfiguration configuration,
                               string rootPath = null)
     : this(service,
            configuration.AuthenticationProviders,
            configuration.StorePermissionsProvider,
            configuration.SystemPermissionsProvider,
            rootPath)
 {
 }
Ejemplo n.º 40
0
 public LatestStatisticsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider storePermissionsProvider)
 {
     this.RequiresBrightstarStorePermission(storePermissionsProvider, get:StorePermissions.Read);
     Get["/{storeName}/statistics/latest"] = parameters =>
         {
             var latest = brightstarService.GetStatistics(parameters["storeName"]);
             if (latest == null) return HttpStatusCode.NotFound;
             return MakeResponseModel(latest);
         };
 }
Ejemplo n.º 41
0
 public SparqlResultModel(string storeName, ulong commitId, IBrightstarService service,
                          SparqlRequestObject sparqlRequest, SparqlResultsFormat resultsFormat, RdfFormat graphFormat)
 {
     _storeName = storeName;
     _commitId = commitId;
     _sparqlRequest = sparqlRequest;
     _service = service;
     ResultsFormat = resultsFormat;
     GraphFormat = graphFormat;
 }
 /// <summary>
 /// Creates a new bootstrapper with store and system access goverened by the specified providers.
 /// </summary>
 /// <param name="brightstarService">The connection to the BrightstarDB stores</param>
 /// <param name="storePermissionsProvider">The store permissions provider to be used by the service</param>
 /// <param name="systemPermissionsProvider">The system permissions provider to be used by the service</param>
 /// <param name="rootPath">The path to the directory containing the service Views and assets folder</param>
 public BrightstarBootstrapper(IBrightstarService brightstarService,
                               AbstractStorePermissionsProvider storePermissionsProvider,
                               AbstractSystemPermissionsProvider systemPermissionsProvider,
     string rootPath = null)
 {
     _brightstarService = brightstarService;
     _storePermissionsProvider = storePermissionsProvider;
     _systemPermissionsProvider = systemPermissionsProvider;
     _rootPathProvider = (rootPath == null ? new DefaultRootPathProvider() : new FixedRootPathProvider(rootPath) as IRootPathProvider);
     //_rootPathProvider = new FixedRootPathProvider(rootPath);
 }
Ejemplo n.º 43
0
        /// <summary>
        /// Create a new bootstrapper from the specified configuration and root path configuration
        /// with an override for the IBrightstarService instance to be used
        /// </summary>
        /// <param name="service">The IBrightstarService instance to be used</param>
        /// <param name="configuration">The service configuration</param>
        /// <param name="rootPath">The root path</param>
        public BrightstarBootstrapper(IBrightstarService service,
                                      BrightstarServiceConfiguration configuration,
                                      string rootPath = null)
            : this(service,
                   configuration.AuthenticationProviders,
                   configuration.StorePermissionsProvider,
                   configuration.SystemPermissionsProvider,
                   rootPath)
        {

        }
 /// <summary>
 /// Creates a new bootstrapper with store and system access goverened by the specified providers.
 /// </summary>
 /// <param name="brightstarService">The connection to the BrightstarDB stores</param>
 /// <param name="storePermissionsProvider">The store permissions provider to be used by the service</param>
 /// <param name="systemPermissionsProvider">The system permissions provider to be used by the service</param>
 /// <param name="rootPath">The path to the directory containing the service Views and assets folder</param>
 public BrightstarBootstrapper(IBrightstarService brightstarService,
                               AbstractStorePermissionsProvider storePermissionsProvider,
                               AbstractSystemPermissionsProvider systemPermissionsProvider,
                               string rootPath = null)
 {
     _brightstarService         = brightstarService;
     _storePermissionsProvider  = storePermissionsProvider;
     _systemPermissionsProvider = systemPermissionsProvider;
     _rootPathProvider          = (rootPath == null ? new DefaultRootPathProvider() : new FixedRootPathProvider(rootPath) as IRootPathProvider);
     //_rootPathProvider = new FixedRootPathProvider(rootPath);
 }
Ejemplo n.º 45
0
 public BenchmarkRunner(BenchmarkArgs args)
 {
     SourceFiles = Directory.GetFiles(args.TestDataDirectory, "*.nt", SearchOption.AllDirectories);
     BenchmarkLogging.Info("Found {0} source NTriples files for benchmark test", SourceFiles.Length);
     if (args.MaxNumberFiles > 0 && args.MaxNumberFiles < SourceFiles.Length)
     {
         SourceFiles = SourceFiles.Take(args.MaxNumberFiles).ToArray();
         BenchmarkLogging.Info("Limited number of source files to be processed to {0} (from command-line options)", SourceFiles.Length);
     }
     _brightstar = new EmbeddedBrightstarService(".");
     _storeName = "BenchmarkStore_" + DateTime.Now.ToString("yyMMdd_HHmmss");
 }
Ejemplo n.º 46
0
 public BenchmarkRunner(BenchmarkArgs args)
 {
     SourceFiles = Directory.GetFiles(args.TestDataDirectory, "*.nt", SearchOption.AllDirectories);
     BenchmarkLogging.Info("Found {0} source NTriples files for benchmark test", SourceFiles.Length);
     if (args.MaxNumberFiles > 0 && args.MaxNumberFiles < SourceFiles.Length)
     {
         SourceFiles = SourceFiles.Take(args.MaxNumberFiles).ToArray();
         BenchmarkLogging.Info("Limited number of source files to be processed to {0} (from command-line options)", SourceFiles.Length);
     }
     _brightstar = new EmbeddedBrightstarService(".");
     _storeName  = "BenchmarkStore_" + DateTime.Now.ToString("yyMMdd_HHmmss");
 }
Ejemplo n.º 47
0
        public CommitPointsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider permissionsProvider)
        {
            this.RequiresBrightstarStorePermission(permissionsProvider, get: StorePermissions.ViewHistory, post: StorePermissions.Admin);

            Get["/{storeName}/commits"] = parameters =>
            {
                int      skip      = Request.Query["skip"].TryParse <int>(0);
                int      take      = Request.Query["take"].TryParse <int>(DefaultPageSize);
                DateTime timestamp = Request.Query["timestamp"].TryParse <DateTime>();
                DateTime earliest  = Request.Query["earliest"].TryParse <DateTime>();
                DateTime latest    = Request.Query["latest"].TryParse <DateTime>();

                var request = this.Bind <CommitPointsRequestModel>();
                ViewBag.Title = request.StoreName + " - Commit History";

                if (timestamp != default(DateTime))
                {
                    // Request for a single commit point
                    var commitPoint = brightstarService.GetCommitPoint(parameters["storeName"], timestamp);
                    return(commitPoint == null ? HttpStatusCode.NotFound : MakeResponseObject(commitPoint));
                }
                if (earliest != default(DateTime) && latest != default(DateTime))
                {
                    IEnumerable <ICommitPointInfo> results =
                        brightstarService.GetCommitPoints(parameters["storeName"], latest, earliest, skip, take + 1);
                    var resourceUri = String.Format("commits?latest={0}&earliest={1}", latest.ToString("s"), earliest.ToString("s"));
                    return(Negotiate.WithPagedList(request, results.Select(MakeResponseObject), skip, take, DefaultPageSize, resourceUri));
                }
                IEnumerable <ICommitPointInfo> commitPointInfos = brightstarService.GetCommitPoints(parameters["storeName"], skip, take + 1);
                return(Negotiate.WithPagedList(request, commitPointInfos.Select(MakeResponseObject), skip, take, DefaultPageSize, "commits"));
            };

            Post["/{storeName}/commits"] = parameters =>
            {
                var commitPoint = this.Bind <CommitPointResponseModel>();
                if (commitPoint == null ||
                    String.IsNullOrEmpty(commitPoint.StoreName) ||
                    !commitPoint.StoreName.Equals(parameters["storeName"]))
                {
                    return(HttpStatusCode.BadRequest);
                }

                var commitPointInfo = brightstarService.GetCommitPoint(parameters["storeName"], commitPoint.Id);
                if (commitPointInfo == null)
                {
                    return(HttpStatusCode.BadRequest);
                }

                brightstarService.RevertToCommitPoint(parameters["storeName"], commitPointInfo);
                return(HttpStatusCode.OK);
            };
        }
Ejemplo n.º 48
0
        public StoresModule(IBrightstarService brightstarService, AbstractSystemPermissionsProvider systemPermissionsProvider)
        {
            this.RequiresBrightstarSystemPermission(systemPermissionsProvider, get:SystemPermissions.ListStores, post:SystemPermissions.CreateStore);

            Get["/"] = parameters =>
            {
                ViewBag.Title = "Stores";
                var stores = brightstarService.ListStores();
                return
                    Negotiate.WithModel(new StoresResponseModel
                        {
                            Stores = stores.ToList()
                        });
                };

            Post["/"] = parameters =>
                {
                    ViewBag.Title = "Stores";
                    var request = this.Bind<CreateStoreRequestObject>();
                    if (request == null || String.IsNullOrEmpty(request.StoreName))
                    {
                        return HttpStatusCode.BadRequest;
                    }

                    // Return 409 Conflict if attempt to create a store with a name that is currently in use
                    if (brightstarService.DoesStoreExist(request.StoreName))
                    {
                        return HttpStatusCode.Conflict;
                    }

                    // Attempt to create the store
                    try
                    {
                        PersistenceType? storePersistenceType = request.GetBrightstarPersistenceType();
                        if (storePersistenceType.HasValue)
                        {
                            brightstarService.CreateStore(request.StoreName, storePersistenceType.Value);
                        }
                        else
                        {
                            brightstarService.CreateStore(request.StoreName);
                        }
                    }
                    catch (ArgumentException)
                    {
                        return HttpStatusCode.BadRequest;   
                    }
                    return
                        Negotiate.WithModel(new StoreResponseModel(request.StoreName))
                                 .WithStatusCode(HttpStatusCode.Created);
                };
        }
Ejemplo n.º 49
0
        public StoresModule(IBrightstarService brightstarService, AbstractSystemPermissionsProvider systemPermissionsProvider)
        {
            this.RequiresBrightstarSystemPermission(systemPermissionsProvider, get: SystemPermissions.ListStores, post: SystemPermissions.CreateStore);

            Get["/"] = parameters =>
            {
                ViewBag.Title = "Stores";
                var stores = brightstarService.ListStores();
                return
                    (Negotiate.WithModel(new StoresResponseModel
                {
                    Stores = stores.ToList()
                }));
            };

            Post["/"] = parameters =>
            {
                ViewBag.Title = "Stores";
                var request = this.Bind <CreateStoreRequestObject>();
                if (request == null || String.IsNullOrEmpty(request.StoreName))
                {
                    return(HttpStatusCode.BadRequest);
                }

                // Return 409 Conflict if attempt to create a store with a name that is currently in use
                if (brightstarService.DoesStoreExist(request.StoreName))
                {
                    return(HttpStatusCode.Conflict);
                }

                // Attempt to create the store
                try
                {
                    PersistenceType?storePersistenceType = request.GetBrightstarPersistenceType();
                    if (storePersistenceType.HasValue)
                    {
                        brightstarService.CreateStore(request.StoreName, storePersistenceType.Value);
                    }
                    else
                    {
                        brightstarService.CreateStore(request.StoreName);
                    }
                }
                catch (ArgumentException)
                {
                    return(HttpStatusCode.BadRequest);
                }
                return
                    (Negotiate.WithModel(new StoreResponseModel(request.StoreName))
                     .WithStatusCode(HttpStatusCode.Created));
            };
        }
 public LatestStatisticsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider storePermissionsProvider)
 {
     this.RequiresBrightstarStorePermission(storePermissionsProvider, get: StorePermissions.Read);
     Get["/{storeName}/statistics/latest"] = parameters =>
     {
         var latest = brightstarService.GetStatistics(parameters["storeName"]);
         if (latest == null)
         {
             return(HttpStatusCode.NotFound);
         }
         return(MakeResponseModel(latest));
     };
 }
        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;
        }
Ejemplo n.º 52
0
        /// <summary>
        /// Create a new bootstrapper that initializes itself from the brightstarService section
        /// of the application (or web) configuration file.
        /// </summary>
        /// <exception cref="ConfigurationErrorsException">Raised if the brightstarService configuration
        /// section does not exist in the application configuration file, or if the configuration is
        /// invalid.</exception>
        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 ??
                                        new FallbackStorePermissionsProvider(StorePermissions.All);
            _systemPermissionsProvider = config.SystemPermissionsProvider ??
                                         new FallbackSystemPermissionsProvider(SystemPermissions.All);
            _authenticationProviders = config.AuthenticationProviders ??
                                       new Collection<IAuthenticationProvider> {new NullAuthenticationProvider()};
        }
Ejemplo n.º 53
0
        private static void QueryCommitPoint(IBrightstarService client, ICommitPointInfo commitPointInfo)
        {
            const string sparqlQuery =
                "SELECT ?l WHERE { ?s <http://www.w3.org/2000/01/rdf-schema#label> ?l } ORDER BY ?l";
            var resultsStream = client.ExecuteQuery(commitPointInfo, sparqlQuery);
            var resultsDoc    = XDocument.Load(resultsStream);
            var labels        = new List <string>();

            foreach (var row in resultsDoc.SparqlResultRows())
            {
                labels.Add(row.GetColumnValue("l").ToString());
            }
            Console.WriteLine("Query returns: {0}", string.Join(", ", labels));
        }
Ejemplo n.º 54
0
        public CommitPointsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider permissionsProvider)
        {
            this.RequiresBrightstarStorePermission(permissionsProvider, get:StorePermissions.ViewHistory, post:StorePermissions.Admin);

            Get["/{storeName}/commits"] = parameters =>
                {
                    int skip = Request.Query["skip"].TryParse<int>(0);
                    int take = Request.Query["take"].TryParse<int>(DefaultPageSize);
                    DateTime timestamp = Request.Query["timestamp"].TryParse<DateTime>();
                    DateTime earliest = Request.Query["earliest"].TryParse<DateTime>();
                    DateTime latest = Request.Query["latest"].TryParse<DateTime>();

                    var request = this.Bind<CommitPointsRequestModel>();
                    ViewBag.Title = request.StoreName + " - Commit History";
                    
                    if (timestamp != default(DateTime))
                    {
                        // Request for a single commit point
                        var commitPoint = brightstarService.GetCommitPoint(parameters["storeName"], timestamp);
                        return commitPoint == null ? HttpStatusCode.NotFound : MakeResponseObject(commitPoint);
                    }
                    if (earliest != default(DateTime) && latest != default(DateTime))
                    {
                        IEnumerable<ICommitPointInfo> results =
                            brightstarService.GetCommitPoints(parameters["storeName"], latest, earliest, skip, take + 1);
                        var resourceUri = String.Format("commits?latest={0}&earliest={1}", latest.ToString("s"), earliest.ToString("s"));
                        return Negotiate.WithPagedList(request, results.Select(MakeResponseObject), skip, take, DefaultPageSize, resourceUri);
                    }
                    IEnumerable<ICommitPointInfo> commitPointInfos = brightstarService.GetCommitPoints(parameters["storeName"], skip, take + 1);
                    return Negotiate.WithPagedList(request, commitPointInfos.Select(MakeResponseObject), skip, take, DefaultPageSize, "commits");
                };

            Post["/{storeName}/commits"] = parameters =>
                {
                    var commitPoint = this.Bind<CommitPointResponseModel>();
                    if (commitPoint == null ||
                        String.IsNullOrEmpty(commitPoint.StoreName) ||
                        !commitPoint.StoreName.Equals(parameters["storeName"]))
                    {
                        return HttpStatusCode.BadRequest;
                    }

                    var commitPointInfo = brightstarService.GetCommitPoint(parameters["storeName"], commitPoint.Id);
                    if (commitPointInfo == null) return HttpStatusCode.BadRequest;

                    brightstarService.RevertToCommitPoint(parameters["storeName"], commitPointInfo);
                    return HttpStatusCode.OK;
                };
        }
Ejemplo n.º 55
0
 public static IJobInfo WaitForJob(IJobInfo job, IBrightstarService client, string storeName)
 {
     var cycleCount = 0;
     while (!job.JobCompletedOk && !job.JobCompletedWithErrors && cycleCount < 100)
     {
         Thread.Sleep(500);
         cycleCount++;
         job = client.GetJobInfo(storeName, job.JobId);
     }
     if (!job.JobCompletedOk && !job.JobCompletedWithErrors)
     {
         Assert.Fail("Job did not complete in time.");
     }
     return job;
 }
Ejemplo n.º 56
0
        private static List <ICommitPointInfo> ListCommitPoints(IBrightstarService client, string storeName)
        {
            var ret = new List <ICommitPointInfo>();
            int commitPointNumber = 0;

            // Retrieve 10 most recent commit point info from the store
            foreach (var commitPointInfo in client.GetCommitPoints(storeName, 0, 10))
            {
                ret.Add(commitPointInfo);
                Console.WriteLine("#{0}: ID: {1} Commited at: {2}", commitPointNumber++, commitPointInfo.Id, commitPointInfo.CommitTime);
                // Query this commit point
                QueryCommitPoint(client, commitPointInfo);
            }
            return(ret);
        }
Ejemplo n.º 57
0
 static bool RunImportJob(IBrightstarService client, string storeName, string fileName, out string finalMessage )
 {
     var importJobInfo = client.StartImport(storeName, fileName);
     while(!(importJobInfo.JobCompletedOk || importJobInfo.JobCompletedWithErrors))
     {
         System.Threading.Thread.Sleep(1000);
         importJobInfo = client.GetJobInfo(storeName, importJobInfo.JobId);
     }
     finalMessage = importJobInfo.StatusMessage;
     if (importJobInfo.ExceptionInfo != null)
     {
         finalMessage += " Exception Detail:" + importJobInfo.ExceptionInfo;
     }
     return importJobInfo.JobCompletedOk;
 }
Ejemplo n.º 58
0
 static bool RunCompressJob(IBrightstarService client, string storeName, out string finalMessage)
 {
     var compressJob = client.ConsolidateStore(storeName);
     while (!(compressJob.JobCompletedOk || compressJob.JobCompletedWithErrors))
     {
         System.Threading.Thread.Sleep(1000);
         compressJob = client.GetJobInfo(storeName, compressJob.JobId);
     }
     finalMessage = compressJob.StatusMessage;
     if (compressJob.ExceptionInfo != null)
     {
         finalMessage += " Exception Detail:" + compressJob.ExceptionInfo;
     }
     return compressJob.JobCompletedOk;
 }
Ejemplo n.º 59
0
        public static IJobInfo WaitForJob(IJobInfo job, IBrightstarService client, string storeName)
        {
            var cycleCount = 0;

            while (!job.JobCompletedOk && !job.JobCompletedWithErrors && cycleCount < 100)
            {
                Thread.Sleep(500);
                cycleCount++;
                job = client.GetJobInfo(storeName, job.JobId);
            }
            if (!job.JobCompletedOk && !job.JobCompletedWithErrors)
            {
                Assert.Fail("Job did not complete in time.");
            }
            return(job);
        }