Exemple #1
0
        protected CalendarDayViewModel(CalendarDateViewModel date, string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            if (date == null)
            {
                throw new ArgumentNullException("date");
            }

            Name  = name;
            _date = date;
        }
Exemple #2
0
        private void OnRefresh()
        {
            var now = DateTime.Now;

            // We need to retrieve the data once per year. Reset the calendar on 1st of January
            if (now.DayOfYear == 1)
            {
                Days = null;
            }

            if (Days == null)
            {
                var timeCalendarDayMap = new Dictionary <DateTime, CalendarDateViewModel>();

                foreach (var calendar in _calendars)
                {
                    ParseCalendars(timeCalendarDayMap, calendar);
                }

                Days = new ObservableCollection <CalendarDateViewModel>(timeCalendarDayMap.Values.OrderBy(x => x.Date));
            }

            CalendarDayViewModel  nextPublicHoliday = null;
            CalendarDateViewModel nextDate          = null;

            // Find the next holiday
            foreach (var date in Days)
            {
                if (nextPublicHoliday != null &&
                    nextDate != null)
                {
                    break;
                }

                if (date.Date.DayOfYear <= now.DayOfYear)
                {
                    if (date.Date.DayOfYear == now.DayOfYear)
                    {
                        Today = date;
                    }

                    continue;
                }

                if (nextDate == null)
                {
                    nextDate = date;
                    continue;
                }

                foreach (var day in date.Days)
                {
                    if (nextPublicHoliday == null &&
                        day is HolidayCalendarDayViewModel)
                    {
                        nextPublicHoliday = day;
                        break;
                    }
                }
            }

            NextPublicHoliday = nextPublicHoliday;
            NextDate          = nextDate;
            IsVisible         = true;
        }
Exemple #3
0
 public UNObservancesDayViewModel(CalendarDateViewModel date, string name)
     : base(date, name)
 {
 }
Exemple #4
0
 public GoodToKnowCalendarDayViewModel(CalendarDateViewModel date, string name)
     : base(date, name)
 {
 }
Exemple #5
0
 public FunCalendarDayViewModel(CalendarDateViewModel date, string name)
     : base(date, name)
 {
 }
Exemple #6
0
        private void ParseCalendars(IDictionary <DateTime, CalendarDateViewModel> result, string calendarType)
        {
            Log.TraceEntry();

            var parameters = new Dictionary <string, string>
            {
                { "format", "json" },
                { "start_year", "current_year" },
                { "end_year", "current_year" },
                { "tz", "Europe%2FLondon" },
                { "id", calendarType }
            };

            var days = _restClient.MakeRequest <Day[]>(BaseUrl, null, null, parameters);

            Log.TraceMsg("ParseCalendars: Parsing calendar type {0}", calendarType);

            foreach (var day in days)
            {
                try
                {
                    // Some of the results span over weeks, etc. Ignore these.
                    if (string.IsNullOrWhiteSpace(day.Date))
                    {
                        continue;
                    }

                    var date = DateTime.Parse(day.Date);

                    CalendarDateViewModel vmDate;
                    if (!result.TryGetValue(date, out vmDate))
                    {
                        result[date] = vmDate = new CalendarDateViewModel(date);
                    }

                    CalendarDayViewModel dayViewModel;

                    switch (calendarType)
                    {
                    case HolidayId:
                        dayViewModel = new HolidayCalendarDayViewModel(vmDate, day.Name);
                        break;

                    case FunId:
                        dayViewModel = new FunCalendarDayViewModel(vmDate, day.Name);
                        break;

                    case GoodToKnowId:
                        dayViewModel = new GoodToKnowCalendarDayViewModel(vmDate, day.Name);
                        break;

                    case UNObservancesId:
                    default:
                        dayViewModel = new UNObservancesDayViewModel(vmDate, day.Name);
                        break;
                    }

                    vmDate.Days.Add(dayViewModel);
                }
                catch (Exception ex)
                {
                    Log.TraceErr("FunCalendarViewModel.ParseCalendars: Failed to parse day. {0}", ex.ToString());

                    throw;
                }
            }

            Log.TraceExit();
        }