예제 #1
0
        string TranslateObjectToElementKey(object obj)
        {
            string elementKey = null;

            if (obj.GetType().IsAssignableFrom(typeof(XPathMessageFilter)))
            {
                elementKey = XPathMessageFilterElementComparer.ParseXPathString((XPathMessageFilter)obj);
            }
            else if (obj.GetType().IsAssignableFrom(typeof(XPathMessageFilterElement)))
            {
                elementKey = XPathMessageFilterElementComparer.ParseXPathString(((XPathMessageFilterElement)obj).Filter);
            }
            else if (obj.GetType().IsAssignableFrom(typeof(string)))
            {
                elementKey = (string)obj;
            }

            if (String.IsNullOrEmpty(elementKey))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                              SR.GetString(SR.ConfigCannotParseXPathFilter, obj.GetType().AssemblyQualifiedName)));
            }

            return(elementKey);
        }
예제 #2
0
        public override bool ContainsKey(object key)
        {
            if (key == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("key");
            }

            string newKey = string.Empty;

            if (key.GetType().IsAssignableFrom(typeof(XPathMessageFilter)))
            {
                newKey = XPathMessageFilterElementComparer.ParseXPathString((XPathMessageFilter)key);
            }
            else if (key.GetType().IsAssignableFrom(typeof(string)))
            {
                newKey = (string)key;
            }
            else
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                              SR.GetString(SR.ConfigInvalidKeyType,
                                                                                           "XPathMessageFilterElement",
                                                                                           typeof(XPathMessageFilter).AssemblyQualifiedName,
                                                                                           key.GetType().AssemblyQualifiedName)));
            }

            return(base.ContainsKey(newKey));
        }
 public override XPathMessageFilterElement this[object key]
 {
     get
     {
         if (key == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("key");
         }
         if (!key.GetType().IsAssignableFrom(typeof(XPathMessageFilter)))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("ConfigInvalidKeyType", new object[] { "XPathMessageFilterElement", typeof(XPathMessageFilter).AssemblyQualifiedName, key.GetType().AssemblyQualifiedName })));
         }
         XPathMessageFilterElement element = (XPathMessageFilterElement)base.BaseGet(key);
         if (element == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new KeyNotFoundException(System.ServiceModel.SR.GetString("ConfigKeyNotFoundInElementCollection", new object[] { key.ToString() })));
         }
         return(element);
     }
     set
     {
         if (this.IsReadOnly())
         {
             base.Add(value);
         }
         if (value == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
         }
         if (key == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("key");
         }
         if (!key.GetType().IsAssignableFrom(typeof(XPathMessageFilter)))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("ConfigInvalidKeyType", new object[] { "XPathMessageFilterElement", typeof(XPathMessageFilter).AssemblyQualifiedName, key.GetType().AssemblyQualifiedName })));
         }
         string a          = XPathMessageFilterElementComparer.ParseXPathString((XPathMessageFilter)key);
         string elementKey = (string)this.GetElementKey(value);
         if (!string.Equals(a, elementKey, StringComparison.Ordinal))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(System.ServiceModel.SR.GetString("ConfigKeysDoNotMatch", new object[] { this.GetElementKey(value).ToString(), key.ToString() }));
         }
         if (base.BaseGet(key) != null)
         {
             base.BaseRemove(key);
         }
         base.Add(value);
     }
 }
        protected override object GetElementKey(ConfigurationElement element)
        {
            if (element == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
            }
            XPathMessageFilterElement element2 = (XPathMessageFilterElement)element;

            if (element2.Filter == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("element", System.ServiceModel.SR.GetString("ConfigXPathFilterIsNull"));
            }
            return(XPathMessageFilterElementComparer.ParseXPathString(element2.Filter));
        }
