public void ConfigurationLookupValue4() { Graph g = new Graph(); String value = ConfigurationLoader.GetConfigurationValue(g, g.CreateBlankNode("a"), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyType))); Assert.Null(value); }
public void ConfigurationLookupValue2() { String graph = Prefixes + @" _:a dnr:type <http://uri> ."; Graph g = new Graph(); g.LoadFromString(graph); String value = ConfigurationLoader.GetConfigurationValue(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.Equal("http://uri/", value); }
public void ConfigurationLookupValue1() { String graph = Prefixes + @" _:a dnr:type ""literal"" ."; Graph g = new Graph(); g.LoadFromString(graph); String value = ConfigurationLoader.GetConfigurationValue(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.AreEqual("literal", value); }
public void ConfigurationLookupValue3() { String graph = Prefixes + @" _:a dnr:type <appsetting:ConfigurationLookupString3> ."; Graph g = new Graph(); g.LoadFromString(graph); _testSettings.SettSetting("ConfigurationLookupString3", "literal"); String value = ConfigurationLoader.GetConfigurationValue(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.Equal("literal", value); }
public void ConfigurationLookupValue3() { String graph = Prefixes + @" _:a dnr:type <appsetting:ConfigurationLookupString3> ."; Graph g = new Graph(); g.LoadFromString(graph); System.Configuration.ConfigurationManager.AppSettings["ConfigurationLookupString3"] = "literal"; String value = ConfigurationLoader.GetConfigurationValue(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.AreEqual("literal", value); }
/// <summary> /// Tries to load a SPARQL Endpoint 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) { BaseEndpoint endpoint = null; obj = null; switch (targetType.FullName) { case QueryEndpoint: String queryEndpointUri = ConfigurationLoader.GetConfigurationValue(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) }); if (queryEndpointUri == null) { return(false); } // Get Default/Named Graphs if specified IEnumerable <String> defaultGraphs = from n in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultGraphUri))) select n.ToString(); IEnumerable <String> namedGraphs = from n in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyNamedGraphUri))) select n.ToString(); endpoint = new SparqlRemoteEndpoint(UriFactory.Create(queryEndpointUri), defaultGraphs, namedGraphs); break; case UpdateEndpoint: String updateEndpointUri = ConfigurationLoader.GetConfigurationValue(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) }); if (updateEndpointUri == null) { return(false); } endpoint = new SparqlRemoteUpdateEndpoint(UriFactory.Create(updateEndpointUri)); break; case FederatedEndpoint: IEnumerable <INode> endpoints = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpoint))) .Concat(ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)))); foreach (INode e in endpoints) { Object temp = ConfigurationLoader.LoadObject(g, e); if (temp is SparqlRemoteEndpoint) { if (endpoint == null) { endpoint = new FederatedSparqlRemoteEndpoint((SparqlRemoteEndpoint)temp); } else { ((FederatedSparqlRemoteEndpoint)endpoint).AddEndpoint((SparqlRemoteEndpoint)temp); } } else { throw new DotNetRdfConfigurationException("Unable to load the SPARQL Endpoint identified by the Node '" + e.ToString() + "' as one of the values for the dnr:queryEndpoint/dnr:endpoint property points to an Object which cannot be loaded as an object which is a SparqlRemoteEndpoint"); } } break; } if (endpoint != null) { // Are there any credentials specified? String user, pwd; ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { endpoint.SetCredentials(user, pwd); } // Is there a Proxy Server specified INode proxyNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyProxy))); if (proxyNode != null) { Object proxy = ConfigurationLoader.LoadObject(g, proxyNode); if (proxy is IWebProxy) { endpoint.Proxy = (IWebProxy)proxy; // Are we supposed to use the same credentials for the proxy as for the endpoint? bool useCredentialsForProxy = ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUseCredentialsForProxy)), false); if (useCredentialsForProxy) { endpoint.UseCredentialsForProxy = true; } } else { throw new DotNetRdfConfigurationException("Unable to load SPARQL Endpoint identified by the Node '" + objNode.ToString() + "' as the value for the dnr:proxy property points to an Object which cannot be loaded as an object of type WebProxy"); } } } obj = endpoint; return(endpoint != null); }
/// <summary> /// Creates a new Base SPARQL Server Configuration based on information from a Configuration Graph /// </summary> /// <param name="context">HTTP Context</param> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> public BaseSparqlServerConfiguration(HttpContext context, IGraph g, INode objNode) : base(context, g, objNode) { //Get the Query Processor to be used INode procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryProcessor)); if (procNode != null) { Object temp = ConfigurationLoader.LoadObject(g, procNode); if (temp is ISparqlQueryProcessor) { this._queryProcessor = (ISparqlQueryProcessor)temp; } else { throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file specifies a value for the Handlers dnr:queryProcessor property which cannot be loaded as an object which implements the ISparqlQueryProcessor interface"); } } //SPARQL Query Default Config this._defaultGraph = ConfigurationLoader.GetConfigurationValue(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri)).ToSafeString(); this._defaultTimeout = ConfigurationLoader.GetConfigurationInt64(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyTimeout), this._defaultTimeout); this._defaultPartialResults = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPartialResults), this._defaultPartialResults); //Handler Configuration this._showQueryForm = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyShowQueryForm), this._showQueryForm); String defQueryFile = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultQueryFile)); if (defQueryFile != null) { defQueryFile = ConfigurationLoader.ResolvePath(defQueryFile); if (File.Exists(defQueryFile)) { using (StreamReader reader = new StreamReader(defQueryFile)) { this._defaultQuery = reader.ReadToEnd(); reader.Close(); } } } //Get Query Syntax to use try { String syntaxSetting = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertySyntax)); if (syntaxSetting != null) { this._syntax = (SparqlQuerySyntax)Enum.Parse(typeof(SparqlQuerySyntax), syntaxSetting); } } catch (Exception ex) { throw new DotNetRdfConfigurationException("Unable to set the Syntax for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:syntax property was not a valid value from the enum VDS.RDF.Parsing.SparqlQuerySyntax", ex); } //Get the SPARQL Describe Algorithm INode describeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDescribeAlgorithm)); if (describeNode != null) { if (describeNode.NodeType == NodeType.Literal) { String algoClass = ((ILiteralNode)describeNode).Value; try { Object desc = Activator.CreateInstance(Type.GetType(algoClass)); if (desc is ISparqlDescribe) { this._describer = (ISparqlDescribe)desc; } else { throw new DotNetRdfConfigurationException("Unable to set the Describe Algorithm for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:describeAlgorithm property was not a type name of a type that implements the ISparqlDescribe interface"); } } catch (DotNetRdfConfigurationException) { throw; } catch (Exception ex) { throw new DotNetRdfConfigurationException("Unable to set the Describe Algorithm for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:describeAlgorithm property was not a type name for a type that can be instantiated", ex); } } } //Get the Query Optimiser INode queryOptNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryOptimiser)); if (queryOptNode != null) { Object queryOpt = ConfigurationLoader.LoadObject(g, queryOptNode); if (queryOpt is IQueryOptimiser) { this._queryOptimiser = (IQueryOptimiser)queryOpt; } else { throw new DotNetRdfConfigurationException("Unable to set the Query Optimiser for the HTTP Handler identified by the Node '" + queryOptNode.ToString() + "' as the value given for the dnr:queryOptimiser property points to an Object which could not be loaded as an object which implements the required IQueryOptimiser interface"); } } //Get the Algebra Optimisers foreach (INode algOptNode in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAlgebraOptimiser))) { Object algOpt = ConfigurationLoader.LoadObject(g, algOptNode); if (algOpt is IAlgebraOptimiser) { this._algebraOptimisers.Add((IAlgebraOptimiser)algOpt); } else { throw new DotNetRdfConfigurationException("Unable to set the Algebra Optimiser for the HTTP Handler identified by the Node '" + algOptNode.ToString() + "' as the value given for the dnr:algebraOptimiser property points to an Object which could not be loaded as an object which implements the required IAlgebraOptimiser interface"); } } //Then get the Update Processor to be used procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUpdateProcessor)); if (procNode != null) { Object temp = ConfigurationLoader.LoadObject(g, procNode); if (temp is ISparqlUpdateProcessor) { this._updateProcessor = (ISparqlUpdateProcessor)temp; } else { throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file specifies a value for the Handlers dnr:updateProcessor property which cannot be loaded as an object which implements the ISparqlUpdateProcessor interface"); } } //Handler Settings this._showUpdateForm = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyShowUpdateForm), this._showUpdateForm); String defUpdateFile = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultUpdateFile)); if (defUpdateFile != null) { defUpdateFile = ConfigurationLoader.ResolvePath(defUpdateFile); if (File.Exists(defUpdateFile)) { using (StreamReader reader = new StreamReader(defUpdateFile)) { this._defaultUpdate = reader.ReadToEnd(); reader.Close(); } } } //Then get the Protocol Processor to be used procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyProtocolProcessor)); if (procNode != null) { Object temp = ConfigurationLoader.LoadObject(g, procNode); if (temp is ISparqlHttpProtocolProcessor) { this._protocolProcessor = (ISparqlHttpProtocolProcessor)temp; } else { throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file specifies a value for the Handlers dnr:protocolProcessor property which cannot be loaded as an object which implements the ISparqlHttpProtocolProcessor interface"); } } if (this._queryProcessor == null && this._updateProcessor == null && this._protocolProcessor == null) { throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file does not specify at least one of a Query/Update/Protocol processor for the server using the dnr:queryProcessor/dnr:updateProcessor/dnr:protocolProcessor properties"); } //Get the Service Description Graph INode descripNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServiceDescription)); if (descripNode != null) { Object descrip = ConfigurationLoader.LoadObject(g, descripNode); if (descrip is IGraph) { this._serviceDescription = (IGraph)descrip; } else { throw new DotNetRdfConfigurationException("Unable to set the Service Description Graph for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:serviceDescription property points to an Object which could not be loaded as an object which implements the required IGraph interface"); } } }
/// <summary> /// Tries to load a SPARQL Query Processor 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; ISparqlQueryProcessor processor = null; INode storeObj; Object temp; INode propStorageProvider = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStorageProvider)); switch (targetType.FullName) { case LeviathanQueryProcessor: INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingDataset))); if (datasetObj != null) { temp = ConfigurationLoader.LoadObject(g, datasetObj); if (temp is ISparqlDataset) { processor = new LeviathanQueryProcessor((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Leviathan Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface"); } } else { // If no dnr:usingDataset try dnr:usingStore instead storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore))); if (storeObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IInMemoryQueryableStore) { processor = new LeviathanQueryProcessor((IInMemoryQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Leviathan Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface"); } } break; case SimpleQueryProcessor: storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore))); if (storeObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is INativelyQueryableStore) { processor = new SimpleQueryProcessor((INativelyQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Simple Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the INativelyQueryableStore interface"); } break; case GenericQueryProcessor: INode managerObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider); if (managerObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, managerObj); if (temp is IQueryableStorage) { processor = new GenericQueryProcessor((IQueryableStorage)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Generic Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object that cannot be loaded as an object which implements the IQueryableStorage interface"); } break; case RemoteQueryProcessor: INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint))); if (endpointObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteEndpoint) { processor = new RemoteQueryProcessor((SparqlRemoteEndpoint)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Remote Query Processor identified by the Node '" + objNode.ToSafeString() + "' as the value given for the dnr:endpoint property points to an Object that cannot be loaded as an object which is a SparqlRemoteEndpoint"); } break; case PelletQueryProcessor: String server = ConfigurationLoader.GetConfigurationValue(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyServer))); if (server == null) { return(false); } String kb = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStore))); if (kb == null) { return(false); } processor = new PelletQueryProcessor(UriFactory.Create(server), kb); break; } obj = processor; return(processor != null); }
/// <summary> /// Tries to load a Reasoner 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; Object output; switch (targetType.FullName) { case PelletReasonerType: String server = ConfigurationLoader.GetConfigurationValue(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyServer))); if (server == null) return false; String kb = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStore))); if (kb == null) return false; output = new PelletReasoner(UriFactory.Create(server), kb); break; case OwlReasonerWrapperType: INode reasonerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyOwlReasoner))); if (reasonerNode == null) return false; Object reasoner = ConfigurationLoader.LoadObject(g, reasonerNode); if (reasoner is IOwlReasoner) { output = new OwlReasonerWrapper((IOwlReasoner)reasoner); } else { throw new DotNetRdfConfigurationException("Unable to load configuration for the OWL Reasoner Wrapper identified by the Node '" + objNode.ToString() + "' as the value for the dnr:owlReasoner property points to an Object which cannot be loaded as an object which implements the IOwlReasoner interface"); } break; default: // Otherwise we'll just attempt to load this as an instance of an IInferenceEngine try { output = (IInferenceEngine)Activator.CreateInstance(targetType); } catch { // Any error means this loader can't load this type return false; } break; } if (output != null) { if (output is IInferenceEngine) { // Now initialise with any specified Graphs IEnumerable<INode> rulesGraphs = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingGraph))); foreach (INode rulesGraph in rulesGraphs) { Object temp = ConfigurationLoader.LoadObject(g, rulesGraph); if (temp is IGraph) { ((IInferenceEngine)output).Initialise((IGraph)temp); } else { throw new DotNetRdfConfigurationException("Unable to load Configuration for the Forward Chaining Reasoner identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:usingGraph property points to an Object which cannot be loaded as an object which implements the IGraph interface"); } } } } obj = output; return true; }