Example #1
0
            /// <summary>
            /// The main entry point for the tool.
            /// </summary>
            public static void Run(string[] args)
            {
                try
                {
                    object param = new StopCacheToolParam();
                    CommandLineArgumentParser.CommandLineParser(ref param, args);
                    cParam = (StopCacheToolParam)param;
                    if (cParam.IsUsage)
                    {
                        AssemblyUsage.PrintLogo(cParam.IsLogo);
                        AssemblyUsage.PrintUsage();
                        return;
                    }

                    if (!ApplyParameters(args))
                    {
                        return;
                    }

                    ICacheServer m         = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    string       getBindIp = string.Empty;
                    if (m != null)
                    {
                        foreach (string cache in s_cacheId)
                        {
                            try
                            {
                                getBindIp = m.GetBindIP();
                                Console.WriteLine("\nStopping cache '{0}' on server {1}:{2}.", cache, getBindIp,
                                                  NCache.Port);

                                m.StopCache(cache);
                                Console.WriteLine("'{0}' successfully stopped on server {1}:{2}.\n", cache, getBindIp,
                                                  NCache.Port);
                            }

                            catch (Exception e)
                            {
                                Console.Error.WriteLine("Failed to stop '{0}'. Error: {1} ", cache, e.Message);
                                Console.Error.WriteLine();
                                Console.Error.WriteLine(e.ToString());
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("Error : {0}", e.Message);

                    Console.Error.WriteLine();
                    Console.Error.WriteLine(e.ToString());
                }
                finally
                {
                    NCache.Dispose();
                }
            }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="address"></param>
        /// <param name="port"></param>
        public CacheServiceClient(string address, int port)
        {
            _address = address;
            _port    = port;

            Initialize();

            _bindIpAddress    = _server.GetBindIP();
            _clusterIpAddress = _server.GetClusterIP();
        }
Example #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="address"></param>
        /// <param name="port"></param>
        public CacheServiceClient(string address, int port, Action <CredentialsEventArgs> getCredentialsAction)
        {
            _address             = address;
            _port                = port;
            _getCacheCredentials = getCredentialsAction;

            Initialize();

            _bindIpAddress    = _server.GetBindIP();
            _clusterIpAddress = _server.GetClusterIP();
        }
Example #4
0
        public void ListCaches()
        {
            ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
            OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support.\n");
            if (Port != -1)
            {
                NCache.Port = Port;
            }
            if (Server != null && !Server.Equals(""))
            {
                NCache.ServerName = Server;
            }

            string getBindIp = string.Empty;


            try
            {
                ICacheServer cacheServer = null;
                try
                {
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                    return;
                }
                getBindIp = cacheServer.GetBindIP();
                OutputProvider.WriteLine("Listing registered caches on server {0}:{1}\n", getBindIp, NCache.Port);
                if (cacheServer != null)
                {
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] caches = cacheServer.GetAllConfiguredCaches();


                    if (caches.Length > 0)
                    {
                        if (!Detail)
                        {
                            OutputProvider.WriteLine("{0,-25} {1,-35} {2,-15}", "Cache-Name", "Topology", "Status(PID)");
                            OutputProvider.WriteLine("{0,-25} {1,-35} {2,-15}", "----------", "--------", "-----------");
                        }

                        if (caches.Length > 0)
                        {
                            for (int i = 0; i < caches.Length; i++)
                            {
                                Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo cacheInfo = caches[i];
                                if (!Detail)
                                {
                                    PrintCacheInfo(cacheInfo.Topology.ToString(), cacheInfo.CacheId, cacheInfo.IsRunning, cacheInfo.ProcessID);
                                }
                                else
                                {
                                    try
                                    {
                                        PrintDetailedCacheInfo(cacheServer.GetCacheStatistics2(cacheInfo.CacheId), cacheInfo.Topology.ToString(), null, cacheInfo.IsRunning, cacheInfo.CacheId, cacheInfo.CachePropString, cacheInfo.ProcessID.ToString());
                                    }
                                    catch (Exception e)
                                    {
                                        if (e.Message != null && e.Message.Contains("No connection could be made because the target machine actively refused it"))
                                        {
                                            PrintDetailedCacheInfo(null, cacheInfo.Topology.ToString(), null, false, cacheInfo.CacheId, cacheInfo.CachePropString, "0");
                                        }
                                        else
                                        {
                                            OutputProvider.WriteErrorLine("Error: {0}", e.Message);
                                            OutputProvider.WriteErrorLine(e.ToString());
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        OutputProvider.WriteLine("There are no registered caches on {0}", NCache.ServerName);
                    }
                }
            }
            catch (Exception e)
            {
                OutputProvider.WriteErrorLine("Error: {0}", e.Message);
                OutputProvider.WriteErrorLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
            OutputProvider.WriteLine((Detail)?"": Environment.NewLine);
        }
Example #5
0
        static public void Run(string[] args)
        {
            try
            {
                object param = new RemoveCacheParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (RemoveCacheParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }

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

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

                if (cParam.Server != null || cParam.Server != string.Empty)
                {
                    NCache.ServerName = cParam.Server;
                }


                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                Console.WriteLine("\nRemoving cache '{0}' on server {1}:{2}.", cParam.CacheId,
                                  cacheServer.GetBindIP(), NCache.Port);
                if (cacheServer != null)
                {
                    string getBindIp = string.Empty;
                    try
                    {
                        Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(cParam.CacheId);

                        if (serverConfig == null)
                        {
                            throw new Exception("Specified cache does not exist.");
                        }
                        if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                        {
                            foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                            {
                                try
                                {
                                    NCache.ServerName = node.IpAddress.ToString();
                                    cacheServer       = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                                    cacheServer.UnregisterCache(cParam.CacheId, null, false);
                                    Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n",
                                                      cParam.CacheId, NCache.ServerName, NCache.Port);
                                }
                                catch (Exception ex)
                                {
                                    Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ",
                                                            cParam.CacheId, NCache.ServerName, NCache.Port);
                                    Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);

                                    LogEvent(ex.Message);
                                }
                                finally
                                {
                                    cacheServer.Dispose();
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                getBindIp = cacheServer.GetBindIP();
                                cacheServer.UnregisterCache(cParam.CacheId, null, false);
                                Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n",
                                                  cParam.CacheId, getBindIp, NCache.Port);
                            }
                            catch (Exception e)
                            {
                                throw e;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ",
                                                cParam.CacheId, cacheServer.GetBindIP(), NCache.Port);
                        Console.Error.WriteLine(ex.Message);
                        LogEvent(ex.Message);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }
Example #6
0
        /// <summary>
        /// Sets the application level parameters to those specified at the command line.
        /// </summary>
        /// <param name="args">array of command line parameters</param>


        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            object param = new ListCachesParam();

            CommandLineArgumentParser.CommandLineParser(ref param, args);
            cParam = (ListCachesParam)param;
            AssemblyUsage.PrintLogo(cParam.IsLogo);



            if (cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }

            if (!cParam.Detail && string.IsNullOrEmpty(cParam.Server) && args.Length != 0 && cParam.Port == -1 && cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }


            if (cParam.Port != -1)
            {
                NCache.Port = cParam.Port;
            }
            if (cParam.Server != null && !cParam.Server.Equals(""))
            {
                NCache.ServerName = cParam.Server;
            }

            string getBindIp = string.Empty;



            try
            {
                ICacheServer m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                getBindIp = m.GetBindIP();
                Console.WriteLine("Listing registered caches on server {0}:{1}\n", getBindIp, NCache.Port);

                if (m != null)
                {
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] caches = m.GetAllConfiguredCaches();
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] partitionedReplicaCaches = m.GetConfiguredPartitionedReplicaCaches();// PartitionedReplicaCaches;

                    if (caches.Length > 0 || partitionedReplicaCaches.Length > 0)
                    {
                        if (!cParam.Detail)
                        {
                            Console.WriteLine("{0,-25} {1,-35} {2,-15}", "Cache-Name", "Scheme", "Status");
                            Console.WriteLine("{0,-25} {1,-35} {2,-15}", "----------", "------", "------");
                        }

                        if (caches.Length > 0)
                        {
                            for (int i = 0; i < caches.Length; i++)
                            {
                                Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo cacheInfo = caches[i];
                                if (!cParam.Detail)
                                {
                                    PrintCacheInfo(m.GetCacheStatistics2(cacheInfo.CacheId), cacheInfo.CacheId, cacheInfo.IsRunning);
                                }
                                else
                                {
                                    PrintDetailedCacheInfo(m.GetCacheStatistics2(cacheInfo.CacheId), null, cParam.PrintConf, cParam.XmlSyntax, cacheInfo.IsRunning, cacheInfo.CacheId, cacheInfo.CachePropString);
                                }
                            }
                        }

                        if (partitionedReplicaCaches.Length > 0)
                        {
                            IEnumerator ide = partitionedReplicaCaches.GetEnumerator();
                            while (ide.MoveNext())
                            {
                                Hashtable cacheTbl = ide.Current as Hashtable;
                                if (cacheTbl != null)
                                {
                                    IDictionaryEnumerator e = cacheTbl.GetEnumerator();
                                    while (e.MoveNext())
                                    {
                                        string partId = e.Key as string;
                                        Cache  cache  = (Cache)e.Value;
                                        if (!detailed)
                                        {
                                            PrintCacheInfo(cache, partId);
                                        }
                                        else
                                        {
                                            PrintDetailedCacheInfo(cache, partId, printConf, xmlSyntax);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are no registered caches on {0}", NCache.ServerName);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }
Example #7
0
        protected void CacheClientStatistics()
        {
            ArrayList           clients      = null;
            List <ICacheServer> cacheServers = new List <ICacheServer>();
            bool isServiceRunning            = true;

            if (!ValidateParameters())
            {
                return;
            }
            if (Clients != null && !Clients.Equals(""))
            {
                clients = GetClients(Clients);
            }
            else
            {
                clients = new ArrayList();
                NCacheRPCService nCache = new NCacheRPCService("");
                clients.Add(nCache.ServerName);
            }

            foreach (var client in clients)
            {
                NCacheRPCService nCache = new NCacheRPCService(client.ToString());
                try
                {
                    ICacheServer cacheServer = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    //NodeStatus status = GetCacheStatistics(_nCache);
                    ClientList.Add(cacheServer.GetBindIP());
                    cacheServers.Add(cacheServer);
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToUpper().Contains("service".ToUpper()))
                    {
                        OutputProvider.WriteErrorLine("NCache Service could not be contacted on server " + client);
                        isServiceRunning = false;
                    }
                    else
                    {
                        cacheServers.Add(null);
                    }
                }
            }
            if (!(Format.Equals("csv", StringComparison.OrdinalIgnoreCase) || Format.Equals("tabular", StringComparison.OrdinalIgnoreCase)))
            {
                throw new ArgumentException("Invalid Format type");
            }
            if (Continuous && MaxSamples > 0)
            {
                throw new Exception("The Continuous parameter and the MaxSamples parameter cannot be used in the same command.");
            }
            _perfmonCounters = CreateCounterList();
            if (Continuous && Format.Equals("csv", StringComparison.OrdinalIgnoreCase))
            {
                FetchAndDisplayContinousulyCSV(cacheServers);
            }
            else if (Continuous && Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))
            {
                Util.ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
                FetchAndDisplayContinousuly(cacheServers);
            }
            else if (MaxSamples > 0)
            {
                if (Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))
                {
                    ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
                    FetchAndDisplayMax(cacheServers);
                }
                else if (Format.Equals("csv", StringComparison.OrdinalIgnoreCase))
                {
                    FetchAndDisplayMaxCSV(cacheServers);
                }
            }

            if (!Continuous && MaxSamples == 0)
            {
                if (isServiceRunning)
                {
                    try
                    {
                        SortedDictionary <string, string[]> CountList = FetchCounters(cacheServers);
                        if (Format.Equals("csv", StringComparison.OrdinalIgnoreCase))
                        {
                            DisplayinCSVFormat(CountList);
                        }
                        else if (Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))
                        {
                            Util.ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
                            DisplayTimeStamp();
                            DisplayCounters(CountList);
                        }
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        OutputProvider.WriteErrorLine(ex);
                    }
                    catch (Exception ex)
                    {
                        OutputProvider.WriteErrorLine(ex);
                    }
                }
            }
        }
Example #8
0
        public void CacheServerStatistics()
        {
            ArrayList           servers      = null;
            bool                isPOR        = false;
            bool                isRegistered = true;
            List <ICacheServer> cacheServers = new List <ICacheServer>();

            if (!ValidateParameters())
            {
                return;
            }
            if (Servers != null && !Servers.Equals(""))
            {
                servers = GetServers(Servers);
            }
            else
            {
                servers = new ArrayList();
                NCacheRPCService nCache = new NCacheRPCService("");
                servers.Add(nCache.ServerName);
            }
            foreach (var server in servers)
            {
                NCacheRPCService nCache = new NCacheRPCService(server.ToString());
                try
                {
                    ICacheServer cacheServer = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    serverList.Add(cacheServer.GetBindIP());
                    NodeStatus status = GetCacheStatistics(nCache);
                    if (status.isRegistered == false)
                    {
                        throw new Exception("The specified cache is not registered on server " + server);
                    }

                    isPOR = status.Topology == Topology.POR;
                    cacheServers.Add(cacheServer);
                    //array of it ICacheServer
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("The specified cache is not registered"))
                    {
                        OutputProvider.WriteErrorLine(ex.Message);
                        isRegistered = false;
                    }
                    else if (ex.Message.ToUpper().Contains("service".ToUpper()))
                    {
                        OutputProvider.WriteErrorLine("NCache Service could not be contacted on server " + server);
                        isRegistered = false;
                    }
                }
            }
            if (isRegistered)
            {
                _mainCounters = GetAllCounters(false);
                if (isPOR)
                {
                    _replicaCounters = GetAllCounters(true);
                }
                if (!(Format.Equals("csv", StringComparison.OrdinalIgnoreCase) || Format.Equals("tabular", StringComparison.OrdinalIgnoreCase)))
                {
                    throw new ArgumentException("Invalid Format type");
                }
                if (Continuous && MaxSamples > 0)
                {
                    throw new Exception("The Continuous parameter and the MaxSamples parameter cannot be used in the same command.");
                }
                if (Continuous && Format.Equals("csv", StringComparison.OrdinalIgnoreCase))
                {
                    FetchAndDisplayContinousulyCSV(cacheServers, isPOR);
                }
                else if (Continuous && Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))
                {
                    ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
                    FetchAndDisplayContinousuly(cacheServers, isPOR);
                }
                else if (MaxSamples > 0)
                {
                    if (Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))
                    {
                        ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
                        FetchAndDisplayMax(cacheServers, isPOR);
                    }
                    else if (Format.Equals("csv", StringComparison.OrdinalIgnoreCase))
                    {
                        FetchAndDisplayMaxCSV(cacheServers, isPOR);
                    }
                }
                if (!Continuous && MaxSamples == 0)
                {
                    try
                    {
                        SortedDictionary <string, string[]> CountList = FetchCounters(cacheServers, isPOR);
                        if (Format.Equals("csv", StringComparison.OrdinalIgnoreCase))
                        {
                            DisplayinCSVFormat(CountList, isPOR);
                        }
                        else if (Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))
                        {
                            ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
                            DisplayTimeStamp();
                            DisplayCounters(CountList, isPOR);
                        }
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        OutputProvider.WriteErrorLine(ex);
                    }
                    catch (Exception ex)
                    {
                        OutputProvider.WriteErrorLine(ex);
                    }
                }
            }
            OutputProvider.WriteLine("\n");
        }
Example #9
0
        /// <summary>
        /// Sets the application level parameters to those specified at the command line.
        /// </summary>
        /// <param name="args">array of command line parameters</param>


        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            object param = new ListCachesParam();

            CommandLineArgumentParser.CommandLineParser(ref param, args);
            cParam = (ListCachesParam)param;
            AssemblyUsage.PrintLogo(cParam.IsLogo);



            if (cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }

            if (!cParam.Detail && string.IsNullOrEmpty(cParam.Server) && args.Length != 0 && cParam.Port == -1 && cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }


            if (cParam.Port != -1)
            {
                NCache.Port = cParam.Port;
            }
            if (cParam.Server != null && !cParam.Server.Equals(""))
            {
                NCache.ServerName = cParam.Server;
            }

            string getBindIp = string.Empty;



            try
            {
                ICacheServer m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                getBindIp = m.GetBindIP();
                Console.WriteLine("Listing registered caches on server {0}:{1}\n", getBindIp, NCache.Port);

                if (m != null)
                {
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] caches = m.GetAllConfiguredCaches();

                    if (caches.Length > 0)
                    {
                        if (!cParam.Detail)
                        {
                            Console.WriteLine("{0,-25} {1,-35} {2,-15}", "Cache-Name", "Scheme", "Status");
                            Console.WriteLine("{0,-25} {1,-35} {2,-15}", "----------", "------", "------");
                        }

                        if (caches.Length > 0)
                        {
                            for (int i = 0; i < caches.Length; i++)
                            {
                                Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo cacheInfo = caches[i];
                                if (!cParam.Detail)
                                {
                                    PrintCacheInfo(cacheInfo.Topology.ToString(), cacheInfo.CacheId, cacheInfo.IsRunning, cacheInfo.ProcessID);
                                }
                                else
                                {
                                    PrintDetailedCacheInfo(m.GetCacheStatistics2(cacheInfo.CacheId), cacheInfo.Topology.ToString(), null, cacheInfo.IsRunning, cacheInfo.CacheId, cacheInfo.CachePropString, cacheInfo.ProcessID.ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are no registered caches on {0}", NCache.ServerName);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }
Example #10
0
        public void StopCache()
        {
            try
            {
                if (!ValidateParameters())
                {
                    return;
                }
                ICacheServer m = null;
                OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support.\n");
                try
                {
                    m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                }

                string            getBindIp = string.Empty;
                CacheServerConfig config    = null;
                if (m != null)
                {
                    foreach (string cache in CachesList)
                    {
                        try
                        {
                            config = m.GetCacheConfiguration((string)cache);
                            if (config != null && config.InProc)
                            {
                                throw new Exception("InProc caches cannot be stopped explicitly.");
                            }
                            getBindIp = m.GetBindIP();
                            OutputProvider.WriteLine("Stopping cache '{0}' on server {1}:{2}.", cache, getBindIp, NCache.Port);

                            m.StopCache(cache, _partId);



                            OutputProvider.WriteLine("'{0}' successfully stopped on server {1}:{2}.\n", cache, getBindIp,
                                                     NCache.Port);
                        }
                        catch (System.Security.SecurityException e)
                        {
                            OutputProvider.WriteErrorLine("Failed to stop '{0}'. Error: {1} ", cache, e.Message);

                            OutputProvider.WriteErrorLine(e.ToString());
                        }
                        catch (Exception e)
                        {
                            OutputProvider.WriteErrorLine("Failed to stop '{0}'.", cache);

                            OutputProvider.WriteErrorLine("Error: " + e.ToString());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                OutputProvider.WriteErrorLine("Error : {0}", e.Message);


                OutputProvider.WriteErrorLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }
Example #11
0
        public static void Run(string[] args)
        {
            try
            {
                object param = new RemoveCacheParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (RemoveCacheParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters()) return;

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

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

                if (cParam.Server != null || cParam.Server != string.Empty)
                {
                    NCache.ServerName = cParam.Server;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                Console.WriteLine("\nRemoving cache '{0}' on server {1}:{2}.", cParam.CacheId,
                                            cacheServer.GetBindIP(), NCache.Port);
                if (cacheServer != null)
                {
                    string getBindIp = string.Empty;
                    try
                    {

                        Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(cParam.CacheId);

                        if (serverConfig == null)
                        {
                            throw new Exception("Specified cache does not exist.");
                        }
                        if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                        {

                            foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                            {
                                try
                                {
                                    NCache.ServerName = node.IpAddress.ToString();
                                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                                    cacheServer.UnregisterCache(cParam.CacheId, null, false);
                                    Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n",
                                        cParam.CacheId, NCache.ServerName, NCache.Port);
                                }
                                catch (Exception ex)
                                {
                                    Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ",
                                        cParam.CacheId, NCache.ServerName, NCache.Port);
                                    Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);

                                    LogEvent(ex.Message);
                                }
                                finally
                                {
                                    cacheServer.Dispose();
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                getBindIp = cacheServer.GetBindIP();
                                cacheServer.UnregisterCache(cParam.CacheId, null, false);
                                Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n",
                                            cParam.CacheId, getBindIp, NCache.Port);
                            }
                            catch (Exception e)
                            {
                                throw e;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ",
                                   cParam.CacheId, cacheServer.GetBindIP(), NCache.Port);
                        Console.Error.WriteLine(ex.Message);
                        LogEvent(ex.Message);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }