using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Juick.Classes; using Microsoft.Phone.Controls; using Microsoft.Phone.Notification; using Microsoft.Xna.Framework.Media; using System.Windows.Media.Imaging; namespace Juick { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { // Holds the push channel that is created or found. //HttpNotificationChannel pushChannel; // unused variable // The name of our push channel. //string channelName = "JuickChannel"; // unused variable InitializeComponent(); /* // Try to find the push channel. pushChannel = HttpNotificationChannel.Find(channelName); // If the channel was not found, then create a new connection to the push service. if (pushChannel == null) { pushChannel = new HttpNotificationChannel(channelName); // Register for all the events before attempting to open the channel. pushChannel.ChannelUriUpdated += new EventHandler(PushChannel_ChannelUriUpdated); pushChannel.ErrorOccurred += new EventHandler(PushChannel_ErrorOccurred); // Register for this notification only if you need to receive the notifications while your application is running. pushChannel.ShellToastNotificationReceived += new EventHandler(PushChannel_ShellToastNotificationReceived); pushChannel.Open(); // Bind this new channel for toast events. pushChannel.BindToShellToast(); } else { // The channel was already open, so just register for all the events. pushChannel.ChannelUriUpdated += new EventHandler(PushChannel_ChannelUriUpdated); pushChannel.ErrorOccurred += new EventHandler(PushChannel_ErrorOccurred); // Register for this notification only if you need to receive the notifications while your application is running. pushChannel.ShellToastNotificationReceived += new EventHandler(PushChannel_ShellToastNotificationReceived); // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point. System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString()); MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString())); }*/ // Set the data context of the listbox control to the sample data Home.DataContext = App.MyFeedView; Last.DataContext = App.LastView; } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { var loginUriPart = "/LoginView.xaml"; var newPostUriPart = "/NewPostView.xaml"; var navigateUri = string.Empty; var FileId = string.Empty; // Get a dictionary of query string keys and values. IDictionary queryStrings = NavigationContext.QueryString; // Ensure that there is at least one key in the query string, and check // whether the "FileId" key is present. navigateUri = string.IsNullOrEmpty(App.Account.Credentials.UserName) ? loginUriPart : newPostUriPart; if (queryStrings.ContainsKey("FileId")) { FileId = queryStrings["FileId"]; navigateUri = string.Format("{0}?FileId={1}", navigateUri, FileId); } if (!string.IsNullOrEmpty(FileId) || navigateUri.StartsWith(loginUriPart)) { NavigationService.Navigate(new Uri(navigateUri, UriKind.Relative)); } } void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e) { Dispatcher.BeginInvoke(() => { // Display the new URI for testing purposes. Normally, the URI would be passed back to your web service at this point. System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString()); MessageBox.Show(String.Format("Channel Uri is {0}", e.ChannelUri.ToString())); }); } void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) { StringBuilder message = new StringBuilder(); string relativeUri = string.Empty; message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString()); // Parse out the information that was part of the message. foreach (string key in e.Collection.Keys) { message.AppendFormat("{0}: {1}\n", key, e.Collection[key]); if (string.Compare( key, "wp:Param", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.CompareOptions.IgnoreCase) == 0) { relativeUri = e.Collection[key]; } } // Display a dialog of all the fields in the toast. Dispatcher.BeginInvoke(() => MessageBox.Show(message.ToString())); } void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e) { // Error handling logic for your particular application would be here. Dispatcher.BeginInvoke(() => MessageBox.Show(String.Format("A push notification {0} error occurred. {1} ({2}) {3}", e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData)) ); } private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { // If selected index is -1 (no selection) do nothing if (((ListBox)sender).SelectedIndex == -1) return; // Navigate to the new page NavigationService.Navigate(new Uri("/ThreadView.xaml?mid=" + App.MyFeedView.Items[((ListBox)sender).SelectedIndex].MID, UriKind.Relative)); // Reset selected index to -1 (no selection) ((ListBox)sender).SelectedIndex = -1; } private void LastBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { // If selected index is -1 (no selection) do nothing if (((ListBox)sender).SelectedIndex == -1) return; // Navigate to the new page NavigationService.Navigate(new Uri(string.Format("/ThreadView.xaml?mid={0}", App.LastView.Items[((ListBox)sender).SelectedIndex].MID), UriKind.Relative)); // Reset selected index to -1 (no selection) ((ListBox)sender).SelectedIndex = -1; } private void ApplicationBarIconButtonClick(object sender, EventArgs e) { App.MyFeedView.Items.Clear(); App.LastView.Items.Clear(); App.MyFeedView.LoadData(); App.LastView.LoadData(); } private void ApplicationBarMenuItemClick(object sender, EventArgs e) { App.Account.SignOut(this); } private void ApplicationBarIconButtonClick1(object sender, EventArgs e) { NavigationService.Navigate(new Uri("/NewPostView.xaml", UriKind.Relative)); } } }