private void AssignPortsIfNotExist()
 {
     try
     {
         if (this.ConfiguredCaches == null || this.ConfiguredCaches.Count <= 0)
         {
             return;
         }
         else
         {
             lock (_lock)
             {
                 Hashtable cachePorts    = new Hashtable();
                 ArrayList occupiedPorts = new ArrayList();
                 foreach (string cache in this.ConfiguredCaches)
                 {
                     if (!cachePorts.Contains(cache.ToLower()))
                     {
                         int managementPort = ManagementPortHandler.GenerateManagementPort(occupiedPorts);
                         cachePorts.Add(cache, managementPort);
                         occupiedPorts.Add(managementPort);
                     }
                 }
                 _cachePortsConfig.WriteConfiguration(cachePorts);
             }
         }
     }
     catch (Exception ex)
     {
         AppUtil.LogEvent("Exception occured while assigning ports : " + ex.ToString(), EventLogEntryType.Error);
     }
 }
 private void SynchronizePortsConfiguration(List <string> configuredCaches)
 {
     try
     {
         ArrayList occupiedPorts = this.GetOccupiedPorts();
         lock (_lock)
         {
             foreach (string cacheId in configuredCaches)
             {
                 if (!_cachePortsTable.Contains(cacheId.ToLower()))
                 {
                     int managementPort = ManagementPortHandler.GenerateManagementPort(occupiedPorts);
                     occupiedPorts.Add(managementPort);
                     _cachePortsConfig.AddConfiguration(cacheId, managementPort);
                     _cachePortsTable.Add(cacheId.ToLower(), managementPort);
                 }
             }
             IDictionaryEnumerator enm      = _cachePortsTable.GetEnumerator();
             List <string>         toRemove = new List <string>();
             while (enm.MoveNext())
             {
                 if (!configuredCaches.Contains(enm.Key.ToString()))
                 {
                     toRemove.Add(enm.Key.ToString().ToLower());
                 }
             }
             if (toRemove.Count > 0)
             {
                 foreach (string cache in toRemove)
                 {
                     _cachePortsConfig.RemoveConfiguration(cache);
                     _cachePortsTable.Remove(cache);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         AppUtil.LogEvent("Exception occured while synchronizing ports configuration : " + ex.ToString(), EventLogEntryType.Error);
     }
 }
        public int RegisterCachePort(string cacheId)
        {
            int managementPort = 0;

            try
            {
                lock (_lock)
                {
                    if (!_cachePortsTable.Contains(cacheId.ToLower()))
                    {
                        managementPort = ManagementPortHandler.GenerateManagementPort(this.GetOccupiedPorts());
                        _cachePortsConfig.AddConfiguration(cacheId, managementPort);
                    }
                }
            }
            catch (Exception ex)
            {
                AppUtil.LogEvent("Exception occured while registering new port : " + ex.ToString(), EventLogEntryType.Error);
            }
            return(managementPort);
        }