Example #1
0
        /// <summary>
        /// 设置(按Key)
        /// </summary>
        /// <param name="key">键值。</param>
        /// <param name="value">缓存数据。</param>
        public void Set(string key, object value)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }
            object value2;

            //if (!_list_key.TryGetValue(key, out value2)) {
            ThreadHelper.Block(_list_key, () => {
                if (!_list_key.TryGetValue(key, out value2))
                {
                    _list_key.Add(key, value);
                }
                else
                {
                    _list_key[key] = value;
                }
            });
            //} else {
            //    ThreadHelper.Block(_list_key, () => {
            //        _list_key[key] = value;
            //    });
            //}
        }
Example #2
0
        /// <summary>
        /// 创建全局唯一对象。
        /// </summary>
        /// <param name="sessionId">会话的唯一标识符。</param>
        /// <param name="timeout">在会话状态提供程序终止会话之前各请求之间所允许的时间(以分钟为单位)。</param>
        /// <param name="isNewSession">是否为新对象。</param>
        /// <returns></returns>
        public static IHttpSessionState Create(string sessionId, int timeout, out bool isNewSession)
        {
            if (string.IsNullOrEmpty(sessionId))
            {
                isNewSession = true;
                return(Create(timeout));
            }

            HttpSessionState result;
            bool             b = false;

            if (!_globals.TryGetValue(sessionId, out result))
            {
                ThreadHelper.Block(_globals, () => {
                    if (!_globals.TryGetValue(sessionId, out result))
                    {
                        b      = true;
                        result = Create(timeout);
                    }
                });
            }
            isNewSession = b;

            return(result);
        }
Example #3
0
        /// <summary>
        /// 获取自定义Attribute列表
        /// </summary>
        /// <param name="customAttributeProvider"></param>
        /// <param name="type">特性类型, instance is type。</param>
        /// <param name="inherit">如果为 true,则指定还在 element 的祖先中搜索自定义特性。</param>
        /// <returns></returns>
        public static System.Collections.IList GetCustomAttributes(
#if !net20
            this
#endif
            System.Reflection.ICustomAttributeProvider customAttributeProvider, System.Type type, bool inherit)
        {
            if (customAttributeProvider == null || type == null)
            {
                return(CreateList(type));
            }

            System.Collections.IList list;
            string key = string.Concat(GetKeyBefore(customAttributeProvider), "_", type.AssemblyQualifiedName);

            if (!_list_key.TryGetValue(key, out list))
            {
                ThreadHelper.Block(_list_key, () => {
                    if (!_list_key.TryGetValue(key, out list))
                    {
                        list = CreateList(type);
                        foreach (var item in customAttributeProvider.GetCustomAttributes(inherit))
                        {
                            if (item.GetType() == type || TypeExtensions.IsInheritFrom(item.GetType(), type))
                            {
                                list.Add(item);
                            }
                        }
                        _list_key.TryAdd(key, list);
                    }
                });
            }

            return(list);
        }
Example #4
0
 /// <summary>
 /// 区块排它锁,带返回值。
 /// </summary>
 /// <param name="action">进入锁之后的回调。</param>
 /// <param name="arg">参数。</param>
 public TResult Block <TArg, TResult>(BlockFunc <TArg, TResult> action, TArg arg)
 {
     Symbol.CommonException.CheckArgumentNull(action, "action");
     Begin();
     try {
         return(ThreadHelper.Block(_sync, action, arg));
     } finally {
         End();
     }
 }
Example #5
0
 /// <summary>
 /// 区块排它锁,带返回值。
 /// </summary>
 /// <param name="action">进入锁之后的回调。</param>
 public T Block <T>(BlockFunc <T> action)
 {
     Symbol.CommonException.CheckArgumentNull(action, "action");
     Begin();
     try {
         return(ThreadHelper.Block <T>(_sync, action));
     } finally {
         End();
     }
 }
Example #6
0
 /// <summary>
 /// 区块排它锁
 /// </summary>
 /// <param name="action">进入锁之后的回调。</param>
 /// <param name="arg">参数。</param>
 public void Block <T>(BlockAction <T> action, T arg)
 {
     Symbol.CommonException.CheckArgumentNull(action, "action");
     Begin();
     try {
         ThreadHelper.Block <T>(_sync, action, arg);
     } finally {
         End();
     }
 }
Example #7
0
 /// <summary>
 /// 区块排它锁
 /// </summary>
 /// <param name="action">进入锁之后的回调。</param>
 public void Block(System.Threading.ThreadStart action)
 {
     Symbol.CommonException.CheckArgumentNull(action, "action");
     Begin();
     try {
         ThreadHelper.Block(_sync, action);
     } finally {
         End();
     }
 }
