Exemplo n.º 1
0
        private int getKeyValueFromDatabase(string appName, LookupPropertyType type, string key)
        {
            object returnObj = null;
            var logParams = new SqlParameter[3];

            logParams[0] = new SqlParameter("@in_appName", SqlDbType.NVarChar, 150);
            logParams[0].Direction = ParameterDirection.Input;
            logParams[0].Value = appName;

            logParams[1] = new SqlParameter("@in_propertyType", SqlDbType.NVarChar, 50);
            logParams[1].Direction = ParameterDirection.Input;
            logParams[1].Value = type.ToString();

            logParams[2] = new SqlParameter("@in_key", SqlDbType.NVarChar, 150);
            logParams[2].Direction = ParameterDirection.Input;
            logParams[2].Value = key;

            using (SqlConnection conn = new SqlConnection(utility.getParameter("RfgTrackingDb")))
            {
                conn.Open();
                {
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "Get_Key_Value";
                        attachParameters(cmd, logParams);

                        returnObj = cmd.ExecuteScalar();


                    }
                }
            }

            if (returnObj == null)
            {
                throw new Exception(
                    String.Format("NameValue Look failed for {0}, {1}, {2}"
                                  , appName, type.ToString(), key));
            }

            return Convert.ToInt32(returnObj);

        }
Exemplo n.º 2
0
        private string buildLookupKey(string appName, LookupPropertyType type, string key)
        {
            var bldr =
                new StringBuilder(
                    String.Concat(appName.Length, type.ToString().Length, key.Length + 3));
            bldr.Append(appName);
            bldr.Append("_");
            bldr.Append(type.ToString());
            bldr.Append("_");
            bldr.Append(key);

            return bldr.ToString();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="appName"></param>
        /// <param name="type"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public int LookupKeyValue(string appName, LookupPropertyType type, string key)
        {
            if (string.IsNullOrEmpty(appName))
                appName = string.Empty;

            if (string.IsNullOrEmpty(key))
                key = string.Empty;

            string lookupKey = buildLookupKey(appName, type, key);

            if (!m_nameValueDef.ContainsKey(lookupKey))
            {
                lock (s_syncRoot)
                {
                    if (!m_nameValueDef.ContainsKey(lookupKey))
                    {
                        m_nameValueDef.Add(lookupKey,
                                           getKeyValueFromDatabase(appName, type, key));
                    }
                }
            }

            return m_nameValueDef[lookupKey];
        }