/// <summary> /// ReSends the message from history data. /// </summary> /// <param name="id">The delivery item identifier to resend.</param> /// <param name="token">The token.</param> /// <returns>Task<System.Boolean>.</returns> /// <exception cref="System.ArgumentException"> /// Message with the specified id not found in the history store, unable to /// resend message. /// </exception> /// <exception cref="System.InvalidOperationException"> /// DeliveryItem is not re-sendable. The message may have originally been delivered with attachments, but attachment /// serialization may have been disabled for the history store /// </exception> /// The cancellation token. public virtual async Task <DeliveryItem> ReSendAsync(Guid id, CancellationToken token) { var di = await HistoryStore.GetAsync(id, token); if (di == null) { throw new ArgumentException( $"Mailer re-send error for delivery item ID '{id}'. Delivery item not found in the history store, unable to resend message"); } if (!di.IsResendable) { throw new InvalidOperationException( $"Mailer re-send error for delivery item ID '{id}'. Delivery item is not re-sendable. The message may have originally been delivered with attachments, but attachment serialization may have been disabled for the history store"); } di.Id = Guid.NewGuid(); di.ProviderMessageId = null; di.IsSuccess = false; di.CreatedDate = DateTimeOffset.UtcNow; di.ExceptionMessage = null; Logger.LogInformation( "Mailer preparing to re-send delivery item ID '{deliveryItemId}' to '{to}' with subject '{subject}'", di.Id, di.ToEmailAddress, di.Subject); ((IMailer)this).PendingDeliverables.Add(di); return(await SendAsync(di.Id, true, token)); }
/// <summary> /// Sends one pending delivery item with the specified identifier. /// </summary> /// <param name="id">The delivery item identifier.</param> /// <param name="autoCloseConnection"> /// If set to <c>true</c> will close connection immediately after delivering the message. /// If caller is sending multiple messages, optionally set to false to leave the mail service connection open. /// </param> /// <param name="token">The cancellation token.</param> /// <returns>Task<IEnumerable<MessageDeliveryItem>>.</returns> public virtual async Task <DeliveryItem> SendAsync( Guid id, bool autoCloseConnection = true, CancellationToken token = new CancellationToken()) { using (await _deliverablesLock.LockAsync()) { var deliveryItem = ((IMailer)this).PendingDeliverables.FirstOrDefault(d => d.Id == id); if (deliveryItem != null) { try { deliveryItem.ProviderMessageId = await DeliverMessageAsync(deliveryItem, autoCloseConnection, token); deliveryItem.IsSuccess = true; Logger.LogInformation( "Mailer delivery {result} for delivery item '{deliveryItemId}' sent to '{to}' with subject '{subject}'", deliveryItem.IsSuccess ? "success" : "failure", deliveryItem.Id, deliveryItem.ToEmailAddress, deliveryItem.Subject ); } catch (Exception ex) { Logger.LogError(1, ex, "Mailer delivery {result} for delivery item '{deliveryItemId}' with exception '{exceptionMessage}'", "error", id, ex.Message); deliveryItem.ExceptionMessage = $"{ex.Message}\n\n{ex.StackTrace}"; } finally { try { await HistoryStore.AddAsync(deliveryItem, token); } catch (Exception ex) { //do not re-throw, record that history fail and allow sendAll to continue delivering other items. Logger.LogError(1, ex, "History store add {result} for delivery item '{deliveryItemId}' with exception '{exceptionMessage}'", "error", id, ex.Message); } PendingDeliveryItems.Remove(deliveryItem); } } return(deliveryItem); } }
public AdvancedWorkflowProvider(string databaseName, HistoryStore historyStore) : base(databaseName, historyStore) { }
public HistoryController(HistoryStore historyStore) { _historyStore = historyStore; }