当前位置: 首页>>代码示例>>C#>>正文


C# StoreWorker.Query方法代码示例

本文整理汇总了C#中BrightstarDB.Server.StoreWorker.Query方法的典型用法代码示例。如果您正苦于以下问题:C# StoreWorker.Query方法的具体用法?C# StoreWorker.Query怎么用?C# StoreWorker.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BrightstarDB.Server.StoreWorker的用法示例。


在下文中一共展示了StoreWorker.Query方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestQueryCaching

        public void TestQueryCaching()
        {
            Configuration.EnableQueryCache = true;

            // create a store
            var sid = CreateStore();

            // initialise and start the store worker
            var storeWorker = new StoreWorker(Configuration.StoreLocation, sid);
            storeWorker.Start();

            // execute transactions
            const string data = @"<http://www.networkedplanet.com/people/gra> <http://www.networkedplanet.com/types/worksfor> <http://www.networkedplanet.com/companies/np>";

            var jobId = storeWorker.ProcessTransaction("", "", "", data, Constants.DefaultGraphUri, "nt");
            JobExecutionStatus jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            while (jobStatus.JobStatus != JobStatus.CompletedOk && jobStatus.JobStatus != JobStatus.TransactionError)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }
            Assert.AreEqual(JobStatus.CompletedOk, jobStatus.JobStatus, "Import failed: {0} : {1}", jobStatus.Information, jobStatus.ExceptionDetail);

            var sw = new Stopwatch();
            sw.Start();
            var queryResult = storeWorker.Query("select * where { ?a ?b ?c }", SparqlResultsFormat.Xml, new[] { Constants.DefaultGraphUri });
            sw.Stop();
            Console.WriteLine("initial query took : " + sw.ElapsedMilliseconds);
            var initTime = sw.ElapsedMilliseconds;

            sw = new Stopwatch();
            sw.Start();
            var cachedResult = storeWorker.Query("select * where { ?a ?b ?c }", SparqlResultsFormat.Xml, new[] { Constants.DefaultGraphUri });
            sw.Stop();
            Console.WriteLine("warm query took : " + sw.ElapsedMilliseconds);

            Thread.Sleep(1000);

            sw = new Stopwatch();
            sw.Start();
            cachedResult = storeWorker.Query("select * where { ?a ?b ?c }", SparqlResultsFormat.Xml, new[] { Constants.DefaultGraphUri });
            sw.Stop();
            Console.WriteLine("cached query took : " + sw.ElapsedMilliseconds);
            var cachedTime = sw.ElapsedMilliseconds;

            Assert.AreEqual(queryResult, cachedResult);
            if (cachedTime >= initTime)
            {
                Assert.Inconclusive(
                    "Expected time to read from cache ({0}ms) to be less than time to execute query ({1}ms).",
                    cachedTime, initTime);
            }

            Configuration.EnableQueryCache = false;
        }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:55,代码来源:StoreWorkerTests.cs

示例2: TestDeleteStoreAfterQuery

        public void TestDeleteStoreAfterQuery()
        {
            // create a store
            var sid = CreateStore();

            // initialise and start the store worker
            var storeWorker = new StoreWorker(Configuration.StoreLocation, sid);
            storeWorker.Start();

            // execute transactions
            const string data = @"<http://www.networkedplanet.com/people/gra> <http://www.networkedplanet.com/types/worksfor> <http://www.networkedplanet.com/companies/np>";

            var jobId = storeWorker.ProcessTransaction("", "", "", data, Constants.DefaultGraphUri, "nt");
            JobExecutionStatus jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            while (jobStatus.JobStatus != JobStatus.CompletedOk)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }

            storeWorker.Query("select * where { ?s ?p ?o }", SparqlResultsFormat.Xml, new[]{Constants.DefaultGraphUri});
            storeWorker.Shutdown(true, () => _storeManager.DeleteStore(Configuration.StoreLocation + "\\"+ sid));            
        }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:23,代码来源:StoreWorkerTests.cs

