private Dictionary <string, DisplayNameExAttribute> GetPropertyDisplayOrderInfo(Type type) { var proOrderDic = MemoryCacheEx.Get(type.FullName) as Dictionary <string, DisplayNameExAttribute>; if (proOrderDic == null) { proOrderDic = new Dictionary <string, DisplayNameExAttribute>(); var proInfos = type.GetProperties(); Type displayOrderType = typeof(DisplayNameExAttribute); var noneOrderProInfos = new List <Tuple <DisplayNameExAttribute, PropertyInfo> >(); foreach (var proInfo in proInfos) { object[] objs = proInfo.GetCustomAttributes(displayOrderType, true); if (objs != null && objs.Length > 0) { noneOrderProInfos.Add(new Tuple <DisplayNameExAttribute, PropertyInfo>((DisplayNameExAttribute)objs[0], proInfo)); } else { //noneOrderProInfos.Add(new Tuple<DisplayNameExAttribute, PropertyInfo>(new DisplayOrderAttribute(int.MaxValue), proInfo)); } } var orderProInfos = noneOrderProInfos.OrderBy((p) => { return(p.Item1.OrderIndex); }); foreach (var item in orderProInfos) { proOrderDic.Add(item.Item2.Name, item.Item1); } MemoryCacheEx.Set(type.FullName, proOrderDic, 10 * 60 * 1000);//10分钟过期 } return(proOrderDic); }
private void ProTransferCompleted(TransferCompletedMessage message) { var rid = message.Header.Rid; string transferCompletedMessageCacheKey = CacheKeyGenerator.GenerateTransferCompletedMessageCacheKey(message); const int revTransferCompletedMessageCacheExpire = 60000; TransferSender sender; if (this._senderDic.TryGetValue(rid, out sender)) { sender.ProResourceCompleted(); MemoryCacheEx.Set(transferCompletedMessageCacheKey, rid, revTransferCompletedMessageCacheExpire); this.SendTransferCompletedAckMessage(message); } else { if (MemoryCacheEx.Get(transferCompletedMessageCacheKey) == null) { //Loger.Warn($"未知的资源ID:{rid}"); } else { MemoryCacheEx.Set(transferCompletedMessageCacheKey, rid, revTransferCompletedMessageCacheExpire); this.SendTransferCompletedAckMessage(message); } } }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="expirationMilliseconds">缓存项有效时间,小于等于0永不过期,单位/毫秒</param> private static void AddIdToCache(object id, int expirationMilliseconds) { if (expirationMilliseconds <= 0) { return; } string key = GetCacheKeyFromObjectId(id); MemoryCacheEx.Set(key, id, expirationMilliseconds, new CacheEntryRemovedCallback(ExpirationCacheEntryRemovedCallback)); }
private void btnSet_Click(object sender, RoutedEventArgs e) { MemoryCacheEx.Set(1, TimeEx.GetTimestamp()); MemoryCacheEx.Set(2, TimeEx.GetTimestamp(), this._expiration, this.CacheItemRemovedCallback); MemoryCacheEx.Set(3, TimeEx.GetTimestamp(), TimeSpan.FromMilliseconds(this._expiration), this.CacheItemRemovedCallback); MemoryCacheEx.Set(4, TimeEx.GetTimestamp(), (t) => { return((DateTimeOffset.Now - t.AddTime).TotalMilliseconds > this._expiration * 2); }, this.CacheItemRemovedCallback); CacheItem cacheItem = new CacheItem(5, TimeEx.GetTimestamp()); cacheItem.AbsoluteExpiration = DateTimeOffset.Now.AddMilliseconds(this._expiration); //cacheItem.SlidingExpiration = slidingExpiration; //cacheItem.CustomerExpiration = customerExpiration; cacheItem.RemovedCallback = this.CacheItemRemovedCallback; //cacheItem.InnerRemovedCallback = true; MemoryCacheEx.Set(cacheItem); }
/// <summary> /// 账号密码登录 /// </summary> /// <param name="input"></param> /// <returns></returns> public UserInfoOutputDto Login(UserInfoInputDto input) { var result = Validator.Validate(input, ruleSet: "Select"); if (!result.IsValid) { Error.Execute(result); return(null); } var user = Get(x => x.UserName.Equals(input.username) && x.PassWord.Equals(input.password)); if (user == null) { Error.Execute("账户密码错误!"); return(null); } var userinfo = Mapper.Map <UserInfoOutputDto>(user); _memorycache.Set("AuthUserInfo_" + userinfo.id, userinfo, 60 * 24); return(userinfo); }
private void RevTimeoutCheckThreadMethod(ThreadExPara para) { const int defaultTimeoutCheckInveral = 100; int timeoutCheckInveral = defaultTimeoutCheckInveral; ReceiveDataItem[] revItems; SendDataNotifyMessage notifyMessage; while (!para.Token.IsCancellationRequested) { try { revItems = this._revItemDic.Values.ToArray(); if (revItems.Length == 0) { try { this._revNewDataNoyifyEventHandle.WaitOne(30000); } catch (ObjectDisposedException) { } continue; } timeoutCheckInveral = defaultTimeoutCheckInveral; foreach (var revItem in revItems) { try { notifyMessage = revItem.NotifyMessage; if (revItem.IsTimeout()) { //Loger.Warn($"RID:[{notifyMessage.Header.Rid}]传输超时,最后一次收到数据时间[{TimeEx.TimestampToDateTime(revItem.LastAccessTimestamp).AddHours(8).ToString("HH:mm:ss.fffffff")}]从传输列表中移除该项"); MemoryCacheEx.Set(CacheKeyGenerator.GenerateRevTimeoutKey(notifyMessage.Header.Rid), notifyMessage.Header.Rid, revItem.MillisecondsTimeout); this.RemoveTransferItem(notifyMessage.Header.Rid, false); } else { if (timeoutCheckInveral > notifyMessage.Timeout) { timeoutCheckInveral = notifyMessage.Timeout; } } } catch (Exception exi) { Loger.Error(exi); } } notifyMessage = null; } catch (ObjectDisposedException) { } catch (Exception ex) { Loger.Error(ex, "RevTimeoutCheckThreadMethod异常"); } try { this._revTimeoutCheckEventHandle.WaitOne(timeoutCheckInveral); } catch (ObjectDisposedException) { } } }