public void ConfigurationLoadObjectGraphCollection1() { String graph = ConfigLookupTests.Prefixes + @" _:a a dnr:GraphCollection ; dnr:type ""VDS.RDF.GraphCollection"" ."; Graph g = new Graph(); g.LoadFromString(graph); BaseGraphCollection collection = ConfigurationLoader.LoadObject(g, g.GetBlankNode("a")) as BaseGraphCollection; Assert.IsNotNull(collection); Assert.AreEqual(typeof(GraphCollection), collection.GetType()); }
/// <summary> /// Creates a new Base Triple Store /// </summary> /// <param name="graphCollection">Graph Collection to use</param> protected BaseTripleStore(BaseGraphCollection graphCollection) { if (graphCollection == null) throw new ArgumentNullException("graphCollection", "Graph Collection must be an non-null instance of a class which derives from BaseGraphCollection"); this._graphs = graphCollection; this.GraphAddedHandler = new GraphEventHandler(this.OnGraphAdded); this.GraphRemovedHandler = new GraphEventHandler(this.OnGraphRemoved); this.GraphChangedHandler = new GraphEventHandler(this.OnGraphChanged); this.GraphMergedHandler = new GraphEventHandler(this.OnGraphMerged); this.GraphClearedHandler = new GraphEventHandler(this.OnGraphCleared); //Attach Handlers to the Graph Collection this._graphs.GraphAdded += this.GraphAddedHandler; this._graphs.GraphRemoved += this.GraphRemovedHandler; }
public void ConfigurationLoadObjectGraphCollection5() { String graph = ConfigLookupTests.Prefixes + @" _:a a dnr:GraphCollection ; dnr:type ""VDS.RDF.WebDemandGraphCollection"" ; dnr:usingGraphCollection _:b . _:b a dnr:GraphCollection ; dnr:type ""VDS.RDF.ThreadSafeGraphCollection"" ; dnr:usingGraphCollection _:c . _:c a dnr:GraphCollection ; dnr:type ""VDS.RDF.GraphCollection"" ."; Graph g = new Graph(); g.LoadFromString(graph); BaseGraphCollection collection = ConfigurationLoader.LoadObject(g, g.GetBlankNode("a")) as BaseGraphCollection; Assert.NotNull(collection); Assert.Equal(typeof(WebDemandGraphCollection), collection.GetType()); }
/// <summary> /// Tries to load a Triple Store based on information from the Configuration Graph. /// </summary> /// <param name="g">Configuration Graph.</param> /// <param name="objNode">Object Node.</param> /// <param name="targetType">Target Type.</param> /// <param name="obj">Output Object.</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; ITripleStore store = null; INode subObj; Object temp; // Get Property Nodes we need INode propStorageProvider = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStorageProvider)), propAsync = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyAsync)); // Check whether to use a specific Graph Collection INode collectionNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingGraphCollection))); // Instantiate the Store Class switch (targetType.FullName) { case TripleStore: if (collectionNode == null) { store = new TripleStore(); } else { BaseGraphCollection graphCollection = ConfigurationLoader.LoadObject(g, collectionNode) as BaseGraphCollection; if (graphCollection == null) { throw new DotNetRdfConfigurationException("Unable to load the Triple Store identified by the Node '" + objNode.ToString() + "' as the dnr:usingGraphCollection points to an object which cannot be loaded as an instance of the required type BaseGraphCollection"); } store = new TripleStore(graphCollection); } break; case WebDemandTripleStore: store = new WebDemandTripleStore(); break; case PersistentTripleStore: subObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider); if (subObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, subObj); if (temp is IStorageProvider) { store = new PersistentTripleStore((IStorageProvider)temp); } else { throw new DotNetRdfConfigurationException("Unable to load a Persistent Triple Store identified by the Node '" + objNode.ToString() + "' as the value given the for dnr:genericManager property points to an Object which could not be loaded as an object which implements the IStorageProvider interface"); } break; } // Read in additional data to be added to the Store if (store != null) { IEnumerable <INode> sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingGraph))); // Read from Graphs foreach (INode source in sources) { temp = ConfigurationLoader.LoadObject(g, source); if (temp is IGraph) { store.Add((IGraph)temp); } else { throw new DotNetRdfConfigurationException("Unable to load data from a Graph for the Triple Store identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:usingGraph property points to an Object that cannot be loaded as an object which implements the IGraph interface"); } } // Load from Embedded Resources sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromEmbedded))); foreach (INode source in sources) { if (source.NodeType == NodeType.Literal) { EmbeddedResourceLoader.Load(store, ((ILiteralNode)source).Value); } else { throw new DotNetRdfConfigurationException("Unable to load data from an Embedded Resource for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:fromEmbedded property is not a Literal Node as required"); } } // Read from Files - we assume these files are Dataset Files sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromFile))); foreach (INode source in sources) { if (source.NodeType == NodeType.Literal) { FileLoader.Load(store, ConfigurationLoader.ResolvePath(((ILiteralNode)source).Value)); } else { throw new DotNetRdfConfigurationException("Unable to load data from a file for the Triple Store identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:fromFile property is not a Literal Node as required"); } } // Finally we'll apply any reasoners if (store is IInferencingTripleStore) { IEnumerable <INode> reasoners = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyReasoner))); foreach (INode reasoner in reasoners) { temp = ConfigurationLoader.LoadObject(g, reasoner); if (temp is IInferenceEngine) { ((IInferencingTripleStore)store).AddInferenceEngine((IInferenceEngine)temp); } else { throw new DotNetRdfConfigurationException("Unable to apply a reasoner for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:reasoner property points to an Object which cannot be loaded as an object which implements the IInferenceEngine interface"); } } } // And as an absolute final step if the store is transactional we'll flush any changes we've made if (store is ITransactionalStore) { ((ITransactionalStore)store).Flush(); } } obj = store; return(store != null); }
/// <summary> /// Creates a new Triple Store using the given Graph collection which may be non-empty /// </summary> /// <param name="graphCollection">Graph Collection</param> public TripleStore(BaseGraphCollection graphCollection) : base(graphCollection) { }