コード例 #1
0
        /// <summary>
        /// Creates a new 4store connector which manages access to the services provided by a 4store server
        /// </summary>
        /// <param name="baseUri">Base Uri of the 4store</param>
        /// <remarks>
        /// <strong>Note:</strong> As of the 0.4.0 release 4store support defaults to Triple Level updates enabled as all recent 4store releases have supported this.  You can still optionally disable this with the two argument version of the constructor
        /// </remarks>
        public FourStoreConnector(String baseUri)
        {
            // Determine the appropriate actual Base Uri
            if (baseUri.EndsWith("sparql/"))
            {
                _baseUri = baseUri.Substring(0, baseUri.IndexOf("sparql/"));
            }
            else if (baseUri.EndsWith("data/"))
            {
                _baseUri = baseUri.Substring(0, baseUri.IndexOf("data/"));
            }
            else if (!baseUri.EndsWith("/"))
            {
                _baseUri = baseUri + "/";
            }
            else
            {
                _baseUri = baseUri;
            }

            _endpoint               = new SparqlRemoteEndpoint(UriFactory.Create(_baseUri + "sparql/"));
            _updateEndpoint         = new SparqlRemoteUpdateEndpoint(UriFactory.Create(_baseUri + "update/"));
            _endpoint.Timeout       = 60000;
            _updateEndpoint.Timeout = 60000;
        }
コード例 #2
0
        public void SparqlRemoteEndpointMemoryLeak2()
        {
            //Do a GC before attempting the test
            GC.GetTotalMemory(true);

            //First off make sure to load some data into the some
            SparqlRemoteUpdateEndpoint updateEndpoint = RemoteEndpoints.GetUpdateEndpoint();

            updateEndpoint.Update("DROP ALL");

            int totalRuns  = 10000;
            int subjects   = 1000;
            int predicates = 10;

            //Loop over making queries to try and reproduce the memory leak
            for (int i = 1; i <= totalRuns; i++)
            {
                //Add new data each time around
                updateEndpoint.Update("INSERT DATA { <http://subject/" + (i % subjects) + "> <http://predicate/" + (i % predicates) + "> <http://object/" + i + "> . }");

                SparqlRemoteEndpoint      endpoint    = RemoteEndpoints.GetQueryEndpoint();
                SparqlParameterizedString queryString = new SparqlParameterizedString();
                queryString.CommandText = "SELECT * WHERE { <http://subject/" + (i % 1000) + "> ?p ?o }";

                ResultCountHandler handler = new ResultCountHandler();
                endpoint.QueryWithResultSet(handler, queryString.ToString());
                Assert.True(handler.Count >= 1 && handler.Count <= subjects, "Result Count " + handler.Count + " is not in expected range 1 <= x < " + (i % 1000));

                if (i % 500 == 0)
                {
                    Debug.WriteLine("Memory Usage after " + i + " Iterations: " + Process.GetCurrentProcess().PrivateMemorySize64);
                }
            }
            Debug.WriteLine("Memory Usage after " + totalRuns + " Iterations: " + Process.GetCurrentProcess().PrivateMemorySize64);
        }
コード例 #3
0
        private static IDataObjectContext MakeSparqlDataObjectContext(ConnectionString connectionString)
        {
            var queryEndpoint = new SparqlRemoteEndpoint(new Uri(connectionString.DnrQuery));

            if (!String.IsNullOrEmpty(connectionString.UserName) && !String.IsNullOrEmpty(connectionString.Password))
            {
                queryEndpoint.SetCredentials(connectionString.UserName, connectionString.Password);
            }
            var queryProcessor = new RemoteQueryProcessor(queryEndpoint);

            ISparqlUpdateProcessor updateProcessor = null;

            if (!String.IsNullOrEmpty(connectionString.DnrUpdate))
            {
#if PORTABLE || SILVERLIGHT
                throw new NotSupportedException("The PCL and mobile builds of BrightstarDB do not currently support stores that use SPARQL Update. The store may be opened as a read-only store by removing the update= parameter in the connection string.");
#else
                var updateEndpoint = new SparqlRemoteUpdateEndpoint(new Uri(connectionString.DnrUpdate));
                if (!String.IsNullOrEmpty(connectionString.UserName) && !String.IsNullOrEmpty(connectionString.Password))
                {
                    updateEndpoint.SetCredentials(connectionString.UserName, connectionString.Password);
                }
                updateProcessor = new RemoteUpdateProcessor(updateEndpoint);
#endif
            }
            return(new SparqlDataObjectContext(queryProcessor, updateProcessor, connectionString.OptimisticLocking));
        }
