Exemplo n.º 1
0
        // Essentially this method does what MobileDeviceCapabilitiesSectionHandler.Create()
        // does, but use this DeviceFiltersSection for retrieving config data instead
        private DeviceFilterDictionary CreateDeviceFilters()
        {
            DeviceFilterDictionary filterDictionary = new DeviceFilterDictionary();

            foreach (DeviceFilterElement deviceFilter in Filters)
            {
                if (deviceFilter.FilterClass != null)
                {
                    filterDictionary.AddCapabilityDelegate(deviceFilter.Name, deviceFilter.GetDelegate());
                }
                else
                {
                    try {
                        filterDictionary.AddComparisonDelegate(
                            deviceFilter.Name, deviceFilter.Compare, deviceFilter.Argument);
                    }
                    catch (Exception e) {
                        throw new ConfigurationErrorsException(
                                  SR.GetString(SR.DevCapSect_UnableAddDelegate, deviceFilter.Name, e.Message));
                    }
                }
            }

            return(filterDictionary);
        }
 internal DeviceFilterDictionary GetDeviceFilters() {
     if (_deviceFilters == null) {
         lock (_deviceFilterslock) {
             if (_deviceFilters == null) {
                 _deviceFilters = CreateDeviceFilters();
             }
         }
     }
     return _deviceFilters;
 }
Exemplo n.º 3
0
 internal DeviceFilterDictionary GetDeviceFilters()
 {
     if (_deviceFilters == null)
     {
         lock (_deviceFilterslock) {
             if (_deviceFilters == null)
             {
                 _deviceFilters = CreateDeviceFilters();
             }
         }
     }
     return(_deviceFilters);
 }
        // Essentially this method does what MobileDeviceCapabilitiesSectionHandler.Create()
        // does, but use this DeviceFiltersSection for retrieving config data instead
        private DeviceFilterDictionary CreateDeviceFilters() {
            DeviceFilterDictionary filterDictionary = new DeviceFilterDictionary();

            foreach (DeviceFilterElement deviceFilter in Filters) {
                if (deviceFilter.FilterClass != null) {
                    filterDictionary.AddCapabilityDelegate(deviceFilter.Name, deviceFilter.GetDelegate());
                }
                else {
                    try {
                        filterDictionary.AddComparisonDelegate(
                            deviceFilter.Name, deviceFilter.Compare, deviceFilter.Argument);
                    }
                    catch (Exception e) {
                        throw new ConfigurationErrorsException(
                            SR.GetString(SR.DevCapSect_UnableAddDelegate, deviceFilter.Name, e.Message));
                    }
                }
            }

            return filterDictionary;
        }
 internal DeviceFilterDictionary(DeviceFilterDictionary original)
 {
     _comparisonEvaluators = (Hashtable)original._comparisonEvaluators.Clone();
     _delegateEvaluators   = (Hashtable)original._delegateEvaluators.Clone();
 }
 internal DeviceFilterDictionary(DeviceFilterDictionary original)
 {
     _comparisonEvaluators = (Hashtable)original._comparisonEvaluators.Clone();
     _delegateEvaluators = (Hashtable)original._delegateEvaluators.Clone();
 }
Exemplo n.º 7
0
        // IConfigurationSectionHandler Methods
        Object IConfigurationSectionHandler.Create(Object parent, Object context,
                                                   XmlNode node)
        {
            // see ASURT 123738
            if (context == null || context.GetType() != typeof(System.Web.Configuration.HttpConfigurationContext))
            {
                return(null);
            }

            DeviceFilterDictionary currentFilterDictionary;

            if (parent == null)
            {
                currentFilterDictionary = new DeviceFilterDictionary();
            }
            else
            {
                currentFilterDictionary = new DeviceFilterDictionary(
                    (DeviceFilterDictionary)parent);
            }

            ConfigurationSectionHelper helper = new ConfigurationSectionHelper();

            foreach (XmlNode child in node.ChildNodes)
            {
                helper.Node = child;

                // skip whitespace and comments
                if (helper.IsWhitespaceOrComment())
                {
                    continue;
                }

                // reject nonelements
                helper.RejectNonElement();

                // handle <filter> tags

                if (child.Name.Equals("filter"))
                {
                    String name      = helper.RemoveStringAttribute("name", true);
                    String className = helper.RemoveStringAttribute("type", false);

                    if (className != null)
                    {
                        const String methodAttributeName = "method";
                        String       methodName          = helper.RemoveStringAttribute(methodAttributeName, false);
                        String       capabilityName      = helper.RemoveStringAttribute("compare", false);
                        String       argumentValue       = helper.RemoveStringAttribute("argument", false);

                        helper.CheckForUnrecognizedAttributes();

                        if (className == String.Empty)
                        {
                            throw new
                                  ConfigurationException(SR.GetString(SR.DevCapSect_EmptyClass), child);
                        }

                        if (methodName == null)
                        {
                            throw new
                                  ConfigurationException(SR.GetString(SR.ConfigSect_MissingAttr, methodAttributeName), child);
                        }

                        if (methodName == String.Empty)
                        {
                            throw new
                                  ConfigurationException(SR.GetString(SR.ConfigSect_MissingValue, methodAttributeName), child);
                        }

                        if (capabilityName != null || argumentValue != null)
                        {
                            String msg;
                            if (capabilityName != null)
                            {
                                msg = SR.GetString(SR.DevCapSect_ExtraCompareDelegator);
                            }
                            else
                            {
                                msg = SR.GetString(SR.DevCapSect_ExtraArgumentDelegator);
                            }

                            throw new ConfigurationException(msg, child);
                        }

                        MobileCapabilities.EvaluateCapabilitiesDelegate evaluator;

                        Type evaluatorClass = Type.GetType(className);

                        if (null == evaluatorClass)
                        {
                            String msg =
                                SR.GetString(SR.DevCapSect_NoTypeInfo, className);
                            throw new ConfigurationException(msg, child);
                        }

                        try
                        {
                            evaluator =
                                (MobileCapabilities.EvaluateCapabilitiesDelegate)
                                MobileCapabilities.EvaluateCapabilitiesDelegate.CreateDelegate(
                                    typeof(MobileCapabilities.EvaluateCapabilitiesDelegate),
                                    evaluatorClass, methodName);
                        }
                        catch (Exception e)
                        {
                            String msg =
                                SR.GetString(SR.DevCapSect_NoCapabilityEval,
                                             methodName, e.Message);
                            throw new ConfigurationException(msg, child);
                        }

                        currentFilterDictionary.AddCapabilityDelegate(name, evaluator);
                    }
                    else
                    {
                        String capabilityName = helper.RemoveStringAttribute("compare", false);
                        String argumentValue  = helper.RemoveStringAttribute("argument", false);
                        String methodName     = helper.RemoveStringAttribute("method", false);

                        helper.CheckForUnrecognizedAttributes();

                        if ((capabilityName == null) || (capabilityName == String.Empty))
                        {
                            throw new ConfigurationException(
                                      SR.GetString(SR.DevCapSect_MustSpecify),
                                      child);
                        }

                        if (methodName != null)
                        {
                            throw new ConfigurationException(
                                      SR.GetString(SR.DevCapSect_ComparisonAlreadySpecified),
                                      child);
                        }

                        try
                        {
                            currentFilterDictionary.AddComparisonDelegate(name, capabilityName, argumentValue);
                        }
                        catch (Exception e)
                        {
                            String msg = SR.GetString(SR.DevCapSect_UnableAddDelegate,
                                                      name, e.Message);
                            throw new ConfigurationException(msg, child);
                        }
                    }
                }
                else
                {
                    String msg = SR.GetString(SR.DevCapSect_UnrecognizedTag,
                                              child.Name);
                    throw new ConfigurationException(msg, child);
                }

                helper.Node = null;
            }

            return(currentFilterDictionary);
        }
        protected object Create(Object parent, Object context, XmlNode node) {
            // see ASURT 123738
            if (context == null || context.GetType() != typeof(System.Web.Configuration.HttpConfigurationContext)) {
                return null;
            }
            
            DeviceFilterDictionary currentFilterDictionary;
            
            if(parent == null)
            {
                currentFilterDictionary = new DeviceFilterDictionary();
            }
            else
            {
                currentFilterDictionary = new DeviceFilterDictionary(
                    (DeviceFilterDictionary)parent);
            }

            ConfigurationSectionHelper helper = new ConfigurationSectionHelper();
            foreach(XmlNode child in node.ChildNodes)
            {
                helper.Node = child;

                // skip whitespace and comments
                if(helper.IsWhitespaceOrComment())
                {
                    continue;
                }
                    
                // reject nonelements
                helper.RejectNonElement();

                // handle <filter> tags

                if(child.Name.Equals("filter"))
                {
                    String name = helper.RemoveStringAttribute("name", true);
                    String className = helper.RemoveStringAttribute("type", false);

                    if(className != null)
                    {
                        const String methodAttributeName = "method";
                        String methodName = helper.RemoveStringAttribute(methodAttributeName, false);
                        String capabilityName = helper.RemoveStringAttribute("compare", false);
                        String argumentValue = helper.RemoveStringAttribute("argument", false);

                        helper.CheckForUnrecognizedAttributes();

                        if(className == String.Empty)
                        {
                            throw new
                                ConfigurationErrorsException(SR.GetString(SR.DevCapSect_EmptyClass), child);
                        }

                        if(methodName == null)
                        {
                            throw new
                                ConfigurationErrorsException(SR.GetString(SR.ConfigSect_MissingAttr, methodAttributeName), child);
                        }

                        if(methodName == String.Empty)
                        {
                            throw new
                                ConfigurationErrorsException(SR.GetString(SR.ConfigSect_MissingValue, methodAttributeName), child);
                        }

                        if(capabilityName != null || argumentValue != null)
                        {
                            String msg;
                            if (capabilityName != null)
                            {
                                msg = SR.GetString(SR.DevCapSect_ExtraCompareDelegator);
                            }
                            else
                            {
                                msg = SR.GetString(SR.DevCapSect_ExtraArgumentDelegator);
                            }
                            
                            throw new ConfigurationErrorsException(msg, child);
                        }

                        MobileCapabilities.EvaluateCapabilitiesDelegate evaluator;

                        Type evaluatorClass = Type.GetType(className);

                        if(null == evaluatorClass)
                        {
                            String msg =
                                SR.GetString(SR.DevCapSect_NoTypeInfo, className);
                            throw new ConfigurationErrorsException(msg, child);
                        }

                        try
                        {
                            evaluator =
                                (MobileCapabilities.EvaluateCapabilitiesDelegate)
                                MobileCapabilities.EvaluateCapabilitiesDelegate.CreateDelegate(
                                    typeof(MobileCapabilities.EvaluateCapabilitiesDelegate),
                                    evaluatorClass, methodName);
                        }
                        catch(Exception e)
                        {
                            String msg =
                                SR.GetString(SR.DevCapSect_NoCapabilityEval,
                                             methodName, e.Message);
                            throw new ConfigurationErrorsException(msg, child);
                        }

                        currentFilterDictionary.AddCapabilityDelegate(name, evaluator);
                    }
                    else
                    {
                        String capabilityName = helper.RemoveStringAttribute("compare", false);
                        String argumentValue = helper.RemoveStringAttribute("argument", false);
                        String methodName = helper.RemoveStringAttribute("method", false);                        

                        helper.CheckForUnrecognizedAttributes();

                        if(String.IsNullOrEmpty(capabilityName))
                        {
                            throw new ConfigurationErrorsException(
                                SR.GetString(SR.DevCapSect_MustSpecify),
                                child);
                        }

                        if(methodName != null)
                        {
                            throw new ConfigurationErrorsException(
                                SR.GetString(SR.DevCapSect_ComparisonAlreadySpecified),
                                child);
                        }

                        try
                        {
                            currentFilterDictionary.AddComparisonDelegate(name, capabilityName, argumentValue);
                        }
                        catch(Exception e)
                        {
                            String msg = SR.GetString(SR.DevCapSect_UnableAddDelegate,
                                                      name, e.Message);
                            throw new ConfigurationErrorsException(msg, child);
                        }
                    }                    
                }
                else
                {
                    String msg = SR.GetString(SR.DevCapSect_UnrecognizedTag,
                                              child.Name);
                    throw new ConfigurationErrorsException(msg, child);
                }

                helper.Node = null;
            }
   
            return currentFilterDictionary;
        }