コード例 #1
0
 public void AddOrUpdateDeploymentInfo(AgentDeploymentInfo deploymentInfo)
 {
     if (deploymentInfo == null)
     {
         throw new ArgumentNullException(nameof(deploymentInfo));
     }
     if (deploymentInfo.get_Agent() == null)
     {
         throw new ArgumentNullException("deploymentInfo.Agent");
     }
     AgentDeploymentWatcher.log.DebugFormat("AddOrUpdateDeploymentInfo started, agentId:{0}, status:{1}", (object)deploymentInfo.get_Agent().get_AgentId(), (object)deploymentInfo.get_StatusInfo().get_Status());
     lock (AgentDeploymentWatcher.syncLockItems)
     {
         AgentDeploymentWatcher.CacheItem cacheItem;
         if (this.Items.TryGetValue(deploymentInfo.get_Agent().get_AgentId(), out cacheItem))
         {
             AgentDeploymentWatcher.log.Debug((object)"AddOrUpdateDeploymentInfo - item found in cache, updating");
             cacheItem.DeploymentInfo = deploymentInfo;
         }
         else
         {
             AgentDeploymentWatcher.log.Debug((object)"AddOrUpdateDeploymentInfo - item not found in cache, creating new item");
             cacheItem = new AgentDeploymentWatcher.CacheItem()
             {
                 DeploymentInfo = deploymentInfo
             };
             cacheItem.LastChecked = DateTime.Now;
             this.Items[deploymentInfo.get_Agent().get_AgentId()] = cacheItem;
         }
         cacheItem.LastUpdated   = DateTime.Now;
         cacheItem.RefreshNeeded = false;
         this.CheckWatcher();
     }
 }
コード例 #2
0
        private void CheckItems(object state)
        {
            AgentDeploymentWatcher.log.Debug((object)"CheckItems started");
            DateTime ExpireTime = DateTime.Now.Subtract(TimeSpan.FromSeconds(120.0));
            List <Action <AgentDeploymentStatus> >         actionList = new List <Action <AgentDeploymentStatus> >();
            IEnumerable <AgentDeploymentWatcher.CacheItem> array1;
            IEnumerable <int> array2;

            lock (AgentDeploymentWatcher.syncLockItems)
            {
                AgentDeploymentWatcher.log.Debug((object)"CheckItems - looking for items to remove");
                array1 = (IEnumerable <AgentDeploymentWatcher.CacheItem>) this.Items.Where <KeyValuePair <int, AgentDeploymentWatcher.CacheItem> >((Func <KeyValuePair <int, AgentDeploymentWatcher.CacheItem>, bool>)(item => item.Value.DeploymentInfo.get_StatusInfo().get_Status() == 1 || item.Value.DeploymentInfo.get_StatusInfo().get_Status() == 2 || item.Value.LastChecked < ExpireTime)).Select <KeyValuePair <int, AgentDeploymentWatcher.CacheItem>, AgentDeploymentWatcher.CacheItem>((Func <KeyValuePair <int, AgentDeploymentWatcher.CacheItem>, AgentDeploymentWatcher.CacheItem>)(item => item.Value)).ToArray <AgentDeploymentWatcher.CacheItem>();
                foreach (AgentDeploymentWatcher.CacheItem cacheItem in array1)
                {
                    AgentDeploymentWatcher.log.DebugFormat("CheckItems - removing item, AgentId:{0}", (object)cacheItem.DeploymentInfo.get_Agent().get_AgentId());
                    this.Items.Remove(cacheItem.DeploymentInfo.get_Agent().get_AgentId());
                }
                if (this.Items.Count == 0)
                {
                    AgentDeploymentWatcher.log.Debug((object)"CheckItems - No remaining items in the cache, stopping Watcher");
                    this.StopWatcher();
                }
                AgentDeploymentWatcher.log.Debug((object)"CheckItems - looking for items to refresh");
                array2 = (IEnumerable <int>) this.Items.Where <KeyValuePair <int, AgentDeploymentWatcher.CacheItem> >((Func <KeyValuePair <int, AgentDeploymentWatcher.CacheItem>, bool>)(item => item.Value.RefreshNeeded || item.Value.LastUpdated < ExpireTime)).Select <KeyValuePair <int, AgentDeploymentWatcher.CacheItem>, int>((Func <KeyValuePair <int, AgentDeploymentWatcher.CacheItem>, int>)(item => item.Key)).ToArray <int>();
            }
            foreach (int agentId in array2)
            {
                AgentDeploymentWatcher.log.DebugFormat("CheckItems - refreshing item AgentId:{0}", (object)agentId);
                AgentDeploymentInfo agentDeploymentInfo = this.LoadAgentDeploymentInfo(agentId);
                lock (AgentDeploymentWatcher.syncLockItems)
                {
                    AgentDeploymentWatcher.CacheItem cacheItem;
                    if (this.Items.TryGetValue(agentDeploymentInfo.get_Agent().get_AgentId(), out cacheItem))
                    {
                        AgentDeploymentWatcher.log.DebugFormat("CheckItems - updating item AgentId:{0}, Status:{1}", (object)agentId, (object)agentDeploymentInfo.get_StatusInfo().get_Status());
                        cacheItem.DeploymentInfo = agentDeploymentInfo;
                        cacheItem.LastUpdated    = DateTime.Now;
                        cacheItem.RefreshNeeded  = false;
                    }
                    else
                    {
                        AgentDeploymentWatcher.log.Debug((object)"CheckItems - item not found in the cache");
                    }
                }
            }
            foreach (AgentDeploymentWatcher.CacheItem cacheItem in array1)
            {
                if (cacheItem.OnFinishedCallback != null && (cacheItem.DeploymentInfo.get_StatusInfo().get_Status() == 1 || cacheItem.DeploymentInfo.get_StatusInfo().get_Status() == 2))
                {
                    cacheItem.OnFinishedCallback(cacheItem.DeploymentInfo.get_StatusInfo().get_Status());
                }
            }
        }