private ConfigurationManager()
        {


            string appID = System.Configuration.ConfigurationManager.AppSettings["ncache.application_id"];
            if(string.IsNullOrEmpty(appID))
                throw new ConfigurationException("ncache.application-id not specified in app.config/web.config file");

            string configFilePath = this.GetFilePath("NCacheNHibernate.xml");



            ConfigurationBuilder configBuilder = new ConfigurationBuilder(configFilePath);
            configBuilder.RegisterRootConfigurationObject(typeof(ApplicationConfiguration));
            configBuilder.ReadConfiguration();

            Object[] configuration = configBuilder.Configuration;

            bool appConfigFound = false;
            if (configuration != null && configuration.Length > 0)
            {
                for (int i = 0; i < configuration.Length; i++)
                {
                    _appConfig = configuration[i] as ApplicationConfiguration;
                    if(_appConfig!=null)
                    if (!string.IsNullOrEmpty(_appConfig.ApplicationID) && _appConfig.ApplicationID.ToLower() == appID.ToLower())
                    {
                        appConfigFound = true;
                        break;
                    }
                }
            }
            
            if (!appConfigFound)
                throw new ConfigurationException("Invalid value of NCache.application_id. Applicaion configuration not found for application-id = " + appID);
            if (string.IsNullOrEmpty(_appConfig.DefaultRegion))
                throw new Alachisoft.NCache.Runtime.Exceptions.ConfigurationException("default-region cannot be null for application-id = " + _appConfig.ApplicationID);
            
            _regionConfigManager = new RegionConfigurationManager(_appConfig.CacheRegions);
            if (!_regionConfigManager.Contains(_appConfig.DefaultRegion))

                throw new Alachisoft.NCache.Runtime.Exceptions.ConfigurationException("Region's configuration not specified for default-region : "+_appConfig.DefaultRegion);

        }
        private static MappingConfiguration.Dom.MappingConfiguration LoadXml()
        {
            MappingConfiguration.Dom.MappingConfiguration config= null;
            lock (_syncRoot)
            {
                if (String.IsNullOrEmpty(m_configFileName))
                    CombinePath();
                try
                {
                    ConfigurationBuilder configBuilder = new ConfigurationBuilder(m_configFileName);
                    configBuilder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Management.MappingConfiguration.Dom.MappingConfiguration));
                    configBuilder.ReadConfiguration();

                    MappingConfiguration.Dom.MappingConfiguration mappingConfiguration = null;
                    Object[] configuration = configBuilder.Configuration;

                    if (configuration != null && configuration.Length > 0)
                    {
                        for (int i = 0; i < configuration.Length; i++)
                        {
                            mappingConfiguration = configuration[i] as MappingConfiguration.Dom.MappingConfiguration;
                            break;
                        }
                    }

                    config = mappingConfiguration;
                }
                catch (Exception)
                { }

                if (config == null)
                    config = new Alachisoft.NCache.Management.MappingConfiguration.Dom.MappingConfiguration();

                if (config.ManagementIPMapping == null)
                    config.ManagementIPMapping = new ServerMapping();

                if (config.ClientIPMapping == null)
                    config.ClientIPMapping = new ServerMapping();
            }
            return config;
        }
示例#3
0
        /// <summary>
        /// Loads and returns all cache configurations from the configuration file.
        /// </summary>
        static public CacheServerConfig[] GetConfiguredCaches()
        {
            if (FileName.Length == 0)
            {
                throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt.");
            }
            try
            {
                ConfigurationBuilder builder = new ConfigurationBuilder(FileName);
                builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                builder.ReadConfiguration();
                Alachisoft.NCache.Config.NewDom.CacheServerConfig[] newCaches = new Alachisoft.NCache.Config.NewDom.CacheServerConfig[builder.Configuration.Length];
                builder.Configuration.CopyTo(newCaches, 0);

                return convertToOldDom(newCaches);
            }
            catch (ManagementException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
        }
示例#4
0
 private static void LoadConfig(string fileName, ref Hashtable properties)
 {
     ConfigurationBuilder builder = new ConfigurationBuilder(fileName);
     builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
     builder.ReadConfiguration();
     Alachisoft.NCache.Config.NewDom.CacheServerConfig[] newCaches = new NewDom.CacheServerConfig[builder.Configuration.Length];
     builder.Configuration.CopyTo(newCaches, 0);
     properties = ConfigConverter.ToHashtable(convertToOldDom(newCaches));
 }
示例#5
0
        private static CacheServerConfig[] LoadConfig(string fileName)
        {
            ConfigurationBuilder builder = new ConfigurationBuilder(fileName);
            builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
            builder.ReadConfiguration();
            Alachisoft.NCache.Config.NewDom.CacheServerConfig[] newCaches = new Alachisoft.NCache.Config.NewDom.CacheServerConfig[builder.Configuration.Length];
            builder.Configuration.CopyTo(newCaches, 0);

            return convertToOldDom(newCaches);
        }
示例#6
0
        private static void LoadXml()
        {
            if (String.IsNullOrEmpty(c_configFileName))
                CombinePath();

            ConfigurationBuilder configBuilder = new ConfigurationBuilder(c_configFileName);
            configBuilder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Management.ClientConfiguration.Dom.ClientConfiguration));
            configBuilder.ReadConfiguration();

            ClientConfiguration.Dom.ClientConfiguration clientConfiguration = null;
            Object[] configuration = configBuilder.Configuration;

            if (configuration != null && configuration.Length > 0)
            {
                for (int i = 0; i < configuration.Length; i++)
                {
                    clientConfiguration = configuration[i] as ClientConfiguration.Dom.ClientConfiguration;
                    break;
                }
            }

            _configuration = clientConfiguration;

            if (_configuration == null)
                _configuration = new Alachisoft.NCache.Management.ClientConfiguration.Dom.ClientConfiguration();

            if (_configuration.NodeConfiguration == null)
                _configuration.NodeConfiguration = new NodeConfiguration();



            _configuration.BindIp = BindIP;
        }
