Ejemplo n.º 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");
        }
 /// <summary>
 /// Populates <see cref="TypeConverterRegistry"/> using values specified in
 /// the <c>typeConverters</c> config section.
 /// </summary>
 /// <param name="parent">
 /// The configuration settings in a corresponding parent
 /// configuration section.
 /// </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 <see langword="null"/>, because the
 /// <see cref="TypeConverterRegistry"/> is populated as a side-effect of
 /// its execution and thus there is no need to return anything.
 /// </returns>
 public object Create(object parent, object configContext, XmlNode section)
 {
     if (section != null)
     {
         XmlNodeList converters = ((XmlElement)section).GetElementsByTagName(ConverterElementName);
         foreach (XmlElement aliasElement in converters)
         {
             string forType       = GetRequiredAttributeValue(aliasElement, ForAttributeName, section);
             string converterType = GetRequiredAttributeValue(aliasElement, TypeAttributeName, section);
             TypeConverterRegistry.RegisterConverter(forType, converterType);
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Register the given custom <see cref="System.ComponentModel.TypeConverter"/>
 /// for all properties of the given <see cref="System.Type"/>.
 /// </summary>
 /// <param name="requiredType">
 /// The <see cref="System.Type"/> of property.
 /// </param>
 /// <param name="typeConverter">
 /// The <see cref="System.ComponentModel.TypeConverter"/> to register.
 /// </param>
 public virtual void RegisterCustomConverter(
     Type requiredType, TypeConverter typeConverter)
 {
     TypeConverterRegistry.RegisterConverter(requiredType, typeConverter);
 }
Ejemplo n.º 4
0
 private void RegisterTypeConverters()
 {
     TypeConverterRegistry.RegisterConverter(typeof(WriteConcern), new WriteConcernTypeConverter());
 }
 private void RegisterTypeConverters()
 {
     TypeConverterRegistry.RegisterConverter(typeof(WriteConcern), new WriteConcernTypeConverter());
     TypeConverterRegistry.RegisterConverter(typeof(ReadPreference), new ReadPreferenceTypeConverter());
     TypeConverterRegistry.RegisterConverter(typeof(MongoServerAddress), new MongoServerAddressTypeConverter());
 }