Exemple #1
0
        internal void UpdateEndpointSections(ContextInformation evaluationContext)
        {
            ExtensionElementCollection endpointExtensions = ExtensionsSection.UnsafeLookupCollection(ConfigurationStrings.EndpointExtensions, evaluationContext);

            // Extension collections are additive only (BasicMap) and do not allow for <clear>
            // or <remove> tags, nor do they allow for overriding an entry.  This allows us
            // to optimize this to only walk the binding extension collection if the counts
            // mismatch.
            if (endpointExtensions.Count != this.properties.Count)
            {
                foreach (ExtensionElement endpointExtension in endpointExtensions)
                {
                    if (null != endpointExtension)
                    {
                        if (!this.properties.Contains(endpointExtension.Name))
                        {
                            Type extensionType = Type.GetType(endpointExtension.Type, false);
                            if (extensionType == null)
                            {
                                ConfigurationHelpers.TraceExtensionTypeNotFound(endpointExtension);
                            }
                            else
                            {
                                ConfigurationProperty property = new ConfigurationProperty(endpointExtension.Name,
                                                                                           extensionType,
                                                                                           null,
                                                                                           ConfigurationPropertyOptions.None);

                                this.properties.Add(property);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        private string GetEndpointName()
        {
            string name = string.Empty;
            ExtensionElementCollection elements = null;
            Type type = base.GetType();

            elements = ExtensionsSection.UnsafeLookupCollection("endpointExtensions", ConfigurationHelpers.GetEvaluationContext(this));
            if (elements == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigExtensionCollectionNotFound", new object[] { "endpointExtensions" }), base.ElementInformation.Source, base.ElementInformation.LineNumber));
            }
            for (int i = 0; i < elements.Count; i++)
            {
                ExtensionElement element = elements[i];
                if (element.Type.Equals(type.AssemblyQualifiedName, StringComparison.Ordinal))
                {
                    name = element.Name;
                    break;
                }
                Type o = Type.GetType(element.Type, false);
                if ((null != o) && type.Equals(o))
                {
                    name = element.Name;
                    break;
                }
            }
            if (string.IsNullOrEmpty(name))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigExtensionTypeNotRegisteredInCollection", new object[] { type.AssemblyQualifiedName, "endpointExtensions" }), base.ElementInformation.Source, base.ElementInformation.LineNumber));
            }
            return(name);
        }
        internal bool CanAdd(string extensionCollectionName, ContextInformation evaluationContext)
        {
            bool retVal = false;

            ExtensionElementCollection collection = ExtensionsSection.UnsafeLookupCollection(extensionCollectionName, evaluationContext);

            if (null != collection && collection.Count != 0)
            {
                string thisAssemblyQualifiedName = ThisType.AssemblyQualifiedName;
                string thisTypeName = ExtensionElement.GetTypeName(thisAssemblyQualifiedName);
                foreach (ExtensionElement extensionElement in collection)
                {
                    string extensionTypeName = extensionElement.Type;
                    if (extensionTypeName.Equals(thisAssemblyQualifiedName, StringComparison.Ordinal))
                    {
                        retVal = true;
                        break;
                    }

                    if (extensionElement.TypeName.Equals(thisTypeName, StringComparison.Ordinal))
                    {
                        Type extensionType = Type.GetType(extensionTypeName, false);
                        if (extensionType != null && extensionType.Equals(ThisType))
                        {
                            retVal = true;
                            break;
                        }
                    }
                }

                if (!retVal && DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning,
                                            TraceCode.ConfiguredExtensionTypeNotFound,
                                            SR.GetString(SR.TraceCodeConfiguredExtensionTypeNotFound),
                                            this.CreateCanAddRecord(extensionCollectionName), this, null);
                }
            }
            else if (DiagnosticUtility.ShouldTraceWarning)
            {
                int    traceCode;
                string traceDescription;
                if (collection != null && collection.Count == 0)
                {
                    traceCode        = TraceCode.ExtensionCollectionIsEmpty;
                    traceDescription = SR.GetString(SR.TraceCodeExtensionCollectionIsEmpty);
                }
                else
                {
                    traceCode        = TraceCode.ExtensionCollectionDoesNotExist;
                    traceDescription = SR.GetString(SR.TraceCodeExtensionCollectionDoesNotExist);
                }
                TraceUtility.TraceEvent(TraceEventType.Warning,
                                        traceCode, traceDescription, this.CreateCanAddRecord(extensionCollectionName), this, null);
            }

            return(retVal);
        }
        private string GetConfigurationElementName()
        {
            string name = string.Empty;
            ExtensionElementCollection elements = null;
            Type thisType = this.ThisType;
            ContextInformation containingEvaluationContext = this.ContainingEvaluationContext;

            if (containingEvaluationContext == null)
            {
                containingEvaluationContext = ConfigurationHelpers.GetEvaluationContext(this);
            }
            if (string.IsNullOrEmpty(this.extensionCollectionName))
            {
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning, 0x8001b, System.ServiceModel.SR.GetString("TraceCodeExtensionCollectionNameNotFound"), this, (Exception)null);
                }
                elements = ExtensionsSection.UnsafeLookupAssociatedCollection(this.ThisType, containingEvaluationContext, out this.extensionCollectionName);
            }
            else
            {
                elements = ExtensionsSection.UnsafeLookupCollection(this.extensionCollectionName, containingEvaluationContext);
            }
            if (elements == null)
            {
                if (string.IsNullOrEmpty(this.extensionCollectionName))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigNoExtensionCollectionAssociatedWithType", new object[] { thisType.AssemblyQualifiedName }), base.ElementInformation.Source, base.ElementInformation.LineNumber));
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigExtensionCollectionNotFound", new object[] { this.extensionCollectionName }), base.ElementInformation.Source, base.ElementInformation.LineNumber));
            }
            for (int i = 0; i < elements.Count; i++)
            {
                ExtensionElement element = elements[i];
                if (element.Type.Equals(thisType.AssemblyQualifiedName, StringComparison.Ordinal))
                {
                    name = element.Name;
                    break;
                }
                Type type = Type.GetType(element.Type, false);
                if ((null != type) && thisType.Equals(type))
                {
                    name = element.Name;
                    break;
                }
            }
            if (string.IsNullOrEmpty(name))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigExtensionTypeNotRegisteredInCollection", new object[] { thisType.AssemblyQualifiedName, this.extensionCollectionName }), base.ElementInformation.Source, base.ElementInformation.LineNumber));
            }
            return(name);
        }
        internal bool CanAdd(string extensionCollectionName, ContextInformation evaluationContext)
        {
            bool flag = false;
            ExtensionElementCollection elements = ExtensionsSection.UnsafeLookupCollection(extensionCollectionName, evaluationContext);

            if ((elements == null) || (elements.Count == 0))
            {
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    int    num;
                    string str3;
                    if ((elements != null) && (elements.Count == 0))
                    {
                        num  = 0x8001c;
                        str3 = System.ServiceModel.SR.GetString("TraceCodeExtensionCollectionIsEmpty");
                    }
                    else
                    {
                        num  = 0x8001a;
                        str3 = System.ServiceModel.SR.GetString("TraceCodeExtensionCollectionDoesNotExist");
                    }
                    TraceUtility.TraceEvent(TraceEventType.Warning, num, str3, this.CreateCanAddRecord(extensionCollectionName), this, null);
                }
                return(flag);
            }
            string assemblyQualifiedName = this.ThisType.AssemblyQualifiedName;

            foreach (ExtensionElement element in elements)
            {
                string str2 = element.Type;
                if (str2.Equals(assemblyQualifiedName, StringComparison.Ordinal))
                {
                    flag = true;
                    break;
                }
                if (assemblyQualifiedName.StartsWith(str2, StringComparison.Ordinal))
                {
                    Type type = Type.GetType(str2, false);
                    if ((type != null) && type.Equals(this.ThisType))
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (!flag && DiagnosticUtility.ShouldTraceWarning)
            {
                TraceUtility.TraceEvent(TraceEventType.Warning, 0x80017, System.ServiceModel.SR.GetString("TraceCodeConfiguredExtensionTypeNotFound"), this.CreateCanAddRecord(extensionCollectionName), this, null);
            }
            return(flag);
        }
        string GetEndpointName()
        {
            string configuredSectionName          = String.Empty;
            ExtensionElementCollection collection = null;
            Type extensionSectionType             = this.GetType();

            collection = ExtensionsSection.UnsafeLookupCollection(ConfigurationStrings.EndpointExtensions, ConfigurationHelpers.GetEvaluationContext(this));

            if (null == collection)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigExtensionCollectionNotFound,
                                                                                                                        ConfigurationStrings.EndpointExtensions),
                                                                                                           this.ElementInformation.Source,
                                                                                                           this.ElementInformation.LineNumber));
            }

            for (int i = 0; i < collection.Count; i++)
            {
                ExtensionElement collectionElement = collection[i];

                // Optimize for assembly qualified names.
                if (collectionElement.Type.Equals(extensionSectionType.AssemblyQualifiedName, StringComparison.Ordinal))
                {
                    configuredSectionName = collectionElement.Name;
                    break;
                }

                // Check type directly for the case that the extension is registered with something less than
                // an full assembly qualified name.
                Type collectionElementType = Type.GetType(collectionElement.Type, false);
                if (null != collectionElementType && extensionSectionType.Equals(collectionElementType))
                {
                    configuredSectionName = collectionElement.Name;
                    break;
                }
            }

            if (String.IsNullOrEmpty(configuredSectionName))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigExtensionTypeNotRegisteredInCollection,
                                                                                                                        extensionSectionType.AssemblyQualifiedName,
                                                                                                                        ConfigurationStrings.EndpointExtensions),
                                                                                                           this.ElementInformation.Source,
                                                                                                           this.ElementInformation.LineNumber));
            }

            return(configuredSectionName);
        }
        private Type GetExtensionType(ContextInformation evaluationContext, string name)
        {
            ExtensionElementCollection elements = ExtensionsSection.UnsafeLookupCollection(this.extensionCollectionName, evaluationContext);

            if (!elements.ContainsKey(name))
            {
                return(null);
            }
            ExtensionElement element = elements[name];
            Type             type    = Type.GetType(element.Type, false);

            if (null == type)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidType", new object[] { element.Type, element.Name }), base.ElementInformation.Source, base.ElementInformation.LineNumber));
            }
            return(type);
        }
        Type GetExtensionType(ContextInformation evaluationContext, string name)
        {
            ExtensionElementCollection collection = ExtensionsSection.UnsafeLookupCollection(this.extensionCollectionName, evaluationContext);

            if (collection.ContainsKey(name))
            {
                ExtensionElement element     = collection[name];
                Type             elementType = Type.GetType(element.Type, false);
                if (null == elementType)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidType, element.Type, element.Name),
                                                                                                               this.ElementInformation.Source,
                                                                                                               this.ElementInformation.LineNumber));
                }
                return(elementType);
            }
            return(null);
        }
