Exemplo n.º 1
0
        /// <summary>
        /// get cache keys
        /// </summary>
        /// <param name="keyAndValues">key and values</param>
        /// <param name="includeObjectName">whether include object name</param>
        /// <returns></returns>
        public static string GetCacheKey(IDictionary <string, dynamic> keyAndValues, bool includeObjectName = true)
        {
            List <string> keys = new List <string>();

            if (includeObjectName)
            {
                Type   type       = typeof(T);
                string objectName = QueryConfig.GetObjectName(type);
                if (!string.IsNullOrWhiteSpace(objectName))
                {
                    keys.Add(objectName);
                }
            }
            if (keyAndValues != null && keyAndValues.Count > 0)
            {
                SortedDictionary <string, dynamic> sortedValues = new SortedDictionary <string, dynamic>();
                foreach (var valItem in keyAndValues)
                {
                    sortedValues.Add(valItem.Key, valItem.Value);
                }
                foreach (var sortValItem in sortedValues)
                {
                    keys.Add(string.Format("{0}${1}", sortValItem.Key, sortValItem.Value));
                }
            }
            return(string.Join(":", keys));
        }
        /// <summary>
        /// set command values
        /// </summary>
        /// <param name="cmd">command</param>
        /// <param name="values">values</param>
        void SetCommand(ICommand cmd, Dictionary <string, dynamic> values = null)
        {
            if (cmd == null)
            {
                return;
            }
            Type type = typeof(T);

            //对象名称
            cmd.ObjectName = QueryConfig.GetObjectName(type);

            #region 主键值

            var primaryKeys = QueryConfig.GetPrimaryKeys(type);
            cmd.ObjectKeys = primaryKeys;
            if (primaryKeys != null && values != null && values.Count > 0)
            {
                SortedDictionary <string, dynamic> primaryValues = new SortedDictionary <string, dynamic>();
                foreach (var key in primaryKeys)
                {
                    if (values.ContainsKey(key))
                    {
                        primaryValues.Add(key, values[key]);
                    }
                }
                cmd.ObjectKeyValues = primaryValues;
            }

            #endregion
        }
Exemplo n.º 3
0
        /// <summary>
        /// generate cache key
        /// </summary>
        /// <param name="keys">keys</param>
        /// <param name="includeObjectName">whether include object name</param>
        /// <returns></returns>
        string GenerateCacheKey(IEnumerable <string> keys, bool includeObjectName = true)
        {
            List <string> keyValues = new List <string>();
            var           type      = typeof(T);

            if (includeObjectName)
            {
                string objectName = QueryConfig.GetObjectName(type);
                if (!string.IsNullOrWhiteSpace(objectName))
                {
                    keyValues.Add(objectName);
                }
            }
            if (keys != null)
            {
                foreach (string key in keys)
                {
                    keyValues.Add(string.Format("{0}${1}", key, valueDic[key]));
                }
            }
            return(string.Join(":", keyValues));
        }
Exemplo n.º 4
0
        /// <summary>
        /// get object name
        /// </summary>
        /// <returns></returns>
        public static string GetObjectName()
        {
            Type type = typeof(T);

            return(QueryConfig.GetObjectName(type));
        }