/// <summary> /// Tries to load a Web Proxy 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; WebProxy proxy = null; // Can we create a Proxy? String server = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyServer))); if (server == null) { return(false); } proxy = new WebProxy(server); // Does the proxy have credentials attached? String user, pwd; ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { proxy.Credentials = new NetworkCredential(user, pwd); } obj = proxy; return(proxy != null); }
public void ConfigurationLookupString4() { Graph g = new Graph(); String value = ConfigurationLoader.GetConfigurationString(g, g.CreateBlankNode("a"), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyType))); Assert.Null(value); }
/// <summary> /// Attempts to load an Object of the given type identified by the given Node and returned as the Type that this loader generates /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Created Object</param> /// <returns>True if the loader succeeded in creating an Object</returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; String server, port, db, user, pwd; int p = -1; //Create the URI Nodes we're going to use to search for things INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer), propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase); //Get Server and Database details server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { server = "localhost"; } db = ConfigurationLoader.GetConfigurationString(g, objNode, propDb); if (db == null) { db = VirtuosoManager.DefaultDB; } //Get Port port = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPort)); if (!Int32.TryParse(port, out p)) { p = VirtuosoManager.DefaultPort; } //Get user credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user == null || pwd == null) { return(false); } //Based on this information create a Manager if possible switch (targetType.FullName) { case NonNativeVirtuosoManager: obj = new NonNativeVirtuosoManager(server, p, db, user, pwd); break; case Virtuoso: //Get Server settings server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } obj = new VirtuosoManager(server, p, db, user, pwd); break; } return(obj != null); }
/// <summary> /// Creates a new Update Handler Configuration /// </summary> /// <param name="context">HTTP Context</param> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> public BaseUpdateHandlerConfiguration(IHttpContext context, IGraph g, INode objNode) : base(context, g, objNode) { // Then get the Update Processor to be used ISparqlUpdateProcessor processor; INode procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateProcessor))); if (procNode == null) { throw new DotNetRdfConfigurationException("Unable to load Update Handler Configuration as the RDF configuration file does not specify a dnr:updateProcessor property for the Handler"); } Object temp = ConfigurationLoader.LoadObject(g, procNode); if (temp is ISparqlUpdateProcessor) { processor = (ISparqlUpdateProcessor)temp; } else { throw new DotNetRdfConfigurationException("Unable to load Update Handler 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"); } this._processor = processor; // Handler Settings this._showUpdateForm = ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyShowUpdateForm)), this._showUpdateForm); String defUpdateFile = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(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(); } } } // Get the Service Description Graph INode descripNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(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"); } } }
public void ConfigurationLookupString1() { String graph = Prefixes + @" _:a dnr:type ""literal"" ."; Graph g = new Graph(); g.LoadFromString(graph); String value = ConfigurationLoader.GetConfigurationString(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.Equal("literal", value); }
public void ConfigurationLookupString2() { String graph = Prefixes + @" _:a dnr:type <http://uri> ."; Graph g = new Graph(); g.LoadFromString(graph); String value = ConfigurationLoader.GetConfigurationString(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.Null(value); }
public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { switch (targetType.FullName) { case FileManager: String storeID = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase)); if (storeID != null) { //Supports using dnr:loadMode to specify the indexes to be used String indices = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); if (indices == null) { obj = new AlexandriaFileManager(ConfigurationLoader.ResolvePath(storeID)); } else { obj = new AlexandriaFileManager(ConfigurationLoader.ResolvePath(storeID), this.ParseIndexTypes(indices)); } return true; } //If we get here then the required dnr:database property was missing throw new DotNetRdfConfigurationException("Unable to load the File Manager identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:database"); break; case FileDataset: INode managerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:genericManager")); if (managerNode == null) { throw new DotNetRdfConfigurationException("Unable to load the File Dataset identified by the Node '" + objNode.ToString() + "' since there we no value for the required property dnr:genericManager"); } Object temp = ConfigurationLoader.LoadObject(g, managerNode); if (temp is AlexandriaFileManager) { obj = new AlexandriaFileDataset((AlexandriaFileManager)temp); return true; } else { throw new DotNetRdfConfigurationException("Unable to load the File Dataset identified by the Node '" + objNode.ToString() + "' since the value for the dnr:genericManager property pointed to an Object which could not be loaded as an object of type AlexandriaFileManager"); } break; } obj = null; return false; }
/// <summary> /// Tries to load a SQL IO Manager 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) { ISqlIOManager manager = null; String server, port, db, user, pwd; //Create the URI Nodes we're going to use to search for things INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer), propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase); //Get Server and Database details server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { server = "localhost"; } db = ConfigurationLoader.GetConfigurationString(g, objNode, propDb); if (db == null) { obj = null; return(false); } //Get user credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); //Based on this information create a Manager if possible switch (targetType.FullName) { case MicrosoftSqlManager: if (user == null || pwd == null) { manager = new MicrosoftSqlStoreManager(server, db); } else { manager = new MicrosoftSqlStoreManager(server, db, user, pwd); } break; case MySqlManager: if (user != null && pwd != null) { manager = new MySqlStoreManager(server, db, user, pwd); } break; } obj = manager; return(manager != null); }
public void ConfigurationLookupString3() { String graph = Prefixes + @" _:a dnr:type <appsetting:ConfigurationLookupString3> ."; Graph g = new Graph(); g.LoadFromString(graph); _testSettings.SettSetting("ConfigurationLookupString3", "literal"); String value = ConfigurationLoader.GetConfigurationString(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.Equal("literal", value); }
public void ConfigurationLookupString3() { String graph = Prefixes + @" _:a dnr:type <appsetting:ConfigurationLookupString3> ."; Graph g = new Graph(); g.LoadFromString(graph); System.Configuration.ConfigurationManager.AppSettings["ConfigurationLookupString3"] = "literal"; String value = ConfigurationLoader.GetConfigurationString(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.AreEqual("literal", value); }
/// <summary> /// Creates a new Quick Connection /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> public QuickConnect(IGraph g, INode objNode) { this._g = g; this._objNode = objNode; //Get Type String typeName = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyType))); if (typeName != null) { try { this._type = System.Type.GetType(typeName); //Force oureslves into the catch block where we try assembly qualifiying the name if (this._type == null) { throw new Exception(); } } catch { //Was it not assembly qualified? Try adding dotNetRDF to ensure it if (!typeName.Contains(',')) { typeName = typeName += ", dotNetRDF"; try { this._type = System.Type.GetType(typeName); } catch { this._type = null; } } } } else { this._type = null; } }
/// <summary> /// Tries to load a Permission 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; IPermission result = null; switch (targetType.FullName) { case Permission: String action = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyAction))); result = new Permission(action); break; case PermissionSet: IEnumerable <String> actions = from n in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyAction))) where n.NodeType == NodeType.Literal select((ILiteralNode)n).Value; result = new PermissionSet(actions); break; } obj = result; return(result != null); }
/// <summary> /// Tries to load an object 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; INode index = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "index")); //INode indexer = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "indexer")); INode searcher = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "searcher")); INode analyzer = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "analyzer")); INode schema = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "schema")); INode version = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "version")); Object tempIndex, tempAnalyzer, tempSchema; int ver = 2900; //Always check for the version ver = ConfigurationLoader.GetConfigurationInt32(g, objNode, version, 2900); switch (targetType.FullName) { case DefaultIndexSchema: obj = new DefaultIndexSchema(); break; case FullTextOptimiser: //Need to get the Search Provider INode providerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, searcher); if (providerNode == null) { throw new DotNetRdfConfigurationException("Unable to load the Full Text Optimiser specified by the Node '" + objNode.ToString() + "' as there was no value specified for the required dnr-ft:searcher property"); } Object tempSearcher = ConfigurationLoader.LoadObject(g, providerNode); if (tempSearcher is IFullTextSearchProvider) { obj = new FullTextOptimiser((IFullTextSearchProvider)tempSearcher); } else { throw new DotNetRdfConfigurationException("Unable to load the Full Text Optimiser specified by the Node '" + objNode.ToString() + "' as the value specified for the dnr-ft:searcher property pointed to an object which could not be loaded as a type that implements the required IFullTextSearchProvider interface"); } break; case LuceneObjectsIndexer: case LucenePredicatesIndexer: case LuceneSubjectsIndexer: case LuceneSearchProvider: //For any Lucene Indexer/Search Provider need to know the Index, Analyzer and Schema to be used //Then get the Index tempIndex = ConfigurationLoader.GetConfigurationNode(g, objNode, index); if (tempIndex == null) { throw new DotNetRdfConfigurationException("Unable to load the Lucene Indexer specified by the Node '" + objNode.ToString() + "' as there was no value specified for the required dnr-ft:index property"); } tempIndex = ConfigurationLoader.LoadObject(g, (INode)tempIndex); if (tempIndex is Directory) { //Next get the Analyzer (assume Standard if none specified) tempAnalyzer = ConfigurationLoader.GetConfigurationNode(g, objNode, analyzer); if (tempAnalyzer == null) { tempAnalyzer = new StandardAnalyzer(this.GetLuceneVersion(ver)); } else { tempAnalyzer = ConfigurationLoader.LoadObject(g, (INode)tempAnalyzer); } if (tempAnalyzer is Analyzer) { //Finally get the Schema (assume Default if none specified) tempSchema = ConfigurationLoader.GetConfigurationNode(g, objNode, schema); if (tempSchema == null) { tempSchema = new DefaultIndexSchema(); } else { tempSchema = ConfigurationLoader.LoadObject(g, (INode)tempSchema); } if (tempSchema is IFullTextIndexSchema) { //Now we can create the Object switch (targetType.FullName) { case LuceneObjectsIndexer: obj = new LuceneObjectsIndexer((Directory)tempIndex, (Analyzer)tempAnalyzer, (IFullTextIndexSchema)tempSchema); break; case LucenePredicatesIndexer: obj = new LucenePredicatesIndexer((Directory)tempIndex, (Analyzer)tempAnalyzer, (IFullTextIndexSchema)tempSchema); break; case LuceneSubjectsIndexer: obj = new LuceneSubjectsIndexer((Directory)tempIndex, (Analyzer)tempAnalyzer, (IFullTextIndexSchema)tempSchema); break; case LuceneSearchProvider: //Before the Search Provider has been loaded determine whether we need to carry out auto-indexing List <INode> sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "buildIndexFor"))).ToList(); if (sources.Count > 0) { //If there are sources to index ensure we have an indexer to index with INode indexerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "buildIndexWith"))); if (indexerNode == null) { throw new DotNetRdfConfigurationException("Unable to load the Lucene Search Provider specified by the Node '" + objNode.ToString() + "' as there were values specified for the dnr-ft:buildIndexFor property but no dnr-ft:buildIndexWith property was found"); } IFullTextIndexer indexer = ConfigurationLoader.LoadObject(g, indexerNode) as IFullTextIndexer; if (indexer == null) { throw new DotNetRdfConfigurationException("Unable to load the Lucene Search Provider specified by the Node '" + objNode.ToString() + "' as the value given for the dnr-ft:buildIndexWith property pointed to an Object which could not be loaded as a type that implements the required IFullTextIndexer interface"); } try { //For Each Source load it and Index it foreach (INode sourceNode in sources) { Object source = ConfigurationLoader.LoadObject(g, sourceNode); if (source is ISparqlDataset) { indexer.Index((ISparqlDataset)source); } else if (source is ITripleStore) { foreach (IGraph graph in ((ITripleStore)source).Graphs) { indexer.Index(graph); } } else if (source is IGraph) { indexer.Index((IGraph)source); } else { throw new DotNetRdfConfigurationException("Unable to load the Lucene Search Provider specified by the Node '" + objNode.ToString() + "' as a value given for the dnr-ft:buildIndexFor property ('" + sourceNode.ToString() + "') pointed to an Object which could not be loaded as a type that implements one of the required interfaces: IGraph, ITripleStore or ISparqlDataset"); } } } finally { indexer.Dispose(); } } //Then we actually load the Search Provider obj = new LuceneSearchProvider(this.GetLuceneVersion(ver), (Directory)tempIndex, (Analyzer)tempAnalyzer, (IFullTextIndexSchema)tempSchema); break; } } else { throw new DotNetRdfConfigurationException("Unable to load the Lucene Indexer specified by the Node '" + objNode.ToString() + "' as the value given for the dnr-ft:schema property pointed to an Object which could not be loaded as a type that implements the required IFullTextIndexSchema interface"); } } else { throw new DotNetRdfConfigurationException("Unable to load the Lucene Indexer specified by the Node '" + objNode.ToString() + "' as the value given for the dnr-ft:analyzer property pointed to an Object which could not be loaded as a type that derives from the required Lucene.Net.Analysis.Analyzer type"); } } else { throw new DotNetRdfConfigurationException("Unable to load the Lucene Indexer specified by the Node '" + objNode.ToString() + "' as the value given for the dnr-ft:index property pointed to an Object which could not be loaded as a type that derives from the required Lucene.Net.Store.Directory type"); } break; default: try { if (this._luceneAnalyzerType.IsAssignableFrom(targetType)) { if (targetType.GetConstructor(new Type[] { typeof(LucVersion) }) != null) { obj = Activator.CreateInstance(targetType, new Object[] { this.GetLuceneVersion(ver) }); } else { obj = Activator.CreateInstance(targetType); } } else if (this._luceneDirectoryType.IsAssignableFrom(targetType)) { String dir = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromFile)); if (dir != null) { try { obj = Activator.CreateInstance(targetType, new Object[] { dir }); } catch { MethodInfo method = targetType.GetMethod("Open", new Type[] { typeof(DirInfo) }); if (method != null) { obj = method.Invoke(null, new Object[] { new DirInfo(ConfigurationLoader.ResolvePath(dir)) }); } } } else { obj = Activator.CreateInstance(targetType); } //Ensure the Index if necessary if (obj != null) { if (ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "ensureIndex")), false)) { IndexWriter writer = new IndexWriter((Directory)obj, new StandardAnalyzer(this.GetLuceneVersion(ver))); writer.Close(); } } } } catch { //Since we know we don't allow loading of all analyzers and directories we allow for users to inject other object factories //which may know how to load those specific instances obj = null; } break; } return(obj != 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 Generic IO Manager 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) { IStorageProvider storageProvider = null; IStorageServer storageServer = null; SparqlConnectorLoadMethod loadMode; obj = null; String server, user, pwd, store, catalog, loadModeRaw; Object temp; INode storeObj; // Create the URI Nodes we're going to use to search for things INode propServer = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyServer)), propDb = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDatabase)), propStore = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStore)), propAsync = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyAsync)), propStorageProvider = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStorageProvider)); switch (targetType.FullName) { case AllegroGraph: // Get the Server, Catalog and Store server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } catalog = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyCatalog))); store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } // Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { storageProvider = new AllegroGraphConnector(server, catalog, store, user, pwd); } else { storageProvider = new AllegroGraphConnector(server, catalog, store); } break; case AllegroGraphServer: // Get the Server, Catalog and User Credentials server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } catalog = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyCatalog))); ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { storageServer = new AllegroGraphServer(server, catalog, user, pwd); } else { storageServer = new AllegroGraphServer(server, catalog); } break; case DatasetFile: // Get the Filename and whether the loading should be done asynchronously String file = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromFile))); if (file == null) { return(false); } file = ConfigurationLoader.ResolvePath(file); bool isAsync = ConfigurationLoader.GetConfigurationBoolean(g, objNode, propAsync, false); storageProvider = new DatasetFileManager(file, isAsync); break; case Dydra: throw new DotNetRdfConfigurationException("DydraConnector is no longer supported by dotNetRDF and is considered obsolete"); case FourStore: // Get the Server and whether Updates are enabled server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } bool enableUpdates = ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEnableUpdates)), true); storageProvider = new FourStoreConnector(server, enableUpdates); break; case Fuseki: // Get the Server URI server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } storageProvider = new FusekiConnector(server); break; case InMemory: // Get the Dataset/Store INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingDataset))); if (datasetObj != null) { temp = ConfigurationLoader.LoadObject(g, datasetObj); if (temp is ISparqlDataset) { storageProvider = new InMemoryManager((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager 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) { temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IInMemoryQueryableStore) { storageProvider = new InMemoryManager((IInMemoryQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager 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"); } } else { // If no dnr:usingStore either then create a new empty store storageProvider = new InMemoryManager(); } } break; case ReadOnly: // Get the actual Manager we are wrapping storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider); temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IStorageProvider) { storageProvider = new ReadOnlyConnector((IStorageProvider)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IStorageProvider interface"); } break; case ReadOnlyQueryable: // Get the actual Manager we are wrapping storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider); temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IQueryableStorage) { storageProvider = new QueryableReadOnlyConnector((IQueryableStorage)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Queryable Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IQueryableStorage interface"); } break; case Sesame: case SesameV5: case SesameV6: // Get the Server and Store ID server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { storageProvider = (IStorageProvider)Activator.CreateInstance(targetType, new Object[] { server, store, user, pwd }); } else { storageProvider = (IStorageProvider)Activator.CreateInstance(targetType, new Object[] { server, store }); } break; case SesameServer: // Get the Server and User Credentials server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { storageServer = new SesameServer(server, user, pwd); } else { storageServer = new SesameServer(server); } break; case Sparql: // Get the Endpoint URI or the Endpoint server = ConfigurationLoader.GetConfigurationString(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) }); // What's the load mode? loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyLoadMode))); loadMode = SparqlConnectorLoadMethod.Construct; if (loadModeRaw != null) { try { loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw); } catch { throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid"); } } if (server == null) { INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpoint)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)) }); if (endpointObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteEndpoint) { storageProvider = new SparqlConnector((SparqlRemoteEndpoint)temp, loadMode); } else { throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint"); } } else { // Are there any Named/Default Graph URIs IEnumerable <Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultGraphUri))) where def.NodeType == NodeType.Uri select((IUriNode)def).Uri; IEnumerable <Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyNamedGraphUri))) where named.NodeType == NodeType.Uri select((IUriNode)named).Uri; if (defGraphs.Any() || namedGraphs.Any()) { storageProvider = new SparqlConnector(new SparqlRemoteEndpoint(UriFactory.Create(server), defGraphs, namedGraphs), loadMode); } else { storageProvider = new SparqlConnector(UriFactory.Create(server), loadMode); } } break; case ReadWriteSparql: SparqlRemoteEndpoint queryEndpoint; SparqlRemoteUpdateEndpoint updateEndpoint; // Get the Query Endpoint URI or the Endpoint server = ConfigurationLoader.GetConfigurationString(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) }); // What's the load mode? loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyLoadMode))); loadMode = SparqlConnectorLoadMethod.Construct; if (loadModeRaw != null) { try { loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw); } catch { throw new DotNetRdfConfigurationException("Unable to load the ReadWriteSparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid"); } } if (server == null) { INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpoint)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)) }); if (endpointObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteEndpoint) { queryEndpoint = (SparqlRemoteEndpoint)temp; } else { throw new DotNetRdfConfigurationException("Unable to load the ReadWriteSparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:queryEndpoint/dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint"); } } else { // Are there any Named/Default Graph URIs IEnumerable <Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultGraphUri))) where def.NodeType == NodeType.Uri select((IUriNode)def).Uri; IEnumerable <Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyNamedGraphUri))) where named.NodeType == NodeType.Uri select((IUriNode)named).Uri; if (defGraphs.Any() || namedGraphs.Any()) { queryEndpoint = new SparqlRemoteEndpoint(UriFactory.Create(server), defGraphs, namedGraphs); ; } else { queryEndpoint = new SparqlRemoteEndpoint(UriFactory.Create(server)); } } // Find the Update Endpoint or Endpoint URI server = ConfigurationLoader.GetConfigurationString(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) }); if (server == null) { INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpoint)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)) }); if (endpointObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteUpdateEndpoint) { updateEndpoint = (SparqlRemoteUpdateEndpoint)temp; } else { throw new DotNetRdfConfigurationException("Unable to load the ReadWriteSparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:updateEndpoint/dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteUpdateEndpoint"); } } else { updateEndpoint = new SparqlRemoteUpdateEndpoint(UriFactory.Create(server)); } storageProvider = new ReadWriteSparqlConnector(queryEndpoint, updateEndpoint, loadMode); break; case SparqlHttpProtocol: // Get the Service URI server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } storageProvider = new SparqlHttpProtocolConnector(UriFactory.Create(server)); break; case Stardog: case StardogV1: case StardogV2: case StardogV3: // Get the Server and Store server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } // Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); // Get Reasoning Mode StardogReasoningMode reasoning = StardogReasoningMode.None; String mode = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyLoadMode))); if (mode != null) { try { reasoning = (StardogReasoningMode)Enum.Parse(typeof(StardogReasoningMode), mode, true); } catch { reasoning = StardogReasoningMode.None; } } if (user != null && pwd != null) { switch (targetType.FullName) { case StardogV1: storageProvider = new StardogV1Connector(server, store, reasoning, user, pwd); break; case StardogV2: storageProvider = new StardogV2Connector(server, store, reasoning, user, pwd); break; case StardogV3: storageProvider = new StardogV3Connector(server, store, user, pwd); break; case Stardog: default: storageProvider = new StardogConnector(server, store, user, pwd); break; } } else { switch (targetType.FullName) { case StardogV1: storageProvider = new StardogV1Connector(server, store, reasoning); break; case StardogV2: storageProvider = new StardogV2Connector(server, store, reasoning); break; case StardogV3: storageProvider = new StardogV3Connector(server, store); break; case Stardog: default: storageProvider = new StardogConnector(server, store); break; } } break; case StardogServer: case StardogServerV1: case StardogServerV2: case StardogServerV3: // Get the Server and User Credentials server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { switch (targetType.FullName) { case StardogServerV1: storageServer = new StardogV1Server(server, user, pwd); break; case StardogServerV2: storageServer = new StardogV2Server(server, user, pwd); break; case StardogServerV3: storageServer = new StardogV3Server(server, user, pwd); break; case StardogServer: default: storageServer = new StardogServer(server, user, pwd); break; } } else { switch (targetType.FullName) { case StardogServerV1: storageServer = new StardogV1Server(server); break; case StardogServerV2: storageServer = new StardogV2Server(server); break; case StardogServerV3: storageServer = new StardogV3Server(server); break; case StardogServer: default: storageServer = new StardogServer(server); break; } } break; } // Set the return object if one has been loaded if (storageProvider != null) { obj = storageProvider; } else if (storageServer != null) { obj = storageServer; } // Check whether this is a standard HTTP manager and if so load standard configuration if (obj is BaseHttpConnector) { BaseHttpConnector connector = (BaseHttpConnector)obj; int timeout = ConfigurationLoader.GetConfigurationInt32(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyTimeout)), 0); if (timeout > 0) { connector.Timeout = timeout; } INode proxyNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyProxy))); if (proxyNode != null) { temp = ConfigurationLoader.LoadObject(g, proxyNode); if (temp is IWebProxy) { connector.Proxy = (IWebProxy)temp; } else { throw new DotNetRdfConfigurationException("Unable to load storage provider/server identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:proxy property pointed to an Object which could not be loaded as an object of the required type WebProxy"); } } } return(obj != null); }
/// <summary> /// Populates the settings from an existing serialized configuration /// </summary> /// <param name="g">Graph</param> /// <param name="objNode">Object Node</param> public virtual void PopulateFrom(IGraph g, INode objNode) { foreach (PropertyInfo property in this._properties.Keys) { ConnectionAttribute attr = this._properties[property]; if (!String.IsNullOrEmpty(attr.PopulateFrom)) { INode n = objNode; if (!String.IsNullOrEmpty(attr.PopulateVia)) { n = ConfigurationLoader.GetConfigurationNode(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateVia))); if (n == null) { continue; } } switch (attr.Type) { case ConnectionSettingType.Boolean: bool b = ConfigurationLoader.GetConfigurationBoolean(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateFrom)), (bool)property.GetValue(this, null)); property.SetValue(this, b, null); break; case ConnectionSettingType.File: case ConnectionSettingType.Password: case ConnectionSettingType.String: String s = ConfigurationLoader.GetConfigurationString(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateFrom))); if (!String.IsNullOrEmpty(s)) { property.SetValue(this, s, null); } else { //May be a URI as the object IUriNode u = ConfigurationLoader.GetConfigurationNode(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateFrom))) as IUriNode; if (u != null) { property.SetValue(this, u.Uri.AbsoluteUri, null); } } break; case ConnectionSettingType.Integer: int i = ConfigurationLoader.GetConfigurationInt32(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateFrom)), (int)property.GetValue(this, null)); property.SetValue(this, i, null); break; case ConnectionSettingType.Enum: String enumStr = ConfigurationLoader.GetConfigurationString(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateFrom))); if (!String.IsNullOrEmpty(enumStr)) { try { Object val = Enum.Parse(property.GetValue(this, null).GetType(), enumStr, false); property.SetValue(this, val, null); } catch { //Ignore errors } } break; } } } }
/// <summary> /// Tries to load a User Group 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; UserGroup result = null; switch (targetType.FullName) { case UserGroup: result = new UserGroup(); // Get the members of the Group IEnumerable <INode> members = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyMember))); foreach (INode member in members) { String username, password; ConfigurationLoader.GetUsernameAndPassword(g, member, true, out username, out password); if (username != null && password != null) { result.AddUser(new NetworkCredential(username, password)); } else { throw new DotNetRdfConfigurationException("Unable to load the User identified by the Node '" + member.ToString() + "' as there does not appear to be a valid username and password specified for this User either via the dnr:user and dnr:password properties or via a dnr:credentials property"); } } // Get the allow list for the Group IEnumerable <INode> allowed = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyAllow))); foreach (INode allow in allowed) { Object temp = ConfigurationLoader.LoadObject(g, allow); if (temp is IPermission) { result.AddAllowedAction((IPermission)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Permission identified by the Node '" + allow.ToString() + "' as the Object specified could not be loaded as an object which implements the IPermission interface"); } } // Get the deny list for the Group IEnumerable <INode> denied = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDeny))); foreach (INode deny in denied) { Object temp = ConfigurationLoader.LoadObject(g, deny); if (temp is IPermission) { result.AddDeniedAction((IPermission)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Permission identified by the Node '" + deny.ToString() + "' as the Object specified could not be loaded as an object which implements the IPermission interface"); } } // Does the User Group require authentication? result.AllowGuests = !ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyRequiresAuthentication)), true); // Is there a permission model specified? String mode = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyPermissionModel))); if (mode != null) { result.PermissionModel = (PermissionModel)Enum.Parse(typeof(PermissionModel), mode); } break; } obj = result; return(result != null); }
/// <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; }
/// <summary> /// Tries to load a Generic IO Manager 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) { IGenericIOManager manager = null; obj = null; String server, user, pwd, store; bool isAsync; Object temp; INode storeObj; //Create the URI Nodes we're going to use to search for things INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer), propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase), propStore = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStore), propAsync = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAsync); switch (targetType.FullName) { #if !NO_SYNC_HTTP case AllegroGraph: //Get the Server, Catalog and Store server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } String catalog = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog)); store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } //Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { manager = new AllegroGraphConnector(server, catalog, store, user, pwd); } else { manager = new AllegroGraphConnector(server, catalog, store); } break; #endif case DatasetFile: //Get the Filename and whether the loading should be done asynchronously String file = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromFile)); if (file == null) { return(false); } file = ConfigurationLoader.ResolvePath(file); isAsync = ConfigurationLoader.GetConfigurationBoolean(g, objNode, propAsync, false); manager = new DatasetFileManager(file, isAsync); break; #if !NO_SYNC_HTTP case Dydra: //Get the Account Name and Store String account = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog)); if (account == null) { return(false); } store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } //Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null) { manager = new DydraConnector(account, store, user); } else { manager = new DydraConnector(account, store); } break; case FourStore: //Get the Server and whether Updates are enabled server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } bool enableUpdates = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEnableUpdates), true); manager = new FourStoreConnector(server, enableUpdates); break; case Fuseki: //Get the Server URI server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } manager = new FusekiConnector(server); break; #endif case InMemory: //Get the Dataset/Store INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingDataset)); if (datasetObj != null) { temp = ConfigurationLoader.LoadObject(g, datasetObj); if (temp is ISparqlDataset) { manager = new InMemoryManager((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager 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, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore)); if (storeObj != null) { temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IInMemoryQueryableStore) { manager = new InMemoryManager((IInMemoryQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager 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"); } } else { //If no dnr:usingStore either then create a new empty store manager = new InMemoryManager(); } } break; #if !NO_SYNC_HTTP case Joseki: //Get the Query and Update URIs server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } String queryService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryPath)); if (queryService == null) { return(false); } String updateService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUpdatePath)); if (updateService == null) { manager = new JosekiConnector(server, queryService); } else { manager = new JosekiConnector(server, queryService, updateService); } break; #endif case ReadOnly: //Get the actual Manager we are wrapping storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IGenericIOManager) { manager = new ReadOnlyConnector((IGenericIOManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IGenericIOManager interface"); } break; case ReadOnlyQueryable: //Get the actual Manager we are wrapping storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IQueryableGenericIOManager) { manager = new QueryableReadOnlyConnector((IQueryableGenericIOManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Queryable Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IQueryableGenericIOManager interface"); } break; #if !NO_SYNC_HTTP case Sesame: case SesameV5: case SesameV6: //Get the Server and Store ID server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { manager = (IGenericIOManager)Activator.CreateInstance(targetType, new Object[] { server, store, user, pwd }); } else { manager = (IGenericIOManager)Activator.CreateInstance(targetType, new Object[] { server, store }); } break; case Sparql: //Get the Endpoint URI or the Endpoint server = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpointUri)); //What's the load mode? String loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); SparqlConnectorLoadMethod loadMode = SparqlConnectorLoadMethod.Construct; if (loadModeRaw != null) { try { #if SILVERLIGHT loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw, false); #else loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw); #endif } catch { throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid"); } } if (server == null) { INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpoint)); if (endpointObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteEndpoint) { manager = new SparqlConnector((SparqlRemoteEndpoint)temp, loadMode); } else { throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint"); } } else { //Are there any Named/Default Graph URIs IEnumerable <Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri)) where def.NodeType == NodeType.Uri select((IUriNode)def).Uri; IEnumerable <Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyNamedGraphUri)) where named.NodeType == NodeType.Uri select((IUriNode)named).Uri; if (defGraphs.Any() || namedGraphs.Any()) { manager = new SparqlConnector(new SparqlRemoteEndpoint(UriFactory.Create(server), defGraphs, namedGraphs), loadMode); } else { manager = new SparqlConnector(UriFactory.Create(server), loadMode); } } break; case SparqlHttpProtocol: //Get the Service URI server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } manager = new SparqlHttpProtocolConnector(UriFactory.Create(server)); break; case Stardog: //Get the Server and Store server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } //Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); //Get Reasoning Mode StardogReasoningMode reasoning = StardogReasoningMode.None; String mode = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); if (mode != null) { try { reasoning = (StardogReasoningMode)Enum.Parse(typeof(StardogReasoningMode), mode); } catch { reasoning = StardogReasoningMode.None; } } if (user != null && pwd != null) { manager = new StardogConnector(server, store, reasoning, user, pwd); } else { manager = new StardogConnector(server, store, reasoning); } break; case Talis: //Get the Store Name and User credentials store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { manager = new TalisPlatformConnector(store, user, pwd); } else { manager = new TalisPlatformConnector(store); } break; #endif } #if !NO_PROXY //Check whether this is a proxyable manager and if we need to load proxy settings if (manager is BaseHttpConnector) { INode proxyNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyProxy)); if (proxyNode != null) { temp = ConfigurationLoader.LoadObject(g, proxyNode); if (temp is WebProxy) { ((BaseHttpConnector)manager).Proxy = (WebProxy)temp; } else { throw new DotNetRdfConfigurationException("Unable to load Generic Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:proxy property pointed to an Object which could not be loaded as an object of the required type WebProxy"); } } } #endif obj = manager; return(manager != null); }
/// <summary> /// Attempts to load an Object of the given type identified by the given Node and returned as the Type that this loader generates /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Created Object</param> /// <returns>True if the loader succeeded in creating an Object</returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; INode managerNode; Object temp; //Create the URI Nodes we're going to use to search for things INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer), propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase); switch (targetType.FullName) { case MicrosoftAdoDataset: managerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); if (managerNode != null) { temp = ConfigurationLoader.LoadObject(g, managerNode); if (temp is MicrosoftAdoManager) { obj = new MicrosoftAdoDataset((MicrosoftAdoManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the object identified by the Node '" + objNode.ToString() + "' since the object pointed to by the dnr:genericManager property could not be loaded as an instance of the required MicrosoftAdoManager class"); } } else { throw new DotNetRdfConfigurationException("Unable to load the object identified by the Node '" + objNode.ToString() + "' as it specified a dnr:type of MicrosoftAdoDataset but failed to specify a dnr:genericManager property to point to a MicrosoftAdoManager"); } break; case AzureAdoManager: case MicrosoftAdoManager: //Get Server and Database details String server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { server = "localhost"; } String db = ConfigurationLoader.GetConfigurationString(g, objNode, propDb); if (db == null) { return(false); } //Get user credentials String user, pwd; ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); bool encrypt = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEncryptConnection), false); String mode = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); AdoAccessMode accessMode = (mode != null ? (AdoAccessMode)Enum.Parse(typeof(AdoAccessMode), mode) : AdoAccessMode.Streaming); //Create the Manager if (user != null && pwd != null) { if (targetType.FullName.Equals(MicrosoftAdoManager)) { obj = new MicrosoftAdoManager(server, db, user, pwd, encrypt, accessMode); } else { obj = new AzureAdoManager(server, db, user, pwd, accessMode); } } else { if (targetType.FullName.Equals(AzureAdoManager)) { throw new DotNetRdfConfigurationException("Unable to load the object identified by the Node '" + objNode.ToString() + "' as an AzureAdoManager as the required dnr:user and dnr:password properties were missing"); } obj = new MicrosoftAdoManager(server, db, encrypt, accessMode); } break; case MicrosoftAdoOptimiser: managerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); if (managerNode != null) { temp = ConfigurationLoader.LoadObject(g, managerNode); if (temp is MicrosoftAdoManager) { obj = new MicrosoftAdoOptimiser((MicrosoftAdoManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the object identified by the Node '" + objNode.ToString() + "' since the object pointed to by the dnr:genericManager property could not be loaded as a MicrosoftAdoManager instance"); } } else { throw new DotNetRdfConfigurationException("Unable to load the object identified by the Node '" + objNode.ToString() + "' as it specified a dnr:type of AdoOptimiser but failed to specify a dnr:genericManager property to point to a MicrosoftAdoManager instance"); } break; } return(obj != null); }
public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { switch (targetType.FullName) { case MongoDBManager: String server = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer)); String storeID = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase)); String collectionID = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog)); String loadMode = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); MongoDBSchemas schema = MongoDBDocumentManager.DefaultSchema; if (loadMode != null) { switch (loadMode) { case "GraphCentric": schema = MongoDBSchemas.GraphCentric; break; case "TripleCentric": schema = MongoDBSchemas.TripleCentric; break; } } if (storeID != null) { AlexandriaMongoDBManager manager; if (server == null) { if (collectionID == null) { manager = new AlexandriaMongoDBManager(storeID, schema); } else { manager = new AlexandriaMongoDBManager(new MongoDBDocumentManager(new MongoConfiguration(), storeID, collectionID, schema)); } } else { //Have a Custom Connection String if (collectionID == null) { manager = new AlexandriaMongoDBManager(new MongoDBDocumentManager(server, storeID, schema)); } else { manager = new AlexandriaMongoDBManager(new MongoDBDocumentManager(server, storeID, collectionID, schema)); } } obj = manager; return(true); } //If we get here then the required dnr:database property was missing throw new DotNetRdfConfigurationException("Unable to load the MongoDB Manager identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:database"); break; case MongoDBDataset: INode managerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:genericManager")); if (managerNode == null) { throw new DotNetRdfConfigurationException("Unable to load the MongoDB Dataset identified by the Node '" + objNode.ToString() + "' since there we no value for the required property dnr:genericManager"); } Object temp = ConfigurationLoader.LoadObject(g, managerNode); if (temp is AlexandriaMongoDBManager) { obj = new AlexandriaMongoDBDataset((AlexandriaMongoDBManager)temp); return(true); } else { throw new DotNetRdfConfigurationException("Unable to load the MongoDB Dataset identified by the Node '" + objNode.ToString() + "' since the value for the dnr:genericManager property pointed to an Object which could not be loaded as an object of type AlexandriaMongoDBManager"); } break; } obj = null; return(false); }
/// <summary> /// Creates a new Base Handler Configuration which loads common Handler settings from a Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> public BaseHandlerConfiguration(IGraph g, INode objNode) { //Are there any User Groups associated with this Handler? IEnumerable <INode> groups = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:userGroup")); foreach (INode group in groups) { Object temp = ConfigurationLoader.LoadObject(g, group); if (temp is UserGroup) { this._userGroups.Add((UserGroup)temp); } else { throw new DotNetRdfConfigurationException("Unable to load Handler Configuration as the RDF Configuration file specifies a value for the Handlers dnr:userGroup property which cannot be loaded as an object which is a UserGroup"); } } //General Handler Settings this._showErrors = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyShowErrors), this._showErrors); String introFile = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyIntroFile)); if (introFile != null) { introFile = ConfigurationLoader.ResolvePath(introFile); if (File.Exists(introFile)) { using (StreamReader reader = new StreamReader(introFile)) { this._introText = reader.ReadToEnd(); reader.Close(); } } } this._stylesheet = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStylesheet)).ToSafeString(); this._corsEnabled = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEnableCors), true); //Cache Settings this._cacheDuration = ConfigurationLoader.GetConfigurationInt32(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCacheDuration), this._cacheDuration); if (this._cacheDuration < MinimumCacheDuration) { this._cacheDuration = MinimumCacheDuration; } if (this._cacheDuration > MaximumCacheDuration) { this._cacheDuration = MaximumCacheDuration; } this._cacheSliding = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCacheSliding), this._cacheSliding); //SPARQL Expression Factories IEnumerable <INode> factories = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyExpressionFactory)); foreach (INode factory in factories) { Object temp = ConfigurationLoader.LoadObject(g, factory); if (temp is ISparqlCustomExpressionFactory) { this._expressionFactories.Add((ISparqlCustomExpressionFactory)temp); } else { throw new DotNetRdfConfigurationException("Unable to load Handler Configuration as the RDF Configuration file specifies a value for the Handlers dnr:expressionFactory property which cannot be loaded as an object which is a SPARQL Expression Factory"); } } //Writer Properties this._writerCompressionLevel = ConfigurationLoader.GetConfigurationInt32(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCompressionLevel), this._writerCompressionLevel); this._writerDtds = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDtdWriting), this._writerDtds); this._writerHighSpeed = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyHighSpeedWriting), this._writerHighSpeed); this._writerMultiThreading = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyMultiThreadedWriting), this._writerMultiThreading); this._writerPrettyPrinting = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPrettyPrinting), this._writerPrettyPrinting); this._writerAttributes = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAttributeWriting), this._writerAttributes); //Load in the Default Namespaces if specified INode nsNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyImportNamespacesFrom)); if (nsNode != null) { Object nsTemp = ConfigurationLoader.LoadObject(g, nsNode); if (nsTemp is IGraph) { this._defaultNamespaces.Import(((IGraph)nsTemp).NamespaceMap); } } }