private void postMessageResponseHandler(MessagePoster.MessageStatus status, Conversation conversation, string message) { try { this.BeginInvoke((MethodInvoker) delegate { //Console.Write(status + " " + message + "\n"); if (status == MessagePoster.MessageStatus.Success || status == MessagePoster.MessageStatus.ConversationNotFound || status == MessagePoster.MessageStatus.MessageEmpty) { messagesToSend.Dequeue(); } if (messagesToSend.Count > 0) { sendEnqueuedMessage(); } else { poster = null; } }); } catch (InvalidOperationException e) { //form closed } }
public async Task <IApiResult <string> > Hello() { var(res, state) = await MessagePoster.CallApiAsync <string>("test2", "test"); FlowTracer.MonitorInfomation("hello"); return(ApiResultHelper.Helper.Succees($"hello1:{res.ResultData}")); }
void sendEnqueuedMessage() { String test = messagesToSend.First(); poster = new MessagePoster(localUser, new MessagePoster.MessagePostDelegate(postMessageResponseHandler)); poster.post(conversation, messagesToSend.First()); }
/// <summary> /// 结果处理 /// </summary> /// <param name="message">当前消息</param> /// <returns></returns> async Task IMessageMiddleware.OnEnd(IInlineMessage message) { var root = FlowTracer.EndMonitor(); if (root != null) { ScopeRuner.ScopeLogger.TraceMonitor(root); } if (ToolsOption.Instance.EnableMarkPoint && (message.Service != ToolsOption.Instance.MarkPointName || message.Method != "post")) { await MessagePoster.PublishAsync(ToolsOption.Instance.MarkPointName, "post", new TraceLinkMessage { Monitor = root, Trace = GlobalContext.CurrentNoLazy?.TraceInfo, Message = new MessageItem { ID = message.ID, State = message.State, Service = message.Service, Method = message.Method, Argument = message.Argument, Result = message.Result, User = GlobalContext.User?.ToDictionary(), Context = GlobalContext.CurrentNoLazy?.ToDictionary() } }); } }
public async Task Context() { var traceInfo = new TraceInfo { Start = new DateTime(2020, 3, 12), CallApp = "UnitTest" }; var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService", Method = "v1/context", TraceInfo = traceInfo, Context = new System.Collections.Generic.Dictionary <string, string> { { "User", new UserInfo { UserId = "20200312", NickName = "agebull", OrganizationId = "20200312" }.ToJson() } } }); msg.OfflineResult(); Console.WriteLine(msg.Result); var ctx = msg.ResultData; Assert.IsTrue(ctx != null, msg.Result); Assert.IsTrue(msg.TraceInfo.CallApp == traceInfo.CallApp, msg.TraceInfo.CallApp); Assert.IsTrue(msg.TraceInfo.Start == traceInfo.Start, msg.TraceInfo.Start?.ToString()); //Assert.IsTrue(ctx.User.OrganizationId == ZeroTeamJwtClaim.UnknownOrganizationId, ctx.User.OrganizationId.ToString()); }
/// <summary> /// 准备 /// </summary> /// <param name="service">当前服务</param> /// <param name="message">当前消息</param> /// <param name="tag">扩展信息</param> /// <param name="next">下一个处理方法</param> /// <returns></returns> async Task IMessageMiddleware.Handle(IService service, IInlineMessage message, object tag, Func <Task> next) { var serviceName = message.Service; if (ToolsOption.Instance.ReverseProxyMap == null || !ToolsOption.Instance.ReverseProxyMap.TryGetValue(message.Service, out serviceName)) { if (string.Equals(service.ServiceName, message.Service, StringComparison.OrdinalIgnoreCase)) { message.State = MessageState.Unhandled; message.ResultCreater = ApiResultHelper.State; await next(); return; } } FlowTracer.BeginStepMonitor($"[反向代理] {serviceName}/{message.Method}"); message.Service = serviceName; try { message.ResultCreater ??= ApiResultHelper.State; await MessagePoster.Post(message, true); } finally { FlowTracer.EndStepMonitor(); } }
/// <summary> /// 准备 /// </summary> /// <param name="service">当前服务</param> /// <param name="message">当前消息</param> /// <param name="tag">扩展信息</param> /// <returns></returns> async Task <bool> IMessageMiddleware.Prepare(IService service, IInlineMessage message, object tag) { if (!(tag is HttpContext context)) { return(true); } string GetHeader(string name) { if (!context.Request.Headers.TryGetValue(name, out var head)) { return(null); } return(head.ToString()); } try { await MessagePoster.CallApiAsync(ToolsOption.Instance.PageInfoService, ToolsOption.Instance.PageInfoApi, new { ApiUrl = context.Request.Path.Value, Appid = GetHeader("x-zmvc-app"), ActionName = GetHeader("x-zmvc-action-code"), PageUrl = GetHeader("Referer"), PageTitle = HttpUtility.UrlDecode(GetHeader("x-zmvc-page-title")), ActionTitle = HttpUtility.UrlDecode(GetHeader("x-zmvc-action-title")) }.ToJson()); } catch { } return(true); }
async Task IHostedService.StartAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { if (!ZeroAppOption.Instance.IsRuning) { await Task.Delay(1000); continue; } await Task.Delay(100); //await Task.Delay(1); //await MessagePoster.PublishAsync("test1", "test/res", "agebull"); //await MessagePoster.PublishAsync("test1", "test/arg", "{'Value':'test'}"); await MessagePoster.PublishAsync("test1", "test/full", "{'name':'test'}"); //await MessagePoster.PublishAsync("test1", "test/void", "agebull"); //await MessagePoster.PublishAsync("test1", "async/res", "{'Value':'test'}"); //await MessagePoster.PublishAsync("test1", "async/arg", "{'Value':'test'}"); //await MessagePoster.PublishAsync("test1", "async/full", "{'Value':'test'}"); //await MessagePoster.PublishAsync("test1", "async/void", "{'Value':'test'}"); } }
async Task IHostedService.StartAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { FlowTracer.BeginMonitor("OrderEvent"); await MessagePoster.PublishAsync("OrderEvent", "offline/v1/new", new UnionOrder { Items = new List <UnionOrderItem> { new UnionOrderItem { ItemType = SkuType.GeneralProduct, SkuName = "女鞋E思Q", SalePrice = 50, Number = 3, Amount = 500, Pay = 100, BaseSkuSid = 878465627947009L } }, Amount = 500, Pay = 500 }); _logger.TraceMonitor(FlowTracer.EndMonitor()); await Task.Delay(1000); } }
public void Setup() { mockRespository = new Mock <IUserMessageRepository>(); mockRespository.Setup(x => x.GetMessages(It.IsAny <string>())).Returns(new List <Message>()); subject = new MessagePoster(mockRespository.Object); }
// 接收事件 public void CQStartup(object sender, CQStartupEventArgs e) { Thread thread; Repeaters.LoadInfo(); MessagePoster.LastOSUTime = DateTime.Now.Hour + 1; MessagePoster.workpath = Application.StartupPath; ScriptDrawer.AssetsPath = Application.StartupPath + "\\data\\image\\"; MessagePoster.logid = Guid.NewGuid().ToString(); MessagePoster.pCQ = e.CQApi; MessagePoster.TenClockLock = (DateTime.Now.Hour >= 22); VoidLifes.pCQ = e.CQApi; ArtificalA.Intelligence.ArtificalAI.DebugLog = true; AllocConsole(); Console.WriteLine("Startup:" + MessagePoster.workpath); Manager.wordcollect = new Storage("wordcollections"); Manager.LCards = new DataArrange("lockcards"); Manager.mHot = new DataArrange("mosthotmessages"); Manager.Hots = new DataArrange("messagehots"); Manager.scrBan = new DataArrange("screenmsgbanners"); UT.inits(); MessagePoster.LoadPTemples(); MessagePoster.LoadFlows(); Thread thread2 = new Thread(new ThreadStart(MessagePoster.Poster));//创建线程 thread2.Start(); thread = new Thread(new ThreadStart(Repeaters.AutoSave)); thread.Start(); Thread thread3 = new Thread(new ThreadStart(DreamYCheater.AutoFightSign));//创建线程 thread3.Start(); VoidLifes.LoadGame(); Console.WriteLine("Message poster thread works properly ."); new QQ(e.CQApi, 1361778219).SendPrivateMessage("机器人服务启动成功。"); }
public async Task Test1() { for (int i = 0; i < 1000; i++) { await MessagePoster.PublishAsync("Markpoint2", "test", new Argument { Value = "Test" }); } //Assert.IsTrue(task.Result.Success, "测试通过"); }
/// <summary> /// 准备 /// </summary> /// <param name="message">当前消息</param> /// <returns></returns> async Task IMessageMiddleware.OnEnd(IInlineMessage message) { if (!GlobalContext.IsOptionTrue("Receipt")) { return; } var receipt = MessageHelper.Simple(message.ID, ToolsOption.Instance.ReceiptService, ToolsOption.Instance.ReceiptApi, message.ToJson()); await MessagePoster.Post(receipt); }
async Task IHostedService.StartAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { await MessagePoster.PublishAsync("tcp", "test", "agebull"); await Task.Delay(10000); } }
void sendEnqueuedMessage() // Siųst iš eilės { if (poster == null && Queue.Count > 0) { messageBeingSent = Queue.Dequeue(); poster = new MessagePoster(PrivateKey, MessagePosterDelegate); poster.post(messageBeingSent.Conversation, messageBeingSent.Text); } }
public async Task NonSupport() { var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService", Method = "abcccceerw" }); Assert.IsTrue(msg.State == MessageState.Unhandled, msg.Result); }
public async Task Test() { var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService", Method = "_health_" }); Assert.IsTrue(msg.State == MessageState.Success, msg.Result); }
public void ReturnsNoMessagesWhenForUnknownUsernameEntered() { mockRespository.Setup(x => x.GetMessages(It.IsAny <string>())).Returns(new List <Message>()); subject = new MessagePoster(mockRespository.Object); var messages = subject.GetUserMessages("joe bloggs"); Assert.AreEqual(0, messages.Count); }
public async Task <string> ParallelCall() { var res = await MessagePoster.Post(new InlineMessage { Topic = "ParallelTest", Title = "hello" }); return(JsonConvert.SerializeObject(res.ResultData, Formatting.Indented)); }
public async Task Exception() { var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService", Method = "v1/exception" }); msg.OfflineResult(); Assert.IsTrue(msg.State == MessageState.FrameworkError, msg.Result); }
public async Task FromServices() { var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService", Method = "v1/FromServices", Argument = "{}" }); Assert.IsTrue(msg.State == MessageState.Success, msg.Result); }
public async Task VoidCall() { var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService", Method = "v1/void", Argument = @"{""argument"": ""value""}" }); Assert.IsTrue(msg.Result == null, msg.Result); }
public async Task XmlString() { var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService", Method = "v1/xml", Argument = @"{""Value"": ""value""}" }); Assert.IsTrue(msg.Result[0] == '<', msg.Result); }
public async Task CustomSerialize() { var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService", Method = "v1/customSerialize", Argument = "<xml><Value>val</Value></xml>" }); msg.OfflineResult(); Console.WriteLine(msg.Result); Assert.IsTrue(msg.State == MessageState.Success, msg.Result); }
public async Task Error() { var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService", Method = "v1/err" }); msg.OfflineResult(); var res = msg.ResultData as IApiResult; Assert.IsFalse(res.Success, msg.Result); }
public async Task FromServices() { var(msg, ser) = await MessagePoster.Post(new InlineMessage { ServiceName = "UnitService", ApiName = "v1/FromServices", Content = @"{ }" }); Assert.True(msg.State == MessageState.Success, msg.Result); }
public async Task FailedMessage() { try { var msg = await MessagePoster.Post(null); Assert.Fail("不应执行"); } catch (Exception ex) { Assert.IsTrue(ex is NotSupportedException, ex.Message); } try { var msg = await MessagePoster.Post(new InlineMessage()); Assert.Fail("不应执行"); } catch (Exception ex) { Assert.IsTrue(ex is NotSupportedException, ex.Message); } try { var msg = await MessagePoster.Post(new InlineMessage { Service = "abbc" }); Assert.Fail("不应执行"); } catch (Exception ex) { Assert.IsTrue(ex is NotSupportedException, ex.Message); } try { var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService" }); Assert.Fail("不应执行"); } catch (Exception ex) { Assert.IsTrue(ex is NotSupportedException, ex.Message); } }
public async Task Argument() { var msg = await MessagePoster.Post(new InlineMessage { Service = "UnitService", Method = "v1/argument", Argument = @"{ ""Value"" : ""string"" }" }); Assert.IsTrue(msg.State == MessageState.Success, msg.Result); }
async Task Debug(int step, object a, object b) { await MessagePoster.CallApiAsync("test3", "Hello2"); var builder = new StringBuilder(); builder.Append(step); builder.Append('.'); builder.Append(a == b ? "链接" : "断开"); builder.Append($"{ Task: {Task.CurrentId}"); builder.Append($" Thread: {Thread.CurrentThread.ManagedThreadId}"); builder.Append($" HashCode: {a?.GetHashCode()}|{b?.GetHashCode()}}"); Logger.Information(builder.ToString()); }
public async Task Argument() { var(msg, ser) = await MessagePoster.Post(new InlineMessage { ServiceName = "UnitService", ApiName = "v1/argument", Content = @"{ ""Value"" : ""string"" }" }); Assert.True(msg.State == MessageState.Success, msg.Result); }