コード例 #1
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            string       failedNodes = string.Empty;
            ICacheServer cacheServer = null;

            try
            {
                object param = new GetCacheConfigurationParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                ccParam = (GetCacheConfigurationParam)param;

                if (ccParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(ccParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }

                string _filename = null;
                string _path     = null;
                if (ccParam.Path != null && ccParam.Path != string.Empty)
                {
                    if (!Path.HasExtension(ccParam.Path))
                    {
                        _filename    = ccParam.CacheId + ".ncconf";
                        ccParam.Path = ccParam.Path + "\\" + _filename;
                    }
                }
                else
                {
                    ccParam.Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                    _filename    = ccParam.CacheId + ".ncconf";
                    ccParam.Path = ccParam.Path + "\\" + _filename;
                }

                if (ccParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (!string.IsNullOrEmpty(ccParam.Server))
                {
                    NCache.ServerName = ccParam.Server;
                }
                else
                {
                    NCache.ServerName = System.Environment.MachineName;
                }

                if (ccParam.Port != -1)
                {
                    NCache.Port = ccParam.Port;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                if (cacheServer != null)
                {
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(ccParam.CacheId);

                    if (serverConfig == null)
                    {
                        throw new Exception("Specified cache is not registered on given server.");
                    }

                    serverConfig.CacheDeployment = null;

                    Console.WriteLine("Creating configuration for cache '{0}' registered on server '{1}:{2}'.", ccParam.CacheId, NCache.ServerName, NCache.Port);

                    StringBuilder xml = new StringBuilder();
                    List <Alachisoft.NCache.Config.NewDom.CacheServerConfig> configurations = new List <Alachisoft.NCache.Config.NewDom.CacheServerConfig>();
                    configurations.Add(serverConfig);
                    ConfigurationBuilder builder = new ConfigurationBuilder(configurations.ToArray());
                    builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                    xml.Append(builder.GetXmlString());
                    WriteXmlToFile(xml.ToString());

                    Console.WriteLine("Cache configuration saved successfully at " + ccParam.Path + ".");
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error : {0}", e.Message);
            }
            finally
            {
                NCache.Dispose();
                if (cacheServer != null)
                {
                    cacheServer.Dispose();
                }
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: javithalion/NCache
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        public static void Run(string[] args)
        {
            string failedNodes = string.Empty;
            ICacheServer cacheServer = null;

            try
            {
                object param = new GetCacheConfigurationParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                ccParam = (GetCacheConfigurationParam)param;

                if (ccParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(ccParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters()) return;

                string _filename = null;
                string _path = null;
                if (ccParam.Path != null && ccParam.Path != string.Empty)
                {
                    if (!Path.HasExtension(ccParam.Path))
                    {

                        _filename = ccParam.CacheId + ".ncconf";
                        ccParam.Path = ccParam.Path + "\\" + _filename;
                    }
                }
                else
                {
                    ccParam.Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                    _filename = ccParam.CacheId + ".ncconf";
                    ccParam.Path = ccParam.Path + "\\" + _filename;
                }

                if (ccParam.Port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                if (!string.IsNullOrEmpty(ccParam.Server))
                {
                    NCache.ServerName = ccParam.Server;
                }
                else
                    NCache.ServerName = System.Environment.MachineName;

                if (ccParam.Port != -1)
                {
                    NCache.Port = ccParam.Port;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                if (cacheServer != null)
                {
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(ccParam.CacheId);

                    if (serverConfig == null) throw new Exception("Specified cache is not registered on given server.");

                    serverConfig.CacheDeployment = null;

                    Console.WriteLine("Creating configuration for cache '{0}' registered on server '{1}:{2}'.", ccParam.CacheId, NCache.ServerName, NCache.Port);

                    StringBuilder xml = new StringBuilder();
                    List<Alachisoft.NCache.Config.NewDom.CacheServerConfig> configurations = new List<Alachisoft.NCache.Config.NewDom.CacheServerConfig>();
                    configurations.Add(serverConfig);
                    ConfigurationBuilder builder = new ConfigurationBuilder(configurations.ToArray());
                    builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                    xml.Append(builder.GetXmlString());
                    WriteXmlToFile(xml.ToString());

                    Console.WriteLine("Cache configuration saved successfully at " + ccParam.Path + ".");
                }

            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error : {0}", e.Message);
            }
            finally
            {
                NCache.Dispose();
                if ( cacheServer != null )
                    cacheServer.Dispose();
            }
        }