Beispiel #1
0
        /// <summary>
        /// 检查数据是否已经接受完全,即是否已经接受到了数据头和数据尾,如果是则开始分析数据
        /// </summary>
        private void CheckDatas()
        {
            Dictionary <String, String> result = null;

            //长度不够
            if (RecieveDatas.Count < 12)
            {
                return;
            }
            //检查头
            for (int counter = 0; counter < 4; counter++)
            {
                if (RecieveDatas[counter] != 255)
                {
                    return;
                }
            }

            //检查尾
            for (int counter = RecieveDatas.Count - 1; counter >= RecieveDatas.Count - 4; counter--)
            {
                if (RecieveDatas[counter] != 0)
                {
                    return;
                }
            }

            result = AnalysisData(RecieveDatas.ToArray());
            RecieveDatas.Clear();

            //接受错误数据
            if (result == null)
            {
                //回复接受失败
                SendMeesageAsync("", CommandEnum.ANSWER_FAILED, null);
            }
            //接受到了数据
            else
            {
                //如果接收到是对方的回信指令,则无需回信
                //命令为接收数据成功
                if ((CommandEnum)int.Parse(result[ANALYSE_KEY_COMMAND]) == CommandEnum.ANSWER_SUCCESS)
                {
                    SendMDel.Invoke(true, "SUCCESS", CommandEnum.NONE);
                }
                //命令为接受数据失败
                else if ((CommandEnum)int.Parse(result[ANALYSE_KEY_COMMAND]) == CommandEnum.ANSWER_FAILED)
                {
                    //SendMDel.Invoke(false, "ANSWER_OUT_OF_TIME", CommandEnum.NONE);
                    //如果重发次数小于最大次数
                    if (ResendTimes < MAX_RESEND)
                    {
                        //重新发送数据
                        SendMeesageAsync(SendContent, SendCommand, SendMDel);
                        //重发次数自增
                        ResendTimes++;
                    }
                    else
                    {
                        //执行代理事件,发送讯息,标识失败,已经达到了最大重发次数
                        SendMDel.Invoke(false, "SEND_FAILED_MAX_RESEND", CommandEnum.NONE);
                    }
                }
                //正常指令
                else
                {
                    //回复接受成功
                    SendMeesageAsync("", CommandEnum.ANSWER_SUCCESS, null);
                    //接受数据成功,则直接调用代理函数
                    GetMessageEvent.Invoke(true, result[ANALYSE_KEY_DATA], (CommandEnum)int.Parse(result[ANALYSE_KEY_COMMAND]));
                }
            }
        }
 public async Task <IActionResult> GetUnreadMessagesInEvent([FromBody] GetMessageEvent command)
 => Json(await _messageEventService.GetUnreadMessagesInEvent(UserId, command.EventId));