Example #1
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);
        }
        /// <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)
        {
            // Check the Configuration File is specified
            String configFile = context.Server.MapPath(ConfigurationManager.AppSettings["dotNetRDFConfig"]);

            if (configFile == null)
            {
                throw new DotNetRdfConfigurationException("Unable to load Wildcard 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
            INode objNode = WebConfigurationLoader.FindObject(g, context.Request.Url, out basePath);

            if (objNode == null)
            {
                throw new DotNetRdfConfigurationException("Unable to load Wildcard Protocol Handler Configuration as the RDF configuration file does not have any configuration associated with an appropriate wildcard URI");
            }
            this._basePath = basePath;

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

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

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

            // Finally cache the Configuration before returning it
            if (config.CacheSliding)
            {
                context.Cache.Add(this._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(this._basePath, 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);
        }