private void ReportAuthError(IUnitOfWork uow, Fr8AccountDO user, InvalidTokenRuntimeException ex) { var activityTemplate = ex?.FailedActivityDTO.ActivityTemplate; var errorMessage = $"Activity {ex?.FailedActivityDTO.Label} was unable to authenticate with remote web-service."; errorMessage += $"Please re-authorize {ex?.FailedActivityDTO.Label} activity " + $"by clicking on the Settings dots in the upper " + $"right corner of the activity and then selecting Choose Authentication. "; // Try getting specific the instructions provided by the terminal. if (!String.IsNullOrEmpty(ex.Message)) { errorMessage += "Additional instructions from the terminal: "; errorMessage += ex.Message; } _pusherNotifier.NotifyUser(new NotificationMessageDTO { NotificationType = NotificationType.GenericFailure, Subject = "Plan Failed", Message = errorMessage, Collapsed = false }, user.Id); }
private async Task ReportAuthDeactivation(IUnitOfWork uow, PlanDO plan, InvalidTokenRuntimeException ex) { var activityTemplate = ex?.FailedActivityDTO.ActivityTemplate; string errorMessage = $"Activity {ex?.FailedActivityDTO.Label} was unable to authenticate with remote web-service."; errorMessage += $"Plan \"{plan.Name}\" which contains failed activity was deactivated."; _pusherNotifier.NotifyUser(new NotificationMessageDTO { NotificationType = NotificationType.GenericFailure, Subject = "Plan Failed", Message = errorMessage, Collapsed = false }, plan.Fr8AccountId); //Sending an Email var account = uow.UserRepository.GetQuery().FirstOrDefault(a => a.Id == plan.Fr8AccountId); try { var userEmail = account.UserName; var emailDO = new EmailDO(); IConfigRepository configRepository = ObjectFactory.GetInstance <IConfigRepository>(); string fromAddress = configRepository.Get("EmailAddress_GeneralInfo"); var emailAddressDO = uow.EmailAddressRepository.GetOrCreateEmailAddress(fromAddress); emailDO.From = emailAddressDO; emailDO.FromID = emailAddressDO.Id; emailDO.AddEmailRecipient(EmailParticipantType.To, uow.EmailAddressRepository.GetOrCreateEmailAddress(userEmail)); emailDO.Subject = "Your plan was deactivated due to authentication expiration"; string htmlText = $"Plan “{plan.Name}” was deactivated due to authentication problems. <br>If you would like to keep it active, please reauthenticate <a href='{Server.ServerUrl}dashboard/plans/{plan.Id}/builder?viewMode=plan'>here</a>"; emailDO.HTMLText = htmlText; uow.EnvelopeRepository.ConfigureTemplatedEmail(emailDO, "PlanDeactivated_Template"); uow.SaveChanges(); await ObjectFactory.GetInstance <IEmailPackager>().Send(new EnvelopeDO { Email = emailDO }); } catch { Logger.GetLogger().Error($"Couldn't send email to user {account.Id} to notify him about plan deactivation"); } }