public void Invalid_keywords_are_detected()
 {
     Assert.Equal(
         Strings.ADP_KeywordNotSupported("love"),
         Assert.Throws <ArgumentException>(
             () => new DbConnectionOptions("Love=ComesQuickly", EntityConnectionStringBuilder.ValidKeywords)).Message);
 }
Exemplo n.º 2
0
        private static NameValuePair ParseInternal(Hashtable parsetable, string connectionString, Hashtable synonyms)
        {
            DebugCheck.NotNull(connectionString);
            var           buffer = new StringBuilder();
            NameValuePair localKeychain = null, keychain = null;

#if DEBUG
            try
            {
#endif
            var nextStartPosition = 0;
            var endPosition       = connectionString.Length;
            while (nextStartPosition < endPosition)
            {
                var startPosition = nextStartPosition;

                string keyname, keyvalue;
                nextStartPosition = GetKeyValuePair(connectionString, startPosition, buffer, out keyname, out keyvalue);
                if (string.IsNullOrEmpty(keyname))
                {
                    // if (nextStartPosition != endPosition) { throw; }
                    break;
                }

#if DEBUG
                Debug.Assert(IsKeyNameValid(keyname), "ParseFailure, invalid keyname");
                Debug.Assert(IsValueValidInternal(keyvalue), "parse failure, invalid keyvalue");
#endif
                var realkeyname = ((null != synonyms) ? (string)synonyms[keyname] : keyname);
                if (!IsKeyNameValid(realkeyname))
                {
                    throw new ArgumentException(Strings.ADP_KeywordNotSupported(keyname));
                }
                parsetable[realkeyname] = keyvalue;     // last key-value pair wins (or first)

                if (null != localKeychain)
                {
                    localKeychain = localKeychain.Next = new NameValuePair();
                }
                else
                {
                    // first time only - don't contain modified chain from UDL file
                    keychain = localKeychain = new NameValuePair();
                }
            }
#if DEBUG
        }

        catch (ArgumentException e)
        {
            ParseComparision(parsetable, connectionString, synonyms, e);
            throw;
        }
        ParseComparision(parsetable, connectionString, synonyms, null);
#endif
            return(keychain);
        }
Exemplo n.º 3
0
        private static Hashtable SplitConnectionString(string connectionString, Hashtable synonyms)
        {
            var parsetable = new Hashtable();
            var parser     = _connectionStringRegex;

            const int KeyIndex = 1, ValueIndex = 2;

            Debug.Assert(KeyIndex == parser.GroupNumberFromName("key"), "wrong key index");
            Debug.Assert(ValueIndex == parser.GroupNumberFromName("value"), "wrong value index");

            if (null != connectionString)
            {
                var match = parser.Match(connectionString);
                if (!match.Success ||
                    (match.Length != connectionString.Length))
                {
                    throw new ArgumentException(Strings.ADP_ConnectionStringSyntax(match.Length));
                }
                var indexValue = 0;
                var keyvalues  = match.Groups[ValueIndex].Captures;
                foreach (Capture keypair in match.Groups[KeyIndex].Captures)
                {
                    var keyname  = keypair.Value.Replace("==", "=").ToLowerInvariant();
                    var keyvalue = keyvalues[indexValue++].Value;
                    if (0 < keyvalue.Length)
                    {
                        switch (keyvalue[0])
                        {
                        case '\"':
                            keyvalue = keyvalue.Substring(1, keyvalue.Length - 2).Replace("\"\"", "\"");
                            break;

                        case '\'':
                            keyvalue = keyvalue.Substring(1, keyvalue.Length - 2).Replace("\'\'", "\'");
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        keyvalue = null;
                    }

                    var realkeyname = ((null != synonyms) ? (string)synonyms[keyname] : keyname);
                    if (!IsKeyNameValid(realkeyname))
                    {
                        throw new ArgumentException(Strings.ADP_KeywordNotSupported(keyname));
                    }
                    parsetable[realkeyname] = keyvalue; // last key-value pair wins (or first)
                }
            }
            return(parsetable);
        }
Exemplo n.º 4
0
        private static NameValuePair ParseInternal(
            IDictionary <string, string> parsetable,
            string connectionString,
            IList <string> validKeywords)
        {
            StringBuilder buffer         = new StringBuilder();
            NameValuePair nameValuePair1 = (NameValuePair)null;
            NameValuePair nameValuePair2 = (NameValuePair)null;
            int           num            = 0;
            int           length         = connectionString.Length;

            while (num < length)
            {
                int    currentPosition = num;
                string keyname;
                string keyvalue;
                num = DbConnectionOptions.GetKeyValuePair(connectionString, currentPosition, buffer, out keyname, out keyvalue);
                if (!string.IsNullOrEmpty(keyname))
                {
                    if (!validKeywords.Contains(keyname))
                    {
                        throw new ArgumentException(Strings.ADP_KeywordNotSupported((object)keyname));
                    }
                    parsetable[keyname] = keyvalue;
                    if (nameValuePair1 != null)
                    {
                        nameValuePair1 = nameValuePair1.Next = new NameValuePair();
                    }
                    else
                    {
                        nameValuePair2 = nameValuePair1 = new NameValuePair();
                    }
                }
                else
                {
                    break;
                }
            }
            return(nameValuePair2);
        }
        private static NameValuePair ParseInternal(IDictionary <string, string> parsetable, string connectionString, IList <string> validKeywords)
        {
            DebugCheck.NotNull(connectionString);
            DebugCheck.NotNull(validKeywords);

            var           buffer = new StringBuilder();
            NameValuePair localKeychain = null, keychain = null;
            var           nextStartPosition = 0;
            var           endPosition       = connectionString.Length;

            while (nextStartPosition < endPosition)
            {
                var startPosition = nextStartPosition;

                string keyname, keyvalue;
                nextStartPosition = GetKeyValuePair(connectionString, startPosition, buffer, out keyname, out keyvalue);
                if (string.IsNullOrEmpty(keyname))
                {
                    break;
                }

                if (!validKeywords.Contains(keyname))
                {
                    throw new ArgumentException(Strings.ADP_KeywordNotSupported(keyname));
                }
                parsetable[keyname] = keyvalue; // last key-value pair wins (or first)

                if (null != localKeychain)
                {
                    localKeychain = localKeychain.Next = new NameValuePair();
                }
                else
                {
                    // first time only - don't contain modified chain from UDL file
                    keychain = localKeychain = new NameValuePair();
                }
            }

            return(keychain);
        }