Exemplo n.º 1
0
        public static void UpdateServerNodes(string cacheId, string[] servers, ref string xml, bool loadBalance)
        {
            LoadXml();

            cacheId = cacheId.ToLower();
            CacheConfiguration cacheConfiguration = null;

            if (_configuration != null && _configuration.CacheConfigurationsMap != null)
            {
                if (!_configuration.CacheConfigurationsMap.TryGetValue(cacheId, out cacheConfiguration))
                {
                    cacheConfiguration         = new CacheConfiguration();
                    cacheConfiguration.CacheId = cacheId;

                    _configuration.CacheConfigurationsMap.Add(cacheId, cacheConfiguration);
                }
            }

            cacheConfiguration.ServersPriorityList.Clear();

            for (int i = 0; i < servers.Length; i++)
            {
                Dom.CacheServer server = new Dom.CacheServer();
                server.ServerName = servers[i];
                server.Priority   = i;
                cacheConfiguration.ServersPriorityList[i] = server;
            }

            cacheConfiguration.LoadBalance = loadBalance;
            SaveConfiguration();
            xml = string.Empty;
        }
Exemplo n.º 2
0
        private static void UpdateConfigs()
        {
            try
            {
                if (ValidateNCacheService())
                {
                    if (cParam.UpdateServerConfig)
                    {
                        if (config != null)
                        {
                            if (config.CacheDeployment.ClientNodes == null)
                            {
                                config.CacheDeployment.ClientNodes = new ClientNodes();
                            }

                            if (config.CacheDeployment.ClientNodes.NodesList == null)
                            {
                                config.CacheDeployment.ClientNodes.NodesList = new List <ClientNode>();
                            }
                        }

                        ClientNode clientNod = new ClientNode();
                        clientNod.Name = cParam.ClientNode;

                        if (config != null)
                        {
                            config.CacheDeployment.ClientNodes.NodesList.Add(clientNod);
                        }


                        foreach (string node in currentServerNodes)
                        {
                            NCache.ServerName = node;
                            cacheServer       = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                            cacheServer.ApplyCacheConfiguration(cParam.CacheId, config, false);
                        }
                        string oldClientNode             = null;
                        ClientConfiguration clientConfig = null;
                        if (currentClientNodes.Count > 0)
                        {
                            oldClientNode     = currentClientNodes[0];
                            NCache.ServerName = oldClientNode;
                            cacheServer       = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            clientConfig      = cacheServer.GetClientConfiguration(cParam.CacheId);
                        }
                    }

                    NCacheRPCService nCache = new NCacheRPCService("");
                    nCache.ServerName = cParam.ClientNode; //clientNode;
                    cacheServer       = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    string xml = string.Empty;
                    cacheServer.UpdateClientServersList(cParam.CacheId, GetSeversPriorityList(), "0");
                    ClientConfiguration clientConfiguration = cacheServer.GetClientConfiguration(cParam.CacheId);
                    CacheConfiguration  cacheConfig         = new CacheConfiguration();
                    cacheConfig = clientConfiguration.CacheConfigurationsMap[cParam.CacheId.ToLower()];
                    //if flag of get mapping is true
                    if (cParam.AcquireServerMapping && _clientIPMapping != null)
                    {
                        if (cacheConfig.ServerMapping == null)
                        {
                            cacheConfig.ServerMapping = new ServerMapping();
                        }
                        cacheConfig.ServerMapping = new ServerMapping(Management.Management.Util.ManagementWorkFlow.GetUpdatedMappingList(cacheConfig.ServerMapping.MappingServers, _clientIPMapping.MappingServers));
                    }

                    clientConfiguration.CacheConfigurationsMap.Remove(cParam.CacheId);
                    clientConfiguration.CacheConfigurationsMap.Add(cParam.CacheId, cacheConfig);
                    if (config != null)
                    {
                        if (config.CacheDeployment.Servers.NodeIdentities != null && config.CacheDeployment.Servers.NodeIdentities.Count != 0)
                        {
                            cacheConfig.ServersPriorityList.Clear();

                            foreach (NodeIdentity identity in config.CacheDeployment.Servers.NodeIdentities)
                            {
                                Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
                                server.ServerName = identity.NodeName;
                                server.Priority   = identity.NodePriority;
                                cacheConfig.ServersPriorityList[identity.NodePriority - 1] = server;
                            }
                        }
                    }
                    cacheServer.UpdateClientConfiguration(cParam.CacheId, clientConfiguration);

                    Console.WriteLine("{0}' successfully added as client node to cache '{1}' on server {2}:{3}.",
                                      cParam.ClientNode, cParam.CacheId, NCache.ServerName, NCache.Port);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.Message);
            }
        }
Exemplo n.º 3
0
        private static CacheServerList GetSeversPriorityList()
        {
            Dictionary<int, Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer> serversPriorityList = new Dictionary<int, Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer>();
            Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
            if (config != null)
            {
                List<Address> hosts = config.CacheDeployment.Servers.GetAllConfiguredNodes();
                Alachisoft.NCache.Management.ICacheServer cs;
                NCacheRPCService cache = new NCacheRPCService("");
                int priority = 0;
                int port = -1;
                foreach (Address addr in hosts)
                {
                    try
                    {
                        string address = addr.IpAddress.ToString();
                        if (_managementIPMapping != null)
                        {
                            if (_managementIPMapping.ContainsKey(address))
                            {
                                Mapping endPoint = _managementIPMapping[address];
                                address = endPoint.PublicIP;
                                port = endPoint.PublicPort;
                            }
                        }
                        server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
                        string tempClientServerName = "";
                        cache.ServerName = address;
                        if (port != -1)
                            cache.Port = port;
                        cs = cache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                        Management.Management.BindedIpMap bindedIps = cs.BindedIp();

                        if (bindedIps.Map.Contains(Alachisoft.NCache.Management.CacheServer.Channel.SocketServer))
                            tempClientServerName = bindedIps.Map[Alachisoft.NCache.Management.CacheServer.Channel.SocketServer].ToString();

                        if (!string.IsNullOrEmpty(tempClientServerName))
                            server.ServerName = tempClientServerName;
                        else
                            server.ServerName = addr.IpAddress.ToString();

                        server.Priority = priority;

                        serversPriorityList.Add(priority, server);
                        priority++;
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Error while adding server :" + cache.ServerName + ":" + cache.Port + "\nException : " + ex.Message);
                    }
                }
            }

            if (serversPriorityList.Count < 1)
            {
                server.ServerName = _server;
                server.Priority = 0;
                serversPriorityList.Add(0, server);
            }

            return new CacheServerList(serversPriorityList);
        }
Exemplo n.º 4
0
        private static void UpdateConfigs()
        {
            try
            {
                if (ValidateNCacheService())
                {
                if (cParam.UpdateServerConfig)
                {
                    if (config != null)
                    {
                        if (config.CacheDeployment.ClientNodes == null)
                            config.CacheDeployment.ClientNodes = new ClientNodes();

                        if (config.CacheDeployment.ClientNodes.NodesList == null)
                            config.CacheDeployment.ClientNodes.NodesList = new List<ClientNode>();
                    }

                        ClientNode clientNod = new ClientNode();
                        clientNod.Name = cParam.ClientNode;

                    if(config != null)
                        config.CacheDeployment.ClientNodes.NodesList.Add(clientNod);

                    foreach (string node in currentServerNodes)
                    {
                        NCache.ServerName = node;
                        cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                        cacheServer.ApplyCacheConfiguration(cParam.CacheId, config, false);
                    }
                    string oldClientNode = null;
                    ClientConfiguration clientConfig = null;
                    if (currentClientNodes.Count > 0)
                    {
                        oldClientNode = currentClientNodes[0];
                        NCache.ServerName = oldClientNode;
                        cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                        clientConfig = cacheServer.GetClientConfiguration(cParam.CacheId);
                    }

                }

                    NCacheRPCService nCache = new NCacheRPCService("");
                    nCache.ServerName = cParam.ClientNode; //clientNode;
                    cacheServer = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    string xml = string.Empty;
                    cacheServer.UpdateClientServersList(cParam.CacheId, GetSeversPriorityList(),"0");
                    ClientConfiguration clientConfiguration = cacheServer.GetClientConfiguration(cParam.CacheId);
                    CacheConfiguration cacheConfig = new CacheConfiguration();
                    cacheConfig = clientConfiguration.CacheConfigurationsMap[cParam.CacheId.ToLower()];
                    //if flag of get mapping is true
                    if (cParam.AcquireServerMapping && _clientIPMapping != null)
                    {
                        if (cacheConfig.ServerMapping == null)
                        {
                            cacheConfig.ServerMapping = new ServerMapping();
                        }
                        cacheConfig.ServerMapping = new ServerMapping(Management.Management.Util.ManagementWorkFlow.GetUpdatedMappingList(cacheConfig.ServerMapping.MappingServers, _clientIPMapping.MappingServers));
                    }

                    clientConfiguration.CacheConfigurationsMap.Remove(cParam.CacheId);
                    clientConfiguration.CacheConfigurationsMap.Add(cParam.CacheId, cacheConfig);
                    if (config != null)
                    {
                        if (config.CacheDeployment.Servers.NodeIdentities != null && config.CacheDeployment.Servers.NodeIdentities.Count != 0)
                        {
                            cacheConfig.ServersPriorityList.Clear();

                            foreach (NodeIdentity identity in config.CacheDeployment.Servers.NodeIdentities)
                            {
                                Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
                                server.ServerName = identity.NodeName;
                                server.Priority = identity.NodePriority;
                                cacheConfig.ServersPriorityList[identity.NodePriority - 1] = server;
                            }
                        }
                    }
                    cacheServer.UpdateClientConfiguration(cParam.CacheId, clientConfiguration);

                    Console.WriteLine("{0}' successfully added as client node to cache '{1}' on server {2}:{3}.",
                        cParam.ClientNode, cParam.CacheId, NCache.ServerName, NCache.Port);
            }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.Message);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///     The main entry point for the tool.
        /// </summary>
        public static void Run(string[] args)
        {
            var failedNodes = string.Empty;

            NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
            CacheServerConfig[] caches       = null;
            ICacheServer        cacheServer  = null;
            CacheServerConfig   _cacheConfig = null;

            try
            {
                object param = new ConfigureCacheParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                ccParam = (ConfigureCacheParam)param;

                if (ccParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(ccParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }

                if (ccParam.Port != -1)
                {
                    NCache.Port = ccParam.Port;
                }

                if (ccParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }

                if (ccParam.Path != null && ccParam.Path != string.Empty)
                {
                    if (Path.HasExtension(ccParam.Path))
                    {
                        var extension = Path.GetExtension(ccParam.Path);

                        if (!extension.Equals(".ncconf") && !extension.Equals(".xml"))
                        {
                            throw new Exception("Incorrect file format. Only .ncconf and .xml are supported.");
                        }
                    }
                    else
                    {
                        throw new Exception("Incorrect configuration file path specified.");
                    }

                    var builder = new ConfigurationBuilder(ccParam.Path);
                    builder.RegisterRootConfigurationObject(typeof(CacheServerConfig));
                    builder.ReadConfiguration();

                    if (builder.Configuration != null)
                    {
                        caches = new CacheServerConfig[builder.Configuration.Length];
                        builder.Configuration.CopyTo(caches, 0);
                    }
                    else
                    {
                        throw new Exception("Configuration cannot be loaded.");
                    }
                    var validator          = new ConfigurationValidator();
                    var _isConfigValidated = validator.ValidateConfiguration(caches);

                    _cacheConfig = caches[0];

                    if (_cacheConfig.CacheSettings.Name == null)
                    {
                        _cacheConfig.CacheSettings.Name = ccParam.CacheId;
                    }

                    if (_cacheConfig.CacheSettings.Storage == null || _cacheConfig.CacheSettings.Storage.Size == -1)
                    {
                        throw new Exception("Cache size is not specified.");
                    }

                    if (_cacheConfig.CacheSettings.EvictionPolicy == null)
                    {
                        _cacheConfig.CacheSettings.EvictionPolicy                 = new EvictionPolicy();
                        _cacheConfig.CacheSettings.EvictionPolicy.Policy          = "priority";
                        _cacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = "normal";
                        _cacheConfig.CacheSettings.EvictionPolicy.EvictionRatio   = 5;
                        _cacheConfig.CacheSettings.EvictionPolicy.Enabled         = true;
                    }

                    if (_cacheConfig.CacheSettings.Cleanup == null)
                    {
                        _cacheConfig.CacheSettings.Cleanup          = new Cleanup();
                        _cacheConfig.CacheSettings.Cleanup.Interval = 15;
                    }

                    if (_cacheConfig.CacheSettings.Log == null)
                    {
                        _cacheConfig.CacheSettings.Log = new Log();
                    }

                    if (_cacheConfig.CacheSettings.PerfCounters == null)
                    {
                        _cacheConfig.CacheSettings.PerfCounters         = new PerfCounters();
                        _cacheConfig.CacheSettings.PerfCounters.Enabled = true;
                    }

                    if (_cacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings == null)
                        {
                            throw new Exception("Cluster settings not specified for the cluster cache.");
                        }

                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel == null)
                        {
                            throw new Exception("Cluster channel related settings not specified for cluster cache.");
                        }

                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort == -1)
                        {
                            throw new Exception("Cluster port not specified for cluster cache.");
                        }
                    }
                }
                else
                {
                    _SimpleCacheConfig.CacheSettings                                = new CacheServerConfigSetting();
                    _SimpleCacheConfig.CacheSettings.Name                           = ccParam.CacheId;
                    _SimpleCacheConfig.CacheSettings.Storage                        = new Storage();
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy                 = new EvictionPolicy();
                    _SimpleCacheConfig.CacheSettings.Cleanup                        = new Cleanup();
                    _SimpleCacheConfig.CacheSettings.Log                            = new Log();
                    _SimpleCacheConfig.CacheSettings.PerfCounters                   = new PerfCounters();
                    _SimpleCacheConfig.CacheSettings.PerfCounters.Enabled           = true;
                    _SimpleCacheConfig.CacheSettings.Storage.Type                   = "heap";
                    _SimpleCacheConfig.CacheSettings.Storage.Size                   = ccParam.CacheSize;
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.Policy          = "priority";
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = "normal";
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.EvictionRatio   = 5;
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled         = false;
                    _SimpleCacheConfig.CacheSettings.Cleanup.Interval               = 15;
                    _SimpleCacheConfig.CacheSettings.CacheTopology                  = new CacheTopology();

                    if (string.IsNullOrEmpty(ccParam.Topology))
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.Topology = "Local";
                    }
                    else
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.Topology = ccParam.Topology;
                    }

                    if (ccParam.IsInProc && _SimpleCacheConfig.CacheSettings.CacheTopology.Topology.Equals("local-cache"))
                    {
                        _SimpleCacheConfig.CacheSettings.InProc = true;
                    }


                    if (_SimpleCacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings         = new Cluster();
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel = new Channel();

                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort  = ccParam.ClusterPort;
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.StatsRepInterval = 600;
                        if (_SimpleCacheConfig.CacheSettings.CacheTopology.Topology == "partitioned-replica")
                        {
                            _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.PortRange = 2;
                        }
                    }

                    if (ccParam.EvictionPolicy != null && ccParam.EvictionPolicy != string.Empty)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Policy  = ccParam.EvictionPolicy;
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled = true;
                    }

                    if (ccParam.Ratio != -1)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.EvictionRatio = ccParam.Ratio;
                    }

                    if (ccParam.CleanupInterval != -1)
                    {
                        _SimpleCacheConfig.CacheSettings.Cleanup.Interval = ccParam.CleanupInterval;
                    }

                    if (ccParam.DefaultPriority != null && ccParam.DefaultPriority != string.Empty)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = ccParam.DefaultPriority;
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled         = true;
                    }
                    _cacheConfig = _SimpleCacheConfig;
                }
                try
                {
                    _cacheConfig.CacheSettings.Name = ccParam.CacheId;

                    if (_cacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        if (_cacheConfig.CacheDeployment == null)
                        {
                            _cacheConfig.CacheDeployment         = new CacheDeployment();
                            _cacheConfig.CacheDeployment.Servers = new ServersNodes();
                        }
                        _cacheConfig.CacheDeployment.Servers.NodesList = GetServers(ccParam.Server);
                    }

                    var serverList  = new Dictionary <int, CacheServer>();
                    var serverCount = 0;
                    foreach (ServerNode node in GetServers(ccParam.Server))
                    {
                        var tempServer = new CacheServer();
                        tempServer.ServerName = node.IP;
                        serverList.Add(serverCount, tempServer);
                        serverCount++;
                    }
                    var servers         = new CacheServerList(serverList);
                    var serversToUpdate = new List <string>();
                    foreach (ServerNode node in GetServers(ccParam.Server))
                    {
                        NCache.ServerName = node.IP;

                        Console.WriteLine(AppendBlankLine("\nCreating cache") + " '{0}' on server '{1}' ", _cacheConfig.CacheSettings.Name, NCache.ServerName);
                        try
                        {
                            cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            if (cacheServer != null)
                            {
                                var serverConfig = cacheServer.GetNewConfiguration(_cacheConfig.CacheSettings.Name);

                                if (serverConfig != null)
                                {
                                    throw new Exception("Specified cache already exists.");
                                }

                                if (serverConfig != null && ccParam.IsOverWrite)
                                {
                                    NCache.ServerName = node.IP;

                                    if (serverConfig.CacheDeployment != null)
                                    {
                                        if (serverConfig.CacheDeployment.ClientNodes != null)
                                        {
                                            _cacheConfig.CacheDeployment.ClientNodes = serverConfig.CacheDeployment.ClientNodes;
                                        }
                                    }
                                }

                                cacheServer.RegisterCache(_cacheConfig.CacheSettings.Name, _cacheConfig, "", ccParam.IsOverWrite, ccParam.IsHotApply);
                                cacheServer.UpdateClientServersList(_cacheConfig.CacheSettings.Name, servers, "NCACHE");
                                serversToUpdate.Add(node.IP);

                                Console.WriteLine("Cache '{0}' successfully created on server {1}:{2} .", _cacheConfig.CacheSettings.Name, NCache.ServerName, NCache.Port);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    ManagementWorkFlow.UpdateServerMappingConfig(serversToUpdate.ToArray());
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (cacheServer != null)
                    {
                        cacheServer.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(AppendBlankLine("Failed") + " to create cache on server '{0}'. ", ccParam.Server);
                Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                LogEvent(ex.Message);
            }
            finally
            {
                NCache.Dispose();
            }
        }
Exemplo n.º 6
0
        public static void UpdateServerNodes(string cacheId, string[] servers, ref string xml,  bool loadBalance)
        {
            LoadXml();

            cacheId = cacheId.ToLower();
            CacheConfiguration cacheConfiguration = null;

            if (_configuration != null && _configuration.CacheConfigurationsMap != null)
            {
                if (!_configuration.CacheConfigurationsMap.TryGetValue(cacheId, out cacheConfiguration))
                {
                    cacheConfiguration = new CacheConfiguration();
                    cacheConfiguration.CacheId = cacheId;

                    _configuration.CacheConfigurationsMap.Add(cacheId, cacheConfiguration);
                }
            }

            cacheConfiguration.ServersPriorityList.Clear();

            for (int i = 0; i < servers.Length; i++)
            {
                Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
                server.ServerName = servers[i];
                server.Priority = i;
                cacheConfiguration.ServersPriorityList[i] = server;
            }

            
            cacheConfiguration.LoadBalance = loadBalance;

            SaveConfiguration();
            
            xml = string.Empty;
        }
Exemplo n.º 7
0
 public bool AddServer(string serverName, int priority)
 {
     CacheServer server = new CacheServer();
     server.ServerName = serverName;
     server.Priority = priority;
     _serversPriorityList[priority] = server;
     return true;
 }
Exemplo n.º 8
0
        public object Clone()
        {
            CacheServer server = new CacheServer();
            server._serverName = _serverName;
            

            return server;
        }
Exemplo n.º 9
0
        private static CacheServerList GetSeversPriorityList()
        {
            Dictionary <int, Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer> serversPriorityList = new Dictionary <int, Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer>();

            Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
            if (config != null)
            {
                List <Address> hosts = config.CacheDeployment.Servers.GetAllConfiguredNodes();
                Alachisoft.NCache.Management.ICacheServer cs;
                NCacheRPCService cache = new NCacheRPCService("");
                int priority           = 0;
                int port = -1;
                foreach (Address addr in hosts)
                {
                    try
                    {
                        string address = addr.IpAddress.ToString();
                        if (_managementIPMapping != null)
                        {
                            if (_managementIPMapping.ContainsKey(address))
                            {
                                Mapping endPoint = _managementIPMapping[address];
                                address = endPoint.PublicIP;
                                port    = endPoint.PublicPort;
                            }
                        }
                        server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
                        string tempClientServerName = "";
                        cache.ServerName = address;
                        if (port != -1)
                        {
                            cache.Port = port;
                        }
                        cs = cache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                        Management.Management.BindedIpMap bindedIps = cs.BindedIp();

                        if (bindedIps.Map.Contains(Alachisoft.NCache.Management.CacheServer.Channel.SocketServer))
                        {
                            tempClientServerName = bindedIps.Map[Alachisoft.NCache.Management.CacheServer.Channel.SocketServer].ToString();
                        }

                        if (!string.IsNullOrEmpty(tempClientServerName))
                        {
                            server.ServerName = tempClientServerName;
                        }
                        else
                        {
                            server.ServerName = addr.IpAddress.ToString();
                        }

                        server.Priority = priority;

                        serversPriorityList.Add(priority, server);
                        priority++;
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Error while adding server :" + cache.ServerName + ":" + cache.Port + "\nException : " + ex.Message);
                    }
                }
            }

            if (serversPriorityList.Count < 1)
            {
                server.ServerName = _server;
                server.Priority   = 0;
                serversPriorityList.Add(0, server);
            }

            return(new CacheServerList(serversPriorityList));
        }