/// <summary> /// The main entry point for the tool. /// </summary> public static 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(); } }
/// <summary> /// Creates and returns an instance of NCache. /// </summary> /// <param name="data"></param> /// <param name="timeout"></param> /// <returns>A reference to <see cref="Cache"/> object.</returns> private static Cache ConnectCacheInstance(CacheConfig data, TimeSpan timeout) { CacheService ncache; ncache = new NCacheRPCService(data.ServerName, (int)data.Port); try { ncache.UseTcp = data.UseTcp; ncache.ServerName = data.ServerName; ncache.Port = data.Port; if(ncache.ServerName == null || ncache.ServerName.Length < 1 || ncache.ServerName.CompareTo(".") == 0 || ncache.ServerName.CompareTo("localhost") == 0) { ncache.ServerName = Environment.MachineName; } } catch(Exception) { throw; } finally { ncache.Dispose(); } return null; }
/// <summary> /// initilaise /// </summary> protected virtual void Initialize() { CacheService cacheService = null; cacheService = new NCacheRPCService(_address, _port); try { _server = cacheService.GetCacheServer(TimeSpan.FromSeconds(7)); } finally { cacheService.Dispose(); } }