public void Init() { _allegroGraphConnector = new AllegroGraphConnector(_agConnData.Url, _agConnData.StoreId, _agConnData.User, _agConnData.Pass); _repository = new PersistentTripleStore(_allegroGraphConnector); _rdf4jMapper = new DotNetRdfMapper(); _logger.LogInformation("[CONFIG] The triple store repository configured correctly."); }
private void InsertGraph(AllegroGraphConnector connector, IGraph g) { var length = 10000; if (g.Triples.Count > length) { var newGraph = new Graph { BaseUri = g.BaseUri }; connector.SaveGraph(newGraph); var section = new List <Triple>(length); foreach (var t in g.Triples) { section.Add(t); if (section.Count == length) { connector.UpdateGraph(g.BaseUri, section, null); section = new List <Triple>(length); } } if (section.Count > 0) { connector.UpdateGraph(g.BaseUri, section, null); } } else { connector.SaveGraph(g); } }
private static void GetRecord(string leiCode, TextWriter output, AllegroGraphConnector allegroGraphConnector) { var g = new Graph(); allegroGraphConnector.LoadGraph(g, "graph://lei.info/" + leiCode); var ts = new TripleStore(); ts.Add(g); var nqw = new NQuadsWriter(); var s = VDS.RDF.Writing.StringWriter.Write(ts, nqw); output.Write(s); output.Flush(); ts.Remove(g.BaseUri); g.Clear(); ts.Dispose(); g.Dispose(); }
public void SparqlViewNativeAllegroGraph() { AllegroGraphConnector agraph = AllegroGraphTests.GetConnection(); PersistentTripleStore store = new PersistentTripleStore(agraph); //Load a Graph into the Store to ensure there is some data for the view to retrieve Graph g = new Graph(); FileLoader.Load(g, "resources\\InferenceTest.ttl"); agraph.SaveGraph(g); //Create the SPARQL View NativeSparqlView view = new NativeSparqlView("CONSTRUCT { ?s ?p ?o } WHERE { GRAPH ?g { ?s ?p ?o . FILTER(IsLiteral(?o)) } }", store); Console.WriteLine("SPARQL View Populated"); TestTools.ShowGraph(view); Console.WriteLine(); }
public void ParsingWriteToStoreHandlerBNodesAcrossBatchesAllegroGraph() { AllegroGraphConnector agraph = AllegroGraphTests.GetConnection(); this.TestWriteToStoreHandlerWithBNodes(agraph); }
public void ParsingWriteToStoreHandlerAllegroGraph() { AllegroGraphConnector agraph = AllegroGraphTests.GetConnection(); this.TestWriteToStoreHandler(agraph); }
/// <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); }
private static void Main(string[] args) { TryReadRecordsCount(args); List <string> leiCodes = new List <string>(); var counter = 0; if (!File.Exists(@"leis.txt")) { var request = WebRequest.CreateHttp(String.Format(Constants.SolrQueryUrl, RetrievalCount)); var response = request.GetResponse(); var stream = response.GetResponseStream(); using (StreamReader reader = new StreamReader(stream)) using (var fs = File.OpenWrite(@"leis.txt")) using (var sw = new StreamWriter(fs)) { var line = ""; while (line != null && !reader.EndOfStream) { line = reader.ReadLine(); if (!String.IsNullOrEmpty(line) && line.Trim().Length == 20) { sw.WriteLine(line); } } } Console.WriteLine("Retrieved records: {0}", leiCodes.Count); } using (var fs = File.OpenRead(@"leis.txt")) using (var sr = new StreamReader(fs)) { for (var i = 0; i < StartIndex; i++) { if (sr.EndOfStream) { break; } sr.ReadLine(); } var line = ""; counter = 0; while (!sr.EndOfStream && counter < Amount) { line = sr.ReadLine(); leiCodes.Add(line); counter++; } } AllegroGraphConnector allegroGraphConnector = CreateConnector(); counter = 0; using (var fs = File.OpenWrite(@"output.nq")) using (var sw = new StreamWriter(fs)) { fs.Seek(0, SeekOrigin.End); foreach (var record in leiCodes) { GetRecord(record, sw, allegroGraphConnector); counter++; if (counter % 1000 == 0) { Console.Write(String.Format("\rParsed {0} records.", counter)); allegroGraphConnector.Dispose(); allegroGraphConnector = CreateConnector(); } } } //ZipRecords(di); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
/// <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); }
static void Main(string[] args) { String server, catalog, repository; char op; Console.WriteLine("AllegroGraph Indexer Utility"); Console.WriteLine("----------------------------"); Console.Write("Server URI: "); server = Console.ReadLine(); if (server.Equals(String.Empty)) { Console.WriteLine("Aborted - you must enter a valid Server URI"); return; } Console.Write("Catalog: "); catalog = Console.ReadLine(); if (catalog.Equals(String.Empty)) { Console.WriteLine("Aborted - you must enter a valid Catalog"); return; } Console.Write("Repository: "); repository = Console.ReadLine(); if (repository.Equals(String.Empty)) { Console.WriteLine("Aborted - you must enter a valid Repository"); return; } Console.WriteLine("Which operation would you like to perform?"); Console.WriteLine("i - Index Store (combine indices)"); Console.WriteLine("I - Index Store (do not combine indices)"); Console.WriteLine("d - Delete Store"); op = (char)Console.Read(); if (op != 'i' && op != 'd' && op != 'I') { Console.WriteLine("Aborted - not a valid operation"); return; } Console.WriteLine(); Console.Write("Are you sure you want to proceed, this operation may take a very long time? [y/n]"); ConsoleKeyInfo key = Console.ReadKey(); Console.WriteLine(); if (key.KeyChar != 'y' && key.KeyChar != 'Y') { Console.WriteLine("Aborted - user aborted"); return; } Console.WriteLine("Making the request - this may take a very long time..."); try { AllegroGraphConnector agraph = new AllegroGraphConnector(server, catalog, repository); DateTime start = DateTime.Now; switch (op) { case 'i': agraph.IndexStore(true); break; case 'I': agraph.IndexStore(false); break; case 'd': agraph.DeleteStore(repository); break; } DateTime end = DateTime.Now; Console.WriteLine("Operation Completed - took " + (end - start).ToString()); } catch (RdfStorageException storeEx) { Console.WriteLine("Error occurred connecting to AllegroGraph:"); Console.WriteLine(storeEx.Message); } catch (WebException webEx) { Console.WriteLine("Error occurred during the Indexing request:"); Console.WriteLine(webEx.Message); } }