Beispiel #1
0
        internal static void ProcessConversationMessage(Device device, ConversationMessage cm)
        {
            var conversation = Conversations.GetByKey(cm.ConversationID);

            if (conversation == null)
            {
                if (cm is ConversationRequestMessage)
                {
                    var       crm       = cm as ConversationRequestMessage;
                    Responder responder = crm.CreateResponder();
                    responder.Id             = crm.ConversationID;
                    responder.Peer           = device;
                    responder.RequestMessage = crm;
                    AttachConversation(responder);
                    ConversationReceived?.Invoke(responder);
                }
                else if (cm is ConversationRecoverRequestMessage)
                {
                    //TODO 反序列化并且提示用户是否同意恢复会话。
                    //如果程序异常退出,对方发来的recoverrequest,这一端并不知情。不会有任何响应。
                    conversation = DeserializeConversation(cm as ConversationRecoverRequestMessage);
                    if (conversation != null)
                    {
                        ConversationRecovered?.Invoke(conversation);
                    }
                    else
                    {
                        var msg = new ConversationRejectMessage(RejectCode.DeSerializeFailed)
                        {
                            ConversationID = cm.ConversationID
                        };
#pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
                        device.Post(msg);
#pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
                    }
                }
            }
            else
            {
                conversation.Process(cm);
            }
        }
        internal void ProcessConversationMessage(Device device, ConversationMessage cm)
        {
            var conversation = Conversations.GetByID(cm.ConversationID);

            if (conversation == null)
            {
                if (cm is ConversationRequestMessage)
                {
                    var       crm       = cm as ConversationRequestMessage;
                    Responder responder = crm.CreateResponder();
                    responder.AppModel       = this;
                    responder.ID             = crm.ConversationID;
                    responder.Peer           = device;
                    responder.RequestMessage = crm;
                    AttachConversation(responder);
                    ConversationReceived?.Invoke(responder);
                }
                else if (cm is ConversationRecoverRequestMessage)
                {
                    //TODO 反序列化并且提示用户是否同意恢复会话。
                    //如果程序异常退出,对方发来的recoverrequest,这一端并不知情。不会有任何响应。
                    conversation = DeserializeConversation(cm as ConversationRecoverRequestMessage);
                    if (conversation != null)
                    {
                        ConversationRecovered?.Invoke(conversation);
                    }
                    else
                    {
                        var msg = new ConversationRejectMessage(RejectCode.DeSerializeFailed);
                        msg.ConversationID = cm.ConversationID;
                        device.Post(msg);
                    }
                }
            }
            else
            {
                conversation.Process(cm);
            }
        }