Пример #1
0
        /// <summary>
        /// Loads the Handler Configuration
        /// </summary>
        /// <param name="context">HTTP Context</param>
        /// <param name="basePath">Base Path for the Server</param>
        /// <returns></returns>
        protected override BaseSparqlServerConfiguration LoadConfig(HttpContext context, out string basePath)
        {
            // Check the Configuration File is specified
            String configFile = context.Server.MapPath(ConfigurationManager.AppSettings["dotNetRDFConfig"]);

            if (configFile == null)
            {
                throw new DotNetRdfConfigurationException("Unable to load Graph Handler Configuration as the Web.Config file does not specify a 'dotNetRDFConfig' AppSetting to specify the RDF configuration file to use");
            }
            IGraph g = WebConfigurationLoader.LoadConfigurationGraph(context, configFile);

            // Then check there is configuration associated with the expected URI
            INode objNode = WebConfigurationLoader.FindObject(g, context.Request.Url, out basePath);

            this._cachePath = basePath;
            if (objNode == null)
            {
                throw new DotNetRdfConfigurationException("Unable to load Graph Handler Configuration as the RDF configuration file does not have any configuration associated with the URI <dotnetrdf:" + context.Request.Path + "> as required");
            }

            // Is our Configuration already cached?
            Object temp = context.Cache[basePath];

            if (temp != null)
            {
                if (temp is BaseSparqlServerConfiguration)
                {
                    basePath = basePath.Substring(0, basePath.Length - 1);
                    return((BaseSparqlServerConfiguration)temp);
                }
                else
                {
                    context.Cache.Remove(basePath);
                }
            }

            SparqlServerConfiguration config = new SparqlServerConfiguration(new WebContext(context), g, objNode);

            // Finally cache the Configuration before returning it
            if (config.CacheSliding)
            {
                context.Cache.Add(basePath, config, new System.Web.Caching.CacheDependency(configFile), System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, config.CacheDuration, 0), System.Web.Caching.CacheItemPriority.Normal, null);
            }
            else
            {
                context.Cache.Add(basePath, config, new System.Web.Caching.CacheDependency(configFile), DateTime.Now.AddMinutes(config.CacheDuration), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
            }
            basePath = basePath.Substring(0, basePath.Length - 1);
            return(config);
        }
        /// <summary>
        /// Processes a request
        /// </summary>
        /// <param name="context">Server Context</param>
        public void ProcessRequest(HttpServerContext context)
        {
            //Get the server options
            RdfServerOptions options = context.Server.AppSettings[RdfServerOptions.ServerOptionsKey] as RdfServerOptions;

            if (options == null)
            {
                throw new DotNetRdfConfigurationException("rdfServer Options were not found");
            }

            //Get the configuration graph
            IGraph g = context.Server.Context[RdfServerOptions.DotNetRdfConfigKey] as IGraph;

            if (g == null)
            {
                g = options.LoadConfigurationGraph();
                if (g == null)
                {
                    throw new DotNetRdfConfigurationException("The HTTP Server does not contain a Configuration Graph in its State Information");
                }
                context.Server.Context[RdfServerOptions.DotNetRdfConfigKey] = g;
            }


            //Generate the expected Path and try and load the Configuration using the appropriate Node
            String expectedPath;

            WebConfigurationLoader.FindObject(g, context.Request.Url, out expectedPath);
            INode objNode = g.GetUriNode(new Uri("dotnetrdf:" + expectedPath));

            if (objNode == null)
            {
                throw new DotNetRdfConfigurationException("The Configuration Graph does not contain a URI Node with the expected URI <dotnetrdf:" + expectedPath + ">");
            }
            this._config = new SparqlServerConfiguration(g, objNode);

            //Dispath the request appropriately
            String path = context.Request.Url.AbsolutePath;

            path = path.Substring(path.LastIndexOf('/') + 1);

            switch (path)
            {
            case "query":
                this.ProcessQueryRequest(context);
                break;

            case "update":
                this.ProcessUpdateRequest(context);
                break;

            case "description":
                //TODO: Add Service Description support
                context.Response.StatusCode = (int)HttpStatusCode.NotImplemented;
                break;

            default:
                //TODO: Can we easily add Protocol Support or not?
                //this.ProcessProtocolRequest(context);
                context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                break;
            }
        }