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); } } }
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); }
public async Task Invoke(HttpContext context) { string userid = context.Request.Headers["Auth"]; string cachekey = "AuthUserInfo_" + userid; //如果是登录 if (context.Request.Path.Value.Contains("/api/v1/UserInfo/add")) { _memorycache.Remove(cachekey); } if (!context.Request.Path.Value.Contains("/api/v1/UserInfo/add") && !context.Request.Path.Value.Contains("/api/v1/UserInfo/login") && !context.Request.Path.Value.Contains("/code") && !context.Request.Path.Value.Contains("/createcode") && !context.Request.Path.Value.Contains("/File/") && !context.Request.Path.Value.Contains("/file") && !context.Request.Path.Value.Contains("/doc") && !context.Request.Path.Value.Contains("/profiler/") && !context.Request.Path.Value.Contains("hangfire") && !context.Request.Path.Value.Contains("swagger")) { if (!string.IsNullOrWhiteSpace(userid)) { var val = _memorycache.Get <UserInfoOutputDto>(cachekey); if (val != null) { await _next.Invoke(context); } else { await LoginAsync(context, 401, "登录超时,重新登录!"); } } else { await LoginAsync(context, 401); } } else { await _next.Invoke(context); } }
private void btnGet_Click(object sender, RoutedEventArgs e) { Loger.Info($"------------------------------------------------------------"); List <int> keyList = new List <int>() { 1, 2, 3, 4, 5, 6 }; foreach (var key in keyList) { object value = MemoryCacheEx.Get(key); if (value != null) { Loger.Info($"缓存Key:{key}对应值为:{value}"); } else { Loger.Warn($"缓存Key:{key}不存在"); } } Loger.Info($"------------------------------------------------------------"); }
private bool ProResourceMode(SendDataNotifyMessage message) { lock (this._revItemDicLock) { var rid = message.Header.Rid; ReceiveDataItem receiveDataItem; if (this._revItemDic.TryGetValue(rid, out receiveDataItem)) { receiveDataItem.UpdateLastAccessTimestamp(); //Loger.Warn($"[RID:{rid}]的接收项已存在,忽略"); return(false); } if (MemoryCacheEx.Get(CacheKeyGenerator.GenerateRevTimeoutKey(rid)) != null) { //Loger.Warn($"[RID:{rid}]接收已超时,忽略"); return(false); } //Loger.Warn($"处理RID[{rid}]发送通知"); receiveDataItem = new ReceiveDataItem(message, this._config.LocalFileDirectory, this._config.TransferThreadCount); if (!this._revItemDic.TryAdd(rid, receiveDataItem)) { receiveDataItem.Close(true); Loger.Error("this._revItemDic.TryAdd失败,原因未知"); return(false); } int millisecondsTimeout; var revItemCount = this._revItemDic.Count; if (revItemCount < 1) { millisecondsTimeout = message.Timeout / this._config.TimeoutHeartMul; } else { millisecondsTimeout = message.Timeout / (revItemCount * this._config.TimeoutHeartMul); } var reqDataSchduleInfoManager = new TransferReqDataSchduleInfoManager(message, this._reqDataThreads, millisecondsTimeout); TransferResourceManager resourceTransferManager; var priority = message.Priority; if (this._priorityResourceTransferManagerSortedList.ContainsKey(priority)) { resourceTransferManager = this._priorityResourceTransferManagerSortedList[priority]; } else { lock (this._priorityResourceTransferManagerSortedListLock) { if (this._priorityResourceTransferManagerSortedList.ContainsKey(priority)) { resourceTransferManager = this._priorityResourceTransferManagerSortedList[priority]; } else { resourceTransferManager = new TransferResourceManager(); this._priorityResourceTransferManagerSortedList.Add(priority, resourceTransferManager); } } } if (resourceTransferManager.AddReqDataSchduleInfoManager(reqDataSchduleInfoManager)) { this.SendReqDataThreadsEventHandleNotify(); return(true); } else { Loger.Error("AddReqDataSchduleInfoManager失败,原因未知"); if (!this._revItemDic.TryRemove(rid, out receiveDataItem)) { receiveDataItem.Close(true); } return(false); } } }