コード例 #1
0
        internal void DispatchHandleMessage(SignalMessage message, SignalConversation conversation)
        {
            List <Task> operations = new List <Task>();

            foreach (var dispatcher in Frames.Keys)
            {
                operations.Add(dispatcher.RunTaskAsync(() =>
                {
                    Frames[dispatcher].HandleMessage(message, conversation);
                }));
            }
            SignalMessageEvent?.Invoke(this, new SignalMessageEventArgs(message, Events.SignalMessageType.NormalMessage));
            Task.WaitAll(operations.ToArray());
        }
コード例 #2
0
        internal async Task DispatchHandleMessage(SignalMessage message, SignalConversation conversation)
        {
            List <Task <AppendResult> > operations = new List <Task <AppendResult> >();

            foreach (var dispatcher in Frames.Keys)
            {
                TaskCompletionSource <AppendResult> taskCompletionSource = new TaskCompletionSource <AppendResult>();
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    AppendResult ar = null;
                    try
                    {
                        ar = (Frames[dispatcher].HandleMessage(message, conversation));
                    }
                    catch (Exception e)
                    {
                        Logger.LogError("DispatchHandleMessage() dispatch failed: {0}\n{1}", e.Message, e.StackTrace);
                    }
                    finally
                    {
                        taskCompletionSource.SetResult(ar);
                    }
                });

                operations.Add(taskCompletionSource.Task);
            }
            SignalMessageEvent?.Invoke(this, new SignalMessageEventArgs(message, Events.SignalPipeMessageType.NormalMessage));
            if (message.Author != null)
            {
                bool wasInstantlyRead = false;
                foreach (var b in operations)
                {
                    AppendResult result = await b;
                    if (result != null && result.WasInstantlyRead)
                    {
                        UpdateMessageExpiration(message, conversation.ExpiresInSeconds);
                        var updatedConversation = SignalDBContext.UpdateMessageRead(message.ComposedTimestamp);
                        await DispatchMessageRead(updatedConversation);

                        wasInstantlyRead = true;
                        break;
                    }
                }
                if (!wasInstantlyRead)
                {
                    await DispatchHandleUnreadMessage(message);
                }
            }
        }
コード例 #3
0
 internal void DispatchPipeEmptyMessage()
 {
     SignalMessageEvent?.Invoke(this, new SignalMessageEventArgs(null, Events.SignalMessageType.PipeEmptyMessage));
 }