private static string ToXml(MappingConfiguration.Dom.MappingConfiguration config)
 {
     StringBuilder sb = new StringBuilder();
     object[] configuration = new object[1];
     configuration[0] = config;
     ConfigurationBuilder cfgBuilder = new ConfigurationBuilder(configuration);
     cfgBuilder.RegisterRootConfigurationObject(typeof(ClientConfiguration.Dom.ClientConfiguration));
     sb.Append(cfgBuilder.GetXmlString());
     return sb.ToString();
 }
        private static string ToXml()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

                sb.Append(ENDSTRING + "<!-- Client configuration file is used by client to connect to out-proc caches. " +
                    ENDSTRING + "This file is automatically generated each time a new cache/cluster is created or " +
                    ENDSTRING + "cache/cluster configuration settings are applied." +
                    ENDSTRING + "-->");


            sb.Append("\n");

            object[] configuration = new object[1];
            configuration[0] = _configuration;
            ConfigurationBuilder cfgBuilder = new ConfigurationBuilder(configuration);
            cfgBuilder.RegisterRootConfigurationObject(typeof(ClientConfiguration.Dom.ClientConfiguration));
            sb.Append(cfgBuilder.GetXmlString());

            return sb.ToString();
        }
 /// <summary>
 /// Save the configuration
 /// </summary>
 /// <param name="configuration"></param>
 public static void SaveConfiguration(object[] configuration)
 {
     StringBuilder xml = new StringBuilder();
     xml.Append("<configuration>\r\n");
     if (configuration != null && configuration.Length > 0)
     {
         ConfigurationBuilder builder = new ConfigurationBuilder(configuration);
         builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
         xml.Append(builder.GetXmlString());
     }
     xml.Append("\r\n</configuration>");
     WriteXmlToFile(xml.ToString());
 }
Beispiel #4
0
        /// <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();
            }
        }