public static void ConveyCommandToAllRunningCacheHost(ConfiguredCacheInfo[] cacheHostprocesses, string Action, string server, IOutputConsole OutputProvider) { foreach (ConfiguredCacheInfo cacheHost in cacheHostprocesses) { NCacheRPCService nCache = new NCacheRPCService(""); nCache.Port = cacheHost.ManagementPort; nCache.ServerName = server; if (nCache.Port > 0) { ICacheServer hostService = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (Action.ToLower().Equals("start")) { OutputProvider.WriteLine("Starting monitoring on server {0}:{1}.", nCache.ServerName, nCache.Port); hostService.StartMonitoringActivity(); } else if (Action.ToLower().Equals("stop")) { OutputProvider.WriteLine("Stop monitoring on server {0}:{1}.", nCache.ServerName, nCache.Port); hostService.StopMonitoringActivity(); } hostService.PublishActivity(); } } }
public void MonitorServer() { try { if (!ValidateParameters()) { return; } if (!Server.Equals(string.Empty)) { NCache.ServerName = Server; } if (Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } else { NCache.Port = Port; } ICacheServer m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (m != null) { try { if (Action.ToLower() == "start") { OutputProvider.WriteLine("Starting monitoring on server {0}:{1}.", NCache.ServerName, NCache.Port); m.StartMonitoringActivity(); } if (Action.ToLower() == "stop") { OutputProvider.WriteLine("Stopping monitoring on server {0}:{1}.", NCache.ServerName, NCache.Port); m.StopMonitoringActivity(); m.PublishActivity(); } } catch (SecurityException e) { OutputProvider.WriteErrorLine("Failed to '{0}' monitoring . Error: {1} ", Action.ToLower(), e.Message); } catch (Exception e) { OutputProvider.WriteErrorLine("Failed to '{0}' monitoring. Error: {1} ", Action.ToLower(), e.Message); } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error : {0}", e.Message); } finally { NCache.Dispose(); } }