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); }
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 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(); } } }
public void VerifyLicense() { ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); string ipAddress = "this machine"; ServerLicenseInfo serverLicenseInfo; try { if (string.IsNullOrEmpty(Server)) { serverLicenseInfo = new ServerLicenseInfo(); } else { NCache = new NCacheRPCService(""); NCache.Port = Port; NCache.ServerName = Server; ipAddress = Server; ICacheServer nCacheServer = null; nCacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (nCacheServer != null) { serverLicenseInfo = nCacheServer.GetServerLicenseInfo(); } else { serverLicenseInfo = new ServerLicenseInfo(); } } OutputProvider.WriteLine("This product is registered to "); OutputProvider.WriteLine("User: "******"Email: " + serverLicenseInfo._email); OutputProvider.WriteLine("Company: " + serverLicenseInfo._companyName); OutputProvider.WriteLine("Edition: " + "NCache OpenSource "); if (LicenseManager.LicenseMode(null) == LicenseManager.LicenseType.UnRegistered) { OutputProvider.WriteLine("\nThe machine does not have a valid registration information. Please register this machine with a FREE installation key.You can get free installation key from http://www.alachisoft.com/activate/RequestKey.php?Edition=NC-OSS-50-4x&Version=5.0&Source=Register-NCache"); OutputProvider.WriteLine("\nIf you are using this machine as NCache client, then you don't need to register NCache on this machine. Only cache server machines are required to be registered"); } else { OutputProvider.WriteLine(""); OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support."); } } catch (Exception ex) { OutputProvider.WriteLine(ex.ToString()); return; } OutputProvider.WriteLine("\n"); }
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(); } }
protected void DisplayTimeStamp() { string toolName = "Cache Client Statistics"; string timeStamp = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"); int length = toolName.Length + timeStamp.Length; string line = new string('-', length + 4); OutputProvider.WriteLine(toolName + " at " + timeStamp); OutputProvider.WriteLine(line); }
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 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 Hashtable GetClass(Alachisoft.NCache.Config.Dom.Class[] cl, System.Reflection.Assembly asm) { Hashtable hash = new Hashtable(); Hashtable att = new Hashtable(); Alachisoft.NCache.Config.Dom.Class c = new Alachisoft.NCache.Config.Dom.Class(); c.Name = Class; System.Type type = asm.GetType(Class, true); string assemblySrt = null; assemblySrt = asm.FullName;//= c.Assembly ; //cg String fullVersion = String.Empty; if (!String.IsNullOrEmpty(assemblySrt)) { String version = assemblySrt.Split(',')[1]; fullVersion = version.Split('=')[1]; } c.ID = Class; if (cl != null) { hash = ClassToHashtable(cl); } if (hash.Contains(c.Name)) { Class existingClass = (Class)hash[c.Name]; att = AttribToHashtable(existingClass.Attributes); } Hashtable attributeList = new Hashtable(); foreach (PropertyInfo pInfo in asm.GetType(Class).GetProperties()) { attributeList.Add(pInfo.Name, pInfo.Name); } c.Attributes = GetClassAttributes(attributeList, type); if (c.Attributes.Count() == 0) { OutputProvider.WriteLine("No indexable property exists in '{0}'", Class); _successful = false; } hash[c.Name] = c; return(hash); }
private void PrintCacheInfo(string schema, string cacheName, bool isRunning, int pId) { string schemeName = schema.ToLower(CultureInfo.CurrentCulture); string running = isRunning ? "Running" : "Stopped"; if (isRunning) { string processId = pId.ToString(); string status = string.Concat(running, "(", processId, ")"); OutputProvider.WriteLine("{0,-25} {1,-35} {2,-15}", cacheName, schemeName, status); } else { OutputProvider.WriteLine("{0,-25} {1,-35} {2,-15}", cacheName, schemeName, running); } }
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 void VerifyLicense() { ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); string ipAddress = "this machine"; ServerLicenseInfo serverLicenseInfo; try { if (string.IsNullOrEmpty(Server)) { serverLicenseInfo = new ServerLicenseInfo(); } else { NCache = new NCacheRPCService(""); NCache.Port = Port; NCache.ServerName = Server; ipAddress = Server; ICacheServer nCacheServer = null; nCacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (nCacheServer != null) { serverLicenseInfo = nCacheServer.GetServerLicenseInfo(); } else { serverLicenseInfo = new ServerLicenseInfo(); } } OutputProvider.WriteLine("This product is registered to "); OutputProvider.WriteLine("User: "******"Email: " + serverLicenseInfo._email); OutputProvider.WriteLine("Company: " + serverLicenseInfo._companyName); OutputProvider.WriteLine("Edition: " + "NCache OpenSource "); OutputProvider.WriteLine(""); OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support."); } catch (Exception ex) { OutputProvider.WriteLine(ex.ToString()); return; } OutputProvider.WriteLine("\n"); }
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 void VerifyLicense() { try { ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); PrintUserInfo(OutputProvider); OutputProvider.WriteLine("\n"); OutputProvider.WriteLine("Edition Installed: NCache 4.9 OpenSource Edition.\n"); OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support.\n"); } catch (Exception ex) { OutputProvider.WriteLine(ex.ToString()); return; } }
protected void StartStress() { try { adapter = new PowerShellAdapter(this); _taskManger = new TestStressManager(CacheName, ItemsCount, TestCaseIterations, TestCaseIterationDelay, GetsPerIteration, UpdatesPerIteration, DataSize, SlidingExpiration, ThreadCount, ReportingInterval, Server, printLogo, OutputProvider, adapter); _taskInstance = _taskManger; _taskManger.StartTasks(); } catch (Exception e) { if (OutputProvider != null) { OutputProvider.WriteLine(e.ToString()); OutputProvider.WriteLine(Environment.NewLine); } } }
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); }
private void DisplayHeaderRow(SortedDictionary <string, string[]> counters, bool hasReplica = false) { TimeZone timeZone = TimeZone.CurrentTimeZone; string name = string.Empty; string counterValue = string.Empty; StringBuilder sb = new StringBuilder(); ArrayList servers = serverList; TimeSpan timeSpan = new TimeSpan(); if (!hasReplica) { for (int i = 0; i < serverList.Count; i++) { foreach (var key in counters.Keys) { name = name + ",\"\\\\" + servers[i] + "\\" + "NCache" + "(" + CacheName + ")\\" + key + "\""; counterValue = "\"" + counterValue + ",\""; } } } else { for (int i = 0; i < serverList.Count; i++) { foreach (var key in counters.Keys) { name = name + ",\"\\\\" + servers[i] + "\\" + "NCache" + "(" + CacheName + ")\\" + key + "\""; counterValue = "\"" + counterValue + ",\""; } foreach (var key in counters.Keys) { name = name + ",\"\\\\" + servers[i] + "\\" + "NCache" + "(" + CacheName + "-replica" + ")\\" + key + "\""; counterValue = "\"" + counterValue + ",\""; } } } timeSpan = timeZone.GetUtcOffset(DateTime.Now); sb.Append("\"(PDH-CSV 4.0) (" + timeZone.StandardName + ") (" + timeSpan.TotalMinutes * -1 + ")\"" + name + ""); OutputProvider.WriteLine(sb); }
private void PrintDataMap(IDictionary <string, List <string> > map, string[] headers, int rowCount, string constantSpace = "") { if (map == null || headers == null || map.Count == 0 || headers.Length == 0 || rowCount < 0) { return; } var stringBuilder = new StringBuilder(10 * map.Count * rowCount); foreach (var header in headers) { stringBuilder .Append(header) .Append(constantSpace); } stringBuilder.AppendLine(); foreach (var header in headers) { stringBuilder .Append(new string('-', header.Length)) .Append(constantSpace); } stringBuilder.AppendLine(); for (var i = 0; i < rowCount; i++) { foreach (var header in headers) { stringBuilder .Append(map[header.Trim()][i]) .Append(constantSpace); } stringBuilder.AppendLine(); } OutputProvider.WriteLine(stringBuilder.ToString()); }
protected void DisplayinCSVFormat(SortedDictionary <string, string[]> counters) { StringBuilder sb = new StringBuilder(); if (!_headerRow) { DisplayHeaderRow(counters); } _headerRow = true; ArrayList servers = ClientList; string counterValue = string.Empty; 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 + ""); OutputProvider.WriteLine(sb); }
public void AddBridgeNode() { try { _bridgeService = new NCBridgeRPCService(Server); if (!ValidateParameters()) { return; } _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); BridgeConfiguration bconfig = _bridgeServer.GetBridgeConfiguration(BridgeId); ToolsUtil.VerifyBridgeConfigurations(bconfig, BridgeId); byte[] userId = null; byte[] paswd = null; if (UserId != string.Empty && Password != string.Empty) { userId = EncryptionUtil.Encrypt(UserId); paswd = EncryptionUtil.Encrypt(Password); } if (bconfig != null && bconfig.NumberOfBridgeNodes >= 2) { OutputProvider.WriteErrorLine("You cannot add more than 2 nodes in a Bridge"); return; } if (!bconfig.GetBridgeNodeList().Contains(NewBridgeNode)) { if (bconfig.GetBridgeNodeList().Count != 0) { bconfig.DeploymentVersion++; bconfig.BridgeNodes = bconfig.BridgeNodes + "," + NewBridgeNode; _bridgeServer.RegisterBridge(bconfig, true, false); //for registering bridge on newly added node NCBridgeRPCService _bridgeNewService = new NCBridgeRPCService(NewBridgeNode); IBridgeServer _bridgeNewServer = _bridgeNewService.GetBridgeServer(TimeSpan.FromSeconds(30)); _bridgeNewServer.RegisterBridge(bconfig, true, false); OutputProvider.WriteLine(NewBridgeNode + " added to " + BridgeId); } else { bconfig.BridgeNodes = NewBridgeNode; bconfig.BridgeActive = NewBridgeNode; NCBridgeRPCService _bridgeNewService = new NCBridgeRPCService(NewBridgeNode); IBridgeServer _bridgeNewServer = _bridgeNewService.GetBridgeServer(TimeSpan.FromSeconds(30)); _bridgeNewServer.RegisterBridge(bconfig, true, false); OutputProvider.WriteLine(NewBridgeNode + " added to " + BridgeId); } //updating target cache config if (bconfig.TargetCacheConfigList != null) { foreach (TargetCacheCofiguration targetCacheConfig in bconfig.TargetCacheConfigList) { try { if (targetCacheConfig != null) { foreach (string server in targetCacheConfig.Servers.Split(',')) { NCacheRPCService NCache = new NCacheRPCService(server);; ICacheServer cacheServer = null; cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); string cacheID = targetCacheConfig.CacheID.ToString(); CacheServerConfig serverConfig = cacheServer.GetCacheConfiguration(cacheID); if (serverConfig.Bridge != null) { serverConfig.Bridge.Servers = bconfig.BridgeNodes; } serverConfig.ConfigVersion++; cacheServer.ConfigureBridgeToCache(serverConfig, userId, paswd, false); } } } catch (Exception e) { OutputProvider.WriteErrorLine(e.Message); return; } } } } else { OutputProvider.WriteErrorLine("Error: Node already exists in bridge"); return; } } catch (Exception e) { OutputProvider.WriteErrorLine("Error: Bridge not registered on server.\n"); OutputProvider.WriteErrorLine(e.Message); } }
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); }
/// <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(); } } }
/// <summary> /// The main entry point for the tool. /// </summary> public void RemoveBridgeCache() { try { _bridgeService = new NCBridgeRPCService(BridgeServer); _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); NCacheRPCService nService = new NCacheRPCService(CacheServer); cacheServer = nService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (!ValidateParameters()) { return; } //********************************** config = cacheServer.GetCacheConfiguration(CacheName); if (config == null) { OutputProvider.WriteErrorLine("Error : The cache'{0}' does not exist on server {1}:{2} .", CacheName, NCache.ServerName, NCache.Port); return; } { //OutputProvider.WriteErrorLine("Error : The Bidge {0} is running on {1} , please stop Bridge and try again .", BridgeId, NCache.ServerName); //return; } if (config.CacheType.ToLower().Equals("local-cache")) { OutputProvider.WriteLine("Local Cache cannot be added as a bridge cache"); return; } //cacheServer = GetCacheServers(config.Cluster.GetAllConfiguredNodes()); if (_bridgeServer != null) { try { OutputProvider.WriteLine("Removing Cache To Bridge '{0}' on {1}:{2}.", BridgeId, _bridgeService.ServerName, _bridgeService.Port); Alachisoft.NCache.Bridging.Configuration.BridgeConfiguration bridgeConfig = _bridgeServer.GetBridgeConfiguration(BridgeId); ToolsUtil.VerifyBridgeConfigurations(bridgeConfig, BridgeId); if (bridgeConfig == null) { OutputProvider.WriteErrorLine("No Bridge with Bridge ID '{0} exists' on Server {1}:{2}.", BridgeId, _bridgeService.ServerName, _bridgeService.Port); return; } TargetCacheCofiguration targtCacheConfig = new TargetCacheCofiguration(); targtCacheConfig.CacheID = CacheName; targtCacheConfig.Servers = cacheServer.GetHostName(); targtCacheConfig.IsConnected = true; { if (!VerifyBridgeMasterCache(BridgeId, false, bridgeConfig)) { targtCacheConfig.IsMaster = true; } targtCacheConfig.Status = BridgeCacheStateParam.Active.ToString(); } List <TargetCacheCofiguration> previouslyAddedCaches = bridgeConfig.TargetCacheConfigList; int removedCacheIndex = -1; if (previouslyAddedCaches.Count >= 1) { int iteration = 0; //checking validations regarding bridge foreach (TargetCacheCofiguration pCache in previouslyAddedCaches) { //if exists than remove if (pCache.CacheID.ToLower().Equals(CacheName.ToLower())) { if (pCache.CacheAlias.ToLower().Equals(Alias.ToLower()) || string.IsNullOrEmpty(Alias)) { removedCacheIndex = iteration; if (pCache.IsMaster) { OutputProvider.WriteErrorLine("Failed to Remove Cache to bridge '{0}'. Error: Master cache cannot be removed ", BridgeId); return; } } } if (pCache.Status.Equals("passive")) { OutputProvider.WriteErrorLine("Failed to Remove Cache to bridge '{0}'. Error: No both bridge caches can be passive ", BridgeId); return; } iteration++; } } else { OutputProvider.WriteErrorLine("Failed to Remove Cache There is currently no Cache Added in Bridge {0} ", BridgeId); return; } // if (removedCacheIndex >= 0) { bridgeConfig.TargetCacheConfigList.RemoveAt(removedCacheIndex); } else { OutputProvider.WriteErrorLine("Bridge Cache Does not exists with name{0} in Bridge '{1}'", CacheName, BridgeId); return; } //Adding Bridge to config.ncconf BridgeConfig bridgeConf = config.Bridge; config.Bridge = null; byte[] userId = null; byte[] paswd = null; if (UserId != string.Empty && Password != string.Empty) { userId = EncryptionUtil.Encrypt(UserId); paswd = EncryptionUtil.Encrypt(Password); } //writing to config.ncconf config.ConfigVersion++; cacheServer.ConfigureBridgeToCache(config, userId, paswd, true); cacheServer.HotApplyBridgeReplicator(CacheName, false); ConveyToRegisteredNodes(); char[] separater = { ',' }; // write in all bridge nodes bridge.nconnf file bool write = false; foreach (string bridgeIp in bridgeConfig.BridgeNodes.Split(separater).ToList()) { try{ _bridgeService = new NCBridgeRPCService(bridgeIp); _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); _bridgeServer.RegisterBridge(bridgeConfig, true, true); write = true; OutputProvider.WriteLine("Removed Bridge Cache {0} From Bridge {1}", CacheName, BridgeId); } catch (Exception e) { OutputProvider.WriteErrorLine("Removing Bridge Cache {0} From Bridge Server{1} Gives Error: {2}", bridgeConf, bridgeIp, e.Message); } } } catch (SecurityException e) { OutputProvider.WriteErrorLine("Failed to Remove Cache to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } catch (Exception e) { OutputProvider.WriteErrorLine("Failed to Remove Cache to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error: {0}", e.Message); } finally { if (_bridgeService != null) { _bridgeService.Dispose(); } if (NCache != null) { NCache.Dispose(); } } }
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(); } }
private void AddLuceneQueryIndexDefaults() { if (!ValidateParameters()) { return; } bool successful = true; AssemblyDef asm = null; //ArrayList cc = new ArrayList(); Alachisoft.NCache.Config.Dom.Class[] queryClasses = null; string failedNodes = string.Empty; string serverName = string.Empty; try { if (Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } if (Server != null && Server != string.Empty) { NCache.ServerName = Server; } if (Port != -1) { NCache.Port = Port; } 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; } ToolsUtil.VerifyClusterConfigurations(cacheServer.GetNewConfiguration(CacheName), CacheName); string extension = ".dll"; if (cacheServer != null) { serverName = cacheServer.GetClusterIP(); if (cacheServer.IsRunning(CacheName)) { throw new Exception(CacheName + " is Running on " + serverName + "\nStop the cache first and try again."); } serverConfig = cacheServer.GetNewConfiguration(CacheName); //ConfiguredCacheInfo[] configuredCaches = cacheServer.GetAllConfiguredCaches(); if (serverConfig == null) { throw new Exception("Specified cache is not registered on the given server."); } //if (! Unregister) //{ try { asm = AssemblyDef.LoadFrom(AssemblyPath); extension = Path.GetExtension(asm.FullName); } catch (Exception e) { string message = string.Format("Could not load assembly \"" + AssemblyPath + "\". {0}", e.Message); OutputProvider.WriteErrorLine("Error : {0}", message); successful = false; return; } if (asm == null) { throw new Exception("Could not load specified Assembly"); } TypeDef type = asm.GetType(Class); if (serverConfig.CacheSettings.QueryIndices == null) { serverConfig.CacheSettings.QueryIndices = new Alachisoft.NCache.Config.Dom.QueryIndex(); serverConfig.CacheSettings.QueryIndices.Classes = queryClasses; } queryClasses = serverConfig.CacheSettings.QueryIndices.Classes; serverConfig.CacheSettings.QueryIndices.Classes = GetSourceClass(GetClass(queryClasses, 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 query indexes on node '{0}' to cache '{1}'.", node.IpAddress, CacheName); cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false); } catch (Exception ex) { OutputProvider.WriteErrorLine("Failed to Add Query Index on '{0}'. ", serverName); OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message); failedNodes = failedNodes + "/n" + node.IpAddress.ToString(); successful = false; } finally { cacheServer.Dispose(); } } } else { try { OutputProvider.WriteLine("Adding query indexes on node '{0}' to cache '{1}'.", serverName, CacheName); cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false); } catch (Exception ex) { OutputProvider.WriteErrorLine("Failed to Add Query Index on '{0}'. ", serverName); OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message); successful = false; } finally { cacheServer.Dispose(); } } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error : {0}", e.Message); successful = false; } finally { NCache.Dispose(); if (successful && !IsUsage) { OutputProvider.WriteLine("Query indexes successfully added."); } } }
public void GenerateQueryIndex() { if (!ValidateParameters()) { return; } System.Reflection.Assembly asm = null; Alachisoft.NCache.Config.Dom.Class[] queryClasses = null; string failedNodes = string.Empty; string serverName = string.Empty; try { string extension = ".dll"; try { asm = System.Reflection.Assembly.LoadFrom(AssemblyPath); extension = Path.GetExtension(asm.FullName); } catch (Exception e) { string message = string.Format("Could not load assembly \"" + AssemblyPath + "\". {0}", e.Message); OutputProvider.WriteErrorLine("Error : {0}", message); _successful = false; return; } if (asm == null) { throw new Exception("Could not load specified Assembly"); } System.Type type = asm.GetType(Class, true); QueryIndex queryIndices = new QueryIndex(); queryIndices.Classes = GetSourceClass(GetClass(queryClasses, asm)); ConfigurationBuilder cfg = new ConfigurationBuilder(); string configurationString = cfg.GetSectionXml(queryIndices, "query-indexes", 1); if (OutputFile == null || OutputFile.Equals(string.Empty)) { if (_successful) { OutputProvider.WriteLine(configurationString); } } else { WriteXmlToFile(configurationString); if (_successful) { OutputProvider.WriteLine("Query Indexes generated for Class '{0}' at {1}", Class, OutputFile); } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error : {0}", e.Message); _successful = false; } finally { OutputProvider.WriteLine(Environment.NewLine); } }
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(); } }
private void PrintDetailedCacheInfo(CacheStatistics s, string topology, string partId, bool isRunning, string cacheName, string configString, string pid) { long MaxSize = 0; string schemeName = topology; bool running = isRunning; OutputProvider.WriteLine("Cache-Name:\t\t{0}", cacheName); OutputProvider.WriteLine("Topology:\t\t{0} ", schemeName); if (running) { OutputProvider.WriteLine("UpTime: " + s.UpTime); if (s.MaxSize != 0) { OutputProvider.WriteLine("Capacity: " + ((s.MaxSize / 1024) / 1024) + " MB"); } else { OutputProvider.WriteLine("Capacity: " + MaxSize + "MB"); } OutputProvider.WriteLine("Item Count: " + s.Count); } OutputProvider.WriteLine("Status:\t\t\t{0}", isRunning ? "Running" : "Stopped"); if (running) { OutputProvider.WriteLine("Process-ID:\t\t{0}", pid); if (s is ClusterCacheStatistics) { System.Text.StringBuilder nodes = new System.Text.StringBuilder(); ClusterCacheStatistics cs = s as ClusterCacheStatistics; OutputProvider.WriteLine("Cluster-size: " + cs.Nodes.Count); MaxSize = (cs.LocalNode.Statistics.MaxSize / 1024) / 1024; foreach (NodeInfo n in cs.Nodes) { nodes.Append(" ").Append(n.Address).Append("\n"); } OutputProvider.WriteLine("{0}", nodes.ToString()); if (partId != null && partId != string.Empty) { if (cs.SubgroupNodes != null && cs.SubgroupNodes.Contains(partId.ToLower())) { nodes = new System.Text.StringBuilder(); ArrayList groupNodes = cs.SubgroupNodes[partId.ToLower()] as ArrayList; OutputProvider.WriteLine("Partition-size: " + groupNodes.Count); foreach (Address address in groupNodes) { nodes.Append(" ").Append(address).Append("\n"); } } OutputProvider.WriteLine("{0}", nodes.ToString()); } } else { OutputProvider.WriteLine(""); } } else { OutputProvider.WriteLine(""); } }
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"); } } }
private void AddLuceneStopWords() { if (!ValidateParameters()) { return; } System.IO.FileInfo fInfo = 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 { fInfo = new System.IO.FileInfo(FilePath); } catch (Exception e) { successFull = false; string message = string.Format("Could not load file \"" + FilePath + "\". {0}", e.Message); OutputProvider.WriteErrorLine("Error: {0}", message); return; } if (serverConfig.CacheSettings.LuceneSettings == null) { serverConfig.CacheSettings.LuceneSettings = new Alachisoft.NCache.Config.Dom.LuceneSettings(); } if (fInfo.Extension != ".txt") { successFull = false; string message = string.Format("\"" + FilePath + "\" is not a Text file. {0}"); OutputProvider.WriteErrorLine("Error: {0}", message); return; } if (serverConfig.CacheSettings.LuceneSettings.StopWordFiles == null) { serverConfig.CacheSettings.LuceneSettings.StopWordFiles = new StopWords(); } if (serverConfig.CacheSettings.LuceneSettings.StopWordFiles.Providers != null) { prov = serverConfig.CacheSettings.LuceneSettings.StopWordFiles.Providers; } serverConfig.CacheSettings.LuceneSettings.StopWordFiles.Providers = GetStopWords(GetProvider(prov, fInfo)); 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 Lucene Stop Words file on node '{0}' to cache '{1}'.", node.IpAddress, CacheName); cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false); } catch (Exception ex) { OutputProvider.WriteErrorLine("Failed to Add Lucene Stop Words file on '{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 Lucene Stop Words file on node '{0}' to cache '{1}'.", serverName, CacheName); cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false); } catch (Exception ex) { OutputProvider.WriteErrorLine("Failed to Add Lucene Stop Words file on '{0}'. ", serverName); OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message); successFull = false; } finally { NCache.Dispose(); if (successFull && !IsUsage) { OutputProvider.WriteLine("Stop words file successfully added"); } } } } } catch (Exception) { successFull = false; throw; } finally { NCache.Dispose(); if (successFull && !IsUsage) { OutputProvider.WriteLine("Stop words file successfully added"); } } }