// Essentially this method does what MobileControlSectionHandler.Create()
        // does, but use MobileControlsSection for retrieving config data instead
        internal static ControlsConfig CreateControlsConfig(MobileControlsSection controlSection) {
            ControlsConfig config = new ControlsConfig(null);

            config["sessionStateHistorySize"] = controlSection.SessionStateHistorySize.ToString(CultureInfo.InvariantCulture);
            config["cookielessDataDictionaryType"] = controlSection.CookielessDataDictionaryType.AssemblyQualifiedName;
            config["allowCustomAttributes"] = controlSection.AllowCustomAttributes.ToString(CultureInfo.InvariantCulture);

            foreach (DeviceElement device in controlSection.Devices) {
                IndividualDeviceConfig deviceConfig = CreateDeviceConfig(config, device);
                AddControlAdapters(deviceConfig, device);

                if (!config.AddDeviceConfig(device.Name, deviceConfig)) {
                    // Problem is due to a duplicated name
                    throw new ConfigurationErrorsException(
                        SR.GetString(SR.MobileControlsSectionHandler_DuplicatedDeviceName, device.Name));
                }
            }

            // Passing null means no config file and line number info will be
            // shown when error happens.  That is because there is no XmlNode of
            // the config section is available when MobileControlsSection is
            // used.  But the error messages raised should still be good enough.
            config.FixupDeviceConfigInheritance(null);

            return config;
        }
        // Essentially this method does what MobileControlSectionHandler.Create()
        // does, but use MobileControlsSection for retrieving config data instead
        internal static ControlsConfig CreateControlsConfig(MobileControlsSection controlSection)
        {
            ControlsConfig config = new ControlsConfig(null);

            config["sessionStateHistorySize"]      = controlSection.SessionStateHistorySize.ToString(CultureInfo.InvariantCulture);
            config["cookielessDataDictionaryType"] = controlSection.CookielessDataDictionaryType.AssemblyQualifiedName;
            config["allowCustomAttributes"]        = controlSection.AllowCustomAttributes.ToString(CultureInfo.InvariantCulture);

            foreach (DeviceElement device in controlSection.Devices)
            {
                IndividualDeviceConfig deviceConfig = CreateDeviceConfig(config, device);
                AddControlAdapters(deviceConfig, device);

                if (!config.AddDeviceConfig(device.Name, deviceConfig))
                {
                    // Problem is due to a duplicated name
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.MobileControlsSectionHandler_DuplicatedDeviceName, device.Name));
                }
            }

            // Passing null means no config file and line number info will be
            // shown when error happens.  That is because there is no XmlNode of
            // the config section is available when MobileControlsSection is
            // used.  But the error messages raised should still be good enough.
            config.FixupDeviceConfigInheritance(null);

            return(config);
        }
 // VSWhidbey 450801. Only create one ControlsConfig per MobileControlsSection instance.
 internal ControlsConfig GetControlsConfig() {
     if (_controlConfig == null) {
         lock (_lock) {
             if (_controlConfig == null) {
                 _controlConfig = MobileControlsSectionHelper.CreateControlsConfig(this);
             }
         }
     }
     return _controlConfig;
 }
예제 #4
0
        // Helper to create a device config given the names of methods
        private IndividualDeviceConfig CreateDeviceConfig(ControlsConfig config,
                                                          ConfigurationSectionHelper helper,
                                                          String deviceName)
        {
            String nameOfDeviceToInheritFrom =
                helper.RemoveStringAttribute("inheritsFrom", false);

            if (nameOfDeviceToInheritFrom == String.Empty)
            {
                nameOfDeviceToInheritFrom = null;
            }

            bool propertiesRequired = nameOfDeviceToInheritFrom == null;

            String predicateClass = helper.RemoveStringAttribute("predicateClass", propertiesRequired);
            // If a predicate class is specified, so must a method.
            String predicateMethod  = helper.RemoveStringAttribute("predicateMethod", predicateClass != null);
            String pageAdapterClass = helper.RemoveStringAttribute("pageAdapter", propertiesRequired);

            IndividualDeviceConfig.DeviceQualifiesDelegate predicateDelegate = null;
            if (predicateClass != null || predicateMethod != null)
            {
                Type predicateClassType = CheckedGetType(predicateClass, "PredicateClass", helper);
                try
                {
                    predicateDelegate =
                        (IndividualDeviceConfig.DeviceQualifiesDelegate)
                        IndividualDeviceConfig.DeviceQualifiesDelegate.CreateDelegate(
                            typeof(IndividualDeviceConfig.DeviceQualifiesDelegate),
                            predicateClassType,
                            predicateMethod);
                }
                catch
                {
                    throw new ConfigurationException(
                              SR.GetString(SR.MobileControlsSectionHandler_CantCreateMethodOnClass,
                                           predicateMethod, predicateClassType.FullName),
                              helper.Node);
                }
            }

            Type pageAdapterType = null;

            if (pageAdapterClass != null)
            {
                pageAdapterType = CheckedGetType(pageAdapterClass, "PageAdapterClass", helper);
            }

            return(new IndividualDeviceConfig(config,
                                              deviceName,
                                              predicateDelegate,
                                              pageAdapterType,
                                              nameOfDeviceToInheritFrom));
        }
예제 #5
0
            public SessionViewStateHistory(HttpContext context)
            {
                _historySize = ControlsConfig.GetFromContext(context).SessionStateHistorySize;
                if (_historySize < 1)
                {
                    throw new Exception(
                              SR.GetString(SR.SessionViewState_InvalidSessionStateHistory));
                }

                _history = new SessionViewStateHistoryItem[_historySize];
            }
 // This constructor takes both a delegate that chooses this
 // device, and a Type to instantiate the appropriate page
 // adapter with.  
 internal IndividualDeviceConfig(ControlsConfig          controlsConfig,
                               String                  name,
                               DeviceQualifiesDelegate deviceQualifiesDelegate,
                               Type                    pageAdapterType,
                               String                  parentConfigName)
 {
     _controlsConfig = controlsConfig;
     _name = name;
     _deviceQualifiesPredicate = deviceQualifiesDelegate;
     _parentConfigName = parentConfigName;
     _parentConfig = null;
     PageAdapterType = pageAdapterType;
 }
예제 #7
0
 // This constructor takes both a delegate that chooses this
 // device, and a Type to instantiate the appropriate page
 // adapter with.
 internal IndividualDeviceConfig(ControlsConfig controlsConfig,
                                 String name,
                                 DeviceQualifiesDelegate deviceQualifiesDelegate,
                                 Type pageAdapterType,
                                 String parentConfigName)
 {
     _controlsConfig           = controlsConfig;
     _name                     = name;
     _deviceQualifiesPredicate = deviceQualifiesDelegate;
     _parentConfigName         = parentConfigName;
     _parentConfig             = null;
     PageAdapterType           = pageAdapterType;
 }
예제 #8
0
 // VSWhidbey 450801. Only create one ControlsConfig per MobileControlsSection instance.
 internal ControlsConfig GetControlsConfig()
 {
     if (_controlConfig == null)
     {
         lock (_lock) {
             if (_controlConfig == null)
             {
                 _controlConfig = MobileControlsSectionHelper.CreateControlsConfig(this);
             }
         }
     }
     return(_controlConfig);
 }
        // Essentially this method does what MobileControlSectionHandler.CreateDeviceConfig()
        // does, but use MobileControlsSection for retrieving config data instead
        private static IndividualDeviceConfig CreateDeviceConfig(ControlsConfig config, DeviceElement device) {
            String nameOfDeviceToInheritFrom = device.InheritsFrom;
            if (nameOfDeviceToInheritFrom != null && nameOfDeviceToInheritFrom.Length == 0) {
                nameOfDeviceToInheritFrom = null;
            }

            IndividualDeviceConfig.DeviceQualifiesDelegate predicateDelegate = null;
            if (device.PredicateClass != null) {
                // If a predicate class is specified, so must a method.
                // The checking is already done in MobileControlsSection
                Debug.Assert(!String.IsNullOrEmpty(device.PredicateMethod));
                predicateDelegate = device.GetDelegate();
            }

            return new IndividualDeviceConfig(config,
                                              device.Name,
                                              predicateDelegate,
                                              device.PageAdapter,
                                              nameOfDeviceToInheritFrom);
        }
        // Essentially this method does what MobileControlSectionHandler.CreateDeviceConfig()
        // does, but use MobileControlsSection for retrieving config data instead
        private static IndividualDeviceConfig CreateDeviceConfig(ControlsConfig config, DeviceElement device)
        {
            String nameOfDeviceToInheritFrom = device.InheritsFrom;

            if (nameOfDeviceToInheritFrom != null && nameOfDeviceToInheritFrom.Length == 0)
            {
                nameOfDeviceToInheritFrom = null;
            }

            IndividualDeviceConfig.DeviceQualifiesDelegate predicateDelegate = null;
            if (device.PredicateClass != null)
            {
                // If a predicate class is specified, so must a method.
                // The checking is already done in MobileControlsSection
                Debug.Assert(!String.IsNullOrEmpty(device.PredicateMethod));
                predicateDelegate = device.GetDelegate();
            }

            return(new IndividualDeviceConfig(config,
                                              device.Name,
                                              predicateDelegate,
                                              device.PageAdapter,
                                              nameOfDeviceToInheritFrom));
        }
예제 #11
0
        // IConfigurationSectionHandler methods
        Object IConfigurationSectionHandler.Create(Object parent, Object context, XmlNode input)
        {
            // see ASURT 123738
            if (context == null || context.GetType() != typeof(System.Web.Configuration.HttpConfigurationContext))
            {
                return(null);
            }

            ControlsConfig config = new ControlsConfig((ControlsConfig)parent);

            // First step through each attribute on the <mobilecontrols> element
            // and update the ControlsConfig dictionary with it.
            XmlAttributeCollection attributes = input.Attributes;

            foreach (XmlNode attribute in attributes)
            {
                config[attribute.Name] = attribute.Value;
            }

            //check validity of cookielessDataDictionary type
            String cookielessDataDictionaryType = config["cookielessDataDictionaryType"];

            if ((cookielessDataDictionaryType != null) &&
                (cookielessDataDictionaryType != String.Empty))
            {
                Type t = Type.GetType(cookielessDataDictionaryType);
                if (t == null)
                {
                    throw new ConfigurationException(
                              SR.GetString(SR.MobileControlsSectionHandler_TypeNotFound,
                                           cookielessDataDictionaryType,
                                           "IDictionary"),
                              input);
                }
                if (!(typeof(IDictionary).IsAssignableFrom(t)))
                {
                    throw new ConfigurationException(
                              SR.GetString(SR.MobileControlsSectionHandler_NotAssignable,
                                           cookielessDataDictionaryType,
                                           "IDictionary"),
                              input);
                }
            }

            // Iterate through each <device> tag within the config section
            ConfigurationSectionHelper helper = new ConfigurationSectionHelper();

            foreach (XmlNode nextNode in input)
            {
                helper.Node = nextNode;

                if (helper.IsWhitespaceOrComment())
                {
                    continue;
                }

                helper.RejectNonElement();

                // handle <device> tags
                switch (nextNode.Name)
                {
                case "device":
                    String deviceName = helper.RemoveStringAttribute("name", false);

                    IndividualDeviceConfig idc = CreateDeviceConfig(config, helper, deviceName);

                    helper.CheckForUnrecognizedAttributes();

                    // Iterate through every control adapter
                    // within the <device>
                    foreach (XmlNode currentChild in nextNode.ChildNodes)
                    {
                        helper.Node = currentChild;

                        if (helper.IsWhitespaceOrComment())
                        {
                            continue;
                        }

                        helper.RejectNonElement();

                        if (!currentChild.Name.Equals("control"))
                        {
                            throw new ConfigurationException(
                                      SR.GetString(SR.MobileControlsSectionHandler_UnknownElementName, "<control>"),
                                      currentChild);
                        }
                        else
                        {
                            String controlName = helper.RemoveStringAttribute("name", true);
                            String adapterName = helper.RemoveStringAttribute("adapter", true);
                            helper.CheckForUnrecognizedAttributes();

                            idc.AddControl(CheckedGetType(controlName, "control", helper, typeof(Control), currentChild),
                                           CheckedGetType(adapterName, "adapter", helper, typeof(IControlAdapter), currentChild));
                        }

                        helper.Node = null;
                    }

                    // Add complete device config to master configs.
                    if (deviceName == String.Empty || deviceName == null)
                    {
                        deviceName = Guid.NewGuid().ToString();
                    }

                    if (!config.AddDeviceConfig(deviceName, idc))
                    {
                        // Problem is due to a duplicated name
                        throw new ConfigurationException(
                                  SR.GetString(SR.MobileControlsSectionHandler_DuplicatedDeviceName, deviceName),
                                  nextNode);
                    }

                    helper.Node = null;
                    break;

                default:
                    throw new ConfigurationException(
                              SR.GetString(SR.MobileControlsSectionHandler_UnknownElementName, "<device>"),
                              nextNode);
                }
            }

            config.FixupDeviceConfigInheritance(input);

            return(config);
        }
        // IConfigurationSectionHandler methods
        /// <internalonly/>
        protected Object Create(Object parent, Object context, XmlNode input)
        {
            // see ASURT 123738
            if (context == null || context.GetType() != typeof(System.Web.Configuration.HttpConfigurationContext)) {
                return null;
            }
            
            ControlsConfig config = new ControlsConfig((ControlsConfig)parent);

            // First step through each attribute on the <mobilecontrols> element
            // and update the ControlsConfig dictionary with it.
            XmlAttributeCollection attributes = input.Attributes;
            foreach (XmlNode attribute in attributes)
            {
                config[attribute.Name] = attribute.Value;
            }

            //check validity of cookielessDataDictionary type
            String cookielessDataDictionaryType = config["cookielessDataDictionaryType"];
            if (!String.IsNullOrEmpty(cookielessDataDictionaryType)) {
                Type t = Type.GetType(cookielessDataDictionaryType);
                if (t == null)  
                {
                    throw new ConfigurationErrorsException(
                        SR.GetString(SR.MobileControlsSectionHandler_TypeNotFound,
                                 cookielessDataDictionaryType,
                                 "IDictionary"),
                        input);
                }
                if (!(typeof(IDictionary).IsAssignableFrom(t)))
                {
                    throw new ConfigurationErrorsException(
                        SR.GetString(SR.MobileControlsSectionHandler_NotAssignable,
                                     cookielessDataDictionaryType,
                                     "IDictionary"),
                        input);
                }

            }

            // Iterate through each <device> tag within the config section
            ConfigurationSectionHelper helper = new ConfigurationSectionHelper();
            foreach(XmlNode nextNode in input)
            {
                helper.Node = nextNode;

                if(helper.IsWhitespaceOrComment())
                {
                    continue;
                }

                helper.RejectNonElement();
                
                // handle <device> tags
                switch(nextNode.Name)
                {
                case "device":
                    String deviceName = helper.RemoveStringAttribute("name", false);
                    
                    IndividualDeviceConfig idc = CreateDeviceConfig(config, helper, deviceName);

                    helper.CheckForUnrecognizedAttributes();

                    // Iterate through every control adapter
                    // within the <device>
                    foreach(XmlNode currentChild in nextNode.ChildNodes)
                    {
                        helper.Node = currentChild;

                        if(helper.IsWhitespaceOrComment())
                        {
                            continue;
                        }

                        helper.RejectNonElement();
                        
                        if (!currentChild.Name.Equals("control"))
                        {
                            throw new ConfigurationErrorsException(
                                SR.GetString(SR.MobileControlsSectionHandler_UnknownElementName, "<control>"),
                                currentChild);
                        }
                        else
                        {
                            String controlName = helper.RemoveStringAttribute("name", true);
                            String adapterName = helper.RemoveStringAttribute("adapter", true);
                            helper.CheckForUnrecognizedAttributes();

                            idc.AddControl(CheckedGetType(controlName, "control", helper, typeof(MobileControl), currentChild),
                                           CheckedGetType(adapterName, "adapter", helper, typeof(IControlAdapter), currentChild));

                        }

                        helper.Node = null;
                    }

                    // Add complete device config to master configs.
                    if (String.IsNullOrEmpty(deviceName)) {
                        deviceName = Guid.NewGuid().ToString();
                    }
                    
                    if (!config.AddDeviceConfig(deviceName, idc))
                    {
                        // Problem is due to a duplicated name
                        throw new ConfigurationErrorsException(
                            SR.GetString(SR.MobileControlsSectionHandler_DuplicatedDeviceName, deviceName),
                            nextNode);
                        
                    }
                    
                    helper.Node = null;
                    break;
                default:
                    throw new ConfigurationErrorsException(
                        SR.GetString(SR.MobileControlsSectionHandler_UnknownElementName, "<device>"),
                        nextNode);
                }
            }

            config.FixupDeviceConfigInheritance(input);

            return config;
            
        }
        // Helper to create a device config given the names of methods
        private IndividualDeviceConfig CreateDeviceConfig(ControlsConfig config,
                                                          ConfigurationSectionHelper helper,
                                                          String deviceName)
        {
            String nameOfDeviceToInheritFrom =
                helper.RemoveStringAttribute("inheritsFrom", false);

            if (nameOfDeviceToInheritFrom != null && nameOfDeviceToInheritFrom.Length == 0) {
                nameOfDeviceToInheritFrom = null;
            }
            
            bool propertiesRequired = nameOfDeviceToInheritFrom == null;

            String predicateClass = helper.RemoveStringAttribute("predicateClass", propertiesRequired);
            // If a predicate class is specified, so must a method.
            String predicateMethod = helper.RemoveStringAttribute("predicateMethod", predicateClass != null);
            String pageAdapterClass = helper.RemoveStringAttribute("pageAdapter", propertiesRequired);

            IndividualDeviceConfig.DeviceQualifiesDelegate predicateDelegate = null;
            if (predicateClass != null || predicateMethod != null)
            {
                Type predicateClassType = CheckedGetType(predicateClass, "PredicateClass", helper, null, null);
                try
                {
                    predicateDelegate =
                        (IndividualDeviceConfig.DeviceQualifiesDelegate)
                        IndividualDeviceConfig.DeviceQualifiesDelegate.CreateDelegate(
                            typeof(IndividualDeviceConfig.DeviceQualifiesDelegate),
                            predicateClassType,
                            predicateMethod);
                }
                catch
                {
                    throw new ConfigurationErrorsException(
                        SR.GetString(SR.MobileControlsSectionHandler_CantCreateMethodOnClass,
                                     predicateMethod, predicateClassType.FullName),
                        helper.Node);
                }
            }
                    
            Type pageAdapterType = null;
            if (pageAdapterClass != null)
            {
                pageAdapterType = CheckedGetType(pageAdapterClass, "PageAdapterClass", helper, typeof(IPageAdapter), null);
            }

            return new IndividualDeviceConfig(config,
                                              deviceName,
                                              predicateDelegate,
                                              pageAdapterType,
                                              nameOfDeviceToInheritFrom);
        }
예제 #14
0
 internal ControlsConfig(ControlsConfig parent)
 {
     _parent = parent;
 }
예제 #15
0
 internal ControlsConfig(ControlsConfig parent)
 {
     _parent = parent;
 }