コード例 #1
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();
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: javithalion/NCache
        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();
            }
        }