private List <PushMessageModel> BuildMessage(NotifyMessage message)
        {
            List <PushMessageModel> pmlist = new List <PushMessageModel>();

            try
            {
                List <NotifyInterfaceSettingModel> nslist = _notifySettingBus.GetListFromCache();
                if (nslist == null || nslist.Count == 0 || message == null)
                {
                    return(null);
                }
                bool isPushNext = false;
                foreach (NotifyInterfaceSettingModel setting in nslist.FindAll(x => x.Status == 2 && x.MessageType.ToString().Equals(message.MessageType, StringComparison.OrdinalIgnoreCase)))
                {
                    PushMessageModel pushMod = new PushMessageModel();
                    pushMod.PushId            = IdentityGenerator.New();
                    pushMod.MessageId         = message.MessageId;
                    pushMod.SettingId         = setting.SettingId;
                    pushMod.MessageKey        = message.MessageKey;
                    pushMod.MessagePriority   = message.MessagePriority;
                    pushMod.MessageType       = message.MessageType;
                    pushMod.PushData          = string.Format("msgid={0}&msgkey={1}&msgtype={2}&data={3}", pushMod.PushId, message.MessageKey, message.MessageType, HttpUtility.UrlEncode(message.NotifyData));
                    pushMod.PushStatus        = PushStatusEnum.UnPush;
                    pushMod.MessageCreateTime = message.CreateTime;
                    pushMod.CreateTime        = DateTime.Now;
                    pushMod.LastModifyTime    = pushMod.CreateTime;
                    pushMod.PushCount         = 0;
                    pushMod.Memo         = string.Format("Add:{0:yyyy-MM-dd HH:mm:ss};{1}", message.CreateTime, Environment.NewLine);
                    pushMod.NextPushTime = ComputePushTimeBusiness.ComputeNextPushTime(pushMod, out isPushNext);

                    pmlist.Add(pushMod);
                }
            }
            catch (Exception ex)
            {
                MetricsKeys.BuilderService_Build.MeterMark("Error");
                Process.Error(message.MessageId, "消息生成中心", "Exception", message.MessageId, "生成推送消息,发生异常:" + ex.GetString(), "");
            }
            finally
            {
                Process.Debug(message.MessageId, "消息生成中心", "finally", message.MessageId, "生成推送消息,条数:" + pmlist.Count, "");
            }
            return(pmlist);
        }
Exemple #2
0
        private void CallbackInternal(PushMessageResult result)
        {
            Check.IsNull(result, "CallbackInternal的参数Obj");
            PushMessageModel model = new PushMessageModel();

            Check.IsNull(result.PushId, "PushMessageResult.PushId");
            PushMessage pushMsg = result.ReferObject as PushMessage;

            Check.IsNull(pushMsg, "PushId查找到的PushMessageModel对象");
            model.PushCount           = pushMsg.PushCount;
            model.SettingId           = pushMsg.SettingId;
            RequestProfile.RequestKey = result.PushId + "_" + pushMsg.PushCount.ToString();
            RequestProfile.MessageKey = result.PushId;

            switch (result.PushStatus)
            {
            case PushResultEnum.Abort:
                model.PushId     = result.PushId;
                model.PushStatus = PushStatusEnum.Abort;
                model.PushCount++;
                model.Memo = string.Format("Abort:{0},{1:yyyy-MM-dd HH:mm:ss};{2}", result.ErrMsg, DateTime.Now, Environment.NewLine);
                break;

            case PushResultEnum.Success:
                model.PushId     = result.PushId;
                model.PushStatus = PushStatusEnum.Pushed;
                model.PushCount++;
                model.Memo = string.Format("Success:{0},{1:yyyy-MM-dd HH:mm:ss};{2}", result.ErrMsg, DateTime.Now, Environment.NewLine);
                break;

            case PushResultEnum.Failed:
                model.PushId     = result.PushId;
                model.PushStatus = PushStatusEnum.Failed;
                bool isPushNext = false;
                //model.PushCount == 3
                //第四次推送的返回
                model.PushCount++;
                model.NextPushTime = ComputePushTimeBusiness.ComputeNextPushTime(model, out isPushNext);
                if (isPushNext)
                {
                    model.PushStatus = PushStatusEnum.UnPush;
                }
                model.Memo = string.Format("Failed:{0},B-{1:yyyy-MM-dd HH:mm:ss},N-{2:yyyy-MM-dd HH:mm:ss};{3}", result.ErrMsg, DateTime.Now, model.NextPushTime, Environment.NewLine);
                break;

            case PushResultEnum.Pushing:
                model.PushId     = result.PushId;
                model.PushStatus = PushStatusEnum.Pushing;
                model.Memo       = string.Format("Pushing:{0},{1:yyyy-MM-dd HH:mm:ss};{2}", result.ErrMsg, DateTime.Now, Environment.NewLine);
                break;

            default:
                break;
            }
            if (!string.IsNullOrWhiteSpace(model.PushId) &&
                (model.PushStatus &
                 (PushStatusEnum.Abort |
                  PushStatusEnum.Pushed |
                  PushStatusEnum.Failed |
                  PushStatusEnum.UnPush |
                  PushStatusEnum.Pushing)) == model.PushStatus)
            {
                model.LastModifyTime = DateTime.Now;
                bool ret = _pushMessageBus.Edit(model);
                if (!ret)
                {
                    lock (m_repeatUpdateTimesLockObj)
                    {
                        //进入补偿更新队列
                        m_repeatUpdateTimes[model.PushId] = 1;
                    }
                    _repeatUpdatePool.Write(model);
                }
                else
                {
                    if (model.PushStatus == PushStatusEnum.UnPush)
                    {
                        string cacheKey = string.Format(CacheKeys.SendToMessageHandler_Arg2, model.PushId, model.PushCount - 1);
                        DistributedCache.Delete(cacheKey);
                    }
                }
                Process.Debug(result.PushId, "消息推送记录", "Callback", result.PushId, string.Format("推送状态:【{0}】,推送结果:【{1}】,更新结果:【{2}】", result.PushStatus.ToString(), result.ErrMsg, ret), "");
            }
        }