Example #1
0
        private async Task RefreshMeetings(bool forceRefresh, CancellationToken token)
        {
            IsBusy = true;
            try
            {
                Meetings.PauseNotifications();

                //var test  = App.Instance.GetInstance<IUseFullDocumentService>();
                //var documents = await test.GetDocumentsAsync();

                var meetings = await _meetingService.GetMeetingsAsync(forceRefresh, token);

                Meetings.Clear();
                Meetings.AddRange(meetings);
                var lastUpdate = _meetingService.GetLastUpdateTime();
                UpdateLastUpdateText(lastUpdate);
            }
            catch (TaskCanceledException ex)
            {
                Debug.WriteLine(ex.Message);
            }
            catch (TokenExpiredException ex)
            {
                Debug.WriteLine(ex.Message);
                this.ShowViewModel <StartupViewModel>();
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.Message);
                await App.Instance.AlertService.ShowExceptionMessageAsync(ex, "Erreur lors de la récupération des rendez-vous.");
            }
            finally
            {
                _pageTokenSource = null;
                Meetings.ResumeNotifications();
                IsBusy = false;
            }
        }
Example #2
0
        private async Task RefreshMeetings(bool forceRefresh)
        {
            IsBusy = true;
            try
            {
                Meetings.PauseNotifications();
                var meetings = await _meetingService.GetMeetingsAsync(forceRefresh, CancellationToken.None);

                Meetings.Clear();

                var flatMeetings = new List <MeetingViewModel>();
                foreach (var meeting in meetings)
                {
                    var currentDate = meeting.StartDate;
                    while (currentDate < meeting.EndDate)
                    {
                        flatMeetings.Add(new MeetingViewModel(meeting, currentDate));
                        currentDate = currentDate.AddDays(1);
                    }
                }

                var groupedMeetings = flatMeetings.GroupBy(m => m.Date).
                                      ToDictionary(m => m.Key, m => m.ToList());

                var finalDate          = DateTime.Now.Date.AddMonths(4);
                var currentGroupedDate = DateTime.Now.Date;
                while (currentGroupedDate <= finalDate)
                {
                    if (groupedMeetings.ContainsKey(currentGroupedDate))
                    {
                        var currentGroup = groupedMeetings[currentGroupedDate];
                        Meetings.Add(new GroupedMeetingViewModel(currentGroupedDate, currentGroup.ToList()));
                    }
                    else
                    {
                        var noMeeting = new Meeting();
                        noMeeting.AllDayEvent = true;
                        noMeeting.EndDate     = currentGroupedDate;
                        noMeeting.StartDate   = currentGroupedDate;
                        // TODO : localisation
                        noMeeting.Title = "Aucun événement";
                        noMeeting.Type  = MeetingType.Unknown;

                        var noMeetings = new List <MeetingViewModel>();
                        noMeetings.Add(new MeetingViewModel(noMeeting, currentGroupedDate));

                        Meetings.Add(new GroupedMeetingViewModel(currentGroupedDate, noMeetings));
                    }

                    currentGroupedDate = currentGroupedDate.AddDays(1);
                }

                _lastUpdate = _meetingService.GetLastUpdateTime();

                RaisePropertyChanged(nameof(Meetings));
                RaisePropertyChanged(nameof(LastUpdate));
            }
            catch (System.Exception ex)
            {
                await Mvx.Resolve <IMessageService>()
                .ShowErrorToastAsync(ex, "Erreur lors de la récupération des rendez-vous.");
            }
            finally
            {
                Meetings.ResumeNotifications();
                IsBusy = false;
            }
        }