Beispiel #1
0
        /// <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>
        /// Initialize a registered cache given by the ID.
        /// </summary>
        /// <param name="cacheId">A string identifier of configuration.</param>
        static public ArrayList GetCacheConfig(string cacheId, string filePath, bool inProc)
        {
            try
            {
                XmlConfigReader configReader = new XmlConfigReader(filePath, cacheId);
                ArrayList       propsList    = configReader.PropertiesList;
                ArrayList       configsList  = CacheConfig.GetConfigs(propsList, DEF_TCP_PORT);

                foreach (CacheConfig config in configsList)
                {
                    if (!inProc)
                    {
                        inProc = config.UseInProc;
                    }
                    break;
                }

                if (inProc)
                {
                    return(configsList);
                }
                return(null);
            }

            catch (ManagementException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
        }
Beispiel #3
0
        /// <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 Alachisoft.NCache.Caching.Cache ConnectCacheInstance(CacheConfig data, TimeSpan timeout, bool autoStart)
        {
            CacheService ncache;

            if (RuntimeContext.CurrentContext == RtContextValue.JVCACHE)
            {
                ncache = new JvCacheRPCService(data.ServerName, (int)data.Port);
            }
            else
            {
                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);
        }
Beispiel #4
0
        /// <summary>
        /// Initialize a registered cache given by the ID.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="timeout"></param>
        /// <exception cref="ArgumentNullException">data is a null reference (Nothing in Visual Basic).</exception>
        /// <returns>A reference to <see cref="Cache"/> object.</returns>
        public static Cache GetCacheInstance(CacheConfig data, TimeSpan timeout)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            try
            {
                if (data == null)
                {
                    return(null);
                }
                if (data.UseInProc)
                {
                    return(CacheFactory.CreateFromPropertyString(data.PropertyString));
                }

                Cache cache = ConnectCacheInstance(data, timeout);
                return(cache);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Populates the object from specified configuration object.
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        internal static CacheConfig FromConfiguration(CacheServerConfig configuration)
        {
            CacheConfig cConfig = null;

            if (configuration != null)
            {
                cConfig = new CacheConfig();

                cConfig._useInProc = configuration.InProc;
                cConfig.CacheId    = configuration.Name;


                if (configuration.Cluster != null)
                {
                    if (configuration.Cluster.Channel != null)
                    {
                        cConfig._clusterPort      = configuration.Cluster.Channel.TcpPort;
                        cConfig._clusterPortRange = configuration.Cluster.Channel.PortRange;
                    }
                    cConfig._useHeartBeat = configuration.Cluster.UseHeartbeat;
                    cConfig._servers      = FromHostListToServers(configuration.Cluster.Channel.InitialHosts);

                    string topology = string.Empty;
                    switch (configuration.Cluster.Topology)
                    {
                    case "partitioned": topology = "partitioned-server"; break;

                    case "replicated": topology = "replicated-server"; break;
                    }
                    cConfig._cacheType = topology;
                }
                else
                {
                    cConfig._cacheType = "local-cache";
                }

                if (configuration.Cleanup != null)
                {
                    cConfig._cleanInterval = configuration.Cleanup.Interval * 1000; ///to millisec
                }

                if (configuration.EvictionPolicy != null)
                {
                    cConfig._evictRatio = (float)Decimal.ToDouble(configuration.EvictionPolicy.EvictionRatio);
                }

                if (configuration.Storage != null)
                {
                    cConfig._cacheMaxSize = configuration.Storage.Size * 1048576; ///from mb to bytes
                }

                if (configuration.Log != null)
                {
                    cConfig._errorLogsEnabled    = configuration.Log.TraceErrors;
                    cConfig._detailedLogsEnabled = configuration.Log.TraceDebug;
                }
            }
            return(cConfig);
        }
Beispiel #6
0
        /// <summary>
        /// Populates the object from specified configuration.
        /// </summary>
        /// <returns></returns>
        internal static CacheConfig FromProperties2(IDictionary properties)
        {
            CacheConfig data = new CacheConfig();

            try
            {
                if (properties.Contains("name"))
                {
                    data._cacheId = properties["name"] as string;
                }
                else
                {
                    throw new ManagementException(@"'name' not specified in configuration.");
                }

                if (properties.Contains("log"))
                {
                    IDictionary cacheLogProps = properties["log"] as IDictionary;
                    if (cacheLogProps.Contains("enabled"))
                    {
                        bool logsEnabled = Convert.ToBoolean(cacheLogProps["enabled"]);
                        if (logsEnabled)
                        {
                            if (cacheLogProps.Contains("trace-errors"))
                            {
                                data.IsErrorLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-errors"]);
                            }
                            if (cacheLogProps.Contains("trace-debug"))
                            {
                                data.IsDetailedLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-debug"]);
                            }
                        }
                    }
                }

                // Get start_port (ClusterPort) and port_range (ClusterPortRange) from the config file
                if (properties.Contains("cluster"))
                {
                    IDictionary clusterProps = properties["cluster"] as IDictionary;
                    if (clusterProps.Contains("channel"))
                    {
                        IDictionary channelProps = clusterProps["channel"] as IDictionary;
                        if (channelProps.Contains("tcp-port"))
                        {
                            data.ClusterPort = Convert.ToInt32(channelProps["tcp-port"]);
                        }
                        data.ClusterPortRange = 1;
                    }
                }
            }
            catch (Exception) { }

            data.UseInProc      = Convert.ToBoolean(properties["inproc"]);
            data.PropertyString = ConfigReader.ToPropertiesString(properties);

            return(data);
        }
Beispiel #7
0
        /// <summary>
        /// Populates the object from specified configuration string.
        /// </summary>
        /// <returns></returns>
        internal static CacheConfig FromPropertyString(string props)
        {
            CacheConfig cConfig = null;

            if (props != null)
            {
                PropsConfigReader pcr         = new PropsConfigReader(props);
                IDictionary       cacheConfig = pcr.Properties;
                cConfig = CacheConfig.FromProperties(cacheConfig);
            }
            return(cConfig);
        }
Beispiel #8
0
 /// <summary>
 /// Initialize a registered cache given by the ID.
 /// </summary>
 /// <param name="cacheId"></param>
 /// <param name="timeout"></param>
 /// <exception cref="ArgumentNullException">cacheId is a null reference (Nothing in Visual Basic).</exception>
 /// <returns>A reference to <see cref="Cache"/> object.</returns>
 public static Cache GetCacheInstance(string cacheId, TimeSpan timeout)
 {
     if (cacheId == null)
     {
         throw new ArgumentNullException("cacheId");
     }
     try
     {
         CacheConfig data = CacheConfigManager.GetCacheConfig(cacheId);
         return(GetCacheInstance(data, timeout));
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #9
0
        /// <summary>
        /// Initialize a registered cache given by the ID.
        /// </summary>
        /// <param name="cacheId">A string identifier of configuration.</param>
        static public ArrayList GetCacheConfig(string cacheId, string userId, string password, bool inProc)
        {
            if (FileName.Length == 0)
            {
                throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt");
            }
            try
            {
                XmlConfigReader configReader = new XmlConfigReader(FileName, cacheId);
                ArrayList       propsList    = configReader.PropertiesList;
                ArrayList       configsList  = CacheConfig.GetConfigs(propsList);

                foreach (CacheConfig config in configsList)
                {
                    if (!inProc)
                    {
                        inProc = config.UseInProc;
                    }
                    break;
                }

                if (inProc)
                {
                    bool      isAuthorize = false;
                    Hashtable ht          = (Hashtable)propsList[0];
                    Hashtable cache       = (Hashtable)ht["cache"];

                    return(configsList);
                }
                return(null);
            }

            catch (SecurityException)
            {
                throw;
            }

            catch (ManagementException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
        }
Beispiel #10
0
        internal static ArrayList GetConfigs(ArrayList props, long tcpPort)
        {
            ArrayList configList = new ArrayList();

            foreach (Hashtable properties in props)
            {
                CacheConfig config = null;

                config = FromProperties(properties, tcpPort);

                if (config != null)
                {
                    configList.Add(config);
                }
            }

            return(configList);
        }
Beispiel #11
0
		/// <summary>
		/// Initialize a registered cache given by the ID.
		/// </summary>
		/// <param name="data"></param>
		/// <param name="timeout"></param>
		/// <exception cref="ArgumentNullException">data is a null reference (Nothing in Visual Basic).</exception>
		/// <returns>A reference to <see cref="Cache"/> object.</returns>
		public static Cache GetCacheInstance(CacheConfig data, TimeSpan timeout)
		{
			if(data == null) throw new ArgumentNullException("data");
			try
			{
				if(data == null) return null;
				if(data.UseInProc)
				{
					return CacheFactory.CreateFromPropertyString(data.PropertyString);
				}

				Cache cache = ConnectCacheInstance(data, timeout);
				return cache;
			}
			catch(Exception)
			{
				throw;
			}
		}
Beispiel #12
0
 /// <summary>
 /// Initialize a registered cache given by the ID.
 /// </summary>
 /// <param name="cacheId">A string identifier of configuration.</param>
 static public CacheConfig GetCacheConfig(string cacheId)
 {
     if (FileName.Length == 0)
     {
         throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt");
     }
     try
     {
         XmlConfigReader configReader = new XmlConfigReader(FileName, cacheId);
         return(CacheConfig.FromProperties(configReader.Properties));
     }
     catch (ManagementException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new ManagementException(e.Message, e);
     }
 }
Beispiel #13
0
        /// <summary>
        /// Initialize a registered cache given by the ID.
        /// </summary>
        /// <param name="cacheId">A string identifier of configuration.</param>
        static public ArrayList GetCacheConfig(string cacheId, string filePath, string userId, string password, bool inProc)
        {
            try
            {
                XmlConfigReader configReader = new XmlConfigReader(filePath, cacheId);
                ArrayList       propsList    = configReader.PropertiesList;
                ArrayList       configsList  = CacheConfig.GetConfigs(propsList, DEF_TCP_PORT);

                foreach (CacheConfig config in configsList)
                {
                    if (!inProc)
                    {
                        inProc = config.UseInProc;
                    }
                    break;
                }

                if (inProc)
                {
                    Hashtable ht    = (Hashtable)propsList[0];
                    Hashtable cache = (Hashtable)ht["cache"];

                    return(configsList);
                }
                return(null);
            }

            catch (SecurityException)
            {
                throw;
            }

            catch (ManagementException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Loads and returns all cache configurations from the configuration file.
        /// </summary>
        static public CacheConfig[] GetConfiguredCaches2()
        {
            if (FileName.Length == 0)
            {
                throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt.");
            }
            try
            {
                XmlConfigReader xcr     = new XmlConfigReader("", "");
                IDictionary     propMap = null;

                propMap = xcr.GetProperties2(CacheConfigManager.FileName);

                ArrayList configList = new ArrayList();

                IDictionaryEnumerator ide = propMap.GetEnumerator();
                while (ide.MoveNext())
                {
                    IDictionary properties = (IDictionary)ide.Value;
                    configList.Add(CacheConfig.FromProperties2(properties));
                }

                CacheConfig[] configs = new CacheConfig[configList.Count];
                for (int i = 0; i < configList.Count; i++)
                {
                    configs[i] = configList[i] as CacheConfig;
                }

                return(configs);
            }
            catch (ManagementException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Initialize a registered cache given by the ID.
        /// </summary>
        /// <param name="cacheId">A string identifier of configuration.</param>
        static public ArrayList GetCacheConfig(string cacheId, bool inProc)
        {
            if (FileName.Length == 0)
            {
                throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt");
            }
            try
            {
                XmlConfigReader configReader = new XmlConfigReader(FileName, cacheId);
                ArrayList       propsList    = configReader.PropertiesList;
                ArrayList       configsList  = CacheConfig.GetConfigs(propsList);

                foreach (CacheConfig config in configsList)
                {
                    if (!inProc)
                    {
                        inProc = config.UseInProc;
                    }
                    break;
                }

                if (inProc)
                {
                    return(configsList);
                }
                return(null);
            }

            catch (ManagementException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
        }
        /// <summary>
        /// Loads and returns all cache configurations from the configuration file.
        /// </summary>
        static public CacheConfig[] GetConfiguredCaches2()
        {
            if (FileName.Length == 0)
            {
                throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt.");
            }
            try
            {
                XmlConfigReader xcr = new XmlConfigReader("", "");
                IDictionary propMap = null;

                propMap = xcr.GetProperties2(CacheConfigManager.FileName);

                ArrayList configList = new ArrayList();

                IDictionaryEnumerator ide = propMap.GetEnumerator();
                while (ide.MoveNext())
                {
                    IDictionary properties = (IDictionary)ide.Value;
                    configList.Add(CacheConfig.FromProperties2(properties));
                }

                CacheConfig[] configs = new CacheConfig[configList.Count];
                for (int i = 0; i < configList.Count; i++)
                {
                    configs[i] = configList[i] as CacheConfig;
                }

                return configs;
            }
            catch (ManagementException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
        }
Beispiel #17
0
		/// <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;
		}
Beispiel #18
0
        /// <summary>
        /// Initializes a new instance of the Cache class.
        /// </summary>
        /// <param name="objectCache"></param>
        /// <param name="config"></param>
        internal Cache(CacheImplBase objectCache, CacheConfig config)
        {
            _cacheImpl = objectCache;
            _config = config;
            _cacheId = config.CacheId;

            if (_cacheImpl != null)
            {
                _serializationContext = _cacheImpl.Name; //Sets the serialization context.
                _cacheId = _cacheImpl.Name;
            }
            _eventManager = new EventManager(_cacheId, null, this);
            _listener = new CacheEventsListener(this, _eventManager);
            _asyncListener = new CacheAsyncEventsListener(this);
             AddRef();
        }
Beispiel #19
0
        /// <summary>
        /// Initializes a new instance of the Cache class.
        /// </summary>
        /// <param name="objectCache"></param>
        /// <param name="config"></param>
        internal InprocCache(Alachisoft.NCache.Caching.Cache objectCache, CacheConfig config, Cache parent)
            : base()
        {
            _nCache = objectCache;

            this.TypeMap = _nCache.GetTypeInfoMap();
            _config = config;
            _parent = parent;

            if (_nCache != null)
            {
                _listener = new CacheEventsListener(_parent.EventListener, _nCache);
                _nCache.OnClientConnected(ClientID, _config.CacheId);
                _serializationContext = _nCache.Name; //Sets the serialization context.
            }

            AddRef();
        }
Beispiel #20
0
        /// <summary>
        /// Populates the object from specified configuration.
        /// </summary>
        /// <returns></returns>
        internal static CacheConfig FromProperties(IDictionary properties)
        {
            CacheConfig data = new CacheConfig();

            if (properties.Contains("partitionid"))
                data.PartitionId = properties["partitionid"].ToString().ToLower();

            IDictionary webprops = properties["web-cache"] as IDictionary;
            IDictionary cacheprops = properties["cache"] as IDictionary;

            if (properties == null)
                throw new ManagementException(@"Invalid configuration; missing 'web-cache' element.");


            try
            {
                if (cacheprops.Contains("cache-classes"))
                {
                    IDictionary cacheClassesProps = cacheprops["cache-classes"] as IDictionary;
                    string cacheName = Convert.ToString(cacheprops["name"]);
                    cacheName = cacheName.ToLower();
                    if (cacheClassesProps.Contains(cacheName))
                    {
                        IDictionary topologyProps = cacheClassesProps[cacheName] as IDictionary;
                        if (topologyProps.Contains("cluster"))
                        {
                            IDictionary clusterProps = topologyProps["cluster"] as IDictionary;
                            if (clusterProps.Contains("channel"))
                            {
                                IDictionary channelProps = clusterProps["channel"] as IDictionary;
                                if (channelProps.Contains("tcp"))
                                {
                                    IDictionary tcpProps = channelProps["tcp"] as IDictionary;
                                    if (tcpProps.Contains("start_port"))
                                    {
                                        data.ClusterPort = Convert.ToInt32(tcpProps["start_port"]);
                                    }
                                    if (tcpProps.Contains("use_heart_beat"))
                                    {
                                        data.UseHeartBeat = Convert.ToBoolean(tcpProps["use_heart_beat"]);
                                    }
                                    if (tcpProps.Contains("port_range"))
                                    {
                                        data.ClusterPortRange = Convert.ToInt32(tcpProps["port_range"]);
                                    }
                                    else
                                    {
                                        data.ClusterPortRange = 2;
                                    }
                                }
                                if (channelProps.Contains("tcpping"))
                                {
                                    IDictionary tcppingProps = channelProps["tcpping"] as IDictionary;
                                    if (tcppingProps.Contains("initial_hosts"))
                                    {
                                        string hostString = (string)tcppingProps["initial_hosts"];
                                        data._servers = FromHostListToServers(hostString);
                                    }
                                }
                            }
                        }

                        if (topologyProps.Contains("type"))
                        {
                            data._cacheType = Convert.ToString(topologyProps["type"]);
                        }

                        if (topologyProps.Contains("clean-interval"))
                        {
                            data._cleanInterval = Convert.ToInt64(topologyProps["clean-interval"]) * 1000; //convert to ms
                        }

                        if (topologyProps.Contains("scavenging-policy"))
                        {
                            IDictionary scavengingProps = topologyProps["scavenging-policy"] as IDictionary;
                            if (scavengingProps.Contains("evict-ratio"))
                            {
                                data._evictRatio = Convert.ToSingle(scavengingProps["evict-ratio"]);
                            }
                        }

                        //We need to extract storage information from the properties 
                        //because user can now change the cache size at runtime.
                        //hot apply configuration option for cache size.
                        if (topologyProps.Contains("storage"))
                        {
                            IDictionary storageProps = topologyProps["storage"] as IDictionary;
                            if (storageProps.Contains("class"))
                            {
                                string storageClass = storageProps["class"] as string;
                                IDictionary storageProviderProps = storageProps[storageClass] as IDictionary;
                                if (storageProviderProps.Contains("max-size"))
                                {
                                    data._cacheMaxSize = Convert.ToInt64(storageProviderProps["max-size"]) * 1024 * 1024; //from MBs to bytes
                                }
                            }
                        }
                        else if (topologyProps.Contains("internal-cache"))
                        {
                            IDictionary internalProps = topologyProps["internal-cache"] as IDictionary;

                            if (internalProps.Contains("clean-interval"))
                            {
                                data._cleanInterval = Convert.ToInt64(internalProps["clean-interval"]) * 1000; //convert to ms
                            }

                            if (internalProps.Contains("scavenging-policy"))
                            {
                                IDictionary scavengingProps = internalProps["scavenging-policy"] as IDictionary;
                                if (scavengingProps.Contains("evict-ratio"))
                                {
                                    data._evictRatio = Convert.ToSingle(scavengingProps["evict-ratio"]);
                                }
                            }

                            if (internalProps.Contains("storage"))
                            {
                                IDictionary storageProps = internalProps["storage"] as IDictionary;
                                if (storageProps.Contains("class"))
                                {
                                    string storageClass = storageProps["class"] as string;
                                    IDictionary storageProviderProps = storageProps[storageClass] as IDictionary;
                                    if (storageProviderProps.Contains("max-size"))
                                    {
                                        data._cacheMaxSize = Convert.ToInt64(storageProviderProps["max-size"]) * 1024 * 1024; //from MBs to bytes
                                    }
                                }
                            }
                        }
                    }
                }

                // Get Error and Detailed logs enable status from the config file
                if (cacheprops.Contains("log"))
                {
                    IDictionary cacheLogProps = cacheprops["log"] as IDictionary;
                    if (cacheLogProps.Contains("enabled"))
                    {
                        bool logsEnabled = Convert.ToBoolean(cacheLogProps["enabled"]);
                        if (logsEnabled)
                        {
                            if (cacheLogProps.Contains("trace-errors"))
                                data.IsErrorLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-errors"]);
                            if (cacheLogProps.Contains("trace-debug"))
                                data.IsDetailedLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-debug"]);
                        }
                    }
                }
                }
            catch (Exception) { }

            data.CacheId = Convert.ToString(webprops["cache-id"]);
            if (data.CacheId == null || data.CacheId.Length == 0)
                throw new ManagementException(@"'cache-id' not specified in configuration.");

            if (webprops.Contains("channel"))
            {
                string channel = Convert.ToString(webprops["channel"]);
                channel = channel.ToLower();
                if (channel.CompareTo("http") == 0)
                    data.UseTcp = false;
            }

            if (webprops.Contains("shared"))
                data.UseInProc = !Convert.ToBoolean(webprops["shared"]);

            if (webprops.Contains("port"))
                data.Port = Convert.ToUInt32(webprops["port"]);
            else
                data.Port = data.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;

            if (webprops.Contains("server"))
                data.ServerName = Convert.ToString(webprops["server"]);

            properties.Remove("id");
            properties.Remove("type");
            data.PropertyString = ConfigReader.ToPropertiesString(properties);



            return data;
        }
Beispiel #21
0
        /// <summary>
        /// Populates the object from specified configuration.
        /// </summary>
        /// <returns></returns>
        internal static CacheConfig FromProperties(IDictionary properties, long tcpPort)
        {
            CacheConfig data = new CacheConfig(tcpPort);

            if (properties.Contains("partitionid"))
                data.PartitionId = properties["partitionid"].ToString().ToLower();

            IDictionary webprops = properties["web-cache"] as IDictionary;
            IDictionary cacheprops = properties["cache"] as IDictionary;

            if (properties == null)
                throw new ManagementException(@"Invalid configuration; missing 'web-cache' element.");

            if (cacheprops != null)
            {
                if (!(cacheprops.Contains("class") && cacheprops.Contains("name")))
                {
                    if (properties.Contains("id"))
                    {
                        cacheprops["name"] = properties["id"].ToString();
                        cacheprops["class"] = properties["id"].ToString();
                    }
                }
            }


            try
            {
                // Get start_port (ClusterPort) and port_range (ClusterPortRange) from the config file
                if (cacheprops.Contains("cache-classes"))
                {
                    IDictionary cacheClassesProps = cacheprops["cache-classes"] as IDictionary;
                    string cacheName = Convert.ToString(cacheprops["name"]);
                    cacheName = cacheName.ToLower();
                    if (cacheClassesProps.Contains(cacheName))
                    {
                        IDictionary topologyProps = cacheClassesProps[cacheName] as IDictionary;
                        if (topologyProps.Contains("cluster"))
                        {
                            IDictionary clusterProps = topologyProps["cluster"] as IDictionary;
                            if (clusterProps.Contains("channel"))
                            {
                                IDictionary channelProps = clusterProps["channel"] as IDictionary;
                                if (channelProps.Contains("tcp"))
                                {
                                    IDictionary tcpProps = channelProps["tcp"] as IDictionary;
                                    if (tcpProps.Contains("start_port"))
                                    {
                                        data.ClusterPort = Convert.ToInt32(tcpProps["start_port"]);
                                    }
                                    if (tcpProps.Contains("port_range"))
                                    {
                                        data.ClusterPortRange = Convert.ToInt32(tcpProps["port_range"]);
                                    }
                                    else
                                    {
                                        data.ClusterPortRange = 2;
                                    }
                                }
                            }
                        }

                        if (topologyProps.Contains("type"))
                        {
                            data._cacheType = Convert.ToString(topologyProps["type"]);
                        }
                    }
                }

                // Get Error and Detailed logs enable status from the config file
                if (cacheprops.Contains("log"))
                {
                    IDictionary cacheLogProps = cacheprops["log"] as IDictionary;
                    if (cacheLogProps.Contains("enabled"))
                    {
                        bool logsEnabled = Convert.ToBoolean(cacheLogProps["enabled"]);
                        if (logsEnabled)
                        {
                            if (cacheLogProps.Contains("trace-errors"))
                                data.IsErrorLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-errors"]);
                            if (cacheLogProps.Contains("trace-debug"))
                                data.IsDetailedLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-debug"]);
                        }
                    }
                }
            }
            catch (Exception) { }

            data.CacheId = Convert.ToString(webprops["cache-id"]);
            if (data.CacheId == null || data.CacheId.Length == 0)
                throw new ManagementException(@"'cache-id' not specified in configuration.");

            if (webprops.Contains("channel"))
            {
                string channel = Convert.ToString(webprops["channel"]);
                channel = channel.ToLower();
                if (channel.CompareTo("http") == 0)
                    data.UseTcp = false;
            }

            if (webprops.Contains("shared"))
                data.UseInProc = !Convert.ToBoolean(webprops["shared"]);

            if (webprops.Contains("port"))
                data.Port = Convert.ToUInt32(webprops["port"]);
           
            if (webprops.Contains("server"))
                data.ServerName = Convert.ToString(webprops["server"]);

            properties.Remove("id");
            properties.Remove("type");
            data.PropertyString = ConfigReader.ToPropertiesString(properties);


            return data;
        }
Beispiel #22
0
        /// <summary>
        /// Populates the object from specified configuration object.
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        internal static CacheConfig FromConfiguration(CacheServerConfig configuration)
        {            
            CacheConfig cConfig = null;
            if (configuration != null)
            {
                cConfig = new CacheConfig();

                cConfig._useInProc = configuration.InProc;
                cConfig.CacheId = configuration.Name;


                if (configuration.Cluster != null)
                {
                    if (configuration.Cluster.Channel != null)
                    {
                        cConfig._clusterPort = configuration.Cluster.Channel.TcpPort;
                        cConfig._clusterPortRange = configuration.Cluster.Channel.PortRange;
                    }
                    cConfig._useHeartBeat = configuration.Cluster.UseHeartbeat;
                    cConfig._servers = FromHostListToServers(configuration.Cluster.Channel.InitialHosts);

                    string topology = string.Empty;
                    switch (configuration.Cluster.Topology)
                    {
                       case "partitioned": topology = "partitioned-server"; break;
                       case "replicated": topology = "replicated-server"; break;
                    }
                    cConfig._cacheType = topology;
                }
                else
                {
                    cConfig._cacheType = "local-cache";
                }

                if (configuration.Cleanup != null)
                {
                    cConfig._cleanInterval = configuration.Cleanup.Interval * 1000; ///to millisec
                }

                if (configuration.EvictionPolicy != null)
                {
                    cConfig._evictRatio = (float)Decimal.ToDouble(configuration.EvictionPolicy.EvictionRatio);
                }

                if (configuration.Storage != null)
                {
                    cConfig._cacheMaxSize = configuration.Storage.Size * 1048576; ///from mb to bytes
                }

                if (configuration.Log != null)
                {
                    cConfig._errorLogsEnabled = configuration.Log.TraceErrors;
                    cConfig._detailedLogsEnabled = configuration.Log.TraceDebug;
                }
                
            }
            return cConfig;
        }
Beispiel #23
0
        /// <summary>
        /// Populates the object from specified configuration.
        /// </summary>
        /// <returns></returns>
        internal static CacheConfig FromProperties(IDictionary properties, long tcpPort)
        {
            CacheConfig data = new CacheConfig(tcpPort);

            if (properties.Contains("partitionid"))
            {
                data.PartitionId = properties["partitionid"].ToString().ToLower();
            }

            IDictionary webprops   = properties["web-cache"] as IDictionary;
            IDictionary cacheprops = properties["cache"] as IDictionary;

            if (properties == null)
            {
                throw new ManagementException(@"Invalid configuration; missing 'web-cache' element.");
            }

            if (cacheprops != null)
            {
                if (!(cacheprops.Contains("class") && cacheprops.Contains("name")))
                {
                    if (properties.Contains("id"))
                    {
                        cacheprops["name"]  = properties["id"].ToString();
                        cacheprops["class"] = properties["id"].ToString();
                    }
                }
            }


            try
            {
                // Get start_port (ClusterPort) and port_range (ClusterPortRange) from the config file
                if (cacheprops.Contains("cache-classes"))
                {
                    IDictionary cacheClassesProps = cacheprops["cache-classes"] as IDictionary;
                    string      cacheName         = Convert.ToString(cacheprops["name"]);
                    cacheName = cacheName.ToLower();
                    if (cacheClassesProps.Contains(cacheName))
                    {
                        IDictionary topologyProps = cacheClassesProps[cacheName] as IDictionary;
                        if (topologyProps.Contains("cluster"))
                        {
                            IDictionary clusterProps = topologyProps["cluster"] as IDictionary;
                            if (clusterProps.Contains("channel"))
                            {
                                IDictionary channelProps = clusterProps["channel"] as IDictionary;
                                if (channelProps.Contains("tcp"))
                                {
                                    IDictionary tcpProps = channelProps["tcp"] as IDictionary;
                                    if (tcpProps.Contains("start_port"))
                                    {
                                        data.ClusterPort = Convert.ToInt32(tcpProps["start_port"]);
                                    }
                                    if (tcpProps.Contains("port_range"))
                                    {
                                        data.ClusterPortRange = Convert.ToInt32(tcpProps["port_range"]);
                                    }
                                    else
                                    {
                                        data.ClusterPortRange = 2;
                                    }
                                }
                            }
                        }

                        if (topologyProps.Contains("type"))
                        {
                            data._cacheType = Convert.ToString(topologyProps["type"]);
                        }
                    }
                }

                // Get Error and Detailed logs enable status from the config file
                if (cacheprops.Contains("log"))
                {
                    IDictionary cacheLogProps = cacheprops["log"] as IDictionary;
                    if (cacheLogProps.Contains("enabled"))
                    {
                        bool logsEnabled = Convert.ToBoolean(cacheLogProps["enabled"]);
                        if (logsEnabled)
                        {
                            if (cacheLogProps.Contains("trace-errors"))
                            {
                                data.IsErrorLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-errors"]);
                            }
                            if (cacheLogProps.Contains("trace-debug"))
                            {
                                data.IsDetailedLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-debug"]);
                            }
                        }
                    }
                }
            }
            catch (Exception) { }

            data.CacheId = Convert.ToString(webprops["cache-id"]);
            if (data.CacheId == null || data.CacheId.Length == 0)
            {
                throw new ManagementException(@"'cache-id' not specified in configuration.");
            }

            if (webprops.Contains("channel"))
            {
                string channel = Convert.ToString(webprops["channel"]);
                channel = channel.ToLower();
                if (channel.CompareTo("http") == 0)
                {
                    data.UseTcp = false;
                }
            }

            if (webprops.Contains("shared"))
            {
                data.UseInProc = !Convert.ToBoolean(webprops["shared"]);
            }

            if (webprops.Contains("port"))
            {
                data.Port = Convert.ToUInt32(webprops["port"]);
            }

            if (webprops.Contains("server"))
            {
                data.ServerName = Convert.ToString(webprops["server"]);
            }

            properties.Remove("id");
            properties.Remove("type");
            data.PropertyString = ConfigReader.ToPropertiesString(properties);


            return(data);
        }
Beispiel #24
0
        /// <summary>
        /// Populates the object from specified configuration.
        /// </summary>
        /// <returns></returns>
        internal static CacheConfig FromProperties(IDictionary properties)
        {
            CacheConfig data = new CacheConfig();

            if (properties.Contains("partitionid"))
            {
                data.PartitionId = properties["partitionid"].ToString().ToLower();
            }

            IDictionary webprops   = properties["web-cache"] as IDictionary;
            IDictionary cacheprops = properties["cache"] as IDictionary;

            if (properties == null)
            {
                throw new ManagementException(@"Invalid configuration; missing 'web-cache' element.");
            }


            try
            {
                if (cacheprops.Contains("cache-classes"))
                {
                    IDictionary cacheClassesProps = cacheprops["cache-classes"] as IDictionary;
                    string      cacheName         = Convert.ToString(cacheprops["name"]);
                    cacheName = cacheName.ToLower();
                    if (cacheClassesProps.Contains(cacheName))
                    {
                        IDictionary topologyProps = cacheClassesProps[cacheName] as IDictionary;
                        if (topologyProps.Contains("cluster"))
                        {
                            IDictionary clusterProps = topologyProps["cluster"] as IDictionary;
                            if (clusterProps.Contains("channel"))
                            {
                                IDictionary channelProps = clusterProps["channel"] as IDictionary;
                                if (channelProps.Contains("tcp"))
                                {
                                    IDictionary tcpProps = channelProps["tcp"] as IDictionary;
                                    if (tcpProps.Contains("start_port"))
                                    {
                                        data.ClusterPort = Convert.ToInt32(tcpProps["start_port"]);
                                    }
                                    if (tcpProps.Contains("use_heart_beat"))
                                    {
                                        data.UseHeartBeat = Convert.ToBoolean(tcpProps["use_heart_beat"]);
                                    }
                                    if (tcpProps.Contains("port_range"))
                                    {
                                        data.ClusterPortRange = Convert.ToInt32(tcpProps["port_range"]);
                                    }
                                    else
                                    {
                                        data.ClusterPortRange = 2;
                                    }
                                }
                                if (channelProps.Contains("tcpping"))
                                {
                                    IDictionary tcppingProps = channelProps["tcpping"] as IDictionary;
                                    if (tcppingProps.Contains("initial_hosts"))
                                    {
                                        string hostString = (string)tcppingProps["initial_hosts"];
                                        data._servers = FromHostListToServers(hostString);
                                    }
                                }
                            }
                        }

                        if (topologyProps.Contains("type"))
                        {
                            data._cacheType = Convert.ToString(topologyProps["type"]);
                        }

                        if (topologyProps.Contains("clean-interval"))
                        {
                            data._cleanInterval = Convert.ToInt64(topologyProps["clean-interval"]) * 1000; //convert to ms
                        }

                        if (topologyProps.Contains("scavenging-policy"))
                        {
                            IDictionary scavengingProps = topologyProps["scavenging-policy"] as IDictionary;
                            if (scavengingProps.Contains("evict-ratio"))
                            {
                                data._evictRatio = Convert.ToSingle(scavengingProps["evict-ratio"]);
                            }
                        }

                        //We need to extract storage information from the properties
                        //because user can now change the cache size at runtime.
                        //hot apply configuration option for cache size.
                        if (topologyProps.Contains("storage"))
                        {
                            IDictionary storageProps = topologyProps["storage"] as IDictionary;
                            if (storageProps.Contains("class"))
                            {
                                string      storageClass         = storageProps["class"] as string;
                                IDictionary storageProviderProps = storageProps[storageClass] as IDictionary;
                                if (storageProviderProps.Contains("max-size"))
                                {
                                    data._cacheMaxSize = Convert.ToInt64(storageProviderProps["max-size"]) * 1024 * 1024; //from MBs to bytes
                                }
                            }
                        }
                        else if (topologyProps.Contains("internal-cache"))
                        {
                            IDictionary internalProps = topologyProps["internal-cache"] as IDictionary;

                            if (internalProps.Contains("clean-interval"))
                            {
                                data._cleanInterval = Convert.ToInt64(internalProps["clean-interval"]) * 1000; //convert to ms
                            }

                            if (internalProps.Contains("scavenging-policy"))
                            {
                                IDictionary scavengingProps = internalProps["scavenging-policy"] as IDictionary;
                                if (scavengingProps.Contains("evict-ratio"))
                                {
                                    data._evictRatio = Convert.ToSingle(scavengingProps["evict-ratio"]);
                                }
                            }

                            if (internalProps.Contains("storage"))
                            {
                                IDictionary storageProps = internalProps["storage"] as IDictionary;
                                if (storageProps.Contains("class"))
                                {
                                    string      storageClass         = storageProps["class"] as string;
                                    IDictionary storageProviderProps = storageProps[storageClass] as IDictionary;
                                    if (storageProviderProps.Contains("max-size"))
                                    {
                                        data._cacheMaxSize = Convert.ToInt64(storageProviderProps["max-size"]) * 1024 * 1024; //from MBs to bytes
                                    }
                                }
                            }
                        }
                    }
                }

                // Get Error and Detailed logs enable status from the config file
                if (cacheprops.Contains("log"))
                {
                    IDictionary cacheLogProps = cacheprops["log"] as IDictionary;
                    if (cacheLogProps.Contains("enabled"))
                    {
                        bool logsEnabled = Convert.ToBoolean(cacheLogProps["enabled"]);
                        if (logsEnabled)
                        {
                            if (cacheLogProps.Contains("trace-errors"))
                            {
                                data.IsErrorLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-errors"]);
                            }
                            if (cacheLogProps.Contains("trace-debug"))
                            {
                                data.IsDetailedLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-debug"]);
                            }
                        }
                    }
                }
            }
            catch (Exception) { }

            data.CacheId = Convert.ToString(webprops["cache-id"]);
            if (data.CacheId == null || data.CacheId.Length == 0)
            {
                throw new ManagementException(@"'cache-id' not specified in configuration.");
            }

            if (webprops.Contains("channel"))
            {
                string channel = Convert.ToString(webprops["channel"]);
                channel = channel.ToLower();
                if (channel.CompareTo("http") == 0)
                {
                    data.UseTcp = false;
                }
            }

            if (webprops.Contains("shared"))
            {
                data.UseInProc = !Convert.ToBoolean(webprops["shared"]);
            }

            if (webprops.Contains("port"))
            {
                data.Port = Convert.ToUInt32(webprops["port"]);
            }
            else
            {
                data.Port = data.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
            }

            if (webprops.Contains("server"))
            {
                data.ServerName = Convert.ToString(webprops["server"]);
            }

            properties.Remove("id");
            properties.Remove("type");
            data.PropertyString = ConfigReader.ToPropertiesString(properties);



            return(data);
        }
Beispiel #25
0
        /// <summary>
        /// Populates the object from specified configuration.
        /// </summary>
        /// <returns></returns>
        internal static CacheConfig FromProperties2(IDictionary properties)
        {
            CacheConfig data = new CacheConfig();

            try
            {
                if (properties.Contains("name"))
                    data._cacheId = properties["name"] as string;
                else
                    throw new ManagementException(@"'name' not specified in configuration.");

                if (properties.Contains("log"))
                {
                    IDictionary cacheLogProps = properties["log"] as IDictionary;
                    if (cacheLogProps.Contains("enabled"))
                    {
                        bool logsEnabled = Convert.ToBoolean(cacheLogProps["enabled"]);
                        if (logsEnabled)
                        {
                            if (cacheLogProps.Contains("trace-errors"))
                                data.IsErrorLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-errors"]);
                            if (cacheLogProps.Contains("trace-debug"))
                                data.IsDetailedLogsEnabled = Convert.ToBoolean(cacheLogProps["trace-debug"]);
                        }
                    }
                }
                if (properties.Contains("cluster"))
                {
                    IDictionary clusterProps = properties["cluster"] as IDictionary;
                    if (clusterProps.Contains("channel"))
                    {
                        IDictionary channelProps = clusterProps["channel"] as IDictionary;
                        if (channelProps.Contains("tcp-port"))
                            data.ClusterPort = Convert.ToInt32(channelProps["tcp-port"]);
                        data.ClusterPortRange = 1;
                    }
                }
            }
            catch (Exception) { }

            data.UseInProc = Convert.ToBoolean(properties["inproc"]);
            data.PropertyString = ConfigReader.ToPropertiesString(properties);

            return data;
        }