static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { Logger.Fatal(eventArgs.ExceptionObject as Exception); }; Config config = JsonConvert.DeserializeObject <Config>(File.ReadAllText(ConfigFilePath)); var date = DateTime.Now; var month = new DateTime(date.Year, date.Month, 1); //TODO first hide all tabs in the HR sheet report var rawUserDataReporter = new RawUserDataReporter(new RawUserDataSheet(config.RawUsersSheetSettings)); var freshestUserDataReporter = new FreshestUserDataReporter(rawUserDataReporter); var currentUsersReporter = new CurrentUsersReporter(freshestUserDataReporter); ReportWriter <List <UserData> > userDataWriter = new ReportWriter <List <UserData> >(currentUsersReporter, new CurrentUsersSheet(config.CurrentUsersSheetSettings)); userDataWriter.Write(); var publicHolidayReporter = new PublicHolidayReporter(config.PublicHolidayApiKey, Enumerable.Range(HolidayYearStart, month.Year - HolidayYearStart + 2).ToList()); CalculateMonthlyReports(freshestUserDataReporter, publicHolidayReporter, month, config); SendAlerts(freshestUserDataReporter, publicHolidayReporter, date, config); }
private static void SendAlerts(FreshestUserDataReporter freshestUserDataReporter, PublicHolidayReporter publicHolidayReporter, DateTime currentDate, Config config) { var currentUsersReporter = new CurrentUsersReporter(freshestUserDataReporter); var userDataAlertReporter = new UserDataAlertReporter(currentUsersReporter, currentDate); JiraApiClient client = new JiraApiClient(config.JiraSettings); var jiraAbsenceReporter = new JiraAbsenceReporter(freshestUserDataReporter, client); var absenceErrorReporter = new AbsenceErrorsReporter(jiraAbsenceReporter, publicHolidayReporter); var userDataAlertWriter = new ReportWriter <List <BaseAlert> >(userDataAlertReporter, new HrAlertGmail(config.HrAlertGmailSettings, currentDate)); var absenceErrorWriter = new ReportWriter <List <AbsenceError> >(absenceErrorReporter, new AbsenceErrorGmail(config.AbsenceErrorGmailSettings)); userDataAlertWriter.Write(); absenceErrorWriter.Write(); }
private static void FillSheetForDateRange(Config config) { var startDate = new DateTime(2019, 03, 1); var endDate = new DateTime(2019, 03, 7); var client = new JiraApiClient(config.JiraSettings); var userReporter = new RawUserDataReporter(new RawUserDataSheet(config.UsersSheetSettings)); var freshestUserDataReporter = new FreshestUserDataReporter(userReporter); var publicHolidayReporter = new PublicHolidayReporter(config.PublicHolidayApiKey, new List <int> { 2019 }); var jiraAbsenceReporter = new JiraAbsenceReporter(freshestUserDataReporter, client); var absenceReporter = new AbsenceReporter(publicHolidayReporter, jiraAbsenceReporter); foreach (var date in DateTimeUtils.EachDay(startDate, endDate)) { if (date.DayOfWeek != DayOfWeek.Saturday && date.DayOfWeek != DayOfWeek.Sunday) { Logger.Info($"Notifying {date:d}"); var currentRangeWorklogsReporter = new WorklogsReporter(freshestUserDataReporter, client, date.Date, date.Date.AddDays(1).AddSeconds(-1)); var attendanceReporter = new AttendanceReporter(freshestUserDataReporter, absenceReporter, currentRangeWorklogsReporter, date.Date, date.Date.AddDays(1).AddSeconds(-1)); SinnersReporter sinnersReporter = new SinnersReporter(freshestUserDataReporter, currentRangeWorklogsReporter, attendanceReporter, date); var gSheetSinnerReportWriter = new ReportWriter <List <IEnumerable <Sinner> > >(sinnersReporter, new SinnerSheet(config.SinnersSheetSettings)); gSheetSinnerReportWriter.Write(); var gmailSinnerReportWriter = new ReportWriter <List <IEnumerable <Sinner> > >(sinnersReporter, new SinnerGmail(config.SinnerNotifierGmailSettings, date)); gmailSinnerReportWriter.Write(); } } }
public UsersActiveInMonthReporter(FreshestUserDataReporter freshestUserDataReporter, DateTime monthStartDate, DateTime monthEndDate) { _freshestUserDataReporter = freshestUserDataReporter; _monthStartDate = monthStartDate; _monthEndDate = monthEndDate; }
private static void CalculateMonthlyReports(FreshestUserDataReporter freshestUserDataReporter, PublicHolidayReporter holidayReporter, DateTime date, Config config) { JiraApiClient client = new JiraApiClient(config.JiraSettings); var jiraAbsenceReporter = new JiraAbsenceReporter(freshestUserDataReporter, client); var absenceReporter = new AbsenceReporter(holidayReporter, jiraAbsenceReporter); var previousDate = date.AddMonths(-1); var previousDateEnd = date.AddSeconds(-1); var previousDateYear = previousDate.Year; var previousDateMonth = previousDate.Month; var previousDateSheetsPrefix = $"{previousDateYear:D4}{previousDateMonth:D2}"; var previousDateActiveUsersReporter = new UsersActiveInMonthReporter( freshestUserDataReporter, previousDate, previousDateEnd); var previousDateWorkHoursReporter = new MonthWorkHoursReporter( holidayReporter, previousDateMonth, previousDateYear); var previousDateWorklogsReporter = new WorklogsReporter( freshestUserDataReporter, client, previousDate, previousDateEnd); var attendanceReporter = new AttendanceReporter( freshestUserDataReporter, absenceReporter, previousDateWorklogsReporter, previousDate, previousDateEnd); var overtimeReporter = new OvertimeReporter( attendanceReporter, previousDateActiveUsersReporter, previousDateWorkHoursReporter, previousDateYear, previousDateMonth); var overtimeWriter = new ReportWriter <List <Overtime> >( overtimeReporter, new OvertimeSheet(config.OvertimeSheetSettings, previousDateSheetsPrefix)); overtimeWriter.Write(); var salaryDataReporter = new SalaryDataReporter( previousDateActiveUsersReporter, attendanceReporter, jiraAbsenceReporter, previousDateYear, previousDateMonth); var salaryDataWriter = new ReportWriter <List <SalaryData> >( salaryDataReporter, new SalaryDataSheet(config.SalaryDataSheetSettings, previousDateSheetsPrefix)); salaryDataWriter.Write(); var dateEnd = date.AddMonths(1).AddSeconds(-1); var month = date.Month; var year = date.Year; var foodStampSheetsPrefix = $"{year:D4}{month:D2}"; var foodStampWorkHoursReporter = new MonthWorkHoursReporter(holidayReporter, month, year); var foodStampActiveUsersReporter = new UsersActiveInMonthReporter(freshestUserDataReporter, date, dateEnd); var foodStampReporter = new FoodStampReporter( foodStampWorkHoursReporter, absenceReporter, foodStampActiveUsersReporter, year, month, previousDateYear, previousDateMonth); var foodStampWriter = new ReportWriter <List <FoodStampData> >( foodStampReporter, new FoodStampSheet(config.FoodStampSheetSettings, foodStampSheetsPrefix)); foodStampWriter.Write(); }
static void Main(string[] args) { Config config = JsonConvert.DeserializeObject <Config>(File.ReadAllText(ConfigFilePath)); AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { Exception exception = eventArgs.ExceptionObject as Exception; Logger.Fatal(exception); ErrorNotificationGmail errorNotificationGmail = new ErrorNotificationGmail(config.ErrorGmailSettings); errorNotificationGmail.Write(exception); }; DateTime runStartDateTime = DateTime.Now; DateTime from = config.DateFrom ?? new DateTime(DateTime.Now.Year, 1, 1); DateTime till = config.DateTo ?? new DateTime(DateTime.Now.Year, 12, 31); DateTime considerWorklogsFrom = DateTime.Now.AddMonths(-config.MonthsToLog).Date; PublicHolidayReporter publicHolidayReporter = new PublicHolidayReporter(config.PublicHolidayApiKey, Enumerable.Range(2016, till.Year - 2016 + 1).ToList()); var shouldReportSinnersToday = !DateTimeUtils.IsNonWorkingDay(publicHolidayReporter.Report(), DateTime.Now); Logger.Info("Running for date range from {0} to {1}", from, till); JiraApiClient client = new JiraApiClient(config.JiraSettings); JiraProjectReporter projectsReporter = new JiraProjectReporter(client); var projectsWriter = new ReportWriter <List <JiraProject> >(projectsReporter, new ProjectSheet(config.ProjectSheetSettings)); projectsWriter.Write(); var rawUserDataReporter = new RawUserDataReporter(new RawUserDataSheet(config.UsersSheetSettings)); var freshestUserDataReporter = new FreshestUserDataReporter(rawUserDataReporter); WorklogsReporter fullInitWorklogsReporter = new WorklogsReporter(freshestUserDataReporter, client, new DateTime(2017, 1, 1), considerWorklogsFrom); WorklogsReporter currentRangeWorklogsReporter = new WorklogsReporter(freshestUserDataReporter, client, from, till); JiraAbsenceReporter jiraAbsenceReporter = new JiraAbsenceReporter(freshestUserDataReporter, client); AbsenceReporter absenceReporter = new AbsenceReporter(publicHolidayReporter, jiraAbsenceReporter); AttendanceReporter attendanceReporter = new AttendanceReporter(freshestUserDataReporter, absenceReporter, currentRangeWorklogsReporter, from, till); var attendanceReportWriter = new ReportWriter <List <Attendance> >(attendanceReporter, new AttendanceGridSheet(config.AttendanceGridSheetSettings)); attendanceReportWriter.Write(); if (shouldReportSinnersToday) { var dateOfSin = DateTimeUtils.GetLastWorkDay(publicHolidayReporter.Report(), DateTime.Now.Date.AddDays(-1)); var currentUsersReporter = new CurrentUsersReporter(freshestUserDataReporter); SinnersReporter sinnersReporter = new SinnersReporter(currentUsersReporter, currentRangeWorklogsReporter, attendanceReporter, dateOfSin); var gSheetSinnerReportWriter = new ReportWriter <List <IEnumerable <Sinner> > >(sinnersReporter, new SinnerSheet(config.SinnersSheetSettings)); gSheetSinnerReportWriter.Write(); var gmailSinnerReportWriter = new ReportWriter <List <IEnumerable <Sinner> > >(sinnersReporter, new SinnerGmail(config.SinnerNotifierGmailSettings, dateOfSin)); gmailSinnerReportWriter.Write(); } else { Logger.Info("Tool wont report sinners because it is weekend or holiday!"); } Logger.Info("Cleaning and filling database"); System.Data.Entity.Database.SetInitializer(new DropCreateDatabaseIfModelChanges <JiraToolDbContext>()); using (JiraToolDbContext ctx = new JiraToolDbContext()) { using (var transaction = ctx.Database.BeginTransaction()) { InsertInitialWorklogs(ctx, fullInitWorklogsReporter); ClearDatabase(ctx, considerWorklogsFrom); WorklogsReporter updateReporter = new WorklogsReporter(freshestUserDataReporter, client, GetDateTimeForUpdate(ctx, considerWorklogsFrom), DateTime.Now); ctx.Absences.AddRange(absenceReporter.Report().Select(AbsenceMapper.ToModel)); ctx.Worklogs.AddRange(updateReporter.Report().Select(WorklogMapper.ToModel)); ctx.Attendance.AddRange(attendanceReporter.Report().Select(AttendanceMapper.ToModel)); ctx.Users.AddRange(freshestUserDataReporter.Report().Select(UserMapper.ToModel)); ctx.SaveChanges(); transaction.Commit(); } } WorklogsFromDbReporter fullHistoryWorklogsReporter = new WorklogsFromDbReporter(freshestUserDataReporter, new JiraToolDbContext(), new DateTime(2017, 1, 1), DateTime.Now); ProjectTimeSpentReporter projectTimeSpentReporter = new ProjectTimeSpentReporter(fullHistoryWorklogsReporter); var projectTimeSpentWriter = new ReportWriter <Dictionary <string, decimal> >(projectTimeSpentReporter, new ProjectTimeSpentSheet(config.ProjectTimeSpentSheetSettings)); projectTimeSpentWriter.Write(); DateTime runEndDateTime = DateTime.Now; ToolRunReporter runReporter = new ToolRunReporter(runStartDateTime, runEndDateTime); ReportWriter <ToolRun> toolRunWriter = new ReportWriter <ToolRun>(runReporter, new RunLogSheet(config.RunLogSheetSettings)); toolRunWriter.Write(); Logger.Info("Tool run finished"); }