Beispiel #1
0
        private static SAFConfigurationParametersMap _CheckCache(int cacheSecs)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;
            SAFConfigurationParametersMap sAFConfigurationParametersMap = currentDomain.GetData("ExpandSAFConfigurationDomainCache") as SAFConfigurationParametersMap;
            bool flag = false;

            if (sAFConfigurationParametersMap == null)
            {
                flag = true;
            }
            else
            {
                double totalSeconds = (DateTime.UtcNow - sAFConfigurationParametersMap.LastUpdate).TotalSeconds;
                if (totalSeconds > (double)cacheSecs || totalSeconds < 0.0)
                {
                    flag = true;
                }
            }
            if (flag)
            {
                sAFConfigurationParametersMap = SAFConfiguration.GetAllParametersFromDB();
                if (sAFConfigurationParametersMap == null)
                {
                    return(null);
                }
                sAFConfigurationParametersMap.LastUpdate = DateTime.UtcNow;
                currentDomain.SetData("ExpandSAFConfigurationDomainCache", sAFConfigurationParametersMap);
            }
            return(sAFConfigurationParametersMap);
        }
        private static string _readParameterBusiness(string parameterFullName, int cacheSecs)
        {
            string result;

            try
            {
                SAFConfigurationParametersMap cacheData = SAFConfiguration._CheckCache(cacheSecs);
                if (cacheData == null || !cacheData.ContainsKey(parameterFullName))
                {
                    result = null;
                }
                else
                {
                    result = cacheData[parameterFullName].value;
                }
            }
            catch (Exception ex)
            {
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.WARNING, "SAFBUSINESS", new string[]
                {
                    "http://sfexpand.SAFBusinessConfig.SAFConfiguration.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    "failed::[" + parameterFullName + "]",
                    ex.ToString()
                });
                result = null;
            }
            return(result);
        }
        public SAFConfigurationParametersMap GetAllParametersFromDB()
        {
            IDbCommand  _cmd = null;
            IDataReader _rd  = null;
            SAFConfigurationParametersMap cacheData = new SAFConfigurationParametersMap();
            SAFConfigurationParametersMap result;

            try
            {
                base.ConnectionString = DBConnectionString.ExpandSAFBusinessConfiguration();
                _cmd = base.CreateCommand("SAFGetConfiguration", CommandType.StoredProcedure);
                base.Connection.Open();
                _rd = _cmd.ExecuteReader(CommandBehavior.CloseConnection);
                while (_rd.Read())
                {
                    SAFConfigurationParameter par = new SAFConfigurationParameter();
                    par.section       = _rd.GetString(0);
                    par.name          = _rd.GetString(1);
                    par.value         = (_rd.IsDBNull(2) ? null : _rd.GetString(2));
                    par.lastUTCupdate = _rd.GetDateTime(3);
                    par.frozen        = _rd.GetBoolean(4);
                    par.hidden        = _rd.GetBoolean(5);
                    cacheData.Add(par.section + "@" + par.name, par);
                }
                result = cacheData;
            }
            catch (Exception ex)
            {
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFBUSINESS", new string[]
                {
                    "http://sfexpand.SAFBusinessConfig.SAFConfigurationDAO.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                result = null;
            }
            finally
            {
                if (_rd != null)
                {
                    _rd.Dispose();
                }
                if (_cmd != null)
                {
                    _cmd.Dispose();
                }
                base.CloseConnection();
            }
            return(result);
        }
        private static SAFConfigurationParametersMap _CheckCache(int cacheSecs)
        {
            AppDomain domainCurr  = AppDomain.CurrentDomain;
            bool      needsUpdate = false;
            SAFConfigurationParametersMap result;

            try
            {
                SAFConfigurationParametersMap cacheData = (SAFConfigurationParametersMap)domainCurr.GetData("SAFConfigurationDomainCache");
                if (cacheData == null)
                {
                    needsUpdate = true;
                }
                else
                {
                    double totSecs = (DateTime.UtcNow - cacheData.LastUpdate).TotalSeconds;
                    if (totSecs > (double)cacheSecs || totSecs < 0.0)
                    {
                        needsUpdate = true;
                    }
                }
                if (needsUpdate)
                {
                    cacheData = new SAFConfigurationDAO().GetAllParametersFromDB();
                    if (cacheData == null)
                    {
                        result = null;
                        return(result);
                    }
                    cacheData.LastUpdate = DateTime.UtcNow;
                    domainCurr.SetData("SAFConfigurationDomainCache", cacheData);
                }
                result = cacheData;
            }
            catch
            {
                result = null;
            }
            finally
            {
            }
            return(result);
        }
Beispiel #5
0
        private static string _readParameterBusiness(string parameterFullName, int cacheSecs)
        {
            SAFConfigurationParametersMap sAFConfigurationParametersMap = SAFConfiguration._CheckCache(cacheSecs);

            if (sAFConfigurationParametersMap == null)
            {
                return(null);
            }
            string result;

            try
            {
                result = sAFConfigurationParametersMap[parameterFullName].value;
            }
            catch (Exception ex)
            {
                LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Configuration.SAFConfiguration::readParameterBusinessChangeable error getting parameter[" + parameterFullName + "]. Err:" + ex.Message, ex);
                result = null;
            }
            return(result);
        }
Beispiel #6
0
        private static SAFConfigurationParametersMap GetAllParametersFromDB()
        {
            SAFConfigurationParametersMap sAFConfigurationParametersMap = new SAFConfigurationParametersMap();
            SAFConfigurationParametersMap result;

            try
            {
                string connectionString = SAFConfiguration.readConnectionStringBusiness();
                using (IDbConnection dbConnection = new SqlConnection(connectionString))
                {
                    dbConnection.Open();
                    using (IDbCommand dbCommand = dbConnection.CreateCommand())
                    {
                        dbCommand.CommandType = CommandType.StoredProcedure;
                        dbCommand.CommandText = "GetAllConfiguration";
                        IDataReader dataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection);
                        while (dataReader.Read())
                        {
                            SAFConfigurationParameter sAFConfigurationParameter = new SAFConfigurationParameter();
                            sAFConfigurationParameter.section       = dataReader.GetString(0);
                            sAFConfigurationParameter.name          = dataReader.GetString(1);
                            sAFConfigurationParameter.value         = (dataReader.IsDBNull(2) ? null : dataReader.GetString(2));
                            sAFConfigurationParameter.lastUTCupdate = dataReader.GetDateTime(3);
                            sAFConfigurationParameter.frozen        = dataReader.GetBoolean(4);
                            sAFConfigurationParameter.hidden        = dataReader.GetBoolean(5);
                            string key = sAFConfigurationParameter.section + "@" + sAFConfigurationParameter.name;
                            sAFConfigurationParametersMap.Add(key, sAFConfigurationParameter);
                        }
                    }
                }
                result = sAFConfigurationParametersMap;
            }
            catch (Exception ex)
            {
                LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Configuration.SAFConfiguration::GetAllParameters failed. Err:" + ex.Message, ex);
                result = null;
            }
            return(result);
        }