Example #1
0
        public bool ValidateParameters()
        {
            try
            {
                if (CacheName == String.Empty || CacheName == null)
                {
                    OutputProvider.WriteErrorLine("Error: Cache name not specified.");
                    return(false);
                }

                if (!string.IsNullOrEmpty(Server))
                {
                    string[] servers = Server.Split(new char[] { ',' });

                    for (int i = 0; i < servers.Length; i++)
                    {
                        if (!ToolsUtil.IsValidIP(servers[i]))
                        {
                            OutputProvider.WriteErrorLine("Error: Invalid Server IP. {0}", servers[i]);
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                OutputProvider.WriteLine("Exception occured while parsing input parameters. Please verify all given parameters are in correct format.");
                OutputProvider.WriteLine(ex.Message);
                return(false);
            }
            ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
            return(true);
        }
Example #2
0
        public void VerifyCacheServer(bool multipleServers)
        {
            int    index  = 0;
            string server = "";

tryNextServer:
            if (multipleServers)
            {
                string[] serverAddress = _serverList[index].Split(':');
                if (serverAddress.Length == 2)
                {
                    if (!ToolsUtil.IsValidIP(serverAddress[0]))
                    {
                        OutputProvider.WriteErrorLine("Error: Invalid Server IP.");
                        throw new Exception("Invalid IP :" + serverAddress[0]);
                    }
                    NCache.ServerName = serverAddress[0];
                    try
                    {
                        NCache.Port = Convert.ToInt32(serverAddress[1]);
                    }
                    catch (Exception)
                    {
                        throw new Exception("Invalid Port :" + serverAddress[1] + "specified for server : " + serverAddress[0] + ".");
                    }
                }
                else
                if (serverAddress.Length == 1)
                {
                    if (!ToolsUtil.IsValidIP(serverAddress[0]))
                    {
                        OutputProvider.WriteErrorLine("Error: Invalid Server IP.");
                        throw new Exception("Invalid Server IP :" + serverAddress[0] + ".");
                    }
                    NCache.ServerName = serverAddress[0];
                    NCache.Port       = Port;
                    if (Port == -1)
                    {
                        NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                    }
                }
                else
                {
                    throw new Exception("Invalid server Address specified, kindly specify as [IPAdress] or [IPAdress]:[Port].");
                }
            }
            else
            {
                if (Port != -1)
                {
                    NCache.Port = Port;
                }
                if (CacheServer != null || CacheServer != string.Empty)
                {
                    NCache.ServerName = CacheServer;
                }
                if (Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
            }
            try
            {
                server      = NCache.ServerName;
                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
            }
            catch (Exception ex)
            {
                if (multipleServers)
                {
                    if (index < _serverList.Length - 1)
                    {
                        OutputProvider.WriteErrorLine("Failed to connect to server : " + NCache.ServerName + ":" + NCache.Port + " \nTrying next server.");
                        index++;
                        goto tryNextServer;
                    }
                }
                throw ex;
            }
        }