public void Execute(IJobExecutionContext context) { var notificationEmail = Settings.GetNotificationEmail(); Logger.Instance.Info($"Job started: {GetType().Name}"); var tasks = new Tasks(); tasks.StartTask(JobName); var priceLevelPrices = new PriceLevelPrices(); priceLevelPrices.UpdateTemporaryTables(); priceLevelPrices.Empty(); string mappedDsnName = Mapping.GetDsnName("PriceLevelPrices"); var newMapping = new Mapping(mappedDsnName); if (newMapping.MigrateData("PriceLevelPrices") && priceLevelPrices.Publish(out var publishDetails)) { Logger.Instance.Info("Pricing synced."); tasks.SetStatus(JobName, "Success"); if (!string.IsNullOrWhiteSpace(notificationEmail)) { Mail.SendProcessCompleteEmail(notificationEmail, publishDetails, $"{JobName} Publish", response => Logger.Instance.Info(response)); } } else { Logger.Instance.Error("Pricing failed to sync."); tasks.SetStatus(JobName, "Failed"); if (!string.IsNullOrWhiteSpace(notificationEmail)) { Mail.SendProcessCompleteEmail(notificationEmail, $"{JobName} Publish failed, please check logs or contact support", $"{JobName} Publish", response => Logger.Instance.Info(response)); } } tasks.EndTask(JobName); Logger.Instance.Info($"Job finished: {GetType().Name}"); }
private void syncPricing_Click(object sender, EventArgs e) { var bw = new BackgroundWorker(); bw.DoWork += (bwSender, bwEventArgs) => { var notificationEmail = Settings.GetNotificationEmail(); var priceLevelPrices = new PriceLevelPrices(); priceLevelPrices.UpdateTemporaryTables(); priceLevelPrices.Empty(); bw.ReportProgress(0, "Populating Local Repository\r\nPlease Wait"); string mappedDsnName = Mapping.GetDsnName("PriceLevelPrices"); var newMapping = new Mapping(mappedDsnName); if (newMapping.MigrateData("PriceLevelPrices")) { bw.ReportProgress(0, "Preparing to publish to LinkGreen\r\nPlease Wait"); if (priceLevelPrices.Publish(out var publishDetails, bw)) { bwEventArgs.Result = new { Message = "Prices have been published successfully", Title = "Published Successfully", Error = "", InfoMessage = string.Empty }; Logger.Instance.Info("Pricing synced."); if (!string.IsNullOrWhiteSpace(notificationEmail)) { Mail.SendProcessCompleteEmail(notificationEmail, publishDetails, "Pricing Publish", response => Logger.Instance.Info(response)); } } else { bwEventArgs.Result = new { Message = "Unable to publish your prices", Title = "Publish Failed", Error = "Unable to publish your prices", InfoMessage = string.Empty }; Logger.Instance.Error("Pricing failed to sync."); if (!string.IsNullOrWhiteSpace(notificationEmail)) { Mail.SendProcessCompleteEmail(notificationEmail, "Pricing Publish failed, please check logs or contact support", "Pricing Publish", response => Logger.Instance.Info(response)); } } } else { if (!newMapping._validFields) { bwEventArgs.Result = new { Message = "Mapping failed, please validate your field mapping", Title = "Publish Failed", Error = "Mapping failed, please validate your field mapping", InfoMessage = string.Empty }; if (!string.IsNullOrWhiteSpace(notificationEmail)) { Mail.SendProcessCompleteEmail(notificationEmail, "Pricing Publish failed, please validate your field mapping.", "Pricing Publish", response => Logger.Instance.Info(response)); } } else { bwEventArgs.Result = new { Message = "An unexepcted error has occurred, please check your logs or contct support", Title = "Publish Failed", Error = "An unexepcted error has occurred, please check your logs or contct support", InfoMessage = string.Empty }; Logger.Instance.Error("Pricing failed to migrate."); if (!string.IsNullOrWhiteSpace(notificationEmail)) { Mail.SendProcessCompleteEmail(notificationEmail, "Product Publish failed, please check logs or contact support", "Pricing Publish", response => Logger.Instance.Info(response)); } } } }; bw.ProgressChanged += Status_BackgroundWorker_ProgressChanged; bw.RunWorkerCompleted += Status_BackgroundWorker_Completed; bw.WorkerReportsProgress = true; bw.RunWorkerAsync(); }