Ejemplo n.º 1
0
        public static void AddCache(string cacheId, CacheServerConfig config)
        {
            LoadXml();

            if (_configuration != null)
            {
                if (_configuration.CacheConfigurationsMap == null)
                    _configuration.CacheConfigurationsMap = new Dictionary<string, CacheConfiguration>();

                if (!_configuration.CacheConfigurationsMap.ContainsKey(cacheId.ToLower()))
                {
                    CacheConfiguration cacheConfiguration = new CacheConfiguration();
                    cacheConfiguration.CacheId = cacheId;

                    if (config.Cluster != null && config.Cluster.Nodes != null)
                    {
                        if (config.Cluster.Nodes.Count != 1)
                        {
                            // Extract server names from config
                            string[] serverList = new string[config.Cluster.NodeIdentities.Count];
                            for (int i = 0; i < serverList.Length; i++)
                            {
                                serverList[i] = config.Cluster.NodeIdentities[i].NodeName;
                            }

                            // Sort priority list i.e. local node at top
                            string[] copyServerList = new string[serverList.Length];
                            for (int i = 0; i < serverList.Length; i++)
                            {
                                if (serverList[i] == cacheConfiguration.BindIp)
                                {
                                    copyServerList[0] = serverList[i];
                                    cacheConfiguration.AddServer(cacheConfiguration.BindIp, 0);
                                }
                                else if (String.IsNullOrEmpty(copyServerList[0]))
                                {
                                    copyServerList[i + 1] = serverList[i];
                                    cacheConfiguration.AddServer(serverList[i], i + 1);
                                }
                                else
                                {
                                    copyServerList[i] = serverList[i];
                                    cacheConfiguration.AddServer(serverList[i], i);
                                }
                            }
                        }
                        else
                            cacheConfiguration.AddServer(config.Cluster.NodeIdentities[0].NodeName, 0);
                    }
                    else
                    {
                        cacheConfiguration.AddLocalServer();
                    }
                   
                    _configuration.CacheConfigurationsMap[cacheId.ToLower()] = cacheConfiguration;
                }
            }

            SaveConfiguration();
        }
Ejemplo n.º 2
0
        public static void AddCache(string cacheId, RtContextValue serverRuntimeContext)
        {
            LoadXml();

            if (_configuration != null)
            {
                if (_configuration.CacheConfigurationsMap == null)
                    _configuration.CacheConfigurationsMap = new Dictionary<string, CacheConfiguration>();

                if (!_configuration.CacheConfigurationsMap.ContainsKey(cacheId.ToLower()))
                {
                    CacheConfiguration cacheConfiguration = new CacheConfiguration();
                    cacheConfiguration.CacheId = cacheId;
                    cacheConfiguration.ServerRuntimeContext = serverRuntimeContext;
                    cacheConfiguration.AddLocalServer();
                    _configuration.CacheConfigurationsMap[cacheId.ToLower()] = cacheConfiguration;
                }
            }

            SaveConfiguration();
        }