private static NameValuePair ParseInternal(Dictionary <string, string> parsetable, string connectionString, bool buildChain, Dictionary <string, string> synonyms, bool firstKey)
        {
            Debug.Assert(null != connectionString, "null connectionstring");
            StringBuilder buffer = new StringBuilder();
            NameValuePair localKeychain = null, keychain = null;

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

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

                Debug.Assert(IsKeyNameValid(keyname), "ParseFailure, invalid keyname");
                Debug.Assert(IsValueValidInternal(keyvalue), "parse failure, invalid keyvalue");
#endif
                string synonym;
                string realkeyname = null != synonyms ?
                                     (synonyms.TryGetValue(keyname, out synonym) ? synonym : null) :
                                     keyname;
                if (!IsKeyNameValid(realkeyname))
                {
                    throw ADP.KeywordNotSupported(keyname);
                }
                if (!firstKey || !parsetable.ContainsKey(realkeyname))
                {
                    parsetable[realkeyname] = keyvalue;     // last key-value pair wins (or first)
                }

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

        catch (ArgumentException e)
        {
            ParseComparison(parsetable, connectionString, synonyms, firstKey, e);
            throw;
        }
        ParseComparison(parsetable, connectionString, synonyms, firstKey, null);
#endif
            return(keychain);
        }
Exemplo n.º 2
0
        static internal void AddEntry(NameValuePermission kvtree, ArrayList entries, DBConnectionString entry)
        {
            Debug.Assert(null != entry, "null DBConnectionString");

            if (null != entry.KeyChain)
            {
                for (NameValuePair keychain = entry.KeyChain; null != keychain; keychain = keychain.Next)
                {
                    NameValuePermission kv;

                    kv = kvtree.CheckKeyForValue(keychain.Name);
                    if (null == kv)
                    {
                        kv = new NameValuePermission(keychain.Name);
                        kvtree.Add(kv); // add directly into live tree
                    }
                    kvtree = kv;

                    kv = kvtree.CheckKeyForValue(keychain.Value);
                    if (null == kv)
                    {
                        DBConnectionString insertValue = ((null != keychain.Next) ? null : entry);
                        kv = new NameValuePermission(keychain.Value, insertValue);
                        kvtree.Add(kv); // add directly into live tree
                        if (null != insertValue)
                        {
                            entries.Add(insertValue);
                        }
                    }
                    else if (null == keychain.Next)
                    { // shorter chain potential
                        if (null != kv._entry)
                        {
                            Debug.Assert(entries.Contains(kv._entry), "entries doesn't contain entry");
                            entries.Remove(kv._entry);
                            kv._entry = kv._entry.Intersect(entry); // union new restrictions into existing tree
                        }
                        else
                        {
                            kv._entry = entry;
                        }
                        entries.Add(kv._entry);
                    }
                    kvtree = kv;
                }
            }
            else
            { // global restrictions, MDAC 84443
                DBConnectionString kentry = kvtree._entry;
                if (null != kentry)
                {
                    Debug.Assert(entries.Contains(kentry), "entries doesn't contain entry");
                    entries.Remove(kentry);
                    kvtree._entry = kentry.Intersect(entry);
                }
                else
                {
                    kvtree._entry = entry;
                }
                entries.Add(kvtree._entry);
            }
        }