public async Task MqttTransportHandlerSendMethodResponseAsyncSendsMessage() { // arrange IChannel channel; var responseBytes = System.Text.Encoding.UTF8.GetBytes(fakeMethodResponseBody); var transport = CreateTransportHandlerWithMockChannel(out channel); var response = new MethodResponseInternal(responseBytes, fakeResponseId, statusSuccess); // act transport.OnConnected(); await transport.SendMethodResponseAsync(response, CancellationToken.None).ConfigureAwait(false); // assert MessageMatcher matches = (msg) => { using (StreamReader reader = new StreamReader(msg.GetBodyStream(), System.Text.Encoding.UTF8)) { string body = reader.ReadToEnd(); return(fakeMethodResponseBody.Equals(body) && msg.MqttTopicName.Equals("$iothub/methods/res/" + statusSuccess + "/?$rid=" + fakeResponseId)); } }; await channel .Received() .WriteAndFlushAsync(Arg.Is <Message>(msg => matches(msg))).ConfigureAwait(false); }
public void MakeSureOnlyASingleProductPurchasedEventOccurs() { var productPurchased = MessageMatcher <ProductPurchased> .Single(msg => msg.CustomerId == customerId && msg.ProductId == productId); //oops two stock services are processing orders now! bus.Consume <PurchaseProduct>(consumerServiceName, new Stock(messagePublisher)); StockUpItem(); executor .Try(() => messagePublisher.Publish(new PurchaseProduct { ProductId = productId, CustomerId = customerId })) .Return() .When(ConfirmationMatcher <PurchaseProduct> .Any(consumerServiceName), productPurchased, MessageMatcher <CustomerBilled> .Any(msg => msg.CustomerId == customerId && msg.ProductId == productId).WaitFor(TimeSpan.FromSeconds(45))); Assert.That(productPurchased.IsMatched); var asserter = new Asserter(); productPurchased.AssertOk(asserter); Assert.IsFalse(asserter.IsOk); Console.WriteLine(asserter); }
public virtual void Setup() { customerBilled = MessageMatcher <CustomerBilled> .Any(msg => msg.CustomerId == customerId && msg.ProductId == productId); receiptWasSent = MessageMatcher <ReceiptWasSent> .Any(msg => msg.CustomerId == customerId && msg.ProductId == productId); productPurchased = MessageMatcher <ProductPurchased> .Any(msg => msg.CustomerId == customerId && msg.ProductId == productId); purchaseProductConfirmation = ConfirmationMatcher <PurchaseProduct> .Any(consumerServiceName); }
void Awake() { if (instance == null) { instance = this; } Events.instance.AddListener <RefreshPlayerListEvent> (OnRefreshPlayerListEvent); Events.instance.AddListener <HostReceiveMessageEvent> (OnHostReceiveMessageEvent); Events.instance.AddListener <AllReceiveMessageEvent> (OnAllReceiveMessageEvent); }
public static void MessageStored(Message message) { var mailbox = VirtualMailBox.Current; // Match thread MessageMatcher.Match(message); mailbox.Messages.Add(message); ViewFilter.Current.UpdateCurrentViewAsync(); // Add to search index ClientState.Current.Search.Store(message); }
protected override void ExecuteCore() { List <UserStatus> delete; using (mailbox.StatusUpdates.ReaderLock) delete = mailbox.StatusUpdates.Where(u => u.SortDate < DateTime.Now.AddDays(-7)).ToList(); foreach (var status in delete) { try { ClientState.Current.DataService.Delete(status); ClientState.Current.Search.Delete(status); } catch (Exception ex) { Logger.Error("An error has occured while purging userstatus, Exception = {0}", LogSource.BackgroundTask, ex); } } Thread.CurrentThread.ExecuteOnUIThread(() => delete.ForEach(d => mailbox.StatusUpdates.Remove(d))); // Find messages that have not been matched List <Message> messages; using (mailbox.Messages.ReaderLock) messages = mailbox.Messages.Where(m => m.ConversationIdentifier == String.Empty && m.DateCreated < DateTime.Now.AddMinutes(1)).ToList(); foreach (var message in messages) { try { MessageMatcher.Match(message); } catch (Exception ex) { Logger.Error("An error has occured while trying to match old message. Exception = {0}", LogSource.BackgroundTask, ex); } } }
public async Task MqttTransportHandler_SendMethodResponseAsync_SendsMessage() { // arrange var responseBytes = Encoding.UTF8.GetBytes(fakeMethodResponseBody); var transport = CreateTransportHandlerWithMockChannel(out IChannel channel); var response = new MethodResponseInternal(responseBytes, fakeResponseId, statusSuccess); MessageMatcher matches = (msg) => { return(StringComparer.InvariantCulture.Equals(msg.MqttTopicName, $"$iothub/methods/res/{statusSuccess}/?$rid={fakeResponseId}")); }; // act transport.OnConnected(); await transport.OpenAsync(CancellationToken.None).ConfigureAwait(false); await transport.SendMethodResponseAsync(response, CancellationToken.None).ConfigureAwait(false); // assert await channel .Received().WriteAndFlushAsync(Arg.Is <Message>(msg => matches(msg))) .ConfigureAwait(false); }
private ISubscription FindApplicableSubscription(IMessage message) { return(MessageMatcher.MatchSubscription(SubscriptionStore, message)); }
protected override void ExecuteCore() { try { Logger.Debug("Retreiving message {0} from {1}", LogSource.Receive, header, config.DisplayName); foreach (var channelMessage in channel.GetMessage(header)) { // Create a duck copy from the mailMessage. var message = new Message { MessageNumber = header.MessageNumber, MessageIdentifier = channelMessage.MessageIdentifier, From = channelMessage.From, ReturnTo = channelMessage.ReturnTo, To = channelMessage.To, CC = channelMessage.CC, BCC = channelMessage.BCC, InReplyTo = channelMessage.InReplyTo, Size = header.Size, Context = channelMessage.Context.ToClearSubject(), OriginalContext = channelMessage.Context, ConversationIdentifier = channelMessage.ConversationId, SourceFolder = channelMessage.SourceFolder, SourceChannelId = channelMessage.SourceChannelId, TargetChannelId = channelMessage.TargetChannelId, Metadata = channelMessage.Metadata, IsRead = channelMessage.IsRead, IsStarred = channelMessage.IsStarred, DateReceived = channelMessage.DateReceived, DateSent = channelMessage.DateSent }; message.Context = message.Context != null?message.Context.Trim() : String.Empty; string bodyText = channelMessage.BodyText.ReadString(); string bodyHtml = channelMessage.BodyHtml.ReadString(); var access = new ClientMessageAccess(message, bodyText, bodyHtml); if (folder.ToStorageFolder() == Folders.SentItems) { // For sent items we sent the TargetChannelId message.TargetChannelId = config.ChannelId; } else { // For all other items we sent the SourceChannelId message.SourceChannelId = config.ChannelId; } // Create BodyPreview field from reader message.BodyPreview = access.GetBodyPreview(); message.BodyHtmlStreamName = access.WriteBodyHtml(); message.BodyTextStreamName = access.WriteBodyText(); message.MessageFolder = folder.ToStorageFolder(); message.Metadata = header.Metadata; // Fix for messages which have a timestamp in the futre if (message.DateReceived > DateTime.Now) { message.DateReceived = DateTime.Now; } // Set IsNew state for message if (!message.IsRead) { message.IsNew = true; } // Save message ClientState.Current.DataService.Save(message); // Message received, process attachments foreach (var attachment in channelMessage.Attachments) { var document = new Document { Filename = attachment.Filename, SourceChannelId = attachment.SourceChannelId, TargetChannelId = attachment.TargetChannelId, DocumentFolder = folder.ToStorageFolder(), ContentType = attachment.ContentType, ContentId = attachment.ContentId, ContentStream = attachment.ContentStream }; document.SourceChannelId = config.ChannelId; document.DateReceived = message.DateReceived; document.DateSent = message.DateSent; document.Message = message; DocumentsHandler.DocumentReceived(document); if (attachment.ContentStream != null) { attachment.ContentStream.Dispose(); attachment.ContentStream = null; } } if (channelMessage.BodyText != null) { channelMessage.BodyText.Dispose(); } if (channelMessage.BodyHtml != null) { channelMessage.BodyHtml.Dispose(); } // Match thread MessageMatcher.Match(message); // Add to search index ClientState.Current.Search.Store(message); new ProfileMatcher(message).Execute(); } } catch (Exception ex) { Logger.Error("An error occured when trying to download header {0}. Exception = {1}", LogSource.BackgroundTask, header, ex); throw; } }
public OrMatcher(MessageMatcher left, MessageMatcher right) { this.left = left; this.right = right; }