static void CoBProcess() { Database.SetInitializer<OenContext>(null); var oenContext = new OenContext(); var heatContext = new HotmailHeatContext(); var settings = new CancelOnBulkingSettings(oenContext); var logger = new Logger(); var heatTestGen = new HeatDataFaking(oenContext, heatContext, logger); #if DEBUG var emails = new string[] { "*****@*****.**" }; #else var emails = settings.NotifyEmails; #endif var jobRepository = new JobRepository(oenContext, logger, true); var CoB = new CancelOnBulking(logger, new MtaAgent(logger, true), new EmailNotification(logger, jobRepository, emails, settings.SmtpServer), oenContext, new EventRepository(oenContext), jobRepository ); heatTestGen.GenerateData(settings.RunIntervalMinutes); try { var nextReset = DateTime.Today.Add(settings.ResetTime); if (nextReset < DateTime.Now) { nextReset = nextReset.AddDays(1); } CoB.FindAndCancelBulkingCampaigns(new PmtaRepository(oenContext), new DeliveryGroupRepository(oenContext), new HeatDataRepository(oenContext, heatContext), settings.RunIntervalMinutes, settings.MinimumRecords, settings.MinimumInboxing, nextReset ); } catch (Exception ex) { logger.Error(ex.UnwrapForLog(true)); } }
private bool MissingSharedResources() { try { _logger.Info("Checking resources"); var oen = new OenContext(); var coBSettings = new CancelOnBulkingSettings(oen); var f21Settings = new Four21Settings(oen); var jobRepository = new JobRepository(new OenContext(), _logger, true); if (!new EmailNotification(_logger, jobRepository, coBSettings.NotifyEmails.Union(f21Settings.NotifyEmails), coBSettings.SmtpServer).EmailNotificationResourcesAvailable()) { return true; } return false; } catch (Exception ex) { _logger.Error(ex.UnwrapForLog(true)); return true; } }
private CancelOnBulking GetNewCancelOnBulking(OenContext oenContext, CancelOnBulkingSettings settings) { var logger = new Logger("COB"); var jobRepository = new JobRepository(oenContext, logger, settings.DatabaseTestMode); #if DEBUG var mta = new PmtaMonitoring.Testing.Mocking.MtaAgentMock(0, logger); #else var mta = new MtaAgent(logger, settings.MtaTestMode); #endif return new CancelOnBulking(logger, mta, new EmailNotification(logger, jobRepository, settings.NotifyEmails, settings.SmtpServer), oenContext, new EventRepository(oenContext), jobRepository ); }
private void RunCancelOnBulkingReset(OenContext oenContext, CancelOnBulkingSettings settings) { var coB = GetNewCancelOnBulking(oenContext, settings); try { _logger.Info("Starting Cancel on Bulking reset"); coB.ResumeMtaQueues(); } catch (Exception ex) { _logger.Error(ex.UnwrapForLog(true)); } _logger.Info("Finished Cancel on Bulking reset"); }
private void RunCancelOnBulking(OenContext oenContext, CancelOnBulkingSettings settings, DateTime nextReset) { var heatContext = new HotmailHeatContext(); var coB = GetNewCancelOnBulking(oenContext, settings); try { _logger.Info("Starting Cancel on Bulking process"); coB.FindAndCancelBulkingCampaigns(new PmtaRepository(oenContext), new DeliveryGroupRepository(oenContext), new HeatDataRepository(oenContext, heatContext), settings.RunIntervalMinutes, settings.MinimumRecords, settings.MinimumInboxing, nextReset); _logger.Info("Finished Cancel on Bulking process"); } catch (Exception ex) { _logger.Error(ex.UnwrapForLog(true)); } }
private void CancelOnBulkingTick(object sender, ElapsedEventArgs e) { _cancelOnBulkingTimer.Stop(); _logger.Info("CancelOnBulking Timer Ticked"); try { var oenContext = new OenContext(); var settings = new CancelOnBulkingSettings(oenContext); var nextReset = GetNextResetTime(oenContext, Event.Monitors.CancelOnBulking, settings.ResetTime); if (DateTime.Now >= nextReset) { RunCancelOnBulkingReset(oenContext, settings); } else if (settings.Enabled && DateTime.Now >= _cancelOnBulkingLastRun.AddMinutes(settings.RunIntervalMinutes)) { RunCancelOnBulking(oenContext, settings, nextReset); _cancelOnBulkingLastRun = DateTime.Now; } else { if (!settings.Enabled) { _logger.Info("Cancel on Bulking Disabled"); } _logger.TraceFormat("Next reset {0}", nextReset); _logger.TraceFormat("LastRun reset {0}", _cancelOnBulkingLastRun); _logger.TraceFormat("Next run {0}", _cancelOnBulkingLastRun.AddMinutes(settings.RunIntervalMinutes)); } } catch (Exception ex) { _logger.Fatal(ex.UnwrapForLog(true)); } UpdateTickInterval(); _cancelOnBulkingTimer.Interval = _timerInterval; _cancelOnBulkingTimer.Start(); }
static void CoBReset() { Database.SetInitializer<OenContext>(null); var oenContext = new OenContext(); var heatContext = new HotmailHeatContext(); var settings = new CancelOnBulkingSettings(oenContext); var logger = new Logger(); #if DEBUG var emails = new string[] { "*****@*****.**" }; #else var emails = settings.NotifyEmails; #endif var jobRepository = new JobRepository(oenContext, logger, true); var CoB = new CancelOnBulking(logger, new MtaAgent(logger, true), new EmailNotification(logger, jobRepository, emails, settings.SmtpServer), oenContext, new EventRepository(oenContext), jobRepository ); try { CoB.ResumeMtaQueues(); } catch (Exception ex) { logger.Error(ex.UnwrapForLog(true)); } }