private void FetchAndDisplayContinousuly(List <ICacheServer> cacheClients) { try { if (SampleInterval < 0 || SampleInterval > int.MaxValue) { throw new ArgumentOutOfRangeException("Number must be either non-negative and less than or equal to Int32.MaxValue"); } while (true) { Thread.Sleep(SampleInterval * 1000); SortedDictionary <string, string[]> CountList = FetchCounters(cacheClients); DisplayTimeStamp(); DisplayCounters(CountList); OutputProvider.WriteLine(" \n\n"); } } catch (ArgumentOutOfRangeException ex) { OutputProvider.WriteErrorLine(ex); } catch (Exception ex) { OutputProvider.WriteErrorLine(ex); } }
public bool ValidateParameters() { _bridgeService.Port = Port; _bridgeService.ServerName = Server; if (Port == -1) { _bridgeService.Port = _bridgeService.UseTcp ? BridgeConfigurationManager.NCacheTcpPort : BridgeConfigurationManager.NCacheHttpPort; } //validate BridgeID if (string.IsNullOrEmpty(BridgeId)) { OutputProvider.WriteErrorLine("Error: BridgeID not specified."); return(false); } if (string.IsNullOrEmpty(Server)) { OutputProvider.WriteErrorLine("Error: Bridge server is not specified."); return(false); } //validate Server if (string.IsNullOrEmpty(DeleteBridgeNode)) { OutputProvider.WriteErrorLine("Error: Server to be removed is not specified."); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public bool ValidateParameters() { _bridgeService.Port = Port; _bridgeService.ServerName = BridgeServer; if (Port == -1) { _bridgeService.Port = _bridgeService.UseTcp ? BridgeConfigurationManager.NCacheTcpPort : BridgeConfigurationManager.NCacheHttpPort; } if (string.IsNullOrEmpty(BridgeId)) { OutputProvider.WriteErrorLine("Error: Bridge-id not specified."); return(false); } if (string.IsNullOrEmpty(CacheName)) { OutputProvider.WriteErrorLine("Error: Cache-id not specified."); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public bool ValidateParameters() { if (string.IsNullOrEmpty(CacheName)) { OutputProvider.WriteErrorLine("Error: Cache name not specified."); return(false); } if (string.IsNullOrEmpty(AssemblyPath)) { OutputProvider.WriteErrorLine("Error: Assembly path not specified."); return(false); } if (string.IsNullOrEmpty(Class)) { OutputProvider.WriteErrorLine("Error: Class name not specified."); return(false); } if (string.IsNullOrEmpty(Name)) { OutputProvider.WriteErrorLine("Error: Provider name not specified."); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public bool ValidateParameters() { if (string.IsNullOrEmpty(BridgeId)) { OutputProvider.WriteErrorLine("Error: Bridge-id not specified."); return(false); } if (string.IsNullOrEmpty(CacheName)) { OutputProvider.WriteErrorLine("Error: Cache-id not specified."); return(false); } bool multipleServers = false; if (CacheServer != null || CacheServer != string.Empty) { _serverList = CacheServer.Split(','); if (_serverList.Length > 1 || (_serverList[0].Contains(":"))) { multipleServers = true; } } VerifyCacheServer(multipleServers); ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
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); }
/// <summary> /// Sets the application level parameters to those specified at the command line. /// </summary> /// <param name="args">array of command line parameters</param> public bool ValidateParameters() { if (Name != null && Name.Length > 0) { CachesList = new ArrayList(); CachesList.AddRange(Name); } NCache = new NCacheRPCService(""); NCache.ServerName = Server; if (String.IsNullOrEmpty(NCache.ServerName)) { NCache.ServerName = System.Environment.MachineName; } NCache.Port = Port; if (NCache.Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } if (CachesList.Count == 0) { OutputProvider.WriteErrorLine("Error: cache name not specified."); } if (CachesList.Count > 1) { _partId = string.Empty; } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public void ClearCache(string cacheId, bool forceClear) { ICache cache = null; try { CacheConnectionOptions cacheParams = new CacheConnectionOptions(); cache = CacheManager.GetCache(cacheId.ToLower(), cacheParams); if (!ForceClear) { long count = cache.Count; OutputProvider.WriteLine(""); OutputProvider.WriteLine("\"" + cacheId + "\" cache currently has " + count + " items. "); OutputProvider.WriteLine("Do you really want to clear it (Y or N)? "); string response = string.Empty; if (isPowershell) { ICollection <PSObject> resp = this.InvokeCommand.InvokeScript("Read-Host"); foreach (PSObject r in resp) { response = r.ToString(); } } else { response = Console.ReadLine(); } if (response != "Y" && response != "y") { OutputProvider.WriteLine(""); OutputProvider.WriteLine("Cache not cleared."); return; } } cache.Clear(); OutputProvider.WriteLine(""); OutputProvider.WriteLine("Cache cleared."); } catch (Exception e) { OutputProvider.WriteLine("Error: " + e.Message); OutputProvider.WriteErrorLine(e.ToString()); } finally { if (cache != null) { cache.Dispose(); } } }
void StartCacheOnServer() { OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support.\n"); string cacheIp = string.Empty; try { ICacheServer cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); CacheServerConfig config = null; if (cacheServer != null) { cacheIp = cacheServer.GetClusterIP(); foreach (string cache in CachesList) { try { config = cacheServer.GetCacheConfiguration(cache); if (config != null && config.InProc) { throw new Exception("InProc caches cannot be started explicitly."); } OutputProvider.WriteLine("Starting cache '{0}' on server {1}:{2}.", cache, cacheIp, NCache.Port); cacheServer.StartCache(cache, _partId); OutputProvider.WriteLine("'{0}' successfully started on server {1}:{2}.\n", cache, cacheIp, NCache.Port); } catch (Exception e) { OutputProvider.WriteErrorLine("Failed to start '{0}' on server {1}.", cache, cacheIp); OutputProvider.WriteErrorLine(e.ToString() + "\n"); } } } } catch (ManagementException ex) { OutputProvider.WriteErrorLine("Error : {0}", "NCache service could not be contacted on server"); OutputProvider.WriteErrorLine(ex.ToString()); } catch (Exception e) { OutputProvider.WriteErrorLine("Error : {0}", e.Message); OutputProvider.WriteErrorLine(e.ToString()); } finally { NCache.Dispose(); } }
public bool ValidateParameters() { if (string.IsNullOrEmpty(Name)) { OutputProvider.WriteErrorLine("\nError: Cache name not specified."); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
protected void StartProcess() { try { } catch (Exception ex) { OutputProvider.WriteErrorLine(ex.ToString()); } }
protected override void StopProcessing() { try { _taskManger.StopTasks(true); } catch (Exception ex) { OutputProvider.WriteErrorLine(ex.ToString()); } }
public void ClearCache(string cacheId, bool forceClear, bool webOnly) { Cache cache = null; try { CacheInitParams cacheParams = new CacheInitParams(); cache = Web.Caching.NCache.InitializeCache(cacheId.ToLower(), cacheParams); if (!ForceClear) { long count = cache.Count; OutputProvider.WriteLine(""); OutputProvider.WriteLine("\"" + cacheId + "\" cache currently has " + count + " items. "); OutputProvider.WriteLine("Do you really want to clear it (Y or N)? "); ICollection <PSObject> response = this.InvokeCommand.InvokeScript("Read-Host"); string resp = string.Empty; foreach (PSObject r in response) { resp = r.ToString(); } if (resp != "Y" && resp != "y") { OutputProvider.WriteLine(""); OutputProvider.WriteLine("Cache not cleared."); return; } } cache.Clear(); OutputProvider.WriteLine(""); OutputProvider.WriteLine("Cache cleared."); } catch (Exception e) { OutputProvider.WriteLine("Error: " + e.Message); OutputProvider.WriteErrorLine(e.ToString()); } finally { if (cache != null) { cache.Dispose(); } } }
public void DumpCacheKeys() { try { if (!ValidateParameters()) { return; } CacheConnectionOptions cacheParams = new CacheConnectionOptions(); ICache cache = CacheManager.GetCache(Name.ToLower(), cacheParams); //cache.ExceptionsEnabled = true; OutputProvider.WriteLine("Cache count: " + cache.Count); IDictionaryEnumerator keys = (IDictionaryEnumerator)cache.GetEnumerator(); if (keys != null) { long index = 0; bool checkFilter = (KeyFilter != ""); KeyFilter = KeyFilter.Trim(); while (keys.MoveNext()) { if ((KeyCount > 0) && (index >= KeyCount)) { break; } if (checkFilter == true) { string tmpKey = (string)keys.Key; if (tmpKey.Contains(KeyFilter) == true) { OutputProvider.WriteLine(tmpKey); } } else { OutputProvider.WriteLine(keys.Key); } index++; } //end while } //end if cache.Dispose(); } //end try block catch (Exception e) { OutputProvider.WriteErrorLine("Error: " + e.Message); OutputProvider.WriteErrorLine(e.ToString()); } OutputProvider.WriteLine(Environment.NewLine); }
public bool ValidateParameters() { if (string.IsNullOrEmpty(CacheName)) { OutputProvider.WriteErrorLine("\nError: Cache name not specified."); return(false); } if (string.IsNullOrEmpty(CounterNames)) { DoNotShowDefaultCounters = false; } return(true); }
protected override void BeginProcessing() { try { #if NETCORE AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += new ResolveEventHandler(Alachisoft.NCache.Automation.Util.AssemblyResolver.GetAssembly); #endif Callingfunc(); } catch (System.Exception ex) { OutputProvider.WriteErrorLine(ex); } }
public void ClearCacheTool() { try { if (!ValidateParameters()) { return; } ClearCache(Name, ForceClear, false); } catch (Exception ex) { OutputProvider.WriteErrorLine("Error: " + ex.Message); OutputProvider.WriteErrorLine(ex.ToString()); } }
protected void DisplayinCSVFormat(SortedDictionary <string, string[]> counters, bool hasReplica = false) { try { StringBuilder sb = new StringBuilder(); if (!_headerRow) { DisplayHeaderRow(counters, hasReplica); } _headerRow = true; ArrayList servers = serverList; string counterValue = string.Empty; if (!hasReplica) { for (int i = 0; i < servers.Count; i++) { foreach (var counterVal in counters) { counterValue = counterValue + ",\"" + counterVal.Value[i] + "\""; } } sb.Append("\"" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture) + "\"" + counterValue + ""); } else { int count = servers.Count * 2; for (int i = 0; i < count; i = i + 2) { foreach (var counterVal in counters) { counterValue = counterValue + ",\"" + counterVal.Value[i] + "\""; } foreach (var counterVal in counters) { counterValue = counterValue + ",\"" + counterVal.Value[i + 1] + "\""; } } sb.Append("\"" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture) + "\"" + counterValue + ""); } OutputProvider.WriteLine(sb); } catch (Exception ex) { OutputProvider.WriteErrorLine(ex.Message); } }
public bool ValidateParameters() { //validate BridgeID if (string.IsNullOrEmpty(BridgeId)) { OutputProvider.WriteErrorLine("Error: BridgeID not specified."); return(false); } if (string.IsNullOrEmpty(Server)) { OutputProvider.WriteErrorLine("Error: Bridge server is not specified."); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public bool ValidateParameters() { if (string.IsNullOrEmpty(CacheName)) { OutputProvider.WriteErrorLine("\nError: Cache name not specified."); return(false); } if (string.IsNullOrEmpty(AssemblyPath)) { OutputProvider.WriteErrorLine("\nError: Assembly Path not specified."); return(false); } if (string.IsNullOrEmpty(Class)) { OutputProvider.WriteErrorLine("\nError: Class name not specified."); return(false); } if (string.IsNullOrEmpty(LuceneType)) { OutputProvider.WriteErrorLine("\nError: Lucene Type not specified."); return(false); } if (string.IsNullOrEmpty(Analyzer)) { OutputProvider.WriteErrorLine("\nError: Analyzer not specified."); return(false); } if (string.IsNullOrEmpty(TermVector)) { OutputProvider.WriteErrorLine("\nError: Term Vector not specified."); return(false); } if (string.IsNullOrEmpty(Pattern)) { OutputProvider.WriteErrorLine("\nError: Pattern not specified."); return(false); } if (string.IsNullOrEmpty(StopWords)) { OutputProvider.WriteErrorLine("\nError: Stop Words not specified."); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public void TestStress() { try { if (!ValidateParameters()) { return; } OutputProvider.WriteLine("cacheId = {0}, total-loop-count = {1}, test-case-iterations = {2}, testCaseIterationDelay = {3}, gets-per-iteration = {4}, updates-per-iteration = {5}, data-size = {6}, expiration = {7}, thread-count = {8}, reporting-interval = {9}.", CacheName, ItemsCount, TestCaseIterations, TestCaseIterationDelay, GetsPerIteration, UpdatesPerIteration, DataSize, SlidingExpiration, ThreadCount, ReportingInterval); OutputProvider.WriteLine("-------------------------------------------------------------------\n"); Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal; } catch (Exception e) { OutputProvider.WriteErrorLine("Error: " + e.Message); } }
public bool ValidateParameters() { try { if (CacheName == String.Empty || CacheName == null) { OutputProvider.WriteErrorLine("Error: Cache name not specified."); 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); }
public bool ValidateParameters() { if ((!ReadThru) && (!WriteThru)) { OutputProvider.WriteErrorLine("Error: ReadThru/WriteThru not specified."); return(false); } if (!string.IsNullOrEmpty(OutputFile)) { string path = Path.GetExtension(OutputFile); if (!(path.Contains(".txt") || path.Contains(".xml"))) { OutputProvider.WriteErrorLine("Invalid file. Please specify path of .xml or .txt file."); return(false); } } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
/// <summary> /// Validate all parameters in property string. /// </summary> public bool ValidateParameters() { if (string.IsNullOrEmpty(Class)) { OutputProvider.WriteErrorLine("\nError: Class name not specified."); return(false); } if (string.IsNullOrEmpty(AssemblyPath)) { OutputProvider.WriteErrorLine("\nError: Assembly path not specified."); return(false); } if (!OutputFile.Equals(string.Empty) && !(Path.GetExtension(OutputFile).Equals(".txt") || Path.GetExtension(OutputFile).Equals(".xml"))) { OutputProvider.WriteErrorLine("\nError: Extension for the file specified is not valid."); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public bool ValidateParameters() { _bridgeService.Port = Port; _bridgeService.ServerName = BridgeServer; if (Port == -1) { _bridgeService.Port = _bridgeService.UseTcp ? BridgeConfigurationManager.NCacheTcpPort : BridgeConfigurationManager.NCacheHttpPort; } if (string.IsNullOrEmpty(BridgeId)) { OutputProvider.WriteErrorLine("Error: Bridge-id not specified."); return(false); } if (string.IsNullOrEmpty(CacheName)) { OutputProvider.WriteErrorLine("Error: Cache-id not specified."); return(false); } bool multipleServers = false; if (CacheServer != null || CacheServer != string.Empty) { _serverList = CacheServer.Split(','); if (_serverList.Length > 1 || (_serverList[0].Contains(":"))) { multipleServers = true; } } VerifyCacheServer(multipleServers); ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
private void FetchAndDisplayMaxCSV(List <ICacheServer> cacheClients) { try { if (SampleInterval < 0 || SampleInterval > int.MaxValue) { throw new ArgumentOutOfRangeException("Number must be either non-negative and less than or equal to Int32.MaxValue"); } for (int i = 0; i < MaxSamples; i++) { Thread.Sleep(SampleInterval * 1000); SortedDictionary <string, string[]> CountList = FetchCounters(cacheClients); DisplayinCSVFormat(CountList); } } catch (ArgumentOutOfRangeException ex) { OutputProvider.WriteErrorLine(ex); } catch (Exception ex) { OutputProvider.WriteErrorLine(ex); } }
private void AddLuceneAnalyzer() { if (!ValidateParameters()) { return; } System.Reflection.Assembly asm = null; Alachisoft.NCache.Config.Dom.LuceneDeployment[] prov = null; string failedNodes = string.Empty; string serverName = string.Empty; ICacheServer cacheServer = null; bool successFull = true; try { if (Port != -1) { NCache.Port = Port; } if (Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } if (Server != null && Server != string.Empty) { NCache.ServerName = Server; } try { cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); } catch (Exception e) { successFull = false; OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server."); return; } if (cacheServer != null) { serverName = cacheServer.GetClusterIP(); if (cacheServer.IsRunning(CacheName)) { successFull = false; throw new Exception(CacheName + " is Running on " + cacheServer.GetClusterIP() + "\nStop the cache first and try again."); } Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(CacheName); if (serverConfig == null) { successFull = false; throw new Exception("Specified cache is not registered on the given server."); } ToolsUtil.VerifyClusterConfigurations(serverConfig, CacheName); try { asm = System.Reflection.Assembly.LoadFrom(AssemblyPath); } catch (Exception e) { successFull = false; string message = string.Format("Could not load assembly \"" + AssemblyPath + "\". {0}", e.Message); OutputProvider.WriteErrorLine("Error: {0}", message); return; } if (asm == null) { successFull = false; throw new Exception("Could not load specified assembly."); } if (serverConfig.CacheSettings.LuceneSettings == null) { serverConfig.CacheSettings.LuceneSettings = new Alachisoft.NCache.Config.Dom.LuceneSettings(); } System.Type type = asm.GetType(Class, true); if (!type.IsSubclassOf(typeof(Analyzer))) { successFull = false; OutputProvider.WriteErrorLine("Error: Specified class does not implement Analyzer."); return; } else { if (serverConfig.CacheSettings.LuceneSettings.Analyzers == null) { serverConfig.CacheSettings.LuceneSettings.Analyzers = new Analyzers(); serverConfig.CacheSettings.LuceneSettings.Analyzers.Providers = prov; } prov = serverConfig.CacheSettings.LuceneSettings.Analyzers.Providers; serverConfig.CacheSettings.LuceneSettings.Analyzers.Providers = GetAnalyzers(GetProvider(prov, asm)); } byte[] userId = null; byte[] paswd = null; if (UserId != string.Empty && Password != string.Empty) { userId = EncryptionUtil.Encrypt(UserId); paswd = EncryptionUtil.Encrypt(Password); } serverConfig.ConfigVersion++; if (serverConfig.CacheSettings.CacheType == "clustered-cache") { foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes()) { NCache.ServerName = node.IpAddress.ToString(); try { cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (cacheServer.IsRunning(CacheName)) { throw new Exception(CacheName + " is Running on " + serverName + "\nStop the cache first and try again."); } OutputProvider.WriteLine("Adding Analyzer on node '{0}' to cache '{1}'.", node.IpAddress, CacheName); cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false); } catch (Exception ex) { OutputProvider.WriteErrorLine("Failed to Lucene Analyzer on node '{0}'. ", serverName); OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message); failedNodes = failedNodes + "/n" + node.IpAddress.ToString(); successFull = false; } finally { cacheServer.Dispose(); } } } else { try { OutputProvider.WriteLine("Adding Analyzer on node '{0}' to cache '{1}'.", serverName, CacheName); cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false); } catch (Exception ex) { OutputProvider.WriteErrorLine("Failed to Lucene Analyzer on node '{0}'. ", serverName); OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message); successFull = false; } finally { NCache.Dispose(); } } } } catch (Exception e) { successFull = false; OutputProvider.WriteErrorLine("Failed to Lucene Analyzer on node '{0}'. ", NCache.ServerName); OutputProvider.WriteErrorLine("Error : {0}", e.Message); } finally { NCache.Dispose(); if (successFull && !IsUsage) { OutputProvider.WriteLine("Analyzer successfully added"); } } }
/// <summary> /// The main entry point for the tool. /// </summary> public void SetBridgeCacheConnection() { try { _bridgeService = new NCBridgeRPCService(BridgeServer); _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); if (!ValidateParameters()) { return; } //********************************** //cacheServer = GetCacheServers(config.Cluster.GetAllConfiguredNodes()); bool isNotMaster = false; int passiveCount = 0; bool cacheExists = false; TargetCacheCofiguration targtCacheConfig = null; if (_bridgeServer != null) { try { OutputProvider.WriteLine("Setting Cache '{0}' Connection To Bridge '{1}' on {2}:{3}.", CacheName, BridgeId, _bridgeService.ServerName, _bridgeService.Port); Alachisoft.NCache.Bridging.Configuration.BridgeConfiguration bridgeConfig = _bridgeServer.GetBridgeConfiguration(BridgeId); ToolsUtil.VerifyBridgeConfigurations(bridgeConfig, BridgeId); List <TargetCacheCofiguration> previouslyAddedCaches = bridgeConfig.TargetCacheConfigList; if (previouslyAddedCaches.Count >= 1) { //checking validations regarding bridge foreach (TargetCacheCofiguration pCache in previouslyAddedCaches) { if (pCache.CacheID.ToLower().Equals(CacheName.ToLower())) { cacheExists = true; isNotMaster = !pCache.IsMaster; targtCacheConfig = pCache; } if (pCache.Status.Equals("passive")) { passiveCount++; } } } else { OutputProvider.WriteErrorLine("No Cache Exists in Bridge {0}", BridgeId); return; } if (previouslyAddedCaches.Count == 2 && !isNotMaster && cacheExists && Connection.ToString().ToLower().Equals("disconnect")) { OutputProvider.WriteErrorLine("Master Cache '{0}'cannot be disconnected,please change the master cache First", CacheName); return; } if (!cacheExists) { OutputProvider.WriteErrorLine("No Cache Exists in Bridge {0} with CacheId {1}", BridgeId, CacheName); } WriteToBridgeConf(bridgeConfig, targtCacheConfig); OutputProvider.WriteLine("Bridge Connection for Bridge {0} set to {1} Successfully!", BridgeId, Connection.ToString()); } catch (SecurityException e) { OutputProvider.WriteErrorLine("Failed to Set Cache Connection Status to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } catch (Exception e) { OutputProvider.WriteErrorLine("Failed to Set Cache Connection Status to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error: {0}", e.Message); } finally { if (_bridgeService != null) { _bridgeService.Dispose(); } } }
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); }
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; } }