Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads the Handler Configuration
        /// </summary>
        /// <param name="context">HTTP Context</param>
        /// <param name="basePath">Base Path of the Handler which this method will determine</param>
        /// <returns></returns>
        protected override BaseProtocolHandlerConfiguration LoadConfig(HttpContext context, out String basePath)
        {
            basePath = context.Request.Path;

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

            if (temp != null)
            {
                if (temp is BaseProtocolHandlerConfiguration)
                {
                    return((BaseProtocolHandlerConfiguration)temp);
                }
                else
                {
                    context.Cache.Remove(context.Request.Path);
                }
            }

            //Check the Configuration File is specified
            String configFile = context.Server.MapPath(ConfigurationManager.AppSettings["dotNetRDFConfig"]);

            if (configFile == null)
            {
                throw new DotNetRdfConfigurationException("Unable to load Protocol 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
            String objUri  = "dotnetrdf:" + context.Request.Path;
            INode  objNode = g.GetUriNode(UriFactory.Create(objUri));

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

            //Finally cache the Configuration before returning it
            if (config.CacheSliding)
            {
                context.Cache.Add(context.Request.Path, 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(context.Request.Path, config, new System.Web.Caching.CacheDependency(configFile), DateTime.Now.AddMinutes(config.CacheDuration), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
            }
            return(config);
        }