async void MainPage_Loaded(object sender, RoutedEventArgs e) { if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("EnablePush")) { MessageDialog messageBox = new MessageDialog("Push Notifications"); messageBox = new MessageDialog("This application supports Push Notifications. Please go to the settings charm to configure credentials and push notification settings."); await messageBox.ShowAsync(); } else if (ApplicationData.Current.LocalSettings.Values.ContainsKey("Username") && ApplicationData.Current.LocalSettings.Values.ContainsKey("Password")) { statusLabel.Text = "Retrieving Messages..."; NotificationService.NotificationServiceClient client = new NotificationService.NotificationServiceClient(); username = ApplicationData.Current.LocalSettings.Values["Username"] as String; password = ApplicationData.Current.LocalSettings.Values["Password"] as String; listView.ItemsSource = null; try { if (await client.AuthenticateUserAsync(username, password)) { var data = await client.GetNotificationsAsync(username); listView.ItemsSource = data; statusLabel.Text = String.Empty; if (timer.IsEnabled) { timer.Stop(); } try { int interval = Int32.Parse(ApplicationData.Current.LocalSettings.Values["RefreshRate"].ToString()); if (interval == 0) { interval = 30; } timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, interval); timer.Tick += timer_Tick; timer.Start(); } catch { MessageDialog dialog = new MessageDialog("Please set refresh rate in settings"); dialog.ShowAsync(); } if (Convert.ToBoolean(ApplicationData.Current.LocalSettings.Values["EnablePush"]) == true) { CreatAndSendPushChannel(); } else { UnregisterSubscriber(); } } else { statusLabel.Text = "Invalid Credentials"; } } catch { new MessageDialog("Unable to connect to Riveu server. Please verify internet connection and re-launch application").ShowAsync(); } } else { statusLabel.Text = "Please configure settings"; } }
async void timer_Tick(object sender, object e) { try { NotificationService.NotificationServiceClient client = new NotificationService.NotificationServiceClient(); if (await client.AuthenticateUserAsync(username, password)) { var data = await client.GetNotificationsAsync(username); if (data.Count != ((ObservableCollection<object>)listView.ItemsSource).Count) { listView.ItemsSource = data; } } } catch { new MessageDialog("Unable to connect to Riveu server. Please verify internet connection and re-launch application").ShowAsync(); } }
async void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e) { if (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated) { _settingsPopup.IsOpen = false; statusLabel.Text = "Retrieving Messages..."; NotificationService.NotificationServiceClient client = new NotificationService.NotificationServiceClient(); username = ApplicationData.Current.LocalSettings.Values["Username"] as String; password = ApplicationData.Current.LocalSettings.Values["Password"] as String; listView.ItemsSource = null; try { if (await client.AuthenticateUserAsync(username, password)) { var data = await client.GetNotificationsAsync(username); listView.ItemsSource = data; statusLabel.Text = String.Empty; if (timer.IsEnabled) { timer.Stop(); } try { int interval = Int32.Parse(ApplicationData.Current.LocalSettings.Values["RefreshRate"].ToString()); if (interval == 0) { interval = 30; } timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, interval); timer.Tick += timer_Tick; timer.Start(); } catch { try { MessageDialog dialog = new MessageDialog("Please set refresh rate in settings"); dialog.ShowAsync(); } catch { //do nothing } } if (Convert.ToBoolean(ApplicationData.Current.LocalSettings.Values["EnablePush"]) == true) { CreatAndSendPushChannel(); } else { UnregisterSubscriber(); } } else { statusLabel.Text = "Invalid Credentials"; } } catch { new MessageDialog("Unable to connect to Riveu server. Please verify internet connection and re-launch application").ShowAsync(); } } }