Exemplo n.º 1
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);
        }
        public override bool ContainsKey(object key)
        {
            if (key == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("key");
            }
            string str = string.Empty;

            if (key.GetType().IsAssignableFrom(typeof(XPathMessageFilter)))
            {
                str = XPathMessageFilterElementComparer.ParseXPathString((XPathMessageFilter)key);
            }
            else
            {
                if (!key.GetType().IsAssignableFrom(typeof(string)))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("ConfigInvalidKeyType", new object[] { "XPathMessageFilterElement", typeof(XPathMessageFilter).AssemblyQualifiedName, key.GetType().AssemblyQualifiedName })));
                }
                str = (string)key;
            }
            return(base.ContainsKey(str));
        }
Exemplo n.º 3
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()));
                }
            }
        }
Exemplo n.º 4
0
        internal static string ParseXPathString(XPathMessageFilter filter, bool throwOnFailure)
        {
            XPathLexer lexer = new XPathLexer(filter.XPath);

            return(XPathMessageFilterElementComparer.ParseXPathString(lexer, filter.Namespaces, throwOnFailure));
        }
Exemplo n.º 5
0
 internal static string ParseXPathString(XPathMessageFilter filter)
 {
     return(XPathMessageFilterElementComparer.ParseXPathString(filter, false));
 }