Esempio n. 1
0
        public async Task LoadData()
        {
            var startDate = DateTimeHelper.GetFirstDayOfWeek(firstDataDate);
            var endDate = DateTimeHelper.GetLastDayOfWeek(startDate);

            var workdayData = new List<WorkDay>();
            var week = new Week();

            var workdayDataCache = await this.cacheManager.RetreiveWorkDays(this.GetDatesList(startDate, endDate));
            if (workdayDataCache == null || !workdayDataCache.Any())
            {
                Logging.LogInfo("GetAllWorkDays call to OutSystems");
                workdayData = await this.dataLayer.GetAllWorkDays(startDate, endDate);
                if(workdayData != null && workdayData.Any())
                    await this.cacheManager.StoreWorkDays(this.GenerateDatesDictionary(workdayData));
            }
            else
            {
                workdayData = workdayDataCache.Values.ToList();
            }
            
            if (workdayData != null && workdayData.Any())
            {
                var workdayList = workdayData.OrderBy(x => x.StartDateTime.GetIso8601WeekOfYear()).ToList();
                
                foreach (var item in workdayList)
                {
                    week.WorkDays.Add(item);
                }
            }
            else
            {
                week = new Week { WeekNumber = startDate.GetIso8601WeekOfYear() };
            }
            week.WorkDays.BubbleSort();
            this.Weeks.Add(week);
            this.Weeks.BubbleSort();

            firstDataDate = endDate.AddDays(1);
        }
Esempio n. 2
0
        private void GenerateWeekData(List<WorkDay> workdayList)
        {
            this.weeks = new List<Week>();

            int weekNumber = 0;
            bool added = false;
            bool isFirst = true;
            Week week = new Week();
            foreach (var item in workdayList)
            {
                int newWeekNumber = item.StartDateTime.GetIso8601WeekOfYear();
                if (newWeekNumber != weekNumber && !isFirst)
                {
                    // add week to list
                    this.weeks.Add(week);
                    added = true;

                    // reset
                    week = new Week();
                    week.WorkDays.Add(item);
                }
                else
                {
                    isFirst = false;
                    added = false;
                    week.WorkDays.Add(item);
                }

                weekNumber = newWeekNumber;
            }

            if (!added)
                this.weeks.Add(week);

        }
Esempio n. 3
0
        public async Task<bool> AddWorkDay(WorkDay newWorkDay)
        {
            // add new week?
            var weekItem = Weeks.FirstOrDefault(x => x.WeekNumber == newWorkDay.StartDateTime.GetIso8601WeekOfYear());
            if (weekItem == null)
            {
                weekItem = new Week();
                weekItem.WorkDays.Add(newWorkDay);
                weekItem.WorkDays.BubbleSort();
                Weeks.Add(weekItem);
                Weeks.BubbleSort();
            }
            else
            {
                var workdayItem = weekItem.WorkDays.FirstOrDefault(x => x.StartDateTime.Date == newWorkDay.StartDateTime.Date);
                if (workdayItem != null)
                    return false;

                weekItem.WorkDays.Add(newWorkDay);
                weekItem.WorkDays.BubbleSort();
                Weeks.Add(weekItem);
                Weeks.BubbleSort();
            }

            Insights.Track("AddWorkDay call to OutSystems");
            return await this.dataLayer.AddWorkDay(newWorkDay);
        }
Esempio n. 4
0
        private void LoadFakeData()
        {
            var workItems = new List<WorkDay> {
                new WorkDay (new DateTime (2015, 7, 28, 11, 0, 0), new DateTime (2015, 7, 28, 17, 0, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 7, 29, 11, 0, 0), new DateTime (2015, 7, 29, 16, 0, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 7, 31, 12, 0, 0), new DateTime (2015, 7, 31, 21, 30, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 8, 1, 10, 0, 0), new DateTime (2015, 8, 1, 14, 0, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 8, 3, 10, 0, 0), new DateTime (2015, 8, 3, 16, 0, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 8, 4, 9, 0, 0), new DateTime (2015, 8, 4, 18, 15, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 8, 6, 9, 30, 0), new DateTime (2015, 8, 6, 18, 30, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 8, 7, 7, 0, 0), new DateTime (2015, 8, 7, 12, 30, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 8, 8, 7, 0, 0), new DateTime (2015, 8, 8, 12, 30, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 8, 9, 7, 0, 0), new DateTime (2015, 8, 9, 12, 30, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 9, 2, 10, 0, 0), new DateTime (2015, 9, 2, 16, 0, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 9, 3, 10, 0, 0), new DateTime (2015, 9, 3, 16, 0, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 9, 4, 9, 0, 0), new DateTime (2015, 9, 4, 18, 15, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 9, 6, 9, 30, 0), new DateTime (2015, 9, 6, 18, 30, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 9, 7, 7, 0, 0), new DateTime (2015, 9, 7, 12, 30, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 10, 3, 10, 0, 0), new DateTime (2015, 10, 3, 16, 0, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 10, 4, 9, 0, 0), new DateTime (2015, 10, 4, 18, 15, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 10, 6, 9, 30, 0), new DateTime (2015, 10, 6, 18, 30, 0), TimeSpan.FromMinutes (30)),
                new WorkDay (new DateTime (2015, 10, 27, 7, 0, 0), new DateTime (2015, 10, 27, 12, 30, 0), TimeSpan.FromMinutes (30)),
            };

            var list = workItems.OrderBy(x => x.StartDateTime.GetIso8601WeekOfYear()).ToList();

            int weekNumber = 0;
            bool added = false;
            bool isFirst = true;
            Week week = new Week();
            foreach (var item in list)
            {
                int newWeekNumber = item.StartDateTime.GetIso8601WeekOfYear();
                if (newWeekNumber != weekNumber && !isFirst)
                {
                    // add week to list
                    weekNumber = newWeekNumber;
                    this.weeks.Add(week);
                    added = true;

                    // reset
                    week = new Week();
                    week.WorkDays.Add(item);
                }
                else
                {
                    isFirst = false;
                    added = false;
                    week.WorkDays.Add(item);
                }
            }

            if (!added)
                this.weeks.Add(week);
        }
Esempio n. 5
0
        private List<Week> GenerateWeekData(List<WorkDay> workdayList)
        {
            var weekList= new List<Week>();

            int weekNumber = 0;
            bool added = false;
            bool isFirst = true;
            Week week = new Week();
            foreach (var item in workdayList)
            {
                int newWeekNumber = item.WeekNumber;
                if (newWeekNumber != weekNumber && !isFirst)
                {
                    // add week to list
                    weekList.Add(week);
                    added = true;

                    // reset
                    week = new Week();
                    week.WorkDays.Add(item);
                }
                else
                {
                    isFirst = false;
                    added = false;
                    week.WorkDays.Add(item);
                }

                weekNumber = newWeekNumber;
            }

            if (!added)
                weekList.Add(week);

            return weekList;
        }
Esempio n. 6
0
		private void AddOrUpdateWorkDayInWeeks(WorkDay workDay)
		{
			var week = Weeks.SingleOrDefault(x => x.WeekNumber == workDay.WeekNumber);
			if (week != null) {
				Weeks.Remove (week);
				var day = week.WorkDays.FirstOrDefault (x => x.StartDateTime.Date == workDay.StartDateTime.Date);
				if (day != null) {					
					week.WorkDays.Remove (day);		
				}

				week.WorkDays.Add (workDay);
			} else {
				week = new Week ();
				week.WorkDays.Add (workDay);
			}

			week.WorkDays.BubbleSort ();
			Weeks.Add (week);
			Weeks.BubbleSort ();
		}