///// <summary> ///// Gets an IList with all instances of LetterSendLog. ///// </summary> //public static List<LetterSendLog> GetByLetter(Guid letterGuid) //{ // List<LetterSendLog> letterSendLogList // = new List<LetterSendLog>(); // IDataReader reader // = DBLetterSendLog.GetByLetter(letterGuid); // while (reader.Read()) // { // LetterSendLog letterSendLog = new LetterSendLog(); // letterSendLog.rowID = Convert.ToInt32(reader["RowID"]); // letterSendLog.letterGuid = new Guid(reader["LetterGuid"].ToString()); // letterSendLog.userGuid = new Guid(reader["UserGuid"].ToString()); // letterSendLog.emailAddress = reader["EmailAddress"].ToString(); // letterSendLog.uTC = Convert.ToDateTime(reader["UTC"]); // letterSendLog.errorOccurred = Convert.ToBoolean(reader["ErrorOccurred"]); // letterSendLog.errorMessage = reader["ErrorMessage"].ToString(); // letterSendLogList.Add(letterSendLog); // } // reader.Close(); // return letterSendLogList; //} /// <summary> /// Gets an IList with page of instances of LetterSendLog. /// </summary> public static List <LetterSendLog> GetPage( Guid letterGuid, int pageNumber, int pageSize, out int totalPages) { totalPages = 1; List <LetterSendLog> letterSendLogList = new List <LetterSendLog>(); using (IDataReader reader = DBLetterSendLog.GetPage( letterGuid, pageNumber, pageSize, out totalPages)) { while (reader.Read()) { LetterSendLog letterSendLog = new LetterSendLog(); letterSendLog.rowID = Convert.ToInt32(reader["RowID"]); letterSendLog.letterGuid = new Guid(reader["LetterGuid"].ToString()); letterSendLog.userGuid = new Guid(reader["UserGuid"].ToString()); letterSendLog.emailAddress = reader["EmailAddress"].ToString(); letterSendLog.uTC = Convert.ToDateTime(reader["UTC"]); letterSendLog.errorOccurred = Convert.ToBoolean(reader["ErrorOccurred"]); letterSendLog.errorMessage = reader["ErrorMessage"].ToString(); letterSendLogList.Add(letterSendLog); } } return(letterSendLogList); }
private void ReportStatus() { TaskQueue task = new TaskQueue(this.taskGuid); if (totalSubscribersToSend > 0) { task.CompleteRatio = (subscribersSentSoFar / totalSubscribersToSend); } else { task.CompleteRatio = 1; //nothing to send so mark as complete } if (task.CompleteRatio >= 1) { task.Status = statusCompleteMessage; if (task.CompleteUTC == DateTime.MinValue) { task.CompleteUTC = DateTime.UtcNow; } Letter letter = new Letter(this.letterGuid); letter.TrackSendComplete(LetterSendLog.GetCount(letter.LetterGuid)); } else { task.Status = string.Format( CultureInfo.InvariantCulture, statusRunningMessage, subscribersSentSoFar, totalSubscribersToSend); } task.LastStatusUpdateUTC = DateTime.UtcNow; task.Save(); nextStatusUpdateTime = DateTime.UtcNow.AddSeconds(updateFrequency); }
///// <summary> ///// Gets an IList with all instances of LetterSendLog. ///// </summary> //public static List<LetterSendLog> GetByLetter(Guid letterGuid) //{ // List<LetterSendLog> letterSendLogList // = new List<LetterSendLog>(); // IDataReader reader // = DBLetterSendLog.GetByLetter(letterGuid); // while (reader.Read()) // { // LetterSendLog letterSendLog = new LetterSendLog(); // letterSendLog.rowID = Convert.ToInt32(reader["RowID"]); // letterSendLog.letterGuid = new Guid(reader["LetterGuid"].ToString()); // letterSendLog.userGuid = new Guid(reader["UserGuid"].ToString()); // letterSendLog.emailAddress = reader["EmailAddress"].ToString(); // letterSendLog.uTC = Convert.ToDateTime(reader["UTC"]); // letterSendLog.errorOccurred = Convert.ToBoolean(reader["ErrorOccurred"]); // letterSendLog.errorMessage = reader["ErrorMessage"].ToString(); // letterSendLogList.Add(letterSendLog); // } // reader.Close(); // return letterSendLogList; //} /// <summary> /// Gets an IList with page of instances of LetterSendLog. /// </summary> public static List<LetterSendLog> GetPage( Guid letterGuid, int pageNumber, int pageSize, out int totalPages) { totalPages = 1; List<LetterSendLog> letterSendLogList = new List<LetterSendLog>(); using (IDataReader reader = DBLetterSendLog.GetPage( letterGuid, pageNumber, pageSize, out totalPages)) { while (reader.Read()) { LetterSendLog letterSendLog = new LetterSendLog(); letterSendLog.rowID = Convert.ToInt32(reader["RowID"]); letterSendLog.letterGuid = new Guid(reader["LetterGuid"].ToString()); letterSendLog.userGuid = new Guid(reader["UserGuid"].ToString()); letterSendLog.emailAddress = reader["EmailAddress"].ToString(); letterSendLog.uTC = Convert.ToDateTime(reader["UTC"]); letterSendLog.errorOccurred = Convert.ToBoolean(reader["ErrorOccurred"]); letterSendLog.errorMessage = reader["ErrorMessage"].ToString(); letterSendLogList.Add(letterSendLog); } } return letterSendLogList; }
/// <summary> /// Compares 2 instances of LetterSendLog. /// </summary> public static int CompareByUtc(LetterSendLog letterSendLog1, LetterSendLog letterSendLog2) { return letterSendLog1.UTC.CompareTo(letterSendLog2.UTC); }
/// <summary> /// Compares 2 instances of LetterSendLog. /// </summary> public static int CompareByRowId(LetterSendLog letterSendLog1, LetterSendLog letterSendLog2) { return letterSendLog1.RowId.CompareTo(letterSendLog2.RowId); }
/// <summary> /// Compares 2 instances of LetterSendLog. /// </summary> public static int CompareByErrorMessage(LetterSendLog letterSendLog1, LetterSendLog letterSendLog2) { return letterSendLog1.ErrorMessage.CompareTo(letterSendLog2.ErrorMessage); }
/// <summary> /// Compares 2 instances of LetterSendLog. /// </summary> public static int CompareByEmailAddress(LetterSendLog letterSendLog1, LetterSendLog letterSendLog2) { return letterSendLog1.EmailAddress.CompareTo(letterSendLog2.EmailAddress); }
private void SendLetter( SmtpSettings smtpSettings, LetterInfo letterInfo, Letter letter, LetterSubscriber subscriber) { // TODO: use multi part email with both html and plain text body // instead of this either or approach bool testMode = false; if ( (ConfigurationManager.AppSettings["NewsletterTestMode"] != null) && (ConfigurationManager.AppSettings["NewsletterTestMode"] == "true") ) { testMode = true; } LetterSendLog mailLog = new LetterSendLog(); mailLog.EmailAddress = subscriber.EmailAddress; mailLog.LetterGuid = letter.LetterGuid; mailLog.UserGuid = subscriber.UserGuid; if (testMode) { Thread.Sleep(3000); // sleep 3 seconds per message to simulate } else { try { if (subscriber.UseHtml) { Email.SendEmail( smtpSettings, letterInfo.FromAddress, subscriber.EmailAddress, string.Empty, string.Empty, letter.Subject, ReplaceHtmlTokens(letter.HtmlBody, subscriber), subscriber.UseHtml, "Normal"); } else { Email.SendEmail( smtpSettings, letterInfo.FromAddress, subscriber.EmailAddress, string.Empty, string.Empty, letter.Subject, ReplaceTextTokens(letter.TextBody, subscriber), subscriber.UseHtml, "Normal"); } } catch (Exception ex) { // TODO: catch more specific exception(s) figure out what ones can be thrown here mailLog.ErrorOccurred = true; mailLog.ErrorMessage = ex.ToString(); log.Error(ex); } } mailLog.Save(); }
/// <summary> /// Deletes an instance of Letter. Returns true on success. /// </summary> /// <param name="letterGuid"> letterGuid </param> /// <returns>bool</returns> public static bool Delete(Guid letterGuid) { LetterSendLog.DeleteByLetter(letterGuid); return(DBLetter.Delete(letterGuid)); }
/// <summary> /// Compares 2 instances of LetterSendLog. /// </summary> public static int CompareByErrorMessage(LetterSendLog letterSendLog1, LetterSendLog letterSendLog2) { return(letterSendLog1.ErrorMessage.CompareTo(letterSendLog2.ErrorMessage)); }
/// <summary> /// Compares 2 instances of LetterSendLog. /// </summary> public static int CompareByUtc(LetterSendLog letterSendLog1, LetterSendLog letterSendLog2) { return(letterSendLog1.UTC.CompareTo(letterSendLog2.UTC)); }
/// <summary> /// Compares 2 instances of LetterSendLog. /// </summary> public static int CompareByEmailAddress(LetterSendLog letterSendLog1, LetterSendLog letterSendLog2) { return(letterSendLog1.EmailAddress.CompareTo(letterSendLog2.EmailAddress)); }
/// <summary> /// Compares 2 instances of LetterSendLog. /// </summary> public static int CompareByRowId(LetterSendLog letterSendLog1, LetterSendLog letterSendLog2) { return(letterSendLog1.RowId.CompareTo(letterSendLog2.RowId)); }
private void SendLetter( SmtpSettings smtpSettings, LetterInfo letterInfo, Letter letter, LetterSubscriber subscriber) { // TODO: use multi part email with both html and plain text body // instead of this either or approach? LetterSendLog mailLog = new LetterSendLog(); mailLog.EmailAddress = subscriber.EmailAddress; mailLog.LetterGuid = letter.LetterGuid; mailLog.UserGuid = subscriber.UserGuid; mailLog.SubscribeGuid = subscriber.SubscribeGuid; if (testMode) { Thread.Sleep(testSleepMilliseconds); // sleep 1 seconds per message to simulate } else { try { if (subscriber.UseHtml) { Email.Send( smtpSettings, letterInfo.FromAddress.Coalesce(notificationFromEmail), letterInfo.FromName.Coalesce(notificationFromAlias), letterInfo.ReplyToAddress.Coalesce(notificationFromAlias), subscriber.EmailAddress, string.Empty, string.Empty, letter.Subject, ReplaceHtmlTokens(letter.HtmlBody, subscriber, letterInfo), subscriber.UseHtml, "Normal"); } else { Email.Send( smtpSettings, letterInfo.FromAddress.Coalesce(notificationFromEmail), letterInfo.FromName.Coalesce(notificationFromAlias), letterInfo.ReplyToAddress.Coalesce(notificationFromEmail), subscriber.EmailAddress, string.Empty, string.Empty, letter.Subject, ReplaceTextTokens(letter.TextBody, subscriber, letterInfo), subscriber.UseHtml, "Normal"); } } catch (Exception ex) { // TODO: catch more specific exception(s) figure out what ones can be thrown here mailLog.ErrorOccurred = true; mailLog.ErrorMessage = ex.ToString(); log.Error(ex); } } mailLog.Save(); }