public static void StartCache(string cacheId) { CacheService cacheService = new NCacheRPCService(null); ICacheServer cs = null; try { cacheService.ServerName = Environment.MachineName; cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (cs != null) { cs.StartCache(cacheId); } } catch (Exception ex) { throw new ManagementException(ex.Message); } finally { if (cs != null) { cs.Dispose(); } cacheService.Dispose(); } }
public static void StartCache(string cacheId, string serverName, int port, string userId, string password) { ICacheServer cs = null; CacheService cacheService = new NCacheRPCService(null); CacheServerConfig config = null; try { cacheService.ServerName = serverName; cacheService.Port = port; cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (cs != null) { config = cs.GetCacheConfiguration(cacheId); if (config != null) { if (!config.InProc) { cs.StartCache(cacheId); } } else { throw new ManagementException("Unable to Start Cache. Specified cache is not registered."); } } } 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(); } }
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(); } }
/// <summary> /// The main entry point for the tool. /// </summary> static public void Run(string[] args) { NCache = new NCacheRPCService(""); string cacheIp = string.Empty; try { object param = new StartCacheToolParam(); CommandLineArgumentParser.CommandLineParser(ref param, args); cParam = (StartCacheToolParam)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)); CacheServerConfig config = null; cacheIp = m.GetClusterIP(); if (m != null) { foreach (string cache in s_cacheId) { try { config = m.GetCacheConfiguration((string)cache); if (config != null && config.InProc) { throw new Exception("InProc caches cannot be started explicitly."); } Console.WriteLine("\nStarting cache '{0}' on server {1}:{2}.", cache, cacheIp, NCache.Port); m.StartCache(cache, string.Empty); Console.WriteLine("'{0}' successfully started on server {1}:{2}.\n", cache, cacheIp, NCache.Port); } catch (Exception e) { Console.Error.WriteLine("Failed to start '{0}' on server {1}.", cache, cacheIp); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString() + "\n"); } } } } catch (ManagementException ex) { Console.Error.WriteLine("Error : {0}", "NCache service could not be contacted on server."); Console.Error.WriteLine(); Console.Error.WriteLine(ex.ToString()); } catch (Exception e) { Console.Error.WriteLine("Error : {0}", e.Message); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); } finally { NCache.Dispose(); } }