예제 #5
0
        protected override Object GetElementKey(ConfigurationElement element)
        {
            if (element == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
            }

            XPathMessageFilterElement configElement = (XPathMessageFilterElement)element;

            if (configElement.Filter == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("element",
                                                                             SR.GetString(SR.ConfigXPathFilterIsNull));
            }

            return(XPathMessageFilterElementComparer.ParseXPathString(configElement.Filter));
        }
예제 #6
0
        static string ParseXPathString(XPathLexer lexer, XmlNamespaceManager namespaceManager, bool throwOnFailure)
        {
            string retVal = String.Empty;

            int currentTokenStart = lexer.FirstTokenChar;

            if (lexer.MoveNext())
            {
                XPathToken    token       = lexer.Token;
                StringBuilder xPathString = new StringBuilder(XPathMessageFilterElementComparer.ParseXPathString(lexer, namespaceManager, throwOnFailure));

                if (XPathTokenID.NameTest == token.TokenID)
                {
                    string nsPrefix = token.Prefix;
                    if (!String.IsNullOrEmpty(nsPrefix))
                    {
                        string ns = namespaceManager.LookupNamespace(nsPrefix);
                        if (!String.IsNullOrEmpty(ns))
                        {
                            xPathString = xPathString.Replace(nsPrefix, ns, currentTokenStart, nsPrefix.Length);
                        }
                        else
                        {
                            if (throwOnFailure)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new IndexOutOfRangeException(SR.GetString(SR.ConfigXPathNamespacePrefixNotFound, nsPrefix)));
                            }
                        }
                    }
                }

                retVal = xPathString.ToString();
            }
            else
            {
                retVal = lexer.ConsumedSubstring();
            }

            return(retVal);
        }
예제 #7
0
        public override XPathMessageFilterElement this[object key]
        {
            get
            {
                if (key == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("key");
                }

                if (!key.GetType().IsAssignableFrom(typeof(XPathMessageFilter)))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                  SR.GetString(SR.ConfigInvalidKeyType,
                                                                                               "XPathMessageFilterElement",
                                                                                               typeof(XPathMessageFilter).AssemblyQualifiedName,
                                                                                               key.GetType().AssemblyQualifiedName)));
                }

                XPathMessageFilterElement retval = (XPathMessageFilterElement)this.BaseGet(key);
                if (retval == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new System.Collections.Generic.KeyNotFoundException(
                                                                                  SR.GetString(SR.ConfigKeyNotFoundInElementCollection,
                                                                                               key.ToString())));
                }
                return(retval);
            }
            set
            {
                if (this.IsReadOnly())
                {
                    Add(value);
                }

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

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

                if (!key.GetType().IsAssignableFrom(typeof(XPathMessageFilter)))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                  SR.GetString(SR.ConfigInvalidKeyType,
                                                                                               "XPathMessageFilterElement",
                                                                                               typeof(XPathMessageFilter).AssemblyQualifiedName,
                                                                                               key.GetType().AssemblyQualifiedName)));
                }

                string oldKey = XPathMessageFilterElementComparer.ParseXPathString((XPathMessageFilter)key);
                string newKey = (string)this.GetElementKey(value);

                if (String.Equals(oldKey, newKey, StringComparison.Ordinal))
                {
                    if (BaseGet(key) != null)
                    {
                        BaseRemove(key);
                    }
                    Add(value);
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.ConfigKeysDoNotMatch,
                                                                                              this.GetElementKey(value).ToString(),
                                                                                              key.ToString()));
                }
            }
        }
예제 #8
0
        internal static string ParseXPathString(XPathMessageFilter filter, bool throwOnFailure)
        {
            XPathLexer lexer = new XPathLexer(filter.XPath);

            return(XPathMessageFilterElementComparer.ParseXPathString(lexer, filter.Namespaces, throwOnFailure));
        }
예제 #9
0
 internal static string ParseXPathString(XPathMessageFilter filter)
 {
     return(XPathMessageFilterElementComparer.ParseXPathString(filter, false));
 }