private void OnEditPostRPCCompleted(object sender, XMLRPCCompletedEventArgs <Post> args)
        {
            EditPostRPC rpc = sender as EditPostRPC;

            rpc.Completed -= OnEditPostRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }

            //Do not change the UI if the connection is cancelled. The user could have started another connection...
            ApplicationBar.IsVisible = true;
            App.WaitIndicationService.HideIndicator();

            if (null == args.Error)
            {
                cleanupPostMedia();
                if (NavigationService.CanGoBack)
                {
                    DataService.Current.FetchCurrentBlogPagesAsync(false);
                    NavigationService.GoBack();
                }
                else
                {
                    throw new ApplicationShouldEndException();
                }
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
        private void OnGetClickStatsRPCCompleted(object sender, XMLRPCCompletedEventArgs <ClickDataPoint> args)
        {
            GetClickStatsRPC rpc = sender as GetClickStatsRPC;

            rpc.Completed -= OnGetClickStatsRPCCompleted;

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                HideStatControls();

                clicksGrid.Visibility = Visibility.Visible;

                ObservableObjectCollection dataSource = Resources["clickStatsDataSource"] as ObservableObjectCollection;
                dataSource.Clear();
                args.Items.ForEach(item => dataSource.Add(item));
            }
            else
            {
                this.HandleException(args.Error);
            }

            loadingStatsProgressBar.Opacity = 0.0;
        }
예제 #3
0
        private void OnDeleteCommentRPCCompleted(object sender, XMLRPCCompletedEventArgs <Comment> args)
        {
            DeleteCommentRPC rpc = sender as DeleteCommentRPC;

            rpc.Completed -= OnDeleteCommentRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }
            else if (null == args.Error)
            {
                //remove the comment from the store--saves us a web call
                App.MasterViewModel.Comments.Remove(args.Items[0]);

                NavigationService.GoBack();
            }
            else
            {
                this.HandleException(args.Error);
            }

            App.WaitIndicationService.HideIndicator();
            ApplicationBar.IsVisible = true;
        }
        public void OnLoadLastNotificationCompleted(object sender, XMLRPCCompletedEventArgs <IntResponseObject> args)
        {
            XmlRemoteProcedureCall <IntResponseObject> rpc = sender as XmlRemoteProcedureCall <IntResponseObject>;

            rpc.Completed -= OnLoadLastNotificationCompleted;
            if (null == args.Error && args.Items.Count > 0)
            {
                IntResponseObject blogIDRespObj = args.Items.First();
                IntResponseObject commentIDObj  = args.Items.Last();

                if (blogIDRespObj.Value == 0)
                {
                    return;
                }

                if (commentIDObj == null || commentIDObj.Value == 0)
                {
                    return;
                }

                string blogID    = string.Format("{0}", blogIDRespObj.Value);
                string commentID = string.Format("{0}", commentIDObj.Value);
                showToastForNewComment(blogID, commentID);
                return;
            }
            else
            {
                Exception e = args.Error;
#if DEBUG
                MessageBoxResult result = MessageBox.Show(String.Format("Error occurred. {0}", e.Message), "Error reading the last notification", MessageBoxButton.OK);
#endif
                Utils.Tools.LogException(String.Format("Error occurred. {0}", e.Message), e);
            }
        }
        private void OnGetMediaItemRPCCompleted(object sender, XMLRPCCompletedEventArgs <MediaItem> args)
        {
            _mediaItemRPC.Completed -= OnGetMediaItemRPCCompleted;
            _mediaItemRPC            = null;

            if (args.Cancelled)
            {
                return;
            }

            if (null == args.Error)
            {
                if (args.Items.Count > 0)
                {
                    MediaItem m = args.Items[0] as MediaItem;
                    App.MasterViewModel.CurrentPost.FeaturedImage = m;
                    SetupFeaturedImage();
                }
            }
            else
            {
                //Error!
                showFeaturedImageLoadingError(args.Error);
            }
        }
예제 #6
0
        private void OnBatchDeleteXmlRPCCompleted(object sender, XMLRPCCompletedEventArgs <Comment> args)
        {
            DeleteCommentsRPC rpc = sender as DeleteCommentsRPC;

            rpc.Completed -= OnBatchDeleteXmlRPCCompleted;

            ApplicationBar.IsVisible = true;
            App.WaitIndicationService.HideIndicator();

            UpdateDisplay();
        }
 private void OnGetApiKeyRPCCompleted(object sender, XMLRPCCompletedEventArgs <Blog> args)
 {
     loadingStatsProgressBar.Opacity = 0.0;
     if (App.MasterViewModel.CurrentBlog.ApiKey != null)
     {
         RetrieveStats(false);
     }
     else
     {
         RetrieveStats(true);
     }
 }
        public void OnLoadLastNotificationCompleted(object sender, XMLRPCCompletedEventArgs <IntResponseObject> args)
        {
            UIThread.Invoke(() =>
            {
                loadingContentProgressBar.Opacity = 0.0;
            });

            XmlRemoteProcedureCall <IntResponseObject> rpc = sender as XmlRemoteProcedureCall <IntResponseObject>;

            rpc.Completed -= OnLoadLastNotificationCompleted;

            PushNotificationsHelper.Instance.OnLoadLastNotificationCompleted(sender, args);
        }
        public void ExecuteAsync()
        {
            ValidateValues();

            if (0 == Comments.Count)
            {
                List<Comment> items = new List<Comment>();
                XMLRPCCompletedEventArgs<Comment> args = new XMLRPCCompletedEventArgs<Comment>(items, null, false, null);
                NotifyCompleted(args);
                return;
            }

            _modifiedComments = Comments.Where(comment => CommentStatus != comment.CommentStatus).ToList();

            if (0 == _modifiedComments.Count)
            {
                List<Comment> items = new List<Comment>();
                XMLRPCCompletedEventArgs<Comment> args = new XMLRPCCompletedEventArgs<Comment>(items, null, false, null);
                NotifyCompleted(args);
                return;
            }

            //initialize our counter ivar
            _numberOfCompletedRPCs = 0;

            //initialize our success/failure collections
            if (null != _successes)
            {
                _successes.Clear();
                _successes = null;
            }
            _successes = new List<XMLRPCCompletedEventArgs<Comment>>();

            if (null != _failures)
            {
                _failures.Clear();
                _failures = null;
            }
            _failures = new List<XMLRPCCompletedEventArgs<Comment>>();

            _operation = AsyncOperationManager.CreateOperation(Guid.NewGuid());

            _modifiedComments.ForEach(comment =>
            {
                comment.CommentStatus = this.CommentStatus;

                EditCommentRPC rpc = new EditCommentRPC(DataService.Current.CurrentBlog, comment);
                rpc.Completed += OnEditCommentRPCCompleted;
                rpc.ExecuteAsync();
            });
        }
        private void OnGetViewStatsRPCCompleted(object sender, XMLRPCCompletedEventArgs <ViewDataPoint> args)
        {
            //DEV NOTE: this link was really helpful getting things going:
            //http://silverlighthack.com/post/2010/10/08/Windows-Phone-7-RTM-Charting-using-the-Silverlight-Control-Toolkit.aspx

            GetViewStatsRPC rpc = sender as GetViewStatsRPC;

            rpc.Completed -= OnGetViewStatsRPCCompleted;

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                if (null == args.Items)
                {
                    return;
                }

                if (0 == args.Items.Count)
                {
                    MessageBox.Show(_localizedStrings.Messages.NoStatsAvailable);
                }
                else
                {
                    if (0 != viewsStatsChart.Series.Count)
                    {
                        HideStatControls();

                        viewsStatsScrollViewer.Visibility = Visibility.Visible;

                        ColumnSeries series = viewsStatsChart.Series[0] as ColumnSeries;

                        DateTimeAxis axis = series.IndependentAxis as DateTimeAxis;
                        axis.Interval     = ConvertStatisticPeriodToInterval();
                        axis.IntervalType = ConvertStatisticPeriodToIntervalType();
                    }

                    ObservableObjectCollection viewStatsDataSource = Resources["viewStatsDataSource"] as ObservableObjectCollection;
                    viewStatsDataSource.Clear();
                    args.Items.ForEach(item => viewStatsDataSource.Add(item));
                }
            }
            else
            {
                this.HandleException(args.Error);
            }

            loadingStatsProgressBar.Opacity = 0;
        }
        private void OnUploadMediaRPCCompleted(object sender, XMLRPCCompletedEventArgs <Media> args)
        {
            UploadFileRPC rpc = sender as UploadFileRPC;

            rpc.Completed -= OnUploadMediaRPCCompleted;

            lock (_syncRoot)
            {
                _mediaUploadRPCs.Remove(rpc);
                if (args.Cancelled)
                {
                    return;
                }

                if (args.Items.Count == 0 || args.Error != null)
                {
                    //uh oh, media upload problem
                    App.WaitIndicationService.KillSpinner();
                    //Move
                    UIThread.Invoke(() =>
                    {
                        ApplicationBar.IsVisible = true;
                        if (!_messageBoxIsShown)
                        {
                            _messageBoxIsShown      = true;
                            String msg              = args.Error != null ? args.Error.Message : _localizedStrings.Prompts.MediaError;
                            MessageBoxResult result = MessageBox.Show(msg, _localizedStrings.Prompts.MediaError, MessageBoxButton.OK);
                            _messageBoxIsShown      = false;
                        }
                    });
                    this.emptyImagesUploadingQueue();
                    return;
                }
                else
                {
                    //Image uploaded correctly. Upload the next picture in the list
                    if (_mediaUploadRPCs.Count > 0)
                    {
                        UploadFileRPC item = _mediaUploadRPCs.First() as UploadFileRPC;
                        item.ExecuteAsync();
                        return;
                    }

                    App.WaitIndicationService.KillSpinner();
                    SavePost();
                }
            }//end lock
        }
        private void OnRegisterTokenCompleted(object sender, XMLRPCCompletedEventArgs <BooleanResponseObject> args)
        {
            RegisterPushNotificationToken rpc = sender as RegisterPushNotificationToken;

            rpc.Completed -= OnRegisterTokenCompleted;
            if (null == args.Error)
            {
                this.sendBlogsList();
                return;
            }
            else
            {
                Exception e = args.Error;
                Utils.Tools.LogException(String.Format("Register Token  error occurred. {0}", e.Message), e);
            }
        }
        private void OnSendBlogsListCompleted(object sender, XMLRPCCompletedEventArgs <BooleanResponseObject> args)
        {
            PushNotificationsSendBlogsList rpc = sender as PushNotificationsSendBlogsList;

            rpc.Completed -= OnSendBlogsListCompleted;
            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                return;
            }
            else
            {
                Exception e = args.Error;
                Utils.Tools.LogException(String.Format("PushNotificationsSendBlogsList  error occurred. {0}", e.Message), e);
            }
        }
        private void OnGetUsersBlogsCompleted(object sender, XMLRPCCompletedEventArgs <Blog> args)
        {
            GetUsersBlogsRPC rpc = sender as GetUsersBlogsRPC;

            rpc.Completed           -= OnGetUsersBlogsCompleted;
            ApplicationBar.IsVisible = true;
            App.WaitIndicationService.KillSpinner();

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                if (1 == args.Items.Count)
                {
                    if (!(DataService.Current.Blogs.Any(b => b.Xmlrpc == args.Items[0].Xmlrpc)))
                    {
                        DataService.Current.AddBlogToStore(args.Items[0]);
                        PushNotificationsHelper.Instance.sendBlogsList();
                    }
                    NavigationService.Navigate(new Uri("/BlogsPage.xaml", UriKind.Relative));
                }
                else
                {
                    ShowBlogSelectionControl(args.Items);
                }
            }
            else
            {
                Exception currentException = args.Error;
                if (currentException is XmlRPCException && (currentException as XmlRPCException).FaultCode == 403) //username or password error
                {
                    UIThread.Invoke(() =>
                    {
                        MessageBox.Show(_localizedStrings.Prompts.UsernameOrPasswordError);
                    });
                }
                else
                {
                    this.HandleException(args.Error);
                }
            }
        }
예제 #15
0
        private void OnNewCommentRPCCompleted(object sender, XMLRPCCompletedEventArgs <Comment> args)
        {
            NewCommentRPC rpc = sender as NewCommentRPC;

            rpc.Completed -= OnNewCommentRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }
            else if (null == args.Error)
            {
                NavigationService.GoBack();
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
예제 #16
0
        private void OnFetchCurrentBlogCommentsCompleted(object sender, XMLRPCCompletedEventArgs <Comment> args)
        {
            GetAllCommentsRPC rpc = sender as GetAllCommentsRPC;

            rpc.Completed -= OnFetchCurrentBlogCommentsCompleted;

            UIThread.Invoke(() =>
            {
                ApplicationBar.IsVisible = true;
                App.WaitIndicationService.HideIndicator();
            });

            if (null == args.Error)
            {
                foreach (Comment comment in args.Items)
                {
                    if (comment.CommentId == this.comment_id)
                    {
                        _currentComment = comment;
                        DataContext     = comment;
                    }
                }

                if (_currentComment == null)
                {
                    UIThread.Invoke(() =>
                    {
                        MessageBox.Show("Could not load the comment!", _localizedStrings.Messages.Info, MessageBoxButton.OK);
                    });
                }
            }
            else
            {
                this.HandleException(args.Error);
            }

            UIThread.Invoke(() =>
            {
                ChangeApplicationBarAppearance();
            });
        }
예제 #17
0
        private void OnDeleteCommentRPCCompleted(object sender, XMLRPCCompletedEventArgs <Comment> args)
        {
            DeleteCommentRPC rpc = sender as DeleteCommentRPC;

            rpc.Completed -= OnDeleteCommentRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }
            else if (null == args.Error)
            {
                NavigationService.GoBack();
            }
            else
            {
                this.HandleException(args.Error);
            }

            App.WaitIndicationService.HideIndicator();
            ApplicationBar.IsVisible = true;
        }
        private void OnNewPostRPCCompleted(object sender, XMLRPCCompletedEventArgs <Post> args)
        {
            NewPostRPC rpc = sender as NewPostRPC;

            rpc.Completed -= OnNewPostRPCCompleted;


            if (args.Cancelled)
            {
                //do not set the connection to null here
                return;
            }

            if (this.isEditingLocalDraft)
            {
                // Local Draft was published
                App.MasterViewModel.CurrentBlog.LocalPostDrafts.Remove(App.MasterViewModel.CurrentPost);
            }
            ApplicationBar.IsVisible = true;
            App.WaitIndicationService.HideIndicator();

            if (null == args.Error)
            {
                cleanupPostMedia();
                DataService.Current.FetchCurrentBlogPostsAsync(false);
                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }
                else
                {
                    throw new ApplicationShouldEndException();
                }
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
        public void ExecuteAsync()
        {
            ValidateValues();

            if (0 == Comments.Count)
            {
                List<Comment> items = new List<Comment>();
                XMLRPCCompletedEventArgs<Comment> args = new XMLRPCCompletedEventArgs<Comment>(items, null, false, null);
                NotifyCompleted(args);
                return;
            }

            //initialize our counter ivar
            _numberOfCompletedRPCs = 0;

            //initialize our success/failure collections
            if (null != _successes)
            {
                _successes.Clear();
                _successes = null;
            }
            _successes = new List<XMLRPCCompletedEventArgs<Comment>>();

            if (null != _failures)
            {
                _failures.Clear();
                _failures = null;
            }
            _failures = new List<XMLRPCCompletedEventArgs<Comment>>();

            _operation = AsyncOperationManager.CreateOperation(Guid.NewGuid());

            foreach (Comment comment in Comments)
            {
                DeleteCommentRPC rpc = new DeleteCommentRPC(DataService.Current.CurrentBlog, comment);
                rpc.Completed += OnDeleteCommentRPCCompleted;
                rpc.ExecuteAsync();
            }
        }
예제 #20
0
        private void OnNewCategoryRPCCompleted(object sender, XMLRPCCompletedEventArgs <Category> args)
        {
            NewCategoryRPC rpc = sender as NewCategoryRPC;

            rpc.Completed -= OnNewCategoryRPCCompleted;

            if (args.Cancelled)
            {
                ApplicationBar.IsVisible = true;
                App.WaitIndicationService.HideIndicator();
            }
            else if (null == args.Error)
            {
                DataService.Current.FetchComplete += OnFetchCurrentBlogCategoriesComplete;
                DataService.Current.FetchCurrentBlogCategories();
            }
            else
            {
                ApplicationBar.IsVisible = true;
                App.WaitIndicationService.HideIndicator();
                this.HandleException(args.Error);
            }
        }
예제 #21
0
        private void OnNewCommentRPCCompleted(object sender, XMLRPCCompletedEventArgs <Comment> args)
        {
            NewCommentRPC rpc = sender as NewCommentRPC;

            rpc.Completed -= OnNewCommentRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }
            else if (null == args.Error)
            {
                //fire off a request for the latest comment so we can get our comment updated
                //with the latest from the server.
                DataService.Current.FetchCurrentBlogCommentsAsync(false);

                NavigationService.GoBack();
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
        private void OnGetUsersBlogsCompleted(object sender, XMLRPCCompletedEventArgs<Blog> args)
        {
            GetUsersBlogsRPC rpc = sender as GetUsersBlogsRPC;
            rpc.Completed -= OnGetUsersBlogsCompleted;
            ApplicationBar.IsVisible = true;
            App.WaitIndicationService.KillSpinner();

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                if (1 == args.Items.Count)
                {
                    if (!(DataService.Current.Blogs.Any(b => b.Xmlrpc == args.Items[0].Xmlrpc)))
                    {
                        DataService.Current.AddBlogToStore(args.Items[0]);
                        PushNotificationsHelper.Instance.sendBlogsList();
                    }
                    NavigationService.Navigate(new Uri("/BlogsPage.xaml", UriKind.Relative));
                }
                else
                {
                    ShowBlogSelectionControl(args.Items);
                }
            }
            else
            {
                Exception currentException = args.Error;
                if (currentException is XmlRPCException && (currentException as XmlRPCException).FaultCode == 403) //username or password error
                {
                    UIThread.Invoke(() =>
                    {
                        MessageBox.Show(_localizedStrings.Prompts.UsernameOrPasswordError);
                    });
                }
                else
                    this.HandleException(args.Error);
            }
        }
        private void OnGetMediaItemRPCCompleted(object sender, XMLRPCCompletedEventArgs<MediaItem> args)
        {
            _mediaItemRPC.Completed -= OnGetMediaItemRPCCompleted;
            _mediaItemRPC = null;

            if (args.Cancelled)
            {
                return;
            }

            if (null == args.Error)
            {
                if (args.Items.Count > 0)
                {
                    MediaItem m = args.Items[0] as MediaItem;
                    App.MasterViewModel.CurrentPost.FeaturedImage = m;
                    SetupFeaturedImage();
                }
            }
            else
            {
                //Error!
                showFeaturedImageLoadingError(args.Error);
            }
        }
        private void OnGetViewStatsRPCCompleted(object sender, XMLRPCCompletedEventArgs<ViewDataPoint> args)
        {
            //DEV NOTE: this link was really helpful getting things going:
            //http://silverlighthack.com/post/2010/10/08/Windows-Phone-7-RTM-Charting-using-the-Silverlight-Control-Toolkit.aspx

            GetViewStatsRPC rpc = sender as GetViewStatsRPC;
            rpc.Completed -= OnGetViewStatsRPCCompleted;

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                if (null == args.Items) return;

                if (0 == args.Items.Count)
                {
                    MessageBox.Show(_localizedStrings.Messages.NoStatsAvailable);
                }
                else
                {
                    if (0 != viewsStatsChart.Series.Count)
                    {
                        HideStatControls();

                        viewsStatsScrollViewer.Visibility = Visibility.Visible;

                        ColumnSeries series = viewsStatsChart.Series[0] as ColumnSeries;

                        DateTimeAxis axis = series.IndependentAxis as DateTimeAxis;
                        axis.Interval = ConvertStatisticPeriodToInterval();
                        axis.IntervalType = ConvertStatisticPeriodToIntervalType();
                    }

                    ObservableObjectCollection viewStatsDataSource = Resources["viewStatsDataSource"] as ObservableObjectCollection;
                    viewStatsDataSource.Clear();
                    args.Items.ForEach(item => viewStatsDataSource.Add(item));
                }
            }
            else
            {
                this.HandleException(args.Error);
            }

            loadingStatsProgressBar.Opacity = 0;
        }
        private void OnShareItemRPCCompleted(object sender, XMLRPCCompletedEventArgs<Post> args)
        {
            GetPostRPC rpc = sender as GetPostRPC;
            rpc.Completed -= OnShareItemRPCCompleted;

            currentXMLRPCConnection = null;
            App.WaitIndicationService.KillSpinner();
            ApplicationBar.IsVisible = true;

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                Post post = args.Items[0];

                // Use the ShareLinkTask launcher to share the post to social networks
                ShareLinkTask shareLinkTask = new ShareLinkTask();
                shareLinkTask.Title = post.Title;
                shareLinkTask.LinkUri = new Uri(post.PermaLink, UriKind.Absolute);
                shareLinkTask.Show();
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
        private void OnBatchEditXmlRPCCompleted(object sender, XMLRPCCompletedEventArgs<Comment> args)
        {
            EditCommentsStatusRPC rpc = sender as EditCommentsStatusRPC;
            rpc.Completed -= OnBatchEditXmlRPCCompleted;
            currentXMLRPCConnection = null;
            App.WaitIndicationService.HideIndicator();
            ApplicationBar.IsVisible = true;

            //switch back to 'single mode'.
            _isModeratingComments = false;
            commentsListBox.IsSelectionEnabled = _isModeratingComments;
            RefreshAppBar();
        }
        private void OnDeletePostRPCCompleted(object sender, XMLRPCCompletedEventArgs<Post> args)
        {
            ApplicationBar.IsVisible = true;
            App.WaitIndicationService.HideIndicator();
            currentXMLRPCConnection = null;

            DeletePostRPC rpc = sender as DeletePostRPC;
            rpc.Completed -= OnDeletePostRPCCompleted;

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                try
                {
                    string postId = args.Items[0].PostId;
                    var postListItem = App.MasterViewModel.CurrentBlog.PostListItems.Single(item => postId.Equals(item.PostId));
                    App.MasterViewModel.CurrentBlog.PostListItems.Remove(postListItem);
                }
                catch (Exception e)
                {
                    Tools.LogException("Post was removed from the server, but an error occurred when removing it from the local DB", e);
                }
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
        private void OnBatchEditXmlRPCCompleted(object sender, XMLRPCCompletedEventArgs<Comment> args)
        {
            EditCommentsStatusRPC rpc = sender as EditCommentsStatusRPC;
            rpc.Completed -= OnBatchEditXmlRPCCompleted;

            ApplicationBar.IsVisible = true;
            App.WaitIndicationService.HideIndicator();

            UpdateDisplay();
        }
 private void OnRegisterTokenCompleted(object sender, XMLRPCCompletedEventArgs<BooleanResponseObject> args)
 {
     RegisterPushNotificationToken rpc = sender as RegisterPushNotificationToken;
     rpc.Completed -= OnRegisterTokenCompleted;
     if (null == args.Error)
     {
         this.sendBlogsList();
         return;
     }
     else
     {
        Exception e = args.Error;
        Utils.Tools.LogException(String.Format("Register Token  error occurred. {0}", e.Message), e);
     }
 }
        public void OnLoadLastNotificationCompleted(object sender, XMLRPCCompletedEventArgs<IntResponseObject> args)
        {
            XmlRemoteProcedureCall<IntResponseObject> rpc = sender as XmlRemoteProcedureCall<IntResponseObject>;
            rpc.Completed -= OnLoadLastNotificationCompleted;
            if (null == args.Error && args.Items.Count > 0)
            {
                IntResponseObject blogIDRespObj = args.Items.First();
                IntResponseObject commentIDObj = args.Items.Last();

                if (blogIDRespObj.Value == 0)
                    return;

                if (commentIDObj == null || commentIDObj.Value == 0)
                    return;

                string blogID = string.Format("{0}", blogIDRespObj.Value);
                string commentID = string.Format("{0}", commentIDObj.Value);
                showToastForNewComment(blogID, commentID);
                return;
            }
            else
            {
                Exception e = args.Error;
            #if DEBUG
                MessageBoxResult result = MessageBox.Show(String.Format("Error occurred. {0}", e.Message), "Error reading the last notification", MessageBoxButton.OK);
            #endif
                Utils.Tools.LogException(String.Format("Error occurred. {0}", e.Message), e);
            }
        }
        private void OnGetUsersBlogsCompleted(object sender, XMLRPCCompletedEventArgs<Blog> args)
        {
            GetUsersBlogsRPC rpc = sender as GetUsersBlogsRPC;
            rpc.Completed -= OnGetUsersBlogsCompleted;

            if (args.Cancelled)
            {
            } 
            else if (null == args.Error)
            {
                App.WaitIndicationService.KillSpinner();
                ApplicationBar.IsVisible = true;

                if (0 == args.Items.Count)
                {
                    this.HandleException(null, _localizedStrings.PageTitles.CheckTheUrl, string.Format(_localizedStrings.Messages.NoBlogsFoundAtThisURL, rpc.Url));
                }
                else if (1 == args.Items.Count)
                {
                    if (!(DataService.Current.Blogs.Any(b => b.Xmlrpc == args.Items[0].Xmlrpc)))
                    {
                        DataService.Current.AddBlogToStore(args.Items[0]);
                        PushNotificationsHelper.Instance.sendBlogsList();
                    }
                    NavigationService.Navigate(new Uri("/BlogsPage.xaml", UriKind.Relative));
                }
                else
                {
                    ShowBlogSelectionControl(args.Items);
                }
            }
            else
            {

                if (useRecoveryFunctions && !(args.Error is WordPress.Model.NoConnectionException) && !(args.Error is XmlRPCException))//do not use the recovery function if the connection is not available
                {
                    useRecoveryFunctions = false; //set this to false, since the recovery functions will be used only once.
                    startRecoveryfunctions();
                }
                else
                {
                    App.WaitIndicationService.KillSpinner();
                    ApplicationBar.IsVisible = true;
                    Exception currentException = args.Error;
                    if (currentException is NotSupportedException || currentException is XmlRPCParserException || currentException is ArgumentNullException)
                    {
                        this.HandleException(currentException, _localizedStrings.PageTitles.CheckTheUrl, _localizedStrings.Messages.CheckTheUrl);
                        UIThread.Invoke(() =>
                        {
                            urlTextBox.Focus();
                        });
                        return;
                    }
                    else if (currentException is XmlRPCException && (currentException as XmlRPCException).FaultCode == 403) //username or password error
                    {
                        UIThread.Invoke(() =>
                        {
                            MessageBox.Show(_localizedStrings.Prompts.UsernameOrPasswordError);
                        });
                    }
                    else
                        this.HandleException(args.Error);
                }
            }
        }
        private void OnNewCommentRPCCompleted(object sender, XMLRPCCompletedEventArgs<Comment> args)
        {
            NewCommentRPC rpc = sender as NewCommentRPC;
            rpc.Completed -= OnNewCommentRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }
            else if (null == args.Error)
            {
                //fire off a request for the latest comment so we can get our comment updated
                //with the latest from the server.
                DataService.Current.FetchCurrentBlogCommentsAsync(false);

                NavigationService.GoBack();
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
        private void OnNewCommentRPCCompleted(object sender, XMLRPCCompletedEventArgs<Comment> args)
        {
            NewCommentRPC rpc = sender as NewCommentRPC;
            rpc.Completed -= OnNewCommentRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }
            else if (null == args.Error)
            {
                NavigationService.GoBack();
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
        private void OnDeleteCommentRPCCompleted(object sender, XMLRPCCompletedEventArgs<Comment> args)
        {
            lock (_syncRoot)
            {
                _numberOfCompletedRPCs++;

                if (null == args.Error)
                {
                    _successes.Add(args);
                }
                else
                {
                    _failures.Add(args);
                }

                if (_numberOfCompletedRPCs == Comments.Count)
                {
                    Exception error = null;
                    if (0 < _failures.Count)
                    {
                        error = _failures[0].Error;
                    }
                    List<Comment> modifiedComments = new List<Comment>();
                    _successes.ForEach(successArgs =>
                    {
                        modifiedComments.Add(successArgs.Items[0]);
                    });

                    XMLRPCCompletedEventArgs<Comment> completedArgs = new XMLRPCCompletedEventArgs<Comment>(Comments.ToList(), error, false, _operation.UserSuppliedState);
                    _operation.PostOperationCompleted(_completedDelegate, completedArgs);
                }
                else
                {
                    int progress = Comments.Count / _numberOfCompletedRPCs;

                    ProgressChangedEventArgs progressArgs = new ProgressChangedEventArgs(progress, null);
                    _operation.Post(_progressReportDelegate, progressArgs);
                }
            }
        }
예제 #35
0
        private void OnGetUsersBlogsCompleted(object sender, XMLRPCCompletedEventArgs <Blog> args)
        {
            GetUsersBlogsRPC rpc = sender as GetUsersBlogsRPC;

            rpc.Completed -= OnGetUsersBlogsCompleted;

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                App.WaitIndicationService.KillSpinner();
                ApplicationBar.IsVisible = true;

                if (0 == args.Items.Count)
                {
                    this.HandleException(null, _localizedStrings.PageTitles.CheckTheUrl, string.Format(_localizedStrings.Messages.NoBlogsFoundAtThisURL, rpc.Url));
                }
                else if (1 == args.Items.Count)
                {
                    if (!(DataService.Current.Blogs.Any(b => b.Xmlrpc == args.Items[0].Xmlrpc)))
                    {
                        DataService.Current.AddBlogToStore(args.Items[0]);
                        PushNotificationsHelper.Instance.sendBlogsList();
                    }
                    NavigationService.Navigate(new Uri("/BlogsPage.xaml", UriKind.Relative));
                }
                else
                {
                    ShowBlogSelectionControl(args.Items);
                }
            }
            else
            {
                if (useRecoveryFunctions && !(args.Error is WordPress.Model.NoConnectionException) && !(args.Error is XmlRPCException)) //do not use the recovery function if the connection is not available
                {
                    useRecoveryFunctions = false;                                                                                       //set this to false, since the recovery functions will be used only once.
                    startRecoveryfunctions();
                }
                else
                {
                    App.WaitIndicationService.KillSpinner();
                    ApplicationBar.IsVisible = true;
                    Exception currentException = args.Error;
                    if (currentException is NotSupportedException || currentException is XmlRPCParserException || currentException is ArgumentNullException)
                    {
                        this.HandleException(currentException, _localizedStrings.PageTitles.CheckTheUrl, _localizedStrings.Messages.CheckTheUrl);
                        UIThread.Invoke(() =>
                        {
                            urlTextBox.Focus();
                        });
                        return;
                    }
                    else if (currentException is XmlRPCException && (currentException as XmlRPCException).FaultCode == 403) //username or password error
                    {
                        UIThread.Invoke(() =>
                        {
                            MessageBox.Show(_localizedStrings.Prompts.UsernameOrPasswordError);
                        });
                    }
                    else
                    {
                        this.HandleException(args.Error);
                    }
                }
            }
        }
        public void OnLoadLastNotificationCompleted(object sender, XMLRPCCompletedEventArgs<IntResponseObject> args)
        {
            UIThread.Invoke(() =>
            {
                loadingContentProgressBar.Opacity = 0.0;
            });

            XmlRemoteProcedureCall<IntResponseObject> rpc = sender as XmlRemoteProcedureCall<IntResponseObject>;
            rpc.Completed -= OnLoadLastNotificationCompleted;

            PushNotificationsHelper.Instance.OnLoadLastNotificationCompleted(sender, args);
        }
 private void OnSendBlogsListCompleted(object sender, XMLRPCCompletedEventArgs<BooleanResponseObject> args)
 {
     PushNotificationsSendBlogsList rpc = sender as PushNotificationsSendBlogsList;
     rpc.Completed -= OnSendBlogsListCompleted;
     if (args.Cancelled)
     {
     }
     else if (null == args.Error)
     {
         return;
     }
     else
     {
         Exception e = args.Error;
         Utils.Tools.LogException(String.Format("PushNotificationsSendBlogsList  error occurred. {0}", e.Message), e);
     }
 }
        private void OnGetPostRPCCompleted(object sender, XMLRPCCompletedEventArgs<Post> args)
        {
            GetPostRPC rpc = sender as GetPostRPC;
            rpc.Completed -= OnGetPostRPCCompleted;
            App.WaitIndicationService.KillSpinner();
            ApplicationBar.IsVisible = true;
            currentXMLRPCConnection = null;

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                Post post = args.Items[0];
                App.MasterViewModel.CurrentPost = post;
                NavigationService.Navigate(new Uri("/EditPostPage.xaml", UriKind.Relative));
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
 private void OnGetApiKeyRPCCompleted(object sender, XMLRPCCompletedEventArgs<Blog> args)
 {
     loadingStatsProgressBar.Opacity = 0.0;
     if (App.MasterViewModel.CurrentBlog.ApiKey != null)
     {
         RetrieveStats(false);
     }
     else
     {
         RetrieveStats(true);
     }
 }
        private void OnEditPostRPCCompleted(object sender, XMLRPCCompletedEventArgs<Post> args)
        {
            EditPostRPC rpc = sender as EditPostRPC;
            rpc.Completed -= OnEditPostRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }

            //Do not change the UI if the connection is cancelled. The user could have started another connection...
            ApplicationBar.IsVisible = true;
            App.WaitIndicationService.HideIndicator();

            if (null == args.Error)
            {
                cleanupPostMedia();
                if (NavigationService.CanGoBack)
                {
                    DataService.Current.FetchCurrentBlogPagesAsync(false);
                    NavigationService.GoBack();
                }
                else
                    throw new ApplicationShouldEndException();
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
        private void OnNewPostRPCCompleted(object sender, XMLRPCCompletedEventArgs<Post> args)
        {
            NewPostRPC rpc = sender as NewPostRPC;
            rpc.Completed -= OnNewPostRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }

            if (this.isEditingLocalDraft)
            {
                // Local Draft was published
                App.MasterViewModel.CurrentBlog.LocalPageDrafts.Remove(App.MasterViewModel.CurrentPost);
            }

            App.WaitIndicationService.HideIndicator();
            ApplicationBar.IsVisible = true;

            if (null == args.Error)
            {
                cleanupPostMedia();
                if (NavigationService.CanGoBack)
                {
                    DataService.Current.FetchCurrentBlogPagesAsync(false);
                    NavigationService.GoBack();
                }
                else
                    throw new ApplicationShouldEndException();
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
        private void OnViewPostRPCCompleted(object sender, XMLRPCCompletedEventArgs<Post> args)
        {
            GetPostRPC rpc = sender as GetPostRPC;
            rpc.Completed -= OnViewPostRPCCompleted;

            currentXMLRPCConnection = null;
            App.WaitIndicationService.KillSpinner();
            ApplicationBar.IsVisible = true;

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                //DEV NOTE: We could fire off a WebBrowserTask here but in testing with the emulator
                //the browser acts a bit odd if there are already tabs open.  The WebBrowserTask
                //creates a new tab for the web content, but doesn't automatically
                //open your new tab if other tabs already exist.
                Post post = args.Items[0];
                string queryStringFormat = "?{0}={1}&{2}={3}";
                string queryString = string.Format(queryStringFormat, BrowserShellPage.TARGET_URL, post.PermaLink, BrowserShellPage.REQUIRE_LOGIN, "1");
                NavigationService.Navigate(new Uri("/BrowserShellPage.xaml" + queryString, UriKind.Relative));
            }
            else
            {
                this.HandleException(args.Error);
            }
        }
        private void OnUploadMediaRPCCompleted(object sender, XMLRPCCompletedEventArgs<Media> args)
        {
            UploadFileRPC rpc = sender as UploadFileRPC;
            rpc.Completed -= OnUploadMediaRPCCompleted;

            lock (_syncRoot)
            {
                _mediaUploadRPCs.Remove(rpc);
                if (args.Cancelled)
                {
                    return;
                }

                if (args.Items.Count == 0 || args.Error != null)
                {
                    //uh oh, media upload problem
                    App.WaitIndicationService.KillSpinner();
                    //Move
                    UIThread.Invoke(() =>
                    {
                        ApplicationBar.IsVisible = true;
                        if (!_messageBoxIsShown)
                        {
                            _messageBoxIsShown = true;
                            String msg = args.Error != null ? args.Error.Message : _localizedStrings.Prompts.MediaError;
                            MessageBoxResult result = MessageBox.Show(msg, _localizedStrings.Prompts.MediaError, MessageBoxButton.OK);
                            _messageBoxIsShown = false;
                        }
                    });
                    this.emptyImagesUploadingQueue();
                    return;
                }
                else
                {
                    //Image uploaded correctly. Upload the next picture in the list
                    if (_mediaUploadRPCs.Count > 0)
                    {
                        UploadFileRPC item = _mediaUploadRPCs.First() as UploadFileRPC;
                        item.ExecuteAsync();
                        return;
                    }

                    App.WaitIndicationService.KillSpinner();
                    SavePost();
                }
            }//end lock
        }
        private void OnDeleteCommentRPCCompleted(object sender, XMLRPCCompletedEventArgs<Comment> args)
        {
            DeleteCommentRPC rpc = sender as DeleteCommentRPC;
            rpc.Completed -= OnDeleteCommentRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }
            else if (null == args.Error)
            {
                //remove the comment from the store--saves us a web call
                App.MasterViewModel.Comments.Remove(args.Items[0]);

                NavigationService.GoBack();
            }
            else
            {
                this.HandleException(args.Error);
            }

            App.WaitIndicationService.HideIndicator();
            ApplicationBar.IsVisible = true;
        }
        private void OnGetSearchTermStatsRPCCompleted(object sender, XMLRPCCompletedEventArgs<SearchTermDataPoint> args)
        {
            GetSearchTermStatsRPC rpc = sender as GetSearchTermStatsRPC;
            rpc.Completed -= OnGetSearchTermStatsRPCCompleted;

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                HideStatControls();

                searchTermsGrid.Visibility = Visibility.Visible;

                ObservableObjectCollection dataSource = Resources["searchTermStatsDataSource"] as ObservableObjectCollection;
                dataSource.Clear();
                args.Items.ForEach(item => dataSource.Add(item));
            }
            else
            {
                this.HandleException(args.Error);
            }

            loadingStatsProgressBar.Opacity = 0.0;
        }
        private void OnEditCommentRPCCompleted(object sender, XMLRPCCompletedEventArgs<Comment> args)
        {
            EditCommentRPC rpc = sender as EditCommentRPC;
            rpc.Completed -= OnEditCommentRPCCompleted;

            if (args.Cancelled)
            {
                return;
            }

            ApplicationBar.IsVisible = true;
            App.WaitIndicationService.HideIndicator();
            if (null == args.Error)
            {
                NavigationService.GoBack();
            }
            else
            {
                this.HandleException(args.Error);
                ChangeApplicationBarAppearance();
            }
        }
        private void OnFetchCurrentBlogCommentsCompleted(object sender, XMLRPCCompletedEventArgs<Comment> args)
        {
            GetAllCommentsRPC rpc = sender as GetAllCommentsRPC;
            rpc.Completed -= OnFetchCurrentBlogCommentsCompleted;

            UIThread.Invoke(() =>
            {
                ApplicationBar.IsVisible = true;
                App.WaitIndicationService.HideIndicator();
            });

            if (null == args.Error)
            {
                foreach (Comment comment in args.Items)
                {
                    if (comment.CommentId == this.comment_id)
                    {
                        _currentComment = comment;
                        DataContext = comment;
                    }
                }

                if (_currentComment == null)
                {
                    UIThread.Invoke(() =>
                    {
                        MessageBox.Show("Could not load the comment!", _localizedStrings.Messages.Info, MessageBoxButton.OK);
                    });
                }
            }
            else
            {
               this.HandleException(args.Error);
            }

            UIThread.Invoke(() =>
            {
                ChangeApplicationBarAppearance();
            });
        }