示例3: TestConsolidateStore

        public void TestConsolidateStore()
        {
            // create a store
            var sid = CreateStore();

            // initialise and start the store worker
            var storeWorker = new StoreWorker(Configuration.StoreLocation, sid);
            storeWorker.Start();

            // execute transactions
            var data =
                @"<http://www.networkedplanet.com/people/gra> <http://www.networkedplanet.com/types/worksfor> <http://www.networkedplanet.com/companies/np>";

            var jobId = storeWorker.ProcessTransaction("","", "", data, Constants.DefaultGraphUri, "nt");
            JobExecutionStatus jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            while (jobStatus.JobStatus != JobStatus.CompletedOk)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }

            jobId = Guid.NewGuid();
            storeWorker.QueueJob(new ConsolidateJob(jobId, null, storeWorker));
            jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            while (jobStatus.JobStatus != JobStatus.CompletedOk && jobStatus.JobStatus != JobStatus.TransactionError)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }

            Assert.AreEqual(JobStatus.CompletedOk, jobStatus.JobStatus);

            // open store and find all triples
            var results = storeWorker.Query("select * where { ?a ?b ?c }", SparqlResultsFormat.Xml, new[] { Constants.DefaultGraphUri });
            var doc = XDocument.Parse(results);
            XNamespace sparqlNs = "http://www.w3.org/2005/sparql-results#";
            Assert.AreEqual(1, doc.Descendants(sparqlNs + "result").Count());

            data =
                @"<http://www.networkedplanet.com/people/gra> <http://www.networkedplanet.com/types/worksfor> <http://www.networkedplanet.com/companies/np>";

            jobId = storeWorker.ProcessTransaction("", "", data, "", Constants.DefaultGraphUri, "nt");
            jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            while (jobStatus.JobStatus != JobStatus.CompletedOk)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }

            Assert.AreEqual(JobStatus.CompletedOk, jobStatus.JobStatus);

            // consolidate again
            jobId = Guid.NewGuid();
            storeWorker.QueueJob(new ConsolidateJob(jobId, null, storeWorker));
            jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            while (jobStatus.JobStatus != JobStatus.CompletedOk && jobStatus.JobStatus != JobStatus.TransactionError)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }

            Assert.AreEqual(JobStatus.CompletedOk, jobStatus.JobStatus);

            results = storeWorker.Query("select * where { ?a ?b ?c }", SparqlResultsFormat.Xml, new[] { Constants.DefaultGraphUri });
            doc = XDocument.Parse(results);
            Assert.AreEqual(0, doc.Descendants(sparqlNs + "result").Count());
        }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:67,代码来源:StoreWorkerTests.cs

示例4: FindWorkingTransaction

        public void FindWorkingTransaction()
        {
           Store store = new Store("c:\\brightstar\\twitteringtest\\", false);
            FileStoreManager fsm = new FileStoreManager(StoreConfiguration.DefaultStoreConfiguration);
            int txnCount = 0;
            foreach (var cp in store.GetCommitPoints())
            {
                var oldStore = fsm.OpenStore("c:\\brightstar\\twitteringtest\\", cp.LocationOffset);
                try
                {
                    oldStore.ExecuteSparqlQuery(TestQuery, SparqlResultsFormat.Xml);
                    Console.WriteLine("Query worked for commit point : {0} @ {1}", cp.LocationOffset, cp.CommitTime);
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("Query failed for commit point : {0} @ {1}", cp.LocationOffset, cp.CommitTime);
                    txnCount++;
                }
            }
            var txnLog = fsm.GetTransactionLog("c:\\brightstar\\twitteringtest");
            var txnList = txnLog.GetTransactionList();
            for(int i = 0 ; i<= txnCount;i++)
            {
                txnList.MoveNext();
                var txnInfo = txnList.Current;
                Console.WriteLine("Transaction #{0}: Start: {1}, Status: {2}, JobId: {3}", i, txnInfo.TransactionStartTime, txnInfo.TransactionStatus, txnInfo.JobId);
            }

            // Going back to last known good
            store.RevertToCommitPoint(new CommitPoint(242472899 , 0, DateTime.UtcNow, Guid.Empty));

            var toReplay = new List<ITransactionInfo>();
            txnList = txnLog.GetTransactionList();
            for(int i = 0; i < 10 ; i++)
            {
                txnList.MoveNext();
                toReplay.Add(txnList.Current);
            }

            var storeWorker = new StoreWorker("c:\\brightstar","twitteringtest");
            for(int i = 9; i >= 0; i--)
            {
                Console.WriteLine("Applying transaction : {0}", toReplay[i].JobId);
                txnLog.GetTransactionData(toReplay[i].DataStartPosition);

                var jobId = Guid.NewGuid();
                var updateJob = new UpdateTransaction(jobId, null, storeWorker);
                updateJob.ReadTransactionDataFromStream(txnLog.GetTransactionData(toReplay[i].DataStartPosition));
                updateJob.Run();

                var readStore = storeWorker.ReadStore as Store;
                var resource = readStore.Resolve(1518601251);
                Assert.IsNotNull(resource);
                try
                {
                    var query = StoreExtensions.ParseSparql(TestQuery);
                    using (var resultStream = new MemoryStream())
                    {
                        storeWorker.Query(query, SparqlResultsFormat.Xml, resultStream,
                                          new[] {Constants.DefaultGraphUri});
                    }
                    Console.WriteLine("Query succeeded");
                }
                catch(Exception ex)
                {
                    Console.WriteLine("Query failed: " + ex.Message);
                    Assert.Fail();
                }
            }
        }
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:71,代码来源:BrokenStoreTests.cs


注:本文中的BrightstarDB.Server.StoreWorker.Query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。