public async Task <int> ViewedMessage([FromBody] MessageStatusRequest request)
        {
            //取得存在cookie的当前账户id
            var temp_id = Int32.Parse(User.Identity.Name);

            var temp_entity = _mapper.Map <MessageEntity>(request);
            var temp        = await MessageAccessor.Change(temp_entity);

            return(temp);
        }
Exemple #2
0
        public override Task <MessageStatusResponse> GetStatus(MessageStatusRequest request, ServerCallContext context)
        {
            var resp = new MessageStatusResponse();
            var info = new MessageStatus(_redis, request.MessageId).GetInfo();

            if (info == null)
            {
                resp.Error = new Error
                {
                    ErrCode = 404,
                    ErrMsg  = "invalid MessageId"
                };
            }
            else
            {
                var pendingNum = info.PendingList.Count();
                var sendedNum  = info.SendedList.Count();
                if (pendingNum == 0 && sendedNum == 0)
                {
                    resp.Status = MessageStatusResponse.Types.Status.Finished;
                }
                else if (pendingNum < info.Total)
                {
                    resp.Status = MessageStatusResponse.Types.Status.Processing;
                }
                else
                {
                    resp.Status = MessageStatusResponse.Types.Status.Pending;
                }
                resp.TotalNum        = info.Total;
                resp.SuccessNum      = info.SuccessList.Count();
                resp.UserBlockNum    = info.UserBlockList.Count();
                resp.SystemFailedNum = info.SystemFailedList.Count();
                resp.SendErrorNum    = info.SendErrorList.Count();
                resp.SendTime        = info.Time;
                if (request.Detail)
                {
                    resp.SuccessList.AddRange(info.SuccessList);
                    resp.UserBlockList.AddRange(info.UserBlockList);
                    resp.SystemFailedList.AddRange(info.SystemFailedList);
                    resp.SendErrorList.AddRange(info.SendErrorList);
                }
            }
            return(Task.FromResult(resp));
        }
Exemple #3
0
        public void MessageStatusRequestTest()
        {
            var messageStatusRequest = new MessageStatusRequest
            {
                mocean_msgid       = "test msgid",
                mocean_resp_format = "json"
            };

            Assert.IsNotNull(messageStatusRequest.mocean_msgid);
            Assert.AreEqual(messageStatusRequest.mocean_msgid, "test msgid");
            Assert.IsNotNull(messageStatusRequest.mocean_resp_format);
            Assert.AreEqual(messageStatusRequest.mocean_resp_format, "json");

            messageStatusRequest = new MessageStatusRequest();
            Assert.IsNull(messageStatusRequest.mocean_msgid);
            Assert.IsNull(messageStatusRequest.mocean_resp_format);
            messageStatusRequest.mocean_msgid = "test msgid";
            Assert.AreEqual(messageStatusRequest.mocean_msgid, "test msgid");
            messageStatusRequest.mocean_resp_format = "json";
            Assert.AreEqual(messageStatusRequest.mocean_resp_format, "json");
        }
Exemple #4
0
        public override Task <Error> Cancel(MessageStatusRequest request, ServerCallContext context)
        {
            var resp = new Error();

            if (string.IsNullOrEmpty(request.MessageId))
            {
                resp.ErrCode = -1;
                resp.ErrMsg  = "Wrong message id";
            }
            else
            {
                var messageStatus = new MessageStatus(_redis, request.MessageId);
                if (messageStatus.GetInfo().Time > Util.GetTimestamp())
                {
                    BackgroundJob.Enqueue <MessageStatus>(x => x.CancelJob(messageStatus.GetMessageId(), null));
                }
                else
                {
                    resp.ErrCode = 9999;
                    resp.ErrMsg  = "Can't Cancel, already processed!";
                }
            }
            return(Task.FromResult(resp));
        }