Exemple #9
0
        internal void UpdateEndpointSections(ContextInformation evaluationContext)
        {
            ExtensionElementCollection elements = ExtensionsSection.UnsafeLookupCollection("endpointExtensions", evaluationContext);

            if (elements.Count != this.properties.Count)
            {
                foreach (ExtensionElement element in elements)
                {
                    if ((element != null) && !this.properties.Contains(element.Name))
                    {
                        Type type = Type.GetType(element.Type, false);
                        if (type == null)
                        {
                            ConfigurationHelpers.TraceExtensionTypeNotFound(element);
                        }
                        else
                        {
                            ConfigurationProperty property = new ConfigurationProperty(element.Name, type, null, ConfigurationPropertyOptions.None);
                            this.properties.Add(property);
                        }
                    }
                }
            }
        }
 internal static ExtensionElementCollection UnsafeLookupAssociatedCollection(Type extensionType, ContextInformation evaluationContext, out string collectionName)
 {
     collectionName = GetExtensionType(extensionType);
     return(ExtensionsSection.UnsafeLookupCollection(collectionName, evaluationContext));
 }
        string GetConfigurationElementName()
        {
            string configurationElementName       = String.Empty;
            ExtensionElementCollection collection = null;
            Type extensionSectionType             = ThisType;

            ContextInformation evaluationContext = this.ContainingEvaluationContext;

            if (evaluationContext == null)
            {
                evaluationContext = ConfigurationHelpers.GetEvaluationContext(this);
            }

            if (String.IsNullOrEmpty(this.extensionCollectionName))
            {
#if DESKTOP
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning,
                                            TraceCode.ExtensionCollectionNameNotFound,
                                            SR.GetString(SR.TraceCodeExtensionCollectionNameNotFound),
                                            this,
                                            (Exception)null);
                }