示例#7
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        public static void Run(string[] args)
        {
            string failedNodes = string.Empty;
            NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
            Alachisoft.NCache.Config.NewDom.CacheServerConfig[] caches = null;
            ICacheServer cacheServer = null;
            Alachisoft.NCache.Config.NewDom.CacheServerConfig _cacheConfig = null;

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

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

                if (!ValidateParameters()) return;

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

                if (ccParam.Port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;

                if (ccParam.Path != null && ccParam.Path != string.Empty)
                {
                    if (Path.HasExtension(ccParam.Path))
                    {
                        string extension = Path.GetExtension(ccParam.Path);

                        if (!extension.Equals(".ncconf") && !extension.Equals(".xml"))
                        {
                            throw new Exception("Incorrect file format. Only .ncconf and .xml are supported.");
                        }
                    }
                    else
                        throw new Exception("Incorrect configuration file path specified.");

                    ConfigurationBuilder builder = new ConfigurationBuilder(ccParam.Path);
                    builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                    builder.ReadConfiguration();

                    if (builder.Configuration != null)
                    {
                        caches = new Alachisoft.NCache.Config.NewDom.CacheServerConfig[builder.Configuration.Length];
                        builder.Configuration.CopyTo(caches, 0);
                    }
                    else
                        throw new Exception("Configuration cannot be loaded.");
                    ConfigurationValidator validator = new ConfigurationValidator();
                    bool _isConfigValidated = validator.ValidateConfiguration(caches);

                    _cacheConfig = caches[0];

                    if (_cacheConfig.CacheSettings.Name == null)
                        _cacheConfig.CacheSettings.Name = ccParam.CacheId;

                    if (_cacheConfig.CacheSettings.Storage == null || _cacheConfig.CacheSettings.Storage.Size == -1)
                    {
                        throw new Exception("Cache size is not specified.");
                    }

                    if (_cacheConfig.CacheSettings.EvictionPolicy == null)
                    {
                        _cacheConfig.CacheSettings.EvictionPolicy = new EvictionPolicy();
                        _cacheConfig.CacheSettings.EvictionPolicy.Policy = "priority";
                        _cacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = "normal";
                        _cacheConfig.CacheSettings.EvictionPolicy.EvictionRatio = 5;
                        _cacheConfig.CacheSettings.EvictionPolicy.Enabled = true;
                    }

                    if (_cacheConfig.CacheSettings.Cleanup == null)
                    {
                        _cacheConfig.CacheSettings.Cleanup = new Cleanup();
                        _cacheConfig.CacheSettings.Cleanup.Interval = 15;
                    }

                    if (_cacheConfig.CacheSettings.Log == null)
                    {
                        _cacheConfig.CacheSettings.Log = new Log();
                    }

                    if (_cacheConfig.CacheSettings.PerfCounters == null)
                    {
                        _cacheConfig.CacheSettings.PerfCounters = new PerfCounters();
                        _cacheConfig.CacheSettings.PerfCounters.Enabled = true;
                    }

                    if (_cacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings == null)
                        {
                            throw new Exception("Cluster settings not specified for the cluster cache.");
                        }

                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel == null)
                        {
                            throw new Exception("Cluster channel related settings not specified for cluster cache.");
                        }

                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort == -1)
                        {
                            throw new Exception("Cluster port not specified for cluster cache.");
                        }
                    }
                }
                else
                {
                    _SimpleCacheConfig.CacheSettings = new Alachisoft.NCache.Config.NewDom.CacheServerConfigSetting();
                    _SimpleCacheConfig.CacheSettings.Name = ccParam.CacheId;
                    _SimpleCacheConfig.CacheSettings.Storage = new Alachisoft.NCache.Config.Dom.Storage();
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy = new EvictionPolicy();
                    _SimpleCacheConfig.CacheSettings.Cleanup = new Cleanup();
                    _SimpleCacheConfig.CacheSettings.Log = new Log();
                    _SimpleCacheConfig.CacheSettings.PerfCounters = new PerfCounters();
                    _SimpleCacheConfig.CacheSettings.PerfCounters.Enabled = true;
                    _SimpleCacheConfig.CacheSettings.Storage.Type = "heap";
                    _SimpleCacheConfig.CacheSettings.Storage.Size = ccParam.CacheSize;
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.Policy = "priority";
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = "normal";
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.EvictionRatio = 5;
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled = false;
                    _SimpleCacheConfig.CacheSettings.Cleanup.Interval = 15;
                    _SimpleCacheConfig.CacheSettings.CacheTopology = new Alachisoft.NCache.Config.NewDom.CacheTopology();

                    if (string.IsNullOrEmpty(ccParam.Topology))
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.Topology = "Local";
                    }
                    else
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.Topology = ccParam.Topology;
                    }

                    if (ccParam.IsInProc && _SimpleCacheConfig.CacheSettings.CacheTopology.Topology.Equals("local-cache"))
                        _SimpleCacheConfig.CacheSettings.InProc = true;

                    if (_SimpleCacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings = new Alachisoft.NCache.Config.NewDom.Cluster();
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel = new Alachisoft.NCache.Config.NewDom.Channel();

                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort = ccParam.ClusterPort;
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.StatsRepInterval = 600;
                        if (_SimpleCacheConfig.CacheSettings.CacheTopology.Topology == "partitioned-replica")
                            _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.PortRange = 2;

                    }

                    if (ccParam.EvictionPolicy != null && ccParam.EvictionPolicy != string.Empty)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Policy = ccParam.EvictionPolicy;
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled = true;
                    }

                    if (ccParam.Ratio != -1)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.EvictionRatio = ccParam.Ratio;
                    }

                    if (ccParam.CleanupInterval != -1)
                    {
                        _SimpleCacheConfig.CacheSettings.Cleanup.Interval = ccParam.CleanupInterval;
                    }

                    if (ccParam.DefaultPriority != null && ccParam.DefaultPriority != string.Empty)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = ccParam.DefaultPriority;
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled = true;
                    }
                    _cacheConfig = _SimpleCacheConfig;
                }
                try
                {
                    _cacheConfig.CacheSettings.Name = ccParam.CacheId;

                    if (_cacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        if (_cacheConfig.CacheDeployment == null)
                        {
                            _cacheConfig.CacheDeployment = new Alachisoft.NCache.Config.NewDom.CacheDeployment();
                            _cacheConfig.CacheDeployment.Servers = new Alachisoft.NCache.Config.NewDom.ServersNodes();

                        }
                        _cacheConfig.CacheDeployment.Servers.NodesList = GetServers(ccParam.Server);
                    }

                    Dictionary<int, Management.ClientConfiguration.Dom.CacheServer> serverList = new Dictionary<int, Management.ClientConfiguration.Dom.CacheServer>();
                    int serverCount = 0;
                    foreach (Alachisoft.NCache.Config.NewDom.ServerNode node in GetServers(ccParam.Server))
                    {
                        Management.ClientConfiguration.Dom.CacheServer tempServer = new Management.ClientConfiguration.Dom.CacheServer();
                        tempServer.ServerName = node.IP;
                        serverList.Add(serverCount, tempServer);
                        serverCount++;
                    }
                    Management.ClientConfiguration.CacheServerList servers = new Management.ClientConfiguration.CacheServerList(serverList);
                    List<string> serversToUpdate = new List<string>();
                    foreach (Alachisoft.NCache.Config.NewDom.ServerNode node in GetServers(ccParam.Server))
                    {
                        NCache.ServerName = node.IP;

                        Console.WriteLine(AppendBlankLine("\nCreating cache") + " '{0}' on server '{1}' ", _cacheConfig.CacheSettings.Name, NCache.ServerName);
                        try
                        {
                            cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            if (cacheServer != null)
                            {
                                Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(_cacheConfig.CacheSettings.Name);

                                if (serverConfig != null)
                                {
                                    throw new Exception("Specified cache already exists.");

                                }

                                else if (serverConfig != null && ccParam.IsOverWrite)
                                {
                                    NCache.ServerName = node.IP;

                                    if (serverConfig.CacheDeployment != null)
                                    {
                                        if (serverConfig.CacheDeployment.ClientNodes != null)
                                            _cacheConfig.CacheDeployment.ClientNodes = serverConfig.CacheDeployment.ClientNodes;
                                    }

                                }

                                cacheServer.RegisterCache(_cacheConfig.CacheSettings.Name, _cacheConfig, "", ccParam.IsOverWrite, ccParam.IsHotApply);
                                cacheServer.UpdateClientServersList(_cacheConfig.CacheSettings.Name, servers, "NCACHE");
                                serversToUpdate.Add(node.IP);

                                Console.WriteLine("Cache '{0}' successfully created on server {1}:{2} .", _cacheConfig.CacheSettings.Name, NCache.ServerName, NCache.Port);
                            }

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    Management.Management.Util.ManagementWorkFlow.UpdateServerMappingConfig(serversToUpdate.ToArray());

                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (cacheServer != null)
                        cacheServer.Dispose();
                }

            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(AppendBlankLine("Failed") + " to create cache on server '{0}'. ", ccParam.Server);
                Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                LogEvent(ex.Message);
            }
            finally
            {
                NCache.Dispose();
            }
        }