public Account CreateAccountByUserInfo(OAuthUserInfo userInfo) { using (var wrap = this.InstanceAutoDetectChangeContextWrap()) { Account account = null; LogUtility.SystemLogger.Debug($"开始创建用户(Account),OAuthUserInfo:\r\n{userInfo.ToJson()}"); var nickname = userInfo.nickname; string userName = GetNewUserName(); account = CreateAccount(userName, "", "", "", userInfo.openid, "", nickname); var url = userInfo.headimgurl.Replace("Http", "Https"); account.HeadImgUrl = url; account.NickName = nickname; account.Sex = (byte)userInfo.sex; account.PicUrl = url; //暂时存为远程地址,让线程异步更新和下载 SaveObject(account); LogUtility.SystemLogger.Debug($"进行异步头像更新:{userInfo.headimgurl}"); //异步下载图片 var operationQueue = new OperationQueue.OperationQueue(); operationQueue.Add($"{account.Id}-{DateTime.Now.Ticks.ToString()}", OperationQueueType.更新用户头像, new List <object>() { account.Id, userInfo.headimgurl }); return(account); } }
public Account CreateOrUpdateByUserInfo(OAuthUserInfo userInfo) { var account = GetObject(z => z.WeixinOpenId == userInfo.openid) ?? CreateAccount(GetNewUserName(), "", "", "", userInfo.openid, "", userInfo.nickname); LogUtility.SystemLogger.Debug($"开始创建用户(Account),OAuthUserInfo:\r\n{userInfo.ToJson()}"); var url = userInfo.headimgurl.Replace("Http", "Https"); account.HeadImgUrl = url; account.NickName = userInfo.nickname; account.Sex = (byte)userInfo.sex; account.PicUrl = url; //暂时存为远程地址,让线程异步更新和下载 SaveObject(account); LogUtility.SystemLogger.Debug($"进行异步头像更新:{userInfo.headimgurl}"); //异步下载图片 var operationQueue = new OperationQueue.OperationQueue(); operationQueue.Add($"{account.Id}-{DateTime.Now.Ticks.ToString()}", OperationQueueType.更新用户头像, new List <object>() { account.Id, userInfo.headimgurl }); return(account); }
/// <summary> /// 操作列队 /// </summary> public static void OperateQueue() { lock (FlushCacheLock) { var mq = new OperationQueue(); var key = mq.GetCurrentKey(); //获取最新的Key while (!string.IsNullOrEmpty(key)) { try { var operationQueueService = SenparcDI.GetService <OperationQueueService>(); var mqItem = mq.GetItem(key); //获取任务项 //识别类型 switch (mqItem.OperationQueueType) { case OperationQueueType.更新用户头像: operationQueueService.UpdateAccountHeadImgAsync((int)mqItem.Data[0], mqItem.Data[1] as string).Wait(); break; default: LogUtility.OperationQueue.ErrorFormat("OperationQueueType未处理:{0}", mqItem.OperationQueueType.ToString()); break; } } catch (Exception ex) { LogUtility.OperationQueue.ErrorFormat($"OperationQueue列队操作失败,已经跳过:{ex.Message}", ex); } mq.Remove(key); //清除 key = mq.GetCurrentKey(); //获取最新的Key } } }