Ejemplo n.º 1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.Parameter != null)
            {
                if (e.Parameter as string == "logout")
                {
                    SaveCredentials("", "", true);
                    RuntimeData.SaveSetting("campus", null);
                    return;
                }
            }

            if (LoadCredentials(out string id, out string pwdHash) == true)
            {
                await LoginAsync(id, pwdHash);
            }
        }
Ejemplo n.º 2
0
 public static bool IsCampusD(string room)
 {
     if (room == null)
     {
         room = "";
     }
     if (room.StartsWith("D"))
     {
         return(true);
     }
     else if (room.StartsWith("A") || room.StartsWith("B") || room.StartsWith("C"))
     {
         return(false);
     }
     else
     {
         RuntimeData.LoadSetting("campus", out string campus);
         return(campus == "D" ? true : false);
     }
 }
Ejemplo n.º 3
0
        private async Task LoginAsync(string userId, string pwdHash)
        {
            LoadingRingGrid.Visibility = Visibility.Visible;
            LoadingRing.IsActive       = true;

            string token;

            try
            {
                token = await WebClient.LoginAsync(userId, pwdHash);
            }
            catch (HttpRequestException)
            {
                ShowErrorMessage("数据获取失败, 请检查网络连接");
                return;
            }

            if (token.Length > 1)
            {
                if (RuntimeData.LoadSetting("courseToastSwitch", out string _cSwitch) == false)
                {
                    RuntimeData.SaveSetting("courseToastSwitch", "on");
                }
                if (RuntimeData.LoadSetting("dailyToastSwitch", out string _dSwitch) == false)
                {
                    RuntimeData.SaveSetting("dailyToastSwitch", "on");
                }
                if (RuntimeData.LoadSetting("imgToastSwitch", out string _switch) == false)
                {
                    RuntimeData.SaveSetting("imgToastSwitch", "on");
                }
                SaveCredentials(userId, pwdHash);

                RuntimeData.Token  = token;
                RuntimeData.UserId = userId;

                // Get static data.
                try
                {
                    Model.StaticDataModel staticData = await WebClient.GetStaticDataAsync();

                    RuntimeData.StartDate    = staticData.StartDate;
                    RuntimeData.StartTimeABC = ImmutableArray.Create(staticData.StartTimeABC.ToArray());
                    RuntimeData.StartTimeD   = ImmutableArray.Create(staticData.StartTimeD.ToArray());
                    RuntimeData.EndTimeABC   = ImmutableArray.Create(staticData.EndTimeABC.ToArray());
                    RuntimeData.EndTimeD     = ImmutableArray.Create(staticData.EndTimeD.ToArray());
                }
                catch (HttpRequestException)
                {
                    ShowErrorMessage("数据获取失败, 请检查网络连接");
                    return;
                }

                // Get student info.
                try
                {
                    RuntimeData.StudentInfo = await WebClient.GetStudentInfoAsync(token);
                }
                catch (HttpRequestException)
                {
                    ShowErrorMessage("数据获取失败, 请检查网络连接");
                    return;
                }
                catch (RequestFailedException ex)
                {
                    ShowErrorMessage($"服务器未知错误,请稍后再试 (1.{ex.Status})");
                    return;
                }

                // Get score.
                try
                {
                    RuntimeData.Score = await WebClient.GetScoreAsync(token);
                }
                catch (HttpRequestException)
                {
                    ShowErrorMessage("数据获取失败, 请检查网络连接");
                    return;
                }
                catch (RequestFailedException ex)
                {
                    ShowErrorMessage($"服务器未知错误,请稍后再试 (2.{ex.Status})");
                    return;
                }

                // Get schedule.
                try
                {
                    RuntimeData.Schedule = await WebClient.GetScheduleAsync(token);
                }
                catch (HttpRequestException)
                {
                    ShowErrorMessage("数据获取失败, 请检查网络连接");
                    return;
                }
                catch (RequestFailedException ex)
                {
                    ShowErrorMessage($"服务器未知错误,请稍后再试 (3.{ex.Status})");
                    return;
                }

                LoadingRing.IsActive       = false;
                LoadingRingGrid.Visibility = Visibility.Collapsed;
                (Window.Current.Content as Frame).Navigate(typeof(MainPage));
            }
            else if (token == "1")
            {
                ShowErrorMessage("用户名与密码不匹配, 请重试");
                return;
            }
            else if (token == "4")
            {
                ShowErrorMessage("教务系统尚未开放,请确认已缴纳学费后等待教务系统开放");
                return;
            }
            else
            {
                ShowErrorMessage($"服务器未知错误,请稍后再试 (0.{token})");
                return;
            }

            void ShowErrorMessage(string message)
            {
                LoginFailedNotification.Show(message, 5000);
                LoadingRing.IsActive       = false;
                LoadingRingGrid.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 4
0
 private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     RuntimeData.SaveSetting("campus", "D");
 }
Ejemplo n.º 5
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            HeaderControl.DataContext = new HeaderInfo(RuntimeData.StudentInfo, RuntimeData.UserId, RuntimeData.Score.GPA);

            ContentFrame.Navigate(typeof(Home));

            try
            {
                var channel = await Windows.Networking.PushNotifications.
                              PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

                await WebClient.PostWnsChannelAsync(RuntimeData.Token, channel.Uri);
            }
            catch (Exception ex)
            {
                await WebClient.ReportException(ex);
            }

            // Reselect campus and reschedule tasks.
            if (RuntimeData.LaunchState)
            {
                RuntimeData.LaunchState = false;
                if (RuntimeData.LoadSetting("campus", out _) == false)
                {
                    CampusSelect campusSelect = new CampusSelect();
                    await campusSelect.ShowAsync();

                    RuntimeData.LoadSetting("campus", out _);
                }

                var tasks = BackgroundTaskRegistration.AllTasks;
                foreach (var task in tasks)
                {
                    task.Value.Unregister(true);
                }
                BackgroundExecutionManager.RemoveAccess();

                var backgroundStatus = await BackgroundExecutionManager.RequestAccessAsync();

                if (backgroundStatus == BackgroundAccessStatus.DeniedBySystemPolicy ||
                    backgroundStatus == BackgroundAccessStatus.DeniedByUser ||
                    backgroundStatus == BackgroundAccessStatus.Unspecified)
                {
                    return;
                }

                var builder = new BackgroundTaskBuilder();
                builder.Name = "Hourly Tile Update Task";
                builder.SetTrigger(new TimeTrigger(30, false));
                builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
                builder.IsNetworkRequested = true;
                builder.Register();
                builder.Name = "Login Tile Update Task";
                builder.SetTrigger(new SystemTrigger(SystemTriggerType.UserPresent, false));
                builder.Register();
            }

            await ScheduleNotificationUpdateTasks.UpdateTile(RuntimeData.Schedule);
        }
Ejemplo n.º 6
0
        public static void ScheduleToast(HuxiImgEntry entry)
        {
            if (RuntimeData.LoadSetting("imgToastSwitch", out string _switch) == false)
            {
                RuntimeData.SaveSetting("imgToastSwitch", "on");
            }
            else
            {
                if (_switch == "off")
                {
                    return;
                }
            }

            ToastContent imageToast = new ToastContent()
            {
                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        //HeroImage = new ToastGenericHeroImage()
                        //{
                        //    Source = entry.Uri,
                        //    AlternateText = "图说虎溪"
                        //},

                        Children =
                        {
                            new AdaptiveImage()
                            {
                                Source           = entry.Uri,
                                AlternateText    = "图说虎溪",
                                HintAlign        = AdaptiveImageAlign.Stretch,
                                HintRemoveMargin = true
                            },
                            new AdaptiveText()
                            {
                                Text = entry.Title
                            },
                            new AdaptiveText()
                            {
                                Text = entry.Content, HintWrap = true, HintMaxLines = 3
                            },
                            new AdaptiveText()
                            {
                                Text = $"摄影  {entry.Author}"
                            }
                        },
                        Attribution = new ToastGenericAttributionText()
                        {
                            Text = "图说虎溪"
                        }
                    }
                }
            };

            var toast = new ToastNotification(imageToast.GetXml());

            toast.SuppressPopup  = true;
            toast.ExpirationTime = DateTime.Now.AddDays(1);
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
Ejemplo n.º 7
0
        public static void ScheduleToast(List <Model.ScheduleEntry> entries)
        {
            bool courseSwitch = true;
            bool dailySwitch  = true;

            if (RuntimeData.LoadSetting("courseToastSwitch", out string _cSwitch) == false)
            {
                RuntimeData.SaveSetting("courseToastSwitch", "on");
            }
            else
            {
                if (_cSwitch == "off")
                {
                    courseSwitch = false;
                }
            }
            if (RuntimeData.LoadSetting("dailyToastSwitch", out string _dSwitch) == false)
            {
                RuntimeData.SaveSetting("dailyToastSwitch", "on");
            }
            else
            {
                if (_dSwitch == "off")
                {
                    dailySwitch = false;
                }
            }


            if (entries.Count == 0)
            {
                return;
            }

            ToastContent dailyGlance = new ToastContent()
            {
                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = "今日课程", HintStyle = AdaptiveTextStyle.Subtitle
                            }
                        }
                    }
                }
            };

            for (int i = 0; i < entries.Count; i++)
            {
                (var startTimeSch, _) = SessionTimeConverter.ConvertShort(entries[i].SessionSpan, CampusSelector.IsCampusD(entries[i].Room));
                DateTime     startTime          = startTimeSch.GetDateTime();
                ToastContent courseNotification = new ToastContent()
                {
                    Visual = new ToastVisual()
                    {
                        BindingGeneric = new ToastBindingGeneric()
                        {
                            Children =
                            {
                                new AdaptiveText()
                                {
                                    Text = entries[i].Name
                                },
                                new AdaptiveText()
                                {
                                    Text = $"{new SessionTimeConverter().Convert(entries[i].SessionSpan, typeof(string), null, null)}  {entries[i].Room}"
                                },
                            }
                        }
                    },
                    Scenario = ToastScenario.Reminder
                };

                dailyGlance.Visual.BindingGeneric.Children.Add
                (
                    new AdaptiveGroup()
                {
                    Children =
                    {
                        new AdaptiveSubgroup()
                        {
                            Children =
                            {
                                new AdaptiveText()
                                {
                                    Text = entries[i].Name, HintStyle = AdaptiveTextStyle.Base
                                },
                                new AdaptiveText()
                                {
                                    Text = $"{new SessionTimeConverter().Convert(entries[i].SessionSpan, typeof(string), null, null)}  {entries[i].Room}", HintStyle = AdaptiveTextStyle.BodySubtle
                                },
                            }
                        }
                    }
                }
                );
                try
                {
                    if (courseSwitch)
                    {
                        ScheduledToastNotification toast = new ScheduledToastNotification(courseNotification.GetXml(), new DateTimeOffset(startTime.AddMinutes(-15), new TimeSpan(8, 0, 0)));
                        toast.ExpirationTime = new DateTimeOffset(startTime.AddMinutes(15), TimeZoneInfo.Local.GetUtcOffset(DateTime.Now));
                        ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
                    }
                }
                catch (ArgumentException) { }
            }

            if (dailySwitch)
            {
                if (DateTime.Now.Hour > 7 || (DateTime.Now.Hour == 7 && DateTime.Now.Minute > 25))
                {
                    ToastNotification dailyGlanceToast = new ToastNotification(dailyGlance.GetXml());
                    dailyGlanceToast.ExpirationTime = DateTime.Now.AddDays(1);
                    ToastNotificationManager.CreateToastNotifier().Show(dailyGlanceToast);
                }
                else
                {
                    ScheduledToastNotification dailyGlanceToast = new ScheduledToastNotification(dailyGlance.GetXml(),
                                                                                                 new DateTimeOffset(new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 7, 30, 0), TimeZoneInfo.Local.GetUtcOffset(DateTime.Now)));
                    dailyGlanceToast.ExpirationTime = DateTime.Now.AddDays(1);
                    ToastNotificationManager.CreateToastNotifier().AddToSchedule(dailyGlanceToast);
                }
            }
        }