private void UpdateStatus(EmailStatus status, XElement errors) { int count = 0; while (true) { try { using (EmailImportDataContext ctx = new EmailImportDataContext()) { var eml = ctx.Emails.Single(e => e.EmailID == email.EmailID); if (status == EmailStatus.InProgress) { eml.InProgress = true; eml.StartTime = DateTime.Now; eml.EndTime = null; } else { eml.Status = status.ToString(); eml.ProcessedCount = eml.ProcessedCount.GetValueOrDefault() + 1; eml.EndTime = DateTime.Now; eml.InProgress = null; eml.Errors = errors; } ctx.SubmitChanges(); } break; } catch (Exception e) { // Increment the retry counter count++; // Log the exception ConfigLogger.Instance.Log(count < 5 ? LogSeverity.Warning : LogSeverity.Error, email.EmailID, e); // Retry up to 5 times if (count >= 5) { break; } // Sleep for a fraction Thread.Sleep(50); } } }
private MailError(EmailStatus type) : base(type.ToString()) { ErrorCounter++; Type = type; }
public String this[EmailStatus exception] => this["Email", exception.ToString()];