コード例 #4
0
        public void SparqlRemoteEndpointAsyncApiUpdate()
        {
            if (!TestConfigManager.GetSettingAsBoolean(TestConfigManager.UseRemoteParsing))
            {
                throw new SkipTestException("Test Config marks Remote Parsing as unavailable, test cannot be run");
            }

            SparqlRemoteUpdateEndpoint endpoint = RemoteEndpoints.GetUpdateEndpoint();
            ManualResetEvent           signal   = new ManualResetEvent(false);

            endpoint.Update("LOAD <http://dbpedia.org/resource/Ilkeston> INTO GRAPH <http://example.org/async/graph>", s =>
            {
                signal.Set();
                signal.Close();
            }, null);

            Thread.Sleep(AsyncTimeout);
            Assert.True(signal.SafeWaitHandle.IsClosed, "Wait Handle should be closed");

            //Check that the Graph was really loaded
            SparqlRemoteEndpoint queryEndpoint = RemoteEndpoints.GetQueryEndpoint();
            IGraph g = queryEndpoint.QueryWithResultGraph("CONSTRUCT FROM <http://example.org/async/graph> WHERE { ?s ?p ?o }");

            Assert.False(g.IsEmpty, "Graph should not be empty");
        }
コード例 #5
0
        /// initialize the singleton with data store URL
        /// It must be called just after the first singleton instance generation

        public void init(string ontSenseURL)
        {
            // to ensure that point is used as separator in decimal numbers
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("");

            //Then create our Endpoint instance
            endpoint = new SparqlRemoteUpdateEndpoint(ontSenseURL);
        }
コード例 #6
0
        public TripleStoreRepository(IOptionsMonitor <ColidTripleStoreOptions> options)
        {
            var updateEndpoint = new SparqlRemoteUpdateEndpoint(options.CurrentValue.UpdateUrl);

            updateEndpoint.SetCredentials(options.CurrentValue.Username, options.CurrentValue.Password);
            _queryEndpoint  = new SparqlRemoteEndpoint(options.CurrentValue.ReadUrl);;
            _updateEndpoint = updateEndpoint;
        }
コード例 #7
0
ファイル: SparqlConnector.cs プロジェクト: yuryk53/dotnetrdf
 /// <summary>
 /// Creates a new connection
 /// </summary>
 /// <param name="queryEndpoint">Query Endpoint</param>
 /// <param name="updateEndpoint">Update Endpoint</param>
 /// <param name="mode">Method for loading graphs</param>
 public ReadWriteSparqlConnector(SparqlRemoteEndpoint queryEndpoint, SparqlRemoteUpdateEndpoint updateEndpoint, SparqlConnectorLoadMethod mode)
     : base(queryEndpoint, mode)
 {
     if (updateEndpoint == null)
     {
         throw new ArgumentNullException("updateEndpoint", "Update Endpoint cannot be null, if you require a read-only SPARQL connector use the base class SparqlConnector instead");
     }
     this._updateEndpoint = updateEndpoint;
 }
コード例 #8
0
        public void SparqlRemoteEndpointAsyncApiUpdate()
        {
            SparqlRemoteUpdateEndpoint endpoint = GetUpdateEndpoint();
            ManualResetEvent           signal   = new ManualResetEvent(false);

            endpoint.Update("LOAD <http://dbpedia.org/resource/Ilkeston> INTO GRAPH <http://example.org/async/graph>", s =>
            {
                signal.Set();
                signal.Close();
            }, null);

            signal.WaitOne(TimeSpan.FromSeconds(10.0)).Should().BeTrue();
        }
        public void SparqlRemoteEndpointAsyncApiUpdate()
        {
            SparqlRemoteUpdateEndpoint endpoint = GetUpdateEndpoint();
            ManualResetEvent           signal   = new ManualResetEvent(false);

            endpoint.Update("LOAD <http://dbpedia.org/resource/Ilkeston> INTO GRAPH <http://example.org/async/graph>", s =>
            {
                signal.Set();
                signal.Close();
            }, null);

            Thread.Sleep(1000);
            Assert.True(signal.SafeWaitHandle.IsClosed, "Wait Handle should be closed");
        }
        /// <summary>
        /// Opens the connection
        /// </summary>
        /// <returns></returns>
        protected override IStorageProvider OpenConnectionInternal()
        {
            SparqlRemoteEndpoint       endpoint       = String.IsNullOrEmpty(this.QueryDefaultGraphUri) ? new SparqlRemoteEndpoint(new Uri(this.QueryEndpointUri)) : new SparqlRemoteEndpoint(new Uri(this.QueryEndpointUri), this.QueryDefaultGraphUri);
            SparqlRemoteUpdateEndpoint updateEndpoint = new SparqlRemoteUpdateEndpoint(new Uri(this.UpdateEndpointUri));

            if (this.UseProxy)
            {
                WebProxy proxy = this.GetProxy();
                endpoint.Proxy       = proxy;
                updateEndpoint.Proxy = proxy;
            }
            ReadWriteSparqlConnector connector = new ReadWriteSparqlConnector(endpoint, updateEndpoint, this.LoadMode);

            connector.SkipLocalParsing = this.SkipLocalParsing;
            return(connector);
        }
