/// <summary> /// Records an unsuccessful attempt to send this SMS. /// </summary> public static async Task RecordRetry(this ISmsQueueItem sms) { if (sms.IsNew) { throw new InvalidOperationException(); } await Database.Update(sms, s => s.Retries++); // Also update this local instance: sms.Retries++; }
/// <summary> /// Sends the specified SMS item. /// It will try several times to deliver the message. The number of retries can be specified in AppConfig of "SMS:MaximumRetries". /// If it is not declared in web.config, then 3 retires will be used. /// Note: The actual SMS Sender component must be implemented as a public type that implements ISMSSender interface. /// The assembly qualified name of that component, must be specified in AppConfig of "SMS:SenderType". /// </summary> public static async Task <bool> Send(ISmsQueueItem smsItem) { if (smsItem.Retries > Config.Get("SMS:MaximumRetries", 3)) { return(false); } try { ISMSSender sender; try { sender = Activator.CreateInstance(Type.GetType(Config.GetOrThrow("SMS:SenderType"))) as ISMSSender; if (sender == null) { throw new Exception("Type is not defined, or it does not implement ISMSSender"); } } catch (Exception ex) { Log.For(typeof(SmsService)).Error(ex, "Can not instantiate the sms sender from App config of " + Config.Get("SMS:SenderType")); return(false); } sender.Deliver(smsItem); await Database.Update(smsItem, o => o.DateSent = LocalTime.Now); return(true); } catch (Exception ex) { await SendError.Raise(new SmsSendingEventArgs(smsItem) { Error = ex }); Log.For(typeof(SmsService)).Error(ex, "Can not send the SMS queue item."); await smsItem.RecordRetry(); return(false); } }
/// <summary> /// Sends the specified SMS item. /// It will try several times to deliver the message. The number of retries can be specified in AppConfig of "SMS.Maximum.Retries". /// If it is not declared in web.config, then 3 retires will be used. /// Note: The actual SMS Sender component must be implemented as a public type that implements ISMSSender interface. /// The assembly qualified name of that component, must be specified in AppConfig of "SMS.Sender.Type". /// </summary> public static bool Send(ISmsQueueItem smsItem) { if (smsItem.Retries > Config.Get <int>("SMS.Maximum.Retries", 3)) { return(false); } try { ISMSSender sender; try { sender = Activator.CreateInstance(Type.GetType(Config.Get("SMS.Sender.Type"))) as ISMSSender; if (sender == null) { throw new Exception("Type is not defined, or it does not implement ISMSSender"); } } catch (Exception ex) { Log.Error("Can not instantiate the sms sender from App config of " + Config.Get("SMS.Sender.Type"), ex); return(false); } sender.Deliver(smsItem); Database.Update(smsItem, o => o.DateSent = LocalTime.Now); return(true); } catch (Exception ex) { OnSendError(smsItem, ex); Log.Error("Can not send the SMS queue item.", ex); smsItem.RecordRetry(); return(false); } }
public SmsSendingEventArgs(ISmsQueueItem item) { Item = item; }
/// <summary> /// Sends the specified SMS item. /// It will try several times to deliver the message. The number of retries can be specified in AppConfig of "SMS:MaximumRetries". /// If it is not declared in web.config, then 3 retires will be used. /// Note: The actual SMS Sender component must be implemented as a public type that implements ISMSSender interface. /// The assembly qualified name of that component, must be specified in AppConfig of "SMS:SenderType". /// </summary> public static Task <bool> Send(this ISmsQueueItem sms) => SmsService.Send(sms);
/// <summary> /// Updates the DateSent field of this item and then soft deletes it. /// </summary> public static Task MarkSent(this ISmsQueueItem sms) { return(Database.EnlistOrCreateTransaction(() => Database.Update(sms, o => o.DateSent = LocalTime.Now))); }
/// <summary> /// Sends the specified SMS item. /// It will try several times to deliver the message. The number of retries can be specified in AppConfig of "SMS.Maximum.Retries". /// If it is not declared in web.config, then 3 retires will be used. /// Note: The actual SMS Sender component must be implemented as a public type that implements ISMSSender interface. /// The assembly qualified name of that component, must be specified in AppConfig of "SMS.Sender.Type". /// </summary> public static bool Send(this ISmsQueueItem sms) => SmsService.Send(sms);
static void OnSendError(ISmsQueueItem email, Exception error) { SendError?.Invoke(email, new EventArgs <Exception>(error)); }
/// <summary> /// Sends the specified SMS item. /// It will try several times to deliver the message. The number of retries can be specified in AppConfig of "SMS.Maximum.Retries". /// If it is not declared in web.config, then 3 retires will be used. /// Note: The actual SMS Sender component must be implemented as a public type that implements ISMSSender interface. /// The assembly qualified name of that component, must be specified in AppConfig of "SMS.Sender.Type". /// </summary> public static bool Send(this ISmsQueueItem sms) { return(SmsService.Send(sms)); }