Exemple #1
0
        public void UpdateAPIKey(IEnumerable <string> apiKeys)
        {
            lock (_updateKeyLockObj)
            {
                if (apiKeys != null && apiKeys.Count() > 0)
                {
                    string[] existKeys = _APIKeys.Keys.ToArray();

                    string[] newKeys = apiKeys.Select(p => p.ToUpper()).ToArray();

                    foreach (string key in existKeys)
                    {
                        if (!newKeys.Contains(key))
                        {
                            APIKey apiKey = null;
                            _APIKeys.TryRemove(key, out apiKey);
                        }
                    }

                    existKeys = _APIKeys.Keys.ToArray();

                    foreach (string key in newKeys)
                    {
                        if (!existKeys.Contains(key))
                        {
                            _APIKeys[key] = new APIKey(key);
                        }
                    }
                }
            }
        }
Exemple #2
0
        public T Call <T>(Func <string, T> callingFunc)
        {
            APIKey key = GetIdioKey();

            lock (key.LockObj)
            {
                return(callingFunc(key.Key));
            }
        }
Exemple #3
0
 protected APIKey GetIdioKey()
 {
     lock (_updateKeyLockObj)
     {
         APIKey key = (from p in _APIKeys.Values
                       orderby p.TimeEclipsed() descending
                       select p).FirstOrDefault();
         key.LastCallingTime = DateTime.Now;
         return(key);
     }
 }