Пример #1
0
        IEnumerator <KeyValuePair <string, string> > IEnumerable <KeyValuePair <string, string> > .GetEnumerator()
        {
            using (RegistryKey key = OpenFifoKey(true))
            {
                int nSize;
                int nPos;

                if (!RegistryUtils.TryGetIntValue(key, "_size", out nSize) || nSize < 1)
                {
                    nSize = _defaultSize;
                }

                // This gives a very tiny race condition if used at the same time in
                // two VS instances.
                // We ignore this as it is just UI helper code and a user can't edit
                //  two windows at the same time
                if (!RegistryUtils.TryGetIntValue(key, "_pos", out nPos) || (nPos < 0) || (nPos >= nSize))
                {
                    nPos = 0;
                }

                HybridCollection <string> hs = new HybridCollection <string>();
                hs.AddRange(key.GetValueNames());

                for (int i = 0; i < nSize; i++)
                {
                    int n = nPos - i;
                    while (n < 0)
                    {
                        n += nSize;
                    }

                    string s = "#" + n.ToString(CultureInfo.InvariantCulture);

                    if (hs.Contains(s))
                    {
                        string v = key.GetValue(s) as string;

                        if (v != null && (_allowWhiteSpace || !string.IsNullOrEmpty(v)))
                        {
                            yield return(new KeyValuePair <string, string>(s, v));
                        }
                    }
                }
            }
        }
Пример #2
0
        IDictionary <string, int> GetNumberValues(string regKey, string subKey)
        {
            if (string.IsNullOrEmpty(regKey))
            {
                throw new ArgumentNullException("regKey");
            }
            if (string.IsNullOrEmpty(subKey))
            {
                throw new ArgumentNullException("subKey");
            }
            IDictionary <string, int> values;

            lock (_lock)
            {
                subKey = regKey + "\\" + subKey;
                using (RegistryKey reg = OpenHKCUKey(subKey))
                {
                    if (reg == null)
                    {
                        return(null);
                    }
                    HybridCollection <string> hs = new HybridCollection <string>();
                    hs.AddRange(reg.GetValueNames());

                    values = new Dictionary <string, int>(hs.Count);

                    foreach (string item in hs)
                    {
                        int width;
                        if (RegistryUtils.TryGetIntValue(reg, item, out width) && width > 0)
                        {
                            values.Add(item, width);
                        }
                    }
                }
            }
            return(values);
        }
Пример #3
0
        public void Add(string item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            else if (!_allowWhiteSpace && string.IsNullOrEmpty(item))
            {
                return; // Don't add whitepace
            }
            using (RegistryKey key = OpenFifoKey(false))
            {
                int nSize;
                int nPos;
                if (!RegistryUtils.TryGetIntValue(key, "_size", out nSize) || nSize < 1)
                {
                    nSize = _defaultSize;
                    key.SetValue("_size", _defaultSize);
                }

                // This gives a very tiny race condition if used at the same time in
                // two VS instances.
                // We ignore this as it is just UI helper code and a user can't edit
                //  two windows at the same time
                if (!RegistryUtils.TryGetIntValue(key, "_pos", out nPos) || (nPos < 0) || (nPos >= nSize))
                {
                    nPos = 0;
                }

                if (nPos < 0 || nPos >= nSize)
                {
                    List <string> names = new List <string>(key.GetValueNames());

                    int nX = nSize;
                    for (int i = nSize - 1; i >= 0; i--)
                    {
                        if (names.Contains("#" + i.ToString(CultureInfo.InvariantCulture)))
                        {
                            break;
                        }

                        nX = i;
                    }

                    if (nX < nSize)
                    {
                        nPos = nX;
                    }
                    else
                    {
                        nPos = 0;
                    }
                }


                nPos++;

                if (nPos > nSize)
                {
                    nPos = 0;
                }

                key.SetValue("_pos", nPos);
                key.SetValue("#" + nPos.ToString(CultureInfo.InvariantCulture), item);
            }
        }