Beispiel #1
0
        public static void StopCache(string cacheId, string serverName, bool isGracefulShutdown)
        {
            ICacheServer cs           = null;
            CacheService cacheService = new NCacheRPCService(null);

            try
            {
                cacheService.ServerName = serverName;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    cs.StopCache(cacheId);
                }
            }
            catch (Exception ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
Beispiel #2
0
        public static void StopCache(string cacheId)
        {
            ICacheServer      cs           = null;
            CacheService      cacheService = new NCacheRPCService(null);
            CacheServerConfig config       = null;

            try
            {
                cacheService.ServerName = Environment.MachineName;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    config = cs.GetCacheConfiguration(cacheId);
                    if (!config.InProc)
                    {
                        cs.StopCache(cacheId);
                    }
                    else
                    {
                        throw new ManagementException("Inproc caches cannot be stopped explicitly.");
                    }
                }
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
Beispiel #3
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();
                }
            }
        public static void StopCache(string cacheId, string serverName, int port, string userId, string password)
        {
            ICacheServer cs = null;

            CacheService cacheService = new NCacheRPCService(null);

            try
            {
                cacheService.ServerName = serverName;
                cacheService.Port       = port;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    cs.StopCache(cacheId);
                }
            }

            catch (SecurityException ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw ex;
            }


            catch (Exception ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
Beispiel #5
0
        public void StopCache()
        {
            try
            {
                if (!ValidateParameters())
                {
                    return;
                }
                ICacheServer m = null;
                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(cache);
                            if (config != null && config.InProc)
                            {
                                throw new Exception("InProc caches cannot be stopped explicitly.");
                            }
                            getBindIp = m.GetClusterIP();
                            OutputProvider.WriteLine("Stopping cache '{0}' on server {1}:{2}.", cache, getBindIp, NCache.Port);
                            m.StopCache(cache, _partId);

                            m.StopCache(cache, string.Empty);

                            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());
                            OutputProvider.WriteLine(Environment.NewLine);
                        }
                        catch (Exception e)
                        {
                            OutputProvider.WriteErrorLine("Failed to stop '{0}'.", cache);

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



                OutputProvider.WriteErrorLine(e.ToString());
                OutputProvider.WriteLine(Environment.NewLine);
            }
            finally
            {
                NCache.Dispose();
            }
        }