public void checkPushNotificationsUserPermissions()
        {
            //The app must ask the user for explicit permission to receive toast notifications.
            UserSettings settings = new UserSettings();
            if (!settings.AskedPermissionForToastPushNotifications)
            {
                StringTable _localizedStrings = App.Current.Resources["StringTable"] as StringTable;
                MessageBoxResult result = MessageBox.Show(_localizedStrings.Prompts.AllowToastPushNotification, _localizedStrings.ControlsText.PushNotifications, MessageBoxButton.OKCancel);
                if (MessageBoxResult.OK == result)
                {
                    settings.EnableToastPushNotifications = true;
                }
                else
                {
                    settings.EnableToastPushNotifications = false;
                }
                settings.AskedPermissionForToastPushNotifications = true;
                settings.Save();

                if (settings.EnableToastPushNotifications == true)
                {
                    Double fontSize = (Double) Application.Current.Resources["ControlFontSize"];
                    var messagePrompt = new MessagePrompt
                    {
                        Title = _localizedStrings.ControlsText.PushNotifications,
                        Body = new TextBlock { Text = _localizedStrings.Prompts.PinToStartPushNotification, FontSize= fontSize, TextWrapping = TextWrapping.Wrap },
                        IsCancelVisible = false
                    };
                    messagePrompt.Show();
                }
            }
        }
        private void OnAcceptButtonClick(object sender, RoutedEventArgs args)
        {
            UserSettings settings = new UserSettings();
            settings.AcceptedEula = true;
            settings.Save();

            Visibility = Visibility.Collapsed;
        }
        public bool pushNotificationsEnabled()
        {
            //check the push notifications user settings
            UserSettings settings = new UserSettings();
            if (!settings.AskedPermissionForToastPushNotifications || !settings.EnableToastPushNotifications)
            {
                return false;
            }

            return true;
        }
        public void enablePushNotifications()
        {
            try
            {
                string device_uuid = this.getDeviceUUID();
                if (device_uuid == null)
                    return;

                //check the push notifications user settings
                UserSettings settings = new UserSettings();
                if (!this.pushNotificationsEnabled())
                {
                    this.disablePushNotifications();
                    return;
                }

                //check if there is a .COM or Jetpack blog in the app.
                List<Blog> blogs = DataService.Current.Blogs.ToList();
                bool presence = false;
                foreach (Blog currentBlog in blogs)
                {
                    if (currentBlog.isWPcom() || currentBlog.hasJetpack())
                    {
                        presence = true;
                        break;
                    }
                }
                if (!presence)
                {
                    System.Diagnostics.Debug.WriteLine("Not found a .COM or Jetpack blog");
                    this.disablePushNotifications();
                    return;
                }

                // 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<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                    pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                    pushChannel.ConnectionStatusChanged += new EventHandler<NotificationChannelConnectionEventArgs>(PushChannel_ConnectionStatusChanged);

                    // Register for this notification since we need to receive the notifications while the application is running.
                    pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

                    try
                    {
                        pushChannel.Open();
                    }
                    catch (InvalidOperationException _pushNotificationChannelOpenFailed)
                    {
                        Utils.Tools.LogException("Cannot open the channel, try it again...", _pushNotificationChannelOpenFailed);
                        try
                        {
                            pushChannel.Open();
                        }
                        catch (InvalidOperationException)
                        {
                            Utils.Tools.LogException("2nd tentative failed", _pushNotificationChannelOpenFailed);
                            return;
                        }
                    }
                    catch (ArgumentException)
                    {
                        return;
                    }

                    try
                    {
                        // Bind this new channel for toast events.
                        pushChannel.BindToShellToast();
                    }
                    catch (InvalidOperationException _pushNotificationChannelBindFailed)
                    {
                        Utils.Tools.LogException("BindToShellToast Failed", _pushNotificationChannelBindFailed);
                        try
                        {
                            pushChannel.BindToShellToast();
                        }
                        catch (InvalidOperationException) { }
                    }

                    try
                    {
                        // Bind this new channel for Tile events.
                        pushChannel.BindToShellTile();
                    }
                    catch (InvalidOperationException _pushNotificationChannelBindFailed)
                    {
                        Utils.Tools.LogException("BindToShellTile Failed", _pushNotificationChannelBindFailed);
                        try
                        {
                            pushChannel.BindToShellTile();
                        }
                        catch (InvalidOperationException) { }
                    }
                }
                else
                {
                    // The channel was already open, so just register for all the events.
                    pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                    pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                    pushChannel.ConnectionStatusChanged += new EventHandler<NotificationChannelConnectionEventArgs>(PushChannel_ConnectionStatusChanged);

                    // Register for this notification since we need to receive the notifications while the application is running.
                    pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

                    System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
                    this.registerDevice(pushChannel.ChannelUri.ToString());
                }
            }
            catch (Exception ex) {
                Utils.Tools.LogException("Unexpected Exception in enablePushnotification", ex);
            }
        }
        private void SavePost()
        {
            //Post post = DataContext as Post;
            //changed to CurrentPost so categories would save
            Post post = App.MasterViewModel.CurrentPost;
            Blog blog = App.MasterViewModel.CurrentBlog;

            if (post.HasMedia() && !post.IsLocalDraft())
            {
                bool galleryEnabled = uploadImagesAsGalleryCheckbox.Visibility == Visibility.Visible &&
                      uploadImagesAsGalleryCheckbox.IsChecked.GetValueOrDefault();
                post.GenerateImageMarkup(blog.PlaceImageAboveText, galleryEnabled);
            }

            //make sure the post has the latest UI data--the Save button is a ToolbarButton
            //which doesn't force focus to change
            post.Title = titleTextBox.Text;
            post.MtKeyWords = tagsTextBox.Text;

            if (post.IsNew)
            {
                if (!post.IsLocalDraft())
                {
                    // Anything but local draft status gets uploaded
                    UserSettings settings = new UserSettings();
                    if (settings.UseTaglineForNewPosts)
                    {
                        post.AddTagline(settings.Tagline);
                    }
                    NewPostRPC rpc = new NewPostRPC(App.MasterViewModel.CurrentBlog, post);
                    rpc.PostType = ePostType.post;
                    rpc.Completed += OnNewPostRPCCompleted;
                    rpc.ExecuteAsync();

                    currentXmlRpcConnection = rpc;
                    this.Focus();
                    ApplicationBar.IsVisible = false;
                    App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.UploadingChanges);

                } else {
                    // Create or update a local draft
                    if (App.MasterViewModel.CurrentPostListItem != null)
                    {
                        if (App.MasterViewModel.CurrentPostListItem.DraftIndex > -1)
                            App.MasterViewModel.CurrentBlog.LocalPostDrafts[App.MasterViewModel.CurrentPostListItem.DraftIndex] = post;
                    }
                    else
                    {
                        blog.LocalPostDrafts.Add(post);
                    }
                    // Exit post editor if the app was not lauched from the sharing feature.
                    if(NavigationService.CanGoBack)
                        NavigationService.GoBack();
                    else
                        throw new ApplicationShouldEndException();
                }
            }
            else
            {
                EditPostRPC rpc = new EditPostRPC(App.MasterViewModel.CurrentBlog, post);
                rpc.Completed += OnEditPostRPCCompleted;
                rpc.ExecuteAsync();

                currentXmlRpcConnection = rpc;
                this.Focus();
                ApplicationBar.IsVisible = false;
                App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.UploadingChanges);
            }
        }