コード例 #11
0
        public void SparqlRemoteEndpointMemoryLeak1()
        {
            /*
             * Dim endpoint = New SparqlRemoteEndpoint(New Uri("http://localhost:8080/sesame/repositories/my_repo"))
             * Dim queryString As SparqlParameterizedString = New SparqlParameterizedString()
             * queryString.Namespaces.AddNamespace("annot", New Uri(oAppSettingsReader.GetValue("BaseUriSite", GetType(System.String)) & "/annotations.owl#"))
             * queryString.CommandText = "SELECT DISTINCT ?text WHERE {?annotation annot:onContent <" & _uriDocument & "> ; annot:onContentPart """ & ContentPart & """ ; annot:text ?text ; annot:isValid ""false""^^xsd:boolean . }"
             * Dim results As SparqlResultSet = endpoint.QueryWithResultSet(queryString.ToString)
             * For Each result As SparqlResult In results
             * Console.WriteLine(DirectCast(result.Value("text"), LiteralNode).Value)
             * Next
             * results.Dispose()
             */

            //Do a GC before attempting the test
            GC.GetTotalMemory(true);

            //First off make sure to load some data into the some
            SparqlRemoteUpdateEndpoint updateEndpoint = RemoteEndpoints.GetUpdateEndpoint();

            updateEndpoint.Update("DROP ALL; INSERT DATA { <http://subject> <http://predicate> <http://object> . }");

            int totalRuns = 10000;

            //Loop over making queries to try and reproduce the memory leak
            for (int i = 1; i <= totalRuns; i++)
            {
                SparqlRemoteEndpoint      endpoint    = RemoteEndpoints.GetQueryEndpoint();
                SparqlParameterizedString queryString = new SparqlParameterizedString();
                queryString.CommandText = "SELECT * WHERE { ?s ?p ?o }";

                SparqlResultSet results = endpoint.QueryWithResultSet(queryString.ToString());
                Assert.Equal(1, results.Count);
                foreach (SparqlResult result in results)
                {
                    //We're just iterating to make sure we touch the whole of the results
                }
                results.Dispose();

                if (i % 500 == 0)
                {
                    Debug.WriteLine("Memory Usage after " + i + " Iterations: " + Process.GetCurrentProcess().PrivateMemorySize64);
                }
            }
            Debug.WriteLine("Memory Usage after " + totalRuns + " Iterations: " + Process.GetCurrentProcess().PrivateMemorySize64);
        }
コード例 #12
0
        public void SparqlRemoteEndpointLongUpdate()
        {
            try
            {
                Options.HttpDebugging = true;

                StringBuilder input = new StringBuilder();
                input.AppendLine("LOAD <http://dbpedia.org/resource/Ilkeston>");
                input.AppendLine(new String('#', 2048));

                SparqlRemoteUpdateEndpoint endpoint = RemoteEndpoints.GetUpdateEndpoint();
                endpoint.Update(input.ToString());
            }
            finally
            {
                Options.HttpDebugging = false;
            }
        }
コード例 #13
0
        public void SparqlRemoteEndpointAsyncApiUpdate()
        {
            SparqlRemoteUpdateEndpoint endpoint = RemoteEndpoints.GetUpdateEndpoint();
            ManualResetEvent           signal   = new ManualResetEvent(false);

            endpoint.Update("LOAD <http://dbpedia.org/resource/Ilkeston> INTO GRAPH <http://example.org/async/graph>", s =>
            {
                signal.Set();
                signal.Close();
            }, null);

            Thread.Sleep(AsyncTimeout);
            Assert.IsTrue(signal.SafeWaitHandle.IsClosed, "Wait Handle should be closed");

            //Check that the Graph was really loaded
            SparqlRemoteEndpoint queryEndpoint = RemoteEndpoints.GetQueryEndpoint();
            IGraph g = queryEndpoint.QueryWithResultGraph("CONSTRUCT FROM <http://example.org/async/graph> WHERE { ?s ?p ?o }");

            Assert.IsFalse(g.IsEmpty, "Graph should not be empty");
        }
コード例 #14
0
        public void SparqlRemoteEndpointLongUpdate()
        {
            Skip.IfNot(TestConfigManager.GetSettingAsBoolean(TestConfigManager.UseRemoteParsing),
                       "Test Config marks Remote Parsing as unavailable, test cannot be run");

            try
            {
                Options.HttpDebugging = true;

                StringBuilder input = new StringBuilder();
                input.AppendLine("LOAD <http://dbpedia.org/resource/Ilkeston>");
                input.AppendLine(new String('#', 2048));

                SparqlRemoteUpdateEndpoint endpoint = RemoteEndpoints.GetUpdateEndpoint();
                endpoint.Update(input.ToString());
            }
            finally
            {
                Options.HttpDebugging = false;
            }
        }
コード例 #15
0
        static void Main(string[] args)
        {
            queue = new Queue <string>();
            count = 0;
            //Then create our Endpoint instance
            endpoint = new SparqlRemoteUpdateEndpoint(ONT_SENSE_URL);

            TcpListener ServerSocket = new TcpListener(PORT);

            ServerSocket.Start();
            Console.WriteLine("OntSense API started on Port " + PORT + ", with " + ONT_SENSE_URL + " Server...");
            TcpClient    clientSocket = ServerSocket.AcceptTcpClient();
            handleClient client       = new handleClient();

            client.startClient(clientSocket);
            while (true)
            {
                string auxString = "";

                lock (queue)
                {
                    if (queue.Count > 0)
                    {
                        auxString = queue.Dequeue();
                    }
                    else
                    {
                        Thread.Yield();
                    }
                }
                if (!auxString.Equals(""))
                {
                    endpoint.Update(auxString);
                }
            }
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: yuryk53/dotnetrdf
        static void DoUpdate(Dictionary <String, String> arguments)
        {
            SparqlRemoteUpdateEndpoint endpoint;
            bool verbose = arguments.ContainsKey("verbose") || arguments.ContainsKey("v");

            if (verbose)
            {
                Options.HttpDebugging = true;
            }

            //First get the Server to which we are going to connect
            try
            {
                if (arguments.ContainsKey("server") && !arguments["server"].Equals(String.Empty))
                {
                    endpoint = new SparqlRemoteUpdateEndpoint(new Uri(arguments["server"]));
                }
                else if (arguments.ContainsKey("service") && !arguments["service"].Equals(String.Empty))
                {
                    endpoint = new SparqlRemoteUpdateEndpoint(new Uri(arguments["service"]));
                }
                else
                {
                    Console.Error.WriteLine("soh: Error: Required --server/--service argument not present");
                    Environment.Exit(-1);
                    return;
                }
            }
            catch (UriFormatException uriEx)
            {
                Console.Error.WriteLine("soh: Error: Malformed SPARQL Update Endpoint URI");
                Console.Error.WriteLine(uriEx.Message);
                Environment.Exit(-1);
                return;
            }
            if (verbose)
            {
                Console.Error.WriteLine("soh: SPARQL Update Endpoint for URI " + endpoint.Uri + " created OK");
            }

            //Then decide where to get the update to execute from
            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds;

            try
            {
                if (arguments.ContainsKey("update") && !arguments["update"].Equals(String.Empty))
                {
                    cmds = parser.ParseFromFile(arguments["update"]);
                }
                else if (arguments.ContainsKey("file") && !arguments["file"].Equals(String.Empty))
                {
                    cmds = parser.ParseFromFile(arguments["file"]);
                }
                else if (arguments.ContainsKey("$1") && !arguments["$1"].Equals(String.Empty))
                {
                    cmds = parser.ParseFromString(arguments["$1"]);
                }
                else
                {
                    Console.Error.WriteLine("soh: Error: Required SPARQL Update not found - may be specified as --file/--update FILE or as final argument");
                    Environment.Exit(-1);
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("soh: Error: Error Parsing SPARQL Update");
                Console.Error.WriteLine(ex.Message);
                Environment.Exit(-1);
                return;
            }

            if (verbose)
            {
                Console.Error.WriteLine("soh: Parsed Update OK");
                Console.Error.WriteLine("soh: dotNetRDF's interpretation of the Update:");
                Console.Error.WriteLine(cmds.ToString());
                Console.Error.WriteLine("soh: Submitting Update");
            }

            try
            {
                endpoint.Update(cmds.ToString());
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("soh: Error: Error while making the SPARQL Update");
                Console.Error.WriteLine(ex.Message);
                Environment.Exit(-1);
                return;
            }
        }
コード例 #17
0
        /// <summary>
        /// Tries to load a SPARQL Endpoint based on information from the Configuration Graph.
        /// </summary>
        /// <param name="g">Configuration Graph.</param>
        /// <param name="objNode">Object Node.</param>
        /// <param name="targetType">Target Type.</param>
        /// <param name="obj">Output Object.</param>
        /// <returns></returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            BaseEndpoint endpoint = null;

            obj = null;

            switch (targetType.FullName)
            {
            case QueryEndpoint:
                String queryEndpointUri = ConfigurationLoader.GetConfigurationValue(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) });
                if (queryEndpointUri == null)
                {
                    return(false);
                }

                // Get Default/Named Graphs if specified
                IEnumerable <String> defaultGraphs = from n in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultGraphUri)))
                                                     select n.ToString();

                IEnumerable <String> namedGraphs = from n in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyNamedGraphUri)))
                                                   select n.ToString();

                endpoint = new SparqlRemoteEndpoint(UriFactory.Create(queryEndpointUri), defaultGraphs, namedGraphs);
                break;

            case UpdateEndpoint:
                String updateEndpointUri = ConfigurationLoader.GetConfigurationValue(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) });
                if (updateEndpointUri == null)
                {
                    return(false);
                }

                endpoint = new SparqlRemoteUpdateEndpoint(UriFactory.Create(updateEndpointUri));
                break;

            case FederatedEndpoint:
                IEnumerable <INode> endpoints = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpoint)))
                                                .Concat(ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint))));
                foreach (INode e in endpoints)
                {
                    Object temp = ConfigurationLoader.LoadObject(g, e);
                    if (temp is SparqlRemoteEndpoint)
                    {
                        if (endpoint == null)
                        {
                            endpoint = new FederatedSparqlRemoteEndpoint((SparqlRemoteEndpoint)temp);
                        }
                        else
                        {
                            ((FederatedSparqlRemoteEndpoint)endpoint).AddEndpoint((SparqlRemoteEndpoint)temp);
                        }
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the SPARQL Endpoint identified by the Node '" + e.ToString() + "' as one of the values for the dnr:queryEndpoint/dnr:endpoint property points to an Object which cannot be loaded as an object which is a SparqlRemoteEndpoint");
                    }
                }
                break;
            }

            if (endpoint != null)
            {
                // Are there any credentials specified?
                String user, pwd;
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
                if (user != null && pwd != null)
                {
                    endpoint.SetCredentials(user, pwd);
                }

                // Is there a Proxy Server specified
                INode proxyNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyProxy)));
                if (proxyNode != null)
                {
                    Object proxy = ConfigurationLoader.LoadObject(g, proxyNode);
                    if (proxy is IWebProxy)
                    {
                        endpoint.Proxy = (IWebProxy)proxy;

                        // Are we supposed to use the same credentials for the proxy as for the endpoint?
                        bool useCredentialsForProxy = ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUseCredentialsForProxy)), false);
                        if (useCredentialsForProxy)
                        {
                            endpoint.UseCredentialsForProxy = true;
                        }
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load SPARQL Endpoint identified by the Node '" + objNode.ToString() + "' as the value for the dnr:proxy property points to an Object which cannot be loaded as an object of type WebProxy");
                    }
                }
            }

            obj = endpoint;
            return(endpoint != null);
        }
コード例 #18
0
        /// <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);
        }
コード例 #19
0
 public LinqUpdateProcessor(SparqlRemoteUpdateEndpoint endpoint)
     : this(new RemoteUpdateProcessor(endpoint))
 {
 }
コード例 #20
0
ファイル: SparqlConnector.cs プロジェクト: yuryk53/dotnetrdf
 /// <summary>
 /// Creates a new connection
 /// </summary>
 /// <param name="queryEndpoint">Query Endpoint</param>
 /// <param name="updateEndpoint">Update Endpoint</param>
 public ReadWriteSparqlConnector(SparqlRemoteEndpoint queryEndpoint, SparqlRemoteUpdateEndpoint updateEndpoint)
     : this(queryEndpoint, updateEndpoint, SparqlConnectorLoadMethod.Construct)
 {
 }
コード例 #21
0
 /// <summary>
 /// Creates a new LINQ Triple Store that operates over a pair of remote SPARQL endpoints
 /// </summary>
 /// <param name="queryEndpoint">Query Endpoint</param>
 /// <param name="updateEndpoint">Update Endpoint</param>
 public LinqTripleStore(SparqlRemoteEndpoint queryEndpoint, SparqlRemoteUpdateEndpoint updateEndpoint)
     : this(new LinqQueryProcessor(queryEndpoint), new LinqUpdateProcessor(updateEndpoint), LinqQueryMethod.RemoteSparql)
 {
 }