コード例 #1
0
        /// <summary>
        /// For webapplications always
        /// <ul>
        /// <li>convert IResources using the current context.</li>
        /// <li>use "web" as default resource protocol</li>
        /// <li>use <see cref="HybridContextStorage"/> as default threading storage</li>
        /// </ul>
        /// </summary>
        static WebSupportModule()
        {
            s_log = LogManager.GetLogger(typeof(WebSupportModule));
#if NET_2_0
            // required to enable accessing HttpContext.Request during IHttpModule.Init() in integrated mode
            ContextHideRequestResponse = null;
            try
            {
                fiHideRequestResponse = typeof(HttpContext).GetField("HideRequestResponse", BindingFlags.Instance | BindingFlags.NonPublic);
//                fiHideRequestResponse.SetValue(HttpContext.Current, false);
                ContextHideRequestResponse = (fiHideRequestResponse != null)?new SafeField(fiHideRequestResponse):null;
            }
            catch (SecurityException sec)
            {
                s_log.Warn(string.Format("failed reflecting field HttpContext.HideRequestResponse due to security restrictions {0}", sec));
            }
#endif

            // register additional resource handler
            ResourceHandlerRegistry.RegisterResourceHandler(WebUtils.DEFAULT_RESOURCE_PROTOCOL, typeof(WebResource));
            // replace default IResource converter
            TypeConverterRegistry.RegisterConverter(typeof(IResource),
                                                    new ResourceConverter(
                                                        new ConfigurableResourceLoader(WebUtils.DEFAULT_RESOURCE_PROTOCOL)));
            // default to hybrid thread storage implementation
            LogicalThreadContext.SetStorage(new HybridContextStorage());

            s_log.Debug("Set default resource protocol to 'web' and installed HttpContext-aware HybridContextStorage");
        }
コード例 #2
0
 /// <summary>
 /// Registers custom IResource implementations.  The supplied
 /// <paramref name="factory"/> is not used since IResourse implementations
 /// are registered with a global <see cref="Spring.Core.IO.ResourceHandlerRegistry"/>
 /// </summary>
 /// <param name="factory">
 /// The object factory.
 /// </param>
 /// <exception cref="Spring.Objects.ObjectsException">
 /// In case of errors.
 /// </exception>
 public override void PostProcessObjectFactory(
     IConfigurableListableObjectFactory factory)
 {
     if (resourceHandlers != null)
     {
         foreach (DictionaryEntry entry in resourceHandlers)
         {
             string protocolName = entry.Key.ToString();
             Type   type         = ResolveRequiredType(entry.Value, "value", "custom IResource implementation");
             ResourceHandlerRegistry.RegisterResourceHandler(protocolName, type);
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Registers resource handlers that are specified in
        /// the <c>resources</c> config section with the <see cref="ResourceHandlerRegistry"/>.
        /// </summary>
        /// <param name="parent">
        /// The configuration settings in a corresponding parent
        /// configuration section. Ignored.
        /// </param>
        /// <param name="configContext">
        /// The configuration context when called from the ASP.NET
        /// configuration system. Otherwise, this parameter is reserved and
        /// is <see langword="null"/>.
        /// </param>
        /// <param name="section">
        /// The <see cref="System.Xml.XmlNode"/> for the section.
        /// </param>
        /// <returns>
        /// This method always returns <c>null</c>, because resource handlers are registered
        /// as a sideffect of its execution and there is no need to return anything.
        /// </returns>
        public object Create(object parent, object configContext, XmlNode section)
        {
            if (section != null)
            {
                XmlNodeList resourceHandlers = ((XmlElement)section).GetElementsByTagName(HandlerElement);

                foreach (XmlElement handler in resourceHandlers)
                {
                    string protocolName = GetRequiredAttributeValue(handler, ProtocolAttribute, section);
                    string typeName     = GetRequiredAttributeValue(handler, TypeAttribute, section);

                    ResourceHandlerRegistry.RegisterResourceHandler(protocolName, typeName);
                }
            }
            return(null);
        }
コード例 #4
0
 void Application_Start(object sender, EventArgs e)
 {
     log4net.Config.XmlConfigurator.Configure();
     ResourceHandlerRegistry.RegisterResourceHandler("web", typeof(WebResource));
 }