コード例 #1
0
 public void TestTypeMappings()
 {
     TypeMappingCollection mappings = new TypeMappingCollection();
       ConfigurationSectionHelper testHelper = new ConfigurationSectionHelper();
       testHelper.TypeMappings = mappings;
       Assert.AreEqual(mappings, testHelper.TypeMappings);
 }
コード例 #2
0
 public void TestLifetimeManagerMappings()
 {
     LifetimeManagerMappingCollection mappings = new LifetimeManagerMappingCollection();
       ConfigurationSectionHelper testHelper = new ConfigurationSectionHelper();
       testHelper.LifetimeManagerMappings = mappings;
       Assert.AreEqual(mappings, testHelper.LifetimeManagerMappings);
 }
コード例 #3
0
 public void TestResolvers()
 {
     ResolverCollection resolvers = new ResolverCollection();
       ConfigurationSectionHelper testHelper = new ConfigurationSectionHelper();
       testHelper.Resolvers = resolvers;
       Assert.AreEqual(resolvers, testHelper.Resolvers);
 }
コード例 #4
0
        private void SetWorkplaceId(string workplaceId)
        {
            if (string.IsNullOrEmpty(workplaceId))
            {
                return;
            }
            Guid wId = new Guid(workplaceId);

            ConfigurationSectionHelper.SetWorkplaceCache(UserConnection, wId);
        }
コード例 #5
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));
        }
コード例 #6
0
 public void TestParsingRegistrations()
 {
     ConfigurationSectionHelper helper = new ConfigurationSectionHelper();
       TypeMappingConfigurationElement element = new TypeMappingConfigurationElement();
       element.TypeName = "System.Object";
       element.MapTo = "RockSolidIoc.Tests.EmptyObject";
       TypeMappingCollection collection = new TypeMappingCollection();
       collection.Add(element);
       helper.TypeMappings = collection;
       Configurator testConfigurator = new Configurator();
       IIocContainer result = testConfigurator.Configure(helper);
       object s = result.Resolve<object>();
       Assert.IsInstanceOfType(s, typeof(EmptyObject));
 }
コード例 #7
0
 public void TestParsingResolvers()
 {
     ConfigurationSectionHelper helper = new ConfigurationSectionHelper();
       ResolverConfigurationElement resolver = new ResolverConfigurationElement();
       resolver.ResolverTypeName = "RockSolidIoc.Tests.MockFriendlyResolver";
       resolver.TypeName = "System.String";
       ResolverCollection collection = new ResolverCollection();
       collection.Add(resolver);
       helper.Resolvers = collection;
       Configurator testConfigurator = new Configurator();
       IIocContainer result = testConfigurator.Configure(helper);
       string s = result.Resolve<string>();
       MockFriendlyResolver.Mock.Verify(p => p.ResolveDependency(typeof(string), result), Times.Exactly(1));
       MockFriendlyResolver.ResetMock();
 }
コード例 #8
0
 public void TestParsingLifetimeManager()
 {
     ConfigurationSectionHelper helper = new ConfigurationSectionHelper();
       LifetimeManagerMappingConfigurationElement element = new LifetimeManagerMappingConfigurationElement();
       element.LifetimeManagerTypeName = "RockSolidIoc.Tests.MockFriendlyLifetimeManager";
       element.TypeName = "System.Object";
       LifetimeManagerMappingCollection collection = new LifetimeManagerMappingCollection();
       collection.Add(element);
       helper.LifetimeManagerMappings = collection;
       Configurator testConfigurator = new Configurator();
       IIocContainer result = testConfigurator.Configure(helper);
       object s = result.Resolve<object>();
       MockFriendlyLifetimeManager.Mock.Verify(p => p.AddInstance(It.IsAny<object>()), Times.Exactly(1));
       MockFriendlyLifetimeManager.ResetMock();
 }
コード例 #9
0
        // Helper method to encapsulate type lookup followed by
        // throwing a ConfigurationException on failure.
        private Type CheckedGetType(String typename,
                                    String whereUsed,
                                    ConfigurationSectionHelper helper)
        {
            Type t = Type.GetType(typename);

            if (t == null)
            {
                throw new ConfigurationException(
                          SR.GetString(SR.MobileControlsSectionHandler_TypeNotFound,
                                       typename,
                                       whereUsed),
                          helper.Node);
            }

            return(t);
        }
コード例 #10
0
        private Type CheckedGetType(String typename,
                                    String whereUsed,
                                    ConfigurationSectionHelper helper,
                                    Type typeImplemented,
                                    XmlNode input)
        {
            Type t = CheckedGetType(typename, whereUsed, helper);

            if (!typeImplemented.IsAssignableFrom(t))
            {
                throw new ConfigurationException(
                          SR.GetString(SR.MobileControlsSectionHandler_NotAssignable,
                                       t,
                                       typeImplemented),
                          input);
            }
            return(t);
        }
コード例 #11
0
        // Helper method to encapsulate type lookup followed by
        // throwing a ConfigurationErrorsException on failure.
        private Type CheckedGetType(String typename,
                                    String whereUsed,
                                    ConfigurationSectionHelper helper,
                                    Type typeImplemented,
                                    XmlNode input)
        {
            Type t = Type.GetType(typename);

            if (t == null)
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.MobileControlsSectionHandler_TypeNotFound,
                                       typename,
                                       whereUsed),
                          helper.Node);
            }

            if (typeImplemented != null && !typeImplemented.IsAssignableFrom(t))
            {
                if (input != null)
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.MobileControlsSectionHandler_NotAssignable,
                                           t,
                                           typeImplemented),
                              input);
                }
                else
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.MobileControlsSectionHandler_NotAssignable,
                                           t,
                                           typeImplemented),
                              helper.Node);
                }
            }

            return(t);
        }
コード例 #12
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);
        }
コード例 #13
0
 private void ResetWorkplace()
 {
     ConfigurationSectionHelper.ResetWorkplaceCache(UserConnection);
 }
コード例 #14
0
        private string GetWorkplacesScript(Guid applicationClientTypeId)
        {
            ConfigurationSectionHelper helper = new ConfigurationSectionHelper(UserConnection);

            return(helper.GetWorkplacesConfig(UserConnection, true, applicationClientTypeId));
        }
コード例 #15
0
 private void ResetCache()
 {
     ConfigurationSectionHelper.ClearCache(UserConnection);
 }
コード例 #16
0
 public void ClearConfigurationScript()
 {
     ConfigurationSectionHelper.ClearCache(UserConnection);
 }