/// <summary> /// Delivers the Http message to the receive activity and waits until the receive is closed before returning /// </summary> /// <param name="bookmarkName"> /// The name of the bookmark to wait for /// </param> /// <param name="receive"> /// The HttpReceive activity to deliver to /// </param> private void DeliverMessage(string bookmarkName, HttpReceive receive) { HttpExceptionHelper.WriteThread( "Delivering message to HttpReceive activity {0} ID {1} \"{2}\"", bookmarkName, receive.Id, receive.DisplayName); var timeLeft = this.serviceHost.WorkflowTimeout; var retryMsecs = 10; while (timeLeft > TimeSpan.Zero) { // When resuming, the workflow might not be ready var result = this.workflowApplication.ResumeBookmark(bookmarkName, this); switch (result) { case BookmarkResumptionResult.Success: if (!this.responseEvent.WaitOne(timeLeft)) { throw HttpExceptionHelper.CreateResponseException( HttpStatusCode.InternalServerError, "Workflow timeout while waiting for response for {0}", bookmarkName); } // If the workflow terminated with an exception throw it if (this.terminationException != null) { throw this.terminationException; } return; case BookmarkResumptionResult.NotFound: throw HttpExceptionHelper.CreateResponseException( HttpStatusCode.InternalServerError, "Workflow was not waiting for bookmark {0}", bookmarkName); case BookmarkResumptionResult.NotReady: HttpExceptionHelper.WriteThread( "Workflow Instance {0} was not ready to receive bookmark {1} retrying...", bookmarkName, this.workflowApplication.Id); // The workflow was not ready to receive the resumption Thread.Sleep(retryMsecs); timeLeft = timeLeft - TimeSpan.FromMilliseconds(retryMsecs); retryMsecs = retryMsecs * 2; break; default: throw new ArgumentOutOfRangeException(); } } throw HttpExceptionHelper.CreateResponseException( HttpStatusCode.InternalServerError, "Unable to deliver message to Workflow ID {0} for bookmark {1}", this.workflowApplication.Id, bookmarkName); }
/// <summary> /// 微信消息处理类 (回调模式) /// </summary> /// <param name="receive"></param> public MessageAPI(HttpReceive receive) : this(receive.Signature, receive.TimeStamp, receive.Nonce, receive.Message) { }
public async Task <IActionResult> Create_forum([FromBody] forumViewModel forumViewmodel) { int titleLength = int.Parse(_configuration.GetSection("Forum_limit:Title_Length").Value); Dictionary <string, string> forumCategories = _configuration.GetSection("Forum_Category:data").Get <Dictionary <string, string> >(); if (string.IsNullOrEmpty(forumViewmodel.forum_Title) || forumViewmodel.forum_Title.Length >= titleLength || forumViewmodel.forum_Title.Length <= 0) { //使用方法尚未理清,可以修改 return(StatusCode(400, new { Code = "400", Message = "题目不合格" })); } if (forumViewmodel.forum_Category == 0 || !forumCategories.ContainsKey(forumViewmodel.forum_Category.ToString())) { //使用方法尚未理清,可以修改 return(StatusCode(400, new { Code = "400", Message = "帖子分类不符合" })); } //获取身份凭证 string phone = HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.OtherPhone).Value; HttpClient hc = _factory.CreateClient("forum_Server"); string Cookie = Request.Headers.FirstOrDefault(h => h.Key == "Cookie").Value; hc.DefaultRequestHeaders.Add("Cookie", Cookie); string response = string.Empty; try { response = await hc.GetStringAsync($"/Userinfo/GetId?phone={phone}"); } catch (Exception ex) { //如果请求过程出现异常,则写入日志 _logger.LogError(ex.StackTrace); } //接收用户服务端的数据 HttpReceive receive = JsonConvert.DeserializeObject <HttpReceive>(response); if (receive.Code != "200") { //返回方式可优化 return(StatusCode(int.Parse(receive.Code))); } Forum forum = BuildForum(receive.data.ID, forumViewmodel); //触发添加帖子事件,使 用户帖子数量+1 _container.Publish("CreateForum", new CreateForumSumbitEven() { userid = receive.data.ID }); try { _forumservice.InsertForum(forum); }catch (Exception ex) { _logger.LogError(ex.StackTrace); return(Json(new { Code = "500", Message = "添加失败" })); } return(Json(new { Code = "200", Message = "添加成功" })); }