public Task Send(NotifyMessage message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (string.IsNullOrWhiteSpace(message.MessageType)) { throw new ArgumentNullException(nameof(message), "message.messageType不能为空"); } var messageType = message.MessageType; var setting = _notifySettingStore.GetBy <NotifySettingBase>(messageType); if (setting == null) { throw new NotifyMessageException("找不到类型是:" + messageType + "的设置"); } if (setting.Status == NotifySettingStatus.Normal) { message.StartSend(); var task = setting.Send(message).ContinueWith(task => { var successSend = task.Result; message.Sent(successSend); _notifyMessageStore.Update(message); _notifySettingStore.SaveChanged(); if (!successSend) { if (message.SendCount <= setting.MaxRetry + 1) { _queue.Add(message, DateTimeOffset.Now.AddSeconds(setting.RetrySpreadSeconds)); } else { message.FailToSent(); } } }); return(task); } if (setting.Status == NotifySettingStatus.Pause) { _notifyMessageStore.Update(message); _notifySettingStore.SaveChanged(); } return(Task.FromResult(0)); }
public abstract Task <bool> Send(NotifyMessage message);