コード例 #1
0
ファイル: SchedulePage.xaml.cs プロジェクト: DL444/ucqu-ng
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            Analytics.TrackEvent("Navigation", new Dictionary <string, string>()
            {
                { "Page", "Schedule" }
            });
            Application.Current.GetService <IMessageService <DaySelectedMessage> >().Register(ScheduleTable);
            Application.Current.GetService <INotificationService>().ClearToast(ToastTypes.ScheduleSummary);
            bool signedIn = Application.Current.GetService <ICredentialService>().IsSignedIn;
            await WellknownDataViewModel.StartUpdateAsync(signedIn);

            await ScheduleViewModel.StartUpdateAsync(signedIn);
        }
コード例 #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            Analytics.TrackEvent("Main page reached", new Dictionary <string, string>()
            {
                { "Size", $"{Window.Current.Bounds}" }
            });
            prevWidth = Window.Current.Bounds.Width;
            Window.Current.SizeChanged += CurrentWindow_SizeChanged;

            if (e.Parameter is string argument && !string.IsNullOrEmpty(argument))
            {
                Analytics.TrackEvent("Launched with parameter", new Dictionary <string, string>()
                {
                    { "Parameter", argument }
                });
                if (argument.Equals("ScoreChanged", StringComparison.Ordinal))
                {
                    NavigationView.SelectedItem = NavigationView.MenuItems.Last();
                }
            }

            bool signedIn = Application.Current.GetService <ICredentialService>().IsSignedIn;

            IAsyncOperation <PushNotificationChannel> channelCreationTask = PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
            Task wellknownUpdateTask   = WellknownDataViewModel.StartUpdateAsync(signedIn);
            Task studentInfoUpdateTask = StudentInfoViewModel.StartUpdateAsync(signedIn);

            await wellknownUpdateTask;
            Task  examsUpdateTask    = ExamsViewModel.StartUpdateAsync(signedIn);
            Task  scheduleUpdateTask = ScheduleViewModel.StartUpdateAsync(signedIn);

            if (!signedIn)
            {
                ISignInService signInService = Application.Current.GetService <ISignInService>();
                try
                {
                    await signInService.SignInAsync(false);

                    signedIn = true;
                    Application.Current.GetService <IMessageService <SignInMessage> >().SendMessage(new SignInMessage(true));
                }
                catch (BackendAuthenticationFailedException ex)
                {
                    Crashes.TrackError(ex);
                    Analytics.TrackEvent("Authentication failed");
                    await((App)Application.Current).SignOutAsync();
                }
                catch (BackendRequestFailedException ex)
                {
                    Crashes.TrackError(ex);
                    Application.Current.GetService <IMessageService <SignInMessage> >().SendMessage(new SignInMessage(false));
                }
            }

            if (signedIn)
            {
                INotificationChannelService channelService = Application.Current.GetService <INotificationChannelService>();
                Task channelUpdateTask;
                try
                {
                    PushNotificationChannel channel = await channelCreationTask;
                    channelUpdateTask = channelService.PostNotificationChannelAsync(new NotificationChannelItem(channel.Uri));
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                    channelUpdateTask = Task.CompletedTask;
                }
                await Task.WhenAll(studentInfoUpdateTask, examsUpdateTask, scheduleUpdateTask, channelUpdateTask);
            }
            else
            {
                await Task.WhenAll(studentInfoUpdateTask, examsUpdateTask, scheduleUpdateTask);
            }
        }