public IExecutableCommand SummaryReportChain(ReportContextWithModel <SummaryEmailModel> context) { CommandChainCreator chain = new CommandChainCreator(); chain.Add(commands.LoadDataAndCreateEmailModelCommand(context)); chain.Add(commands.GenerateEmailCommand(context)); chain.Add(commands.SendEmailCommand(context)); return(chain.FirstCommand); }
public LoadDataAndCreateEmailModelCommand(ILog log, ReportContextWithModel <SummaryEmailModel> context, DBMS.Contracts.IRepositoriesFactory dbmsRepositories, IRepositoriesFactory dalRepositories) { this.log = log; this.context = context; databasesRepository = dbmsRepositories.GetDatabasesRepository(); relationsRepository = dbmsRepositories.GetRelationsRepository(); totalRelationStatisticsRepository = dalRepositories.GetTotalRelationStatisticsRepository(); normalizedStatementStatisticsRepository = dalRepositories.GetNormalizedStatementStatisticsRepository(); }
private static Dictionary <TimeSpan, IExecutableCommand> PlanRegularTasks(ICommandChainFactory chains) { var regularTasks = new Dictionary <TimeSpan, IExecutableCommand>(); regularTasks.Add(new TimeSpan(2, 0, 0), new ActionCommand(() => { DateTime previousDay = DateTime.Now.Date.AddDays(-1); var context = new ReportContextWithModel <SummaryEmailModel>(); context.DateFromInclusive = previousDay; context.DateToExclusive = previousDay.AddDays(1); context.TemplateId = DAL.Contracts.SettingPropertyKeys.EMAIL_TEMPLATE_SUMMARY_REPORT; chains.SummaryReportChain(context).Execute(); return(true); })); return(regularTasks); }
static void Main(string[] args) { var log = Common.Logging.NLog.NLog.Instace; var queue = new CommandProcessingQueue <IExecutableCommand>(log, "ProcessingQueue"); var dalRepositories = DAL.RepositoriesFactory.Instance; var dbmsRepositories = DBMS.Postgres.RepositoriesFactory.Instance; var razorEngine = new RazorEngine(); var commands = new CommandFactory(log, dalRepositories, dbmsRepositories, razorEngine); var chains = new CommandChainFactory(commands); var regularTasks = PlanRegularTasks(chains); var taskScheduler = new RegularTaskScheduler(queue, regularTasks); taskScheduler.Start(); Console.WriteLine("ReportingService is running. Type in S to immediately send current report. Type in any other key to exit..."); bool canQuit = false; do { var line = (Console.ReadLine() ?? "").ToLower(); if (line == "s") { DateTime now = DateTime.Now; var context = new ReportContextWithModel <SummaryEmailModel>(); context.DateFromInclusive = now.AddDays(-1); context.DateToExclusive = now; context.TemplateId = DAL.Contracts.SettingPropertyKeys.EMAIL_TEMPLATE_SUMMARY_REPORT; try { chains.SummaryReportChain(context).Execute(); Console.WriteLine("Current report sent."); } catch (Exception ex) { Console.Write(ex); } canQuit = false; } else { canQuit = true; } } while (!canQuit); taskScheduler.Stop(); taskScheduler.Dispose(); queue.Dispose(); razorEngine.Dispose(); }
public GenerateEmailCommand(ReportContextWithModel <TModel> context, ISettingPropertiesRepository settingPropertiesRepository, IRazorEngine razorEngine) { this.context = context; this.settingPropertiesRepository = settingPropertiesRepository; this.razorEngine = razorEngine; }
public IChainableCommand LoadDataAndCreateEmailModelCommand(ReportContextWithModel <SummaryEmailModel> context) { return(new LoadDataAndCreateEmailModelCommand(log, context, dbmsRepositories, dalRepositories)); }
public IChainableCommand GenerateEmailCommand <TModel>(ReportContextWithModel <TModel> context) { return(new GenerateEmailCommand <TModel>(context, dalRepositories.GetSettingPropertiesRepository(), razorEngine)); }