private void ToastToggle_Toggled(object sender, RoutedEventArgs e) { ToggleSwitch _switch = sender as ToggleSwitch; string str = _switch.IsOn ? "on" : "off"; RuntimeData.SaveSetting(_switch.Tag as string, str); }
private void CampusCombo_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (CampusCombo.SelectedIndex == 0) { RuntimeData.SaveSetting("campus", "ABC"); } else if (CampusCombo.SelectedIndex == 1) { RuntimeData.SaveSetting("campus", "D"); } }
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); } }
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; } }
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { RuntimeData.SaveSetting("campus", "D"); }
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); }
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); } } }