Пример #1
0
        public void LoadConfiguration()
        {
            FileStream  fs = null;
            string      c_configFileName = null;
            XmlDocument configuration    = new XmlDocument();

            try
            {
                if (_cacheId == null)
                {
                    return;
                }

                c_configFileName = DirectoryUtil.GetBaseFilePath("client.ncconf", _search, out _result);


                if (c_configFileName == null)
                {
                    return;
                }

                FileInfo fileInfo = new FileInfo(c_configFileName);
                fs = fileInfo.OpenRead();
                configuration.Load(fs);
                fileInfo = null;

                bool serverPortFound = false;


                XmlNodeList serverPortList = configuration.GetElementsByTagName("ncache-server");
                CultureInfo cultureInfo    = Thread.CurrentThread.CurrentCulture;
                try
                {
                    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
                    if (serverPortList != null && serverPortList.Count > 0)
                    {
                        XmlNode portNode = serverPortList.Item(0);
                        if (portNode != null)
                        {
                            XmlAttributeCollection attributes = portNode.Attributes;
                            if (attributes != null)
                            {
                                if (attributes["port"] != null && attributes["port"].Value != null)
                                {
                                    try
                                    {
                                        _serverPortFromConfig = Convert.ToInt32(attributes["port"].Value);
                                    }
                                    catch (Exception)
                                    { }
                                }


                                if (initParam != null && initParam.IsSet(PORT))
                                {
                                    _serverPort = initParam.Port;
                                }
                                else
                                {
                                    _serverPort = _serverPortFromConfig;
                                }

                                if (initParam != null && initParam.IsSet(OPTIMEOUT))
                                {
                                    _timeout = initParam.ClientRequestTimeOut * 1000;
                                }
                                else
                                {
                                    if (attributes["client-request-timeout"] != null && attributes["client-request-timeout"].Value != null)
                                    {
                                        try
                                        {
                                            _timeout = Convert.ToInt32(attributes["client-request-timeout"].Value) * 1000;
                                        }
                                        catch (Exception) { }
                                    }
                                }

                                if (initParam != null && initParam.IsSet(CONNECTIONRETRIES))
                                {
                                    _retries = initParam.ConnectionRetries;
                                }
                                else
                                {
                                    if (attributes["connection-retries"] != null && attributes["connection-retries"].Value != null)
                                    {
                                        try { _retries = Convert.ToInt32(attributes["connection-retries"].Value); }
                                        catch { }
                                    }
                                }

                                if (initParam != null && initParam.IsSet(RETRYINTERVAL))
                                {
                                    _retrySleep = initParam.RetryInterval * 1000; //: RetryInterval Property returns value/1000
                                }
                                else
                                {
                                    if (attributes["retry-interval"] != null && attributes["retry-interval"].Value != null)
                                    {
                                        try
                                        {
                                            _retrySleep = Convert.ToInt32(attributes["retry-interval"].Value) * 1000;
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }
                                }

                                if (initParam != null && initParam.IsSet(CONNECTIONTIMEOUT))
                                {
                                    _connectionTimeout = initParam.ConnectionTimeout * 1000;
                                }
                                else
                                {
                                    if (attributes["connection-timeout"] != null && attributes["connection-timeout"].Value != null)
                                    {
                                        try
                                        {
                                            _connectionTimeout = Convert.ToInt32(attributes["connection-timeout"].Value) * 1000;
                                        }
                                        catch (Exception)
                                        { }
                                    }
                                }


                                if (initParam != null && initParam.IsSet(RETRYCONNECTIONDELAY))
                                {
                                    _retryConnectionDelay = initParam.RetryConnectionDelay * 1000;
                                }
                                else
                                {
                                    if (attributes["retry-connection-delay"] != null && attributes["retry-connection-delay"].Value != null)
                                    {
                                        try
                                        {
                                            _retryConnectionDelay = Convert.ToInt32(attributes["retry-connection-delay"].Value) * 1000;
                                        }
                                        catch (Exception)
                                        { }
                                    }
                                }
                            }

                            serverPortFound = true;
                        }
                    }

                    if (!serverPortFound)
                    {
                        throw new Runtime.Exceptions.ConfigurationException(
                                  "ncache-server missing in client confiugration");
                    }


                    XmlNodeList cacheList   = configuration.GetElementsByTagName("cache");
                    XmlNodeList cacheConfig = null;

                    for (int i = 0; i < cacheList.Count; i++)
                    {
                        XmlNode cache = cacheList.Item(i);
                        if (cache.Attributes.GetNamedItem("id").Value.ToLower().Equals(_cacheId.ToLower()))
                        {
                            if (cache.Attributes["load-balance"] != null)
                            {
                                this._balanceNodes = Convert.ToBoolean(cache.Attributes["load-balance"].Value);
                            }

                            if (initParam != null && initParam.IsSet(LOADBALANCE))
                            {
                                this._balanceNodes = initParam.LoadBalance;
                            }

                            if (cache.Attributes["default-readthru-provider"] != null)
                            {
                                this._defaultReadThruProvider =
                                    cache.Attributes["default-readthru-provider"].Value.ToString();
                            }

                            if (initParam != null && initParam.IsSet(DEFAULTREADTHRUPROVIDER))
                            {
                                this._defaultReadThruProvider = initParam.DefaultReadThruProvider;
                            }

                            if (cache.Attributes["default-writethru-provider"] != null)
                            {
                                this._defaultWriteThruProvider =
                                    cache.Attributes["default-writethru-provider"].Value.ToString();
                            }

                            if (initParam != null && initParam.IsSet(DEFAULTWRITETHRUPROVIDER))
                            {
                                this._defaultWriteThruProvider = initParam.DefaultWriteThruProvider;
                            }


                            try
                            {
                                if (cache.Attributes["enable-client-logs"] != null)
                                {
                                    this._enableClientLogs =
                                        Convert.ToBoolean(cache.Attributes["enable-client-logs"].Value.ToString());
                                }
                            }
                            catch (Exception)
                            {
                            }

                            if (cache.Attributes["log-level"] != null)
                            {
                                this._enableDetailedClientLogs =
                                    cache.Attributes["log-level"].Value.ToString().ToLower() == "info" ? true : false;
                            }


                            this.serverRuntimeContext = RtContextValue.NCACHE;

                            _importHashmap = true;

                            cacheConfig = cache.ChildNodes;
                            break;
                        }
                    }

                    if (cacheConfig == null)
                    {
                        if (!String.IsNullOrEmpty(_cacheId))
                        {
                            if (_result != Search.GlobalSearch)
                            {
                                _search = _result + 1;
                                LoadConfiguration();
                            }
                        }

                        return;
                    }

                    _search = _result;
                    LoadRemoteServerMappingConfig(cacheConfig);


                    LoadRemoteServerConfig(cacheConfig);
                }
                finally
                {
                    System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
                }
            }

            catch (Runtime.Exceptions.ConfigurationException)
            {
                throw;
            }
            catch (System.IO.IOException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new Runtime.Exceptions.ConfigurationException(
                          "An error occurred while reading client.ncconf. " + e.Message);
            }

            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Пример #2
0
        public void LoadConfiguration()
        {
            FileStream  fs = null;
            string      c_configFileName = null;
            XmlDocument configuration    = new XmlDocument();

            try
            {
                if (_cacheId == null)
                {
                    return;
                }
                c_configFileName = DirectoryUtil.GetBaseFilePath("client.ncconf", _search, out _result);
                if (c_configFileName == null)
                {
                    return;
                }
                FileInfo fileInfo = new FileInfo(c_configFileName);
                fs = fileInfo.OpenRead();
                configuration.Load(fs);
                fileInfo = null;

                bool serverPortFound = false;

                XmlNodeList serverPortList = configuration.GetElementsByTagName("ncache-server");
                if (serverPortList != null && serverPortList.Count > 0)
                {
                    XmlNode portNode = serverPortList.Item(0);
                    if (portNode != null)
                    {
                        XmlAttributeCollection attributes = portNode.Attributes;
                        if (attributes != null)
                        {
                            string currentAttrib = string.Empty;

                            if (initParam.ServerList != null && initParam.ServerList.Length > 0)
                            {
                                if (initParam.ServerList[0].Port > 0)
                                {
                                    _serverPort = initParam.ServerList[0].Port;
                                }
                            }
                            else
                            {
                                if (attributes["port"] != null)
                                {
                                    currentAttrib = attributes["port"].Value;
                                    if (currentAttrib != null)
                                    {
                                        _serverPort = Convert.ToInt32(currentAttrib);
                                    }
                                }
                            }
                        }
                        serverPortFound = true;
                    }
                }

                if (!serverPortFound)
                {
                    throw new Runtime.Exceptions.ConfigurationException("ncache-server missing in client confiugration");
                }

                XmlNodeList cacheList   = configuration.GetElementsByTagName("cache");
                XmlNodeList cacheConfig = null;

                for (int i = 0; i < cacheList.Count; i++)
                {
                    XmlNode cache = cacheList.Item(i);
                    if (cache.Attributes.GetNamedItem("id").Value.ToLower().Equals(_cacheId.ToLower()))
                    {
                        if (cache.Attributes["load-balance"] != null)
                        {
                            this._balanceNodes = Convert.ToBoolean(cache.Attributes["load-balance"].Value);
                        }
                        if (initParam != null && initParam.IsSet(LOADBALANCE))
                        {
                            this._balanceNodes = initParam.LoadBalance;
                        }



                        try
                        {
                            if (cache.Attributes["enable-client-logs"] != null)
                            {
                                this._enableClientLogs = Convert.ToBoolean(cache.Attributes["enable-client-logs"].Value.ToString());
                            }
                        }
                        catch (Exception)
                        { }

                        if (cache.Attributes["log-level"] != null)
                        {
                            this._enableDetailedClientLogs = cache.Attributes["log-level"].Value.ToString().ToLower() == "info" ? true : false;
                        }

                        this.serverRuntimeContext = RtContextValue.NCACHE;
                        _importHashmap            = true;

                        cacheConfig = cache.ChildNodes;
                        break;
                    }
                }

                if (cacheConfig == null)
                {
                    if (!String.IsNullOrEmpty(_cacheId))
                    {
                        if (_result != Search.GlobalSearch)
                        {
                            _search = _result + 1;
                            LoadConfiguration();
                        }
                    }
                    return;
                }
                _search = _result;
                LoadRemoteServerMappingConfig(cacheConfig);

                LoadRemoteServerConfig(cacheConfig);
            }
            catch (Runtime.Exceptions.ConfigurationException)
            {
                throw;
            }
            catch (System.IO.IOException) { throw; }
            catch (Exception e)
            {
                throw new Runtime.Exceptions.ConfigurationException("An error occured while reading client.ncconf. " + e.Message);
            }

            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Пример #3
0
 /// <summary>
 /// see if the client.ncconf is present in the executing assembly local folder. if yes
 /// then returns the local path. otherwise search for the client.ncconf in NCache install folder
 /// and if found returns the file global path.
 /// </summary>
 /// <returns>returns the client.ncconf local or global path if found. otherwise returns null.</returns>
 internal static string GetClientConfigurationPath()
 {
     return(DirectoryUtil.GetBaseFilePath("client.ncconf"));
 }