Esempio n. 1
0
        public void StorageDydraDeleteGraph()
        {
            try
            {
                Options.HttpDebugging = true;

                Graph orig = new Graph();
                orig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                orig.BaseUri = new Uri("http://example.org/storage/dydra/delete");

                DydraConnector dydra = DydraTests.GetConnection();
                dydra.SaveGraph(orig);

                Graph g = new Graph();
                dydra.LoadGraph(g, orig.BaseUri);

                if (orig.Triples.Count == g.Triples.Count)
                {
                    GraphDiffReport report = orig.Difference(g);
                    if (!report.AreEqual)
                    {
                        TestTools.ShowDifferences(report);
                    }
                    Assert.AreEqual(orig, g, "Graphs should be equal");
                }
                else
                {
                    Assert.IsTrue(g.HasSubGraph(orig), "Original Graph should be a sub-graph of retrieved Graph");
                }

                //Now delete the Graph
                dydra.DeleteGraph(orig.BaseUri);

                //And retrieve it again
                g = new Graph();
                dydra.LoadGraph(g, orig.BaseUri);

                Assert.IsTrue(g.IsEmpty, "Graph should be empty as was deleted from repository");
                Assert.AreNotEqual(orig, g, "Graphs should not be equal");
            }
            finally
            {
                Options.HttpDebugging = false;
            }
        }
        public void UpdateGraph(Uri graphUri, GraphDiffReport difference)
        {
            ModifyCommand      modifyCommand = difference.AsUpdate();
            SparqlUpdateParser parser        = new SparqlUpdateParser();

            parser.ParseFromString(modifyCommand.ToString());
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"{BaseUri}{this._repositoriesPrefix}Master{this._updatePath}");

            request.Method      = "POST";
            request.ContentType = "application/sparql-update";
            request.Headers.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
            request.Headers.Add("Api-Version", apiVersion);
            using (StreamWriter writer = new StreamWriter(request.GetRequestStream(), new UTF8Encoding(Options.UseBomForUtf8)))
            {
                writer.Write(EscapeQuery(modifyCommand.ToString()));
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            response.Dispose();
        }
Esempio n. 3
0
        public void StorageSesameSparqlUpdate1()
        {
            if (!TestConfigManager.GetSettingAsBoolean(TestConfigManager.UseRemoteParsing))
            {
                Assert.Inconclusive("Test Config marks Remote Parsing as unavailable, test cannot be run");
            }

            SesameHttpProtocolConnector sesame = SesameTests.GetConnection();

            sesame.Update(@"DROP GRAPH <http://example.org/sparqlUpdateLoad>;
LOAD <http://dbpedia.org/resource/Ilkeston> INTO GRAPH <http://example.org/sparqlUpdateLoad>;
DELETE WHERE 
{ 
  GRAPH <http://example.org/sparqlUpdateLoad> 
  { ?s <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long ; <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat }
}");

            Graph orig = new Graph();

            orig.LoadFromUri(new Uri("http://dbpedia.org/resource/Ilkeston"));
            orig.Retract(orig.GetTriplesWithPredicate(new Uri("http://www.w3.org/2003/01/geo/wgs84_pos#long")).ToList());
            orig.Retract(orig.GetTriplesWithPredicate(new Uri("http://www.w3.org/2003/01/geo/wgs84_pos#lat")).ToList());

            Graph actual = new Graph();

            sesame.LoadGraph(actual, "http://example.org/sparqlUpdateLoad");

            GraphDiffReport diff = orig.Difference(actual);

            if (!diff.AreEqual)
            {
                TestTools.ShowDifferences(diff);
            }

            Assert.AreEqual(orig, actual, "Graphs should be equal");
        }
Esempio n. 4
0
        public void StorageDydraSaveToNamedGraph()
        {
            try
            {
                Options.HttpDebugging = true;

                Graph orig = new Graph();
                orig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                orig.BaseUri = new Uri("http://example.org/storage/dydra/save/named/");

                DydraConnector dydra = DydraTests.GetConnection();
                dydra.SaveGraph(orig);

                Graph g = new Graph();
                dydra.LoadGraph(g, orig.BaseUri);

                if (orig.Triples.Count == g.Triples.Count)
                {
                    GraphDiffReport report = orig.Difference(g);
                    if (!report.AreEqual)
                    {
                        TestTools.ShowDifferences(report);
                    }
                    Assert.AreEqual(orig, g, "Graphs should be equal");
                }
                else
                {
                    Assert.IsTrue(g.HasSubGraph(orig), "Original Graph should be a sub-graph of retrieved Graph");
                }
            }
            finally
            {
                Options.HttpFullDebugging = false;
                Options.HttpDebugging     = false;
            }
        }
Esempio n. 5
0
        public static void ShowDifferences(GraphDiffReport report)
        {
            NTriplesFormatter formatter = new NTriplesFormatter();

            if (report.AreEqual)
            {
                Console.WriteLine("Graphs are Equal");
                Console.WriteLine();
                Console.WriteLine("Blank Node Mapping between Graphs:");
                foreach (KeyValuePair<INode, INode> kvp in report.Mapping)
                {
                    Console.WriteLine(kvp.Key.ToString(formatter) + " => " + kvp.Value.ToString(formatter));
                }
            }
            else
            {
                Console.WriteLine("Graphs are non-equal");
                Console.WriteLine();
                Console.WriteLine("Triples added to 1st Graph to give 2nd Graph:");
                foreach (Triple t in report.AddedTriples)
                {
                    Console.WriteLine(t.ToString(formatter));
                }
                Console.WriteLine();
                Console.WriteLine("Triples removed from 1st Graph to given 2nd Graph:");
                foreach (Triple t in report.RemovedTriples)
                {
                    Console.WriteLine(t.ToString(formatter));
                }
                Console.WriteLine();
                Console.WriteLine("Blank Node Mapping between Graphs:");
                foreach (KeyValuePair<INode, INode> kvp in report.Mapping)
                {
                    Console.WriteLine(kvp.Key.ToString(formatter) + " => " + kvp.Value.ToString(formatter));
                }
                Console.WriteLine();
                Console.WriteLine("MSGs added to 1st Graph to give 2nd Graph:");
                foreach (IGraph msg in report.AddedMSGs)
                {
                    foreach (Triple t in msg.Triples)
                    {
                        Console.WriteLine(t.ToString(formatter));
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
                Console.WriteLine("MSGs removed from 1st Graph to give 2nd Graph:");
                foreach (IGraph msg in report.RemovedMSGs)
                {
                    foreach (Triple t in msg.Triples)
                    {
                        Console.WriteLine(t.ToString(formatter));
                    }
                    Console.WriteLine();
                }
            }
        }
Esempio n. 6
0
        protected void TestAsyncSaveLoad(IGraph g)
        {
            IAsyncStorageProvider provider = this.GetAsyncProvider();

            try
            {
                ManualResetEvent         signal  = new ManualResetEvent(false);
                AsyncStorageCallbackArgs resArgs = null;
                g.BaseUri = UriFactory.Create(SaveGraphUri);
                provider.SaveGraph(g, (_, args, state) =>
                {
                    resArgs = args;
                    signal.Set();
                }, null);

                //Wait for response, max 15s
                signal.WaitOne(WaitDelay);

                if (resArgs == null)
                {
                    this.Fail(provider, "SaveGraph() did not return in " + (WaitDelay / 1000) + " seconds");
                }
                if (resArgs.WasSuccessful)
                {
                    Console.WriteLine("Async SaveGraph() worked OK, trying async LoadGraph() to confirm operation worked as expected");

                    resArgs = null;
                    signal.Reset();
                    Graph h = new Graph();
                    provider.LoadGraph(h, SaveGraphUri, (_, args, state) =>
                    {
                        resArgs = args;
                        signal.Set();
                    }, null);

                    //Wait for response, max 15s
                    signal.WaitOne(WaitDelay);

                    if (resArgs == null)
                    {
                        this.Fail(provider, "LoadGraph() did not return in " + (WaitDelay / 1000) + " seconds");
                    }
                    if (resArgs.WasSuccessful)
                    {
                        Console.WriteLine("Async LoadGraph() worked OK, checking for graph equality...");
                        GraphDiffReport diff = g.Difference(resArgs.Graph);
                        if (!diff.AreEqual)
                        {
                            TestTools.ShowDifferences(diff);
                        }
                        Assert.True(diff.AreEqual, "[" + provider.GetType().Name + "] Graphs were not equal");
                    }
                    else
                    {
                        this.Fail(provider, "LoadGraph() returned error - " + resArgs.Error.Message, resArgs.Error);
                    }
                }
                else
                {
                    this.Fail(provider, "SaveGraph() returned error - " + resArgs.Error.Message, resArgs.Error);
                }
            }
            finally
            {
                provider.Dispose();
            }
        }
 public void WhenTheTwoGraphsAreComparedAndTheResultIsPutIntoAReport()
 {
     this.graphreport = firstgraph.Difference(secondgraph);
 }
Esempio n. 8
0
        public override void Run(string[] args)
        {
            if (args.Length < 2)
            {
                this.ShowUsage();
                return;
            }

            //Check Configuration File is OK
            String config = args[1];

            if (args[1].Equals("-help"))
            {
                this.ShowUsage();
                return;
            }
            if (!File.Exists(config))
            {
                Console.Error.WriteLine("rdfSqlStorage: Error: Specified migration configuration file '" + config + "' does not exist!");
                return;
            }

            //Check for other options
            this.CheckOptions(args);

            try
            {
                Graph g = new Graph();
                g.LoadFromFile(config);
                Console.WriteLine("rdfSqlStorage: Read migration configuration file OK...");

                ConfigurationLoader.AutoDetectObjectFactories(g);

                INode sourceNode = g.GetUriNode(new Uri("dotnetrdf:migration:source"));
                if (sourceNode == null)
                {
                    Console.Error.WriteLine("rdfSqlStorage: Error: Expected to find the source for the migration specified by the special URI <dotnetrdf:migration:source> but it does not exist in the given Configuration File!");
                    return;
                }
                INode targetNode = g.GetUriNode(new Uri("dotnetrdf:migration:target"));
                if (targetNode == null)
                {
                    Console.Error.WriteLine("rdfSqlStorage: Error: Expected to find the target for the migration specified by the special URI <dotnetrdf:migration:target> but it does not exist in the given Configuration File!");
                    return;
                }

                //Try to load the Objects
                Object sourceObj = ConfigurationLoader.LoadObject(g, sourceNode);
                if (!(sourceObj is ISqlIOManager))
                {
                    Console.Error.WriteLine("rdfSqlStorage: Error: Expected the migration source to be loadable as an object of type ISqlIOManager!");
                    return;
                }
                Object targetObj = ConfigurationLoader.LoadObject(g, targetNode);
                if (!(targetObj is IGenericIOManager))
                {
                    Console.Error.WriteLine("rdfSqlStorage: Error: Expected the migration target to be loadable as an object of type IGenericIOManager!");
                    return;
                }
                Console.WriteLine("rdfSqlStorage: Loaded migration source and target OK...");

                //Retrieve Graph list from Migration Source
                ISqlIOManager source = (ISqlIOManager)sourceObj;
                Console.WriteLine("rdfSqlStorage: Retrieving Graph URIs from migration source...");
                try
                {
                    source.Open(true);
                    List <Uri> uris = source.GetGraphUris();
                    Console.WriteLine("rdfSqlStorage: Migration source has " + uris.Count + " Graph URIs");

                    //Start migrating Graphs
                    IGenericIOManager target = (IGenericIOManager)targetObj;
                    for (int i = 0; i < uris.Count; i++)
                    {
                        Console.WriteLine("rdfSqlStorage: Migrating Graph '" + uris[i].ToSafeString() + "' (" + (i + 1) + " of " + uris.Count + ")...");

                        String id = source.GetGraphID(uris[i]);

                        using (Graph temp = new Graph())
                        {
                            temp.BaseUri = uris[i];
                            Console.WriteLine("rdfSqlStorage: Loading Graph into memory...");
                            source.LoadTriples(temp, id);
                            Console.WriteLine("rdfSqlStorage: Loaded " + temp.Triples.Count + " Triple(s)");

                            Console.WriteLine("rdfSqlStorage: Saving Graph to migration target...");
                            target.SaveGraph(temp);
                            Console.WriteLine("rdfSqlStorage: Saved Graph OK");

                            if (this._verify)
                            {
                                Console.WriteLine("rdfSqlStorage: Retrieving newly saved Graph from migration target to verify data migration...");
                                using (Graph temp2 = new Graph())
                                {
                                    target.LoadGraph(temp2, uris[i]);
                                    Console.WriteLine("rdfSqlStorage: Retrieved newly saved Graph OK, proceeding to verify data...");

                                    GraphDiffReport report = temp.Difference(temp2);
                                    if (!report.AreEqual)
                                    {
                                        Console.Error.WriteLine("rdfSqlStorage: Warning: Data Verification failed: " + report.AddedTriples.Count() + " incorrect Ground Triple(s) and " + report.AddedMSGs.Count() + " incorrect MSGs containing " + report.AddedMSGs.Sum(x => x.Triples.Count) + " non-Ground Triple(s)");
                                        if (this._halt)
                                        {
                                            Console.Error.WriteLine("rdfSqlStorage: Error: Halting due to data verification failure!");
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("rdfSqlStorage: Data Verified OK!");
                                    }
                                    temp2.Dispose();
                                }
                            }

                            temp.Dispose();
                        }
                        GC.GetTotalMemory(true);
                        Console.WriteLine();
                    }

                    Console.WriteLine("rdfSqlStorage: Finishing Migrating Graphs!");
                }
                finally
                {
                    source.Close(true);
                }
            }
            catch (RdfParserSelectionException selEx)
            {
                Console.Error.WriteLine("rdfSqlStorage: Error: Specified migration configuration file is not in a RDF format that the tool understands!");
                this.PrintErrorTrace(selEx);
            }
            catch (RdfParseException parseEx)
            {
                Console.Error.WriteLine("rdfSqlStorage: Error: Specified migration configuration file is not valid RDF!");
                this.PrintErrorTrace(parseEx);
            }
            catch (DotNetRdfConfigurationException configEx)
            {
                Console.Error.WriteLine("rdfSqlStorage: Error: Specified migration configuration file contains malformed configuration information!");
                this.PrintErrorTrace(configEx);
            }
        }