#endif

                collection = ExtensionsSection.UnsafeLookupAssociatedCollection(ThisType, evaluationContext, out this.extensionCollectionName);
            }
            else
            {
                collection = ExtensionsSection.UnsafeLookupCollection(this.extensionCollectionName, evaluationContext);
            }

            if (null == collection)
            {
                if (String.IsNullOrEmpty(this.extensionCollectionName))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigNoExtensionCollectionAssociatedWithType,
                                                                                                                            extensionSectionType.AssemblyQualifiedName),
                                                                                                               this.ElementInformation.Source,
                                                                                                               this.ElementInformation.LineNumber));
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigExtensionCollectionNotFound,
                                                                                                                            this.extensionCollectionName),
                                                                                                               this.ElementInformation.Source,
                                                                                                               this.ElementInformation.LineNumber));
                }
            }

            for (int i = 0; i < collection.Count; i++)
            {
                ExtensionElement collectionElement = collection[i];

                // Optimize for assembly qualified names.
                if (collectionElement.Type.Equals(extensionSectionType.AssemblyQualifiedName, StringComparison.Ordinal))
                {
                    configurationElementName = collectionElement.Name;
                    break;
                }

                // Check type directly for the case that the extension is registered with something less than
                // an full assembly qualified name.
                Type collectionElementType = Type.GetType(collectionElement.Type, false);
                if (null != collectionElementType && extensionSectionType.Equals(collectionElementType))
                {
                    configurationElementName = collectionElement.Name;
                    break;
                }
            }

            if (String.IsNullOrEmpty(configurationElementName))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigExtensionTypeNotRegisteredInCollection,
                                                                                                                        extensionSectionType.AssemblyQualifiedName,
                                                                                                                        this.extensionCollectionName),
                                                                                                           this.ElementInformation.Source,
                                                                                                           this.ElementInformation.LineNumber));
            }

            return(configurationElementName);
        }