Beispiel #1
0
        //public static (DateTime start, DateTime end) Convert(string value)
        //{
        //    (var start, var end) = ConvertShort(value);
        //    return (start.GetDateTime(), end.GetDateTime());
        //}
        public static (Model.ScheduleTime start, Model.ScheduleTime end) ConvertShort(string value)
        {
            RuntimeData.LoadSetting("campus", out string campus);
            bool isCampusD = campus == "D" ? true : false;

            return(ConvertShort(value, isCampusD));
        }
Beispiel #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (RuntimeData.LoadSetting("campus", out string campus) == false)
            {
                CampusCombo.SelectedIndex = 0;
            }
            else
            {
                if (campus == "ABC")
                {
                    CampusCombo.SelectedIndex = 0;
                }
                else if (campus == "D")
                {
                    CampusCombo.SelectedIndex = 1;
                }
            }

            if (RuntimeData.LoadSetting("courseToastSwitch", out string courseSwitch) == true)
            {
                CourseToastToggle.IsOn = courseSwitch == "on" ? true : false;
            }
            if (RuntimeData.LoadSetting("dailyToastSwitch", out string dailySwitch) == true)
            {
                DailyToastToggle.IsOn = dailySwitch == "on" ? true : false;
            }
            if (RuntimeData.LoadSetting("imgToastSwitch", out string imgSwitch) == true)
            {
                HuxiImgToastToggle.IsOn = imgSwitch == "on" ? true : false;
            }
        }
Beispiel #3
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (!(value is string valueStr))
            {
                return("");
            }
            string[] segements = valueStr.Split('-');
            RuntimeData.LoadSetting("campus", out string campus);
            bool isCampusD = campus == "D" ? true : false;

            if (segements.Length == 2)
            {
                int start = int.Parse(segements[0]);
                int end   = int.Parse(segements[1]);
                if (start > 11)
                {
                    start = 11;
                }
                if (end > 11)
                {
                    end = 11;
                }
                if (isCampusD)
                {
                    return($"{RuntimeData.StartTimeD[start - 1]}-{RuntimeData.EndTimeD[end - 1]}");
                }
                else
                {
                    return($"{RuntimeData.StartTimeABC[start - 1]}-{RuntimeData.EndTimeABC[end - 1]}");
                }
            }
            else if (segements.Length == 1)
            {
                int session = int.Parse(segements[0]);
                if (session > 11)
                {
                    session = 11;
                }
                if (isCampusD)
                {
                    return($"{RuntimeData.StartTimeD[session - 1]}-{RuntimeData.EndTimeD[session - 1]}");
                }
                else
                {
                    return($"{RuntimeData.StartTimeABC[session - 1]}-{RuntimeData.EndTimeABC[session - 1]}");
                }
            }
            else
            {
                return("");
            }
        }
Beispiel #4
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);
     }
 }
Beispiel #5
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;
            }
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
                }
            }
        }