Example #8
0
 /// <summary>
 /// 输出一个一行信息(时间 level&gt;消息)。
 /// </summary>
 /// <param name="level">级别</param>
 /// <param name="message">消息</param>
 protected override void OnWriteLine(string level, string message)
 {
     ThreadHelper.Block(_syncThis, () => {
         System.IO.TextWriter writer = CreateWriter();
         if (writer == null)
         {
             return;
         }
         try {
             writer.WriteLine("{0} {1}>{2}", System.DateTime.Now.ToString("HH:mm:ss.fffffff"), level, message);
         } catch { }
         try { writer.Flush(); } catch { }
     });
 }
Example #9
0
 static Symbol.Collections.Generic.NameValueCollection <string> GetValues(ICustomAttributeProvider provider)
 {
     Symbol.Collections.Generic.NameValueCollection <string> list;
     if (!_list.TryGetValue(provider, out list))
     {
         ThreadHelper.Block(_list, () => {
             if (!_list.TryGetValue(provider, out list))
             {
                 list = new Symbol.Collections.Generic.NameValueCollection <string>(StringComparer.OrdinalIgnoreCase);
                 GetValues(provider, list, true);
                 _list.TryAdd(provider, list);
             }
         });
     }
     return(list);
 }
Example #10
0
        //_list_condition_func
        PreSelectBuilderFunc GetPreSelectBuilderFunc(System.Type type, string value)
        {
            PreSelectBuilderFunc func;
            string key = type.AssemblyQualifiedName + "|" + value;

            if (!_list_condition_func.TryGetValue(key, out func))
            {
                ThreadHelper.Block(_list_condition_func, () => {
                    if (!_list_condition_func.TryGetValue(value, out func))
                    {
                        if (value.StartsWith("$this.", StringComparison.OrdinalIgnoreCase))
                        {
                            string path = value.Substring("$this.".Length);
                            func        = (dataContext, dataReader, entity) => {
                                return(FastObject.Path(entity, path));
                            };
                        }
                        if (value.StartsWith("$reader.", StringComparison.OrdinalIgnoreCase))
                        {
                            string p10 = value.Substring("$reader.".Length);
                            if (p10.IndexOf('.') > -1)
                            {
                                string name = p10.Split('.')[0];
                                string path = p10.Substring(name.Length + 1);
                                func        = (dataContext, dataReader, entity) => {
                                    return(FastObject.Path(DataReaderHelper.Current(dataReader, name), path));
                                };
                            }
                            else
                            {
                                func = (dataContext, dataReader, entity) => {
                                    return(DataReaderHelper.Current(dataReader, p10));
                                };
                            }
                        }
                        _list_condition_func.TryAdd(key, func);
                    }
                });
            }
            return(func);
        }
Example #11
0
        static System.Collections.Generic.List <BindItem> TryGetBind(System.Type entityType)
        {
            string key = entityType.AssemblyQualifiedName;

            System.Collections.Generic.List <BindItem> list;
            if (!_list_key.TryGetValue(key, out list))
            {
                ThreadHelper.Block(_list_key, () => {
                    if (!_list_key.TryGetValue(key, out list))
                    {
                        if (entityType.IsValueType || entityType == typeof(string) || entityType == typeof(object) || TypeExtensions.IsNullableType(entityType))
                        {
                            _list_key.TryAdd(key, null);
                            return;
                        }

                        list = new System.Collections.Generic.List <BindItem>();
                        foreach (System.Reflection.PropertyInfo propertyInfo in entityType.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.SetProperty))
                        {
                            var binder = AttributeExtensions.GetCustomAttribute <DataBinderAttribute>(propertyInfo);
                            if (binder == null)
                            {
                                continue;
                            }
                            BindItem bindItem = new BindItem()
                            {
                                propertyInfo = propertyInfo,
                                binder       = binder,
                                bindAction   = binder.Bind,
                            };
                            list.Add(bindItem);
                        }
                        _list_key.TryAdd(key, list.Count == 0 ? null : list);
                    }
                });
            }
            return(list);
        }
Example #12
0
        /// <summary>
        /// 设置(按对象和字段)
        /// </summary>
        /// <param name="entity">当前实体对象。</param>
        /// <param name="field">当前字段。</param>
        /// <param name="value">缓存数据。</param>
        public void Set(object entity, string field, object value)
        {
            if (entity == null || string.IsNullOrEmpty(field))
            {
                return;
            }
            System.Collections.Generic.Dictionary <string, object> list;
            if (!_list_object.TryGetValue(entity, out list))
            {
                ThreadHelper.Block(_list_object, () => {
                    if (!_list_object.TryGetValue(entity, out list))
                    {
                        list = new System.Collections.Generic.Dictionary <string, object>();
                        _list_object.Add(entity, list);
                    }
                });
            }
            object value2;

            //if (!list.TryGetValue(field, out value2)) {
            ThreadHelper.Block(list, () => {
                if (!list.TryGetValue(field, out value2))
                {
                    list.Add(field, value);
                }
                else
                {
                    list[field] = value;
                }
            });
            //} else {
            //    ThreadHelper.Block(list, () => {
            //        list[field] = value;
            //    });
            //}
        }