protected internal override bool TryAdd(string name, Binding binding, Configuration config)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name");
            }

            if (null == binding)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding");
            }

            if (null == config)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config");
            }

            ServiceModelSectionGroup       sg             = ServiceModelSectionGroup.GetSectionGroup(config);
            CustomBindingElementCollection customBindings = sg.Bindings.CustomBinding.Bindings;
            CustomBindingElement           configElement  = new CustomBindingElement(name);

            customBindings.Add(configElement);

            ExtensionElementCollection collection = sg.Extensions.BindingElementExtensions;

            CustomBinding customBinding = (CustomBinding)binding;

            foreach (BindingElement bindingElement in customBinding.Elements)
            {
                BindingElementExtensionElement bindingElementExtension;
                bool foundMatch = TryCreateMatchingExtension(bindingElement, collection, false, configElement.CollectionElementBaseType.AssemblyQualifiedName, out bindingElementExtension);
                if (!foundMatch)
                {
                    foundMatch = TryCreateMatchingExtension(bindingElement, collection, true, configElement.CollectionElementBaseType.AssemblyQualifiedName, out bindingElementExtension);
                }
                if (!foundMatch)
                {
                    break;
                }
                bindingElementExtension.InitializeFrom(bindingElement);
                configElement.Add(bindingElementExtension);
            }

            bool retval = configElement.Count == customBinding.Elements.Count;

            if (!retval)
            {
                customBindings.Remove(configElement);
            }

            return(retval);
        }
Esempio n. 2
0
        protected internal override bool TryAdd(string name, Binding binding, System.Configuration.Configuration config)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name");
            }
            if (binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding");
            }
            if (config == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config");
            }
            ServiceModelSectionGroup       sectionGroup = ServiceModelSectionGroup.GetSectionGroup(config);
            CustomBindingElementCollection bindings     = sectionGroup.Bindings.CustomBinding.Bindings;
            CustomBindingElement           element      = new CustomBindingElement(name);

            bindings.Add(element);
            ExtensionElementCollection bindingElementExtensions = sectionGroup.Extensions.BindingElementExtensions;
            CustomBinding binding2 = (CustomBinding)binding;

            foreach (BindingElement element2 in binding2.Elements)
            {
                BindingElementExtensionElement element3;
                bool flag = this.TryCreateMatchingExtension(element2, bindingElementExtensions, false, element.CollectionElementBaseType.AssemblyQualifiedName, out element3);
                if (!flag)
                {
                    flag = this.TryCreateMatchingExtension(element2, bindingElementExtensions, true, element.CollectionElementBaseType.AssemblyQualifiedName, out element3);
                }
                if (!flag)
                {
                    break;
                }
                element3.InitializeFrom(element2);
                element.Add(element3);
            }
            bool flag2 = element.Count == binding2.Elements.Count;

            if (!flag2)
            {
                bindings.Remove(element);
            }
            return(flag2);
        }