Example #1
0
 /* This is impure and testable given some finagling with moq. */
 public void SendEmail(string email)
 {
     if (!smtp.SendEmail(email))
     {
         log.Error("Customer email not sent");
     }
 }
Example #2
0
        public void ReportRemovedDataFiles(List <string> fileUrls)
        {
            if (fileUrls != null && fileUrls.Count > 0)
            {
                Logger.Info($"Removed data files to include in the report: {string.Join(", ", fileUrls)}");

                if (env.SMTP_NOTIFICATIONS_ON)
                {
                    Logger.Info("SMTP_NOTIFICATIONS_ON = true, sending email");

                    var body = new StringBuilder();
                    body.AppendLine($"Report for Topcat robot run {DateTime.Now}");
                    body.AppendLine();
                    body.AppendLine("The following files have been removed:");
                    foreach (var url in fileUrls)
                    {
                        body.AppendLine(url);
                    }

                    smtpClient.SendEmail(env.SMTP_FROM, env.SMTP_TO, "MEOW - Removed data files", body.ToString());

                    Logger.Info("Email sent successfully");
                }
                else
                {
                    Logger.Info("SMTP_NOTIFICATIONS_ON = false");
                }
            }
            else
            {
                Logger.Info("No data files removed, reporting not needed");
            }
        }
 /* I don't have to incur try-catches in my calling code */
 public Result <Request> SendEmail(Request request)
 {
     if (!smtp.SendEmail(request.Email))
     {
         return("Customer email not sent");
     }
     else
     {
         return(request);
     }
 }
Example #4
0
        // static with no hidden dependencies = totally testable now
        public static Result <Request> SendEmail(Request request, ISmtpClient smtp, ILog log)
        {
            const string error = "Customer email not sent";

            if (!smtp.SendEmail(request.Email))
            {
                log.Error(error);
                return(error);
            }
            else
            {
                return(request);
            }
        }
        public async Task <IActionResult> OnPostAsync()
        {
            var result = await _validator.ValidateAsync(Email);

            if (result.IsValid)
            {
                await _smtpClient.SendEmail(Email.EmailAddress, Email.Subject, Email.Message);

                ViewData["FormMessage"] = "Message sent comrade!";
                ViewData["FormSuccess"] = result.IsValid;
            }
            else
            {
                ViewData["FormMessage"] = result.Errors.First().ErrorMessage;
                ViewData["FormSuccess"] = result.IsValid;
            }

            return(Page());
        }
Example #6
0
        public void Publish(bool metadataOnly = false)
        {
            try
            {
                List <Record> recordsToPublish;

                // retrieve records
                using (var db = store.OpenSession())
                {
                    var robotPublisher = GetPublisher(db);

                    recordsToPublish = robotPublisher.GetRecordsPendingUpload();
                    Logger.Info($"Found {recordsToPublish.Count} records to publish");
                }

                var oldDataFiles = new Dictionary <string, List <string> >();

                // publish records
                foreach (var record in recordsToPublish)
                {
                    var recordId  = Helpers.RemoveCollection(record.Id);
                    var dataFiles = dataService.GetDataFiles(recordId);

                    using (var db = store.OpenSession())
                    {
                        var robotPublisher = GetPublisher(db);
                        if (robotPublisher.PublishRecord(record, metadataOnly) && dataFiles.Count > 0)
                        {
                            oldDataFiles.Add(recordId, dataFiles);
                        }
                    }
                }

                // cleanup and reporting
                var removedFiles = new List <string>();
                foreach (var entry in oldDataFiles)
                {
                    var currentDataFiles = dataService.GetDataFiles(entry.Key);
                    foreach (var oldDataFile in entry.Value)
                    {
                        if (!currentDataFiles.Contains(oldDataFile))
                        {
                            removedFiles.Add(oldDataFile);
                        }
                    }

                    dataService.RemoveRollbackFiles(entry.Key);
                }

                dataService.ReportRemovedDataFiles(removedFiles);
            }
            catch (Exception e)
            {
                Logger.Error("Error in publishing process", e);

                if (env.SMTP_NOTIFICATIONS_ON)
                {
                    Logger.Info("SMTP_NOTIFICATIONS_ON = true, sending email");

                    smtpClient.SendEmail(env.SMTP_FROM, env.SMTP_TO, "MEOW - Publishing error",
                                         $"Something went wrong which caused the process to stop unexpectedly. Check the logs at {ConfigurationManager.AppSettings["LogFilePath"]}\n\n{e}");

                    Logger.Info("Email sent successfully");
                }
                else
                {
                    Logger.Info("SMTP_NOTIFICATIONS_ON = false");
                }
            }
        }