public SmtpOperationStatus TestSmtpSettings() { CheckSmtpPermissions(); var settings = ToSmtpSettings(CoreContext.Configuration.SmtpSettings); var smtpTestOp = new SmtpOperation(settings, CurrentTenant, CurrentUser); SMTPTasks.QueueTask(smtpTestOp.RunJob, smtpTestOp.GetDistributedTask()); return(ToSmtpOperationStatus()); }
private static SmtpOperationStatus ToSmtpOperationStatus() { var operations = SMTPTasks.GetTasks().ToList(); foreach (var o in operations) { if (!string.IsNullOrEmpty(o.InstanseId) && Process.GetProcesses().Any(p => p.Id == int.Parse(o.InstanseId))) { continue; } o.SetProperty(SmtpOperation.PROGRESS, 100); SMTPTasks.RemoveTask(o.Id); } var operation = operations .FirstOrDefault(t => t.GetProperty <int>(SmtpOperation.OWNER) == TenantProvider.CurrentTenantID); if (operation == null) { return(null); } if (DistributedTaskStatus.Running < operation.Status) { operation.SetProperty(SmtpOperation.PROGRESS, 100); SMTPTasks.RemoveTask(operation.Id); } var result = new SmtpOperationStatus { Id = operation.Id, Completed = operation.GetProperty <bool>(SmtpOperation.FINISHED), Percents = operation.GetProperty <int>(SmtpOperation.PROGRESS), Status = operation.GetProperty <string>(SmtpOperation.RESULT), Error = operation.GetProperty <string>(SmtpOperation.ERROR), Source = operation.GetProperty <string>(SmtpOperation.SOURCE) }; return(result); }