Exemplo n.º 1
0
        public WorkYear(int year, WorkDayParserSettings parserSettings, int hitListLookBackInWeeks, float hoursPerDay, PNSearchViewModel pnSearch, PositionSearchViewModel positionSearch)
        {
            this.hitListLookBackInWeeks = hitListLookBackInWeeks;
            this.pnSearch       = pnSearch;
            this.positionSearch = positionSearch;
            this.Year           = year;
            this.Months         = new ObservableCollection <WorkMonth>();
            this.Weeks          = new ObservableCollection <WorkWeek>();

            var germanSpecialDays = SpecialDaysUtils.GetGermanSpecialDays(year);

            var cal = new GregorianCalendar();

            for (int month = 1; month <= cal.GetMonthsInYear(year); month++)
            {
                WorkMonth wm = new WorkMonth(year, month, germanSpecialDays, parserSettings, hoursPerDay);
                this.Months.Add(wm);
                foreach (var workWeek in wm.Weeks)
                {
                    this.Weeks.Add(workWeek);
                    workWeek.PropertyChanged += this.workWeek_PropertyChanged;
                }
            }
            this.ProjectHitlist  = new QuickFillObservableCollection <HitlistInfo>();
            this.PositionHitlist = new QuickFillObservableCollection <HitlistInfo>();
            this.UpdateProjectHitlistAsync();
            this.UpdatePositionHitlistAsync();
        }
Exemplo n.º 2
0
        public WorkYear(int year, WorkDayParserSettings parserSettings, int hitListLookBackInWeeks, float hoursPerDay, PNSearchViewModel pnSearch, PositionSearchViewModel positionSearch)
        {
            this.hitListLookBackInWeeks = hitListLookBackInWeeks;
            this.pnSearch       = pnSearch;
            this.positionSearch = positionSearch;
            this.Year           = year;
            this.Months         = new ObservableCollection <WorkMonth>();

            var germanSpecialDays = SpecialDaysUtils.GetGermanSpecialDays(year);

            var calendar = new GregorianCalendar();

            for (var month = 1; month <= calendar.GetMonthsInYear(year); month++)
            {
                var workMonth = new WorkMonth(year, month, germanSpecialDays, parserSettings, hoursPerDay);
                this.Months.Add(workMonth);
            }

            this.ProjectHitlist  = new QuickFillObservableCollection <HitlistInfo>();
            this.PositionHitlist = new QuickFillObservableCollection <HitlistInfo>();

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
            {
                this.UpdateProjectHitlistAsync().SafeFireAndForget(onException: exception => { logger.Error(exception, "Error while updating the Project Hitlist."); });
                this.UpdatePositionHitlistAsync().SafeFireAndForget(onException: exception => { logger.Error(exception, "Error while updating the Position Hitlist."); });

                foreach (var month in this.Months)
                {
                    foreach (var week in month.Weeks)
                    {
                        week.PropertyChanged += this.WorkWeek_PropertyChanged;
                    }
                }
            }));
        }
Exemplo n.º 3
0
 private static async Task <IEnumerable <HitlistInfo> > GetProjectHitlistAsync(IEnumerable <WorkMonth> months, int lookBackInWeeks, PNSearchViewModel pnSearchViewModel)
 {
     return(await Task.Factory.StartNew(() => {
         var allDays = months.SelectMany(m => m.Days);
         var daysFromLookback = lookBackInWeeks > 0 ? allDays.Where(m => m.DateTime > DateTime.Now.AddDays(lookBackInWeeks * -7)) : allDays;
         var hitlistInfos = daysFromLookback
                            .SelectMany(d => d.Items)
                            .GroupBy(p => p.Project)
                            .Select(g =>
                                    new HitlistInfo(
                                        g.Key,
                                        g.Count(),
                                        g.Sum(wi => wi.HoursDuration),
                                        g.OrderByDescending(p => p.WorkDay.DateTime)
                                        .Select(p => pnSearchViewModel.GetDescriptionForProjectNumber(p.Project))
                                        .FirstOrDefault())
                                    );
         return hitlistInfos.OrderByDescending(g => g.HoursUsed);
     }));
 }