/// <summary> /// The main entry point for the tool. /// </summary>ju static public void Run(string[] args) { System.Reflection.Assembly asm = null; Alachisoft.NCache.Config.Dom.Class[] queryClasses = null; string failedNodes = string.Empty; bool sucessful = false; string serverName = string.Empty; try { object param = new RemoveQueryIndexParam(); CommandLineArgumentParser.CommandLineParser(ref param, args); cParam = (RemoveQueryIndexParam)param; if (cParam.IsUsage) { AssemblyUsage.PrintLogo(cParam.IsLogo); AssemblyUsage.PrintUsage(); return; } if (!ValidateParameters()) { return; } if (cParam.Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } if (cParam.Server != null && cParam.Server != string.Empty) { NCache.ServerName = cParam.Server; } if (cParam.Port != -1) { NCache.Port = cParam.Port; } cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (cacheServer != null) { Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(cParam.CacheId); serverName = cacheServer.GetClusterIP(); if (cacheServer.IsRunning(cParam.CacheId)) { throw new Exception(cParam.CacheId + " is Running on " + serverName + "Stop the cache first."); } if (serverConfig == null) { throw new Exception("Specified cache is not registered on given server."); } Console.WriteLine("Removing query indexes on node '{0}' from cache '{1}'.", serverName, cParam.CacheId); if (serverConfig.CacheSettings.QueryIndices != null) { if (serverConfig.CacheSettings.QueryIndices.Classes != null) { queryClasses = serverConfig.CacheSettings.QueryIndices.Classes; } else { return; } if (queryClasses != null) { serverConfig.CacheSettings.QueryIndices.Classes = GetSourceClass(GetClass(queryClasses)); if (serverConfig.CacheSettings.QueryIndices.Classes != null) { for (int i = 0; i < serverConfig.CacheSettings.QueryIndices.Classes.Length; i++) { if (serverConfig.CacheSettings.QueryIndices.Classes[i].AttributesTable.Count < 1) { serverConfig.CacheSettings.QueryIndices.Classes[i] = null; } } bool NoClasses = true; foreach (Class cls in serverConfig.CacheSettings.QueryIndices.Classes) { if (cls != null) { NoClasses = false; break; } } if (NoClasses) { serverConfig.CacheSettings.QueryIndices = null; } } else { } } } else { throw new Exception("No such Query Index class found. "); return; } 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(cParam.CacheId)) { throw new Exception(cParam.CacheId + " is Running on " + serverName + "Stop the cache first."); } cacheServer.RegisterCache(cParam.CacheId, serverConfig, "", true, cParam.IsHotApply); } catch (Exception ex) { Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message); failedNodes = failedNodes + "/n" + node.IpAddress.ToString(); LogEvent(ex.Message); sucessful = false; } finally { cacheServer.Dispose(); } } } else { try { cacheServer.RegisterCache(cParam.CacheId, serverConfig, "", true, cParam.IsHotApply); } catch (Exception ex) { Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message); LogEvent(ex.Message); sucessful = false; } finally { cacheServer.Dispose(); } } } sucessful = true; } catch (Exception e) { Console.Error.WriteLine("Failed to Remove Query Index on node '{0}'. ", serverName); Console.Error.WriteLine("Error : {0}", e.Message); LogEvent(e.Message); sucessful = false; } finally { NCache.Dispose(); if (sucessful && !cParam.IsUsage) { Console.WriteLine("Query indexes successfully removed."); } } }