private void OnGetNewBlogRecentPostsRPCProgressChanged(object sender, ProgressChangedEventArgs args)
        {
            GetRecentPostsRPC rpc = sender as GetRecentPostsRPC;
            Blog newBlog          = _trackedBlogs.Where(blog => blog.BlogId == rpc.BlogId).FirstOrDefault();

            if (null != newBlog)
            {
                this.DebugLog("OnGetNewBlogRecentPostsRPCProgressChanged-- Blog: " + newBlog.BlogName);
            }
            this.DebugLog("OnGetNewBlogRecentPostsRPCProgressChanged-- Progress: " + args.ProgressPercentage.ToString());
            this.DebugLog("OnGetNewBlogRecentPostsRPCProgressChanged-- UserState: " + args.UserState);
        }
        public bool FetchCurrentBlogPostsAsync(bool more)
        {
            if (null == CurrentBlog)
            {
                throw new ArgumentException("CurrentBlog may not be null", "CurrentBlog");
            }

            //we're already downloading data here--don't allow scenarios where we could be
            //kicking off another download
            if (_trackedBlogs.Contains(CurrentBlog))
            {
                return(false);
            }

            CurrentBlog.showLoadingIndicator();

            int numerberOfPosts = 0;

            if (more)
            {
                numerberOfPosts = Math.Max(CurrentBlog.PostListItems.Count, CHUNK_SIZE);
                if (CurrentBlog.HasOlderPosts)
                {
                    numerberOfPosts += CHUNK_SIZE;
                }
                else
                {
                    //removing this block you will enable the refresh of posts when reached the end of the list and no more posts are available
                    CurrentBlog.hideLoadingIndicator();
                    return(false);
                }
            }
            else
            {
                numerberOfPosts = CHUNK_SIZE;
            }

            GetRecentPostsRPC rpc = new GetRecentPostsRPC(CurrentBlog);

            rpc.NumberOfPosts = numerberOfPosts;
            rpc.Completed    += OnFetchCurrentBlogPostsCompleted;

            CurrentBlog.IsLoadingPosts = true;

            rpc.ExecuteAsync();
            return(true);
        }
        private void OnGetNewBlogCommentsCompleted(object sender, XMLRPCCompletedEventArgs <Comment> args)
        {
            GetAllCommentsRPC rpc = sender as GetAllCommentsRPC;

            rpc.Completed       -= OnGetNewBlogCommentsCompleted;
            rpc.ProgressChanged -= OnGetCommentsRPCProgressChanged;

            Blog newBlog = _trackedBlogs.Where(blog => blog.BlogId == rpc.BlogId).FirstOrDefault();

            if (null == newBlog)
            {
                return;
            }

            //report the error, but keep trying to get data
            if (null != args.Error)
            {
                this.DebugLog("OnFetchNewBlogCommentsCompleted: Exception occurred (" + newBlog.BlogName + ")");
                this.DebugLog(args.Error.ToString());
                NotifyExceptionOccurred(new ExceptionEventArgs(args.Error));
            }
            else
            {
                foreach (Comment comment in args.Items)
                {
                    newBlog.Comments.Add(comment);
                }
                this.DebugLog("Blog '" + newBlog.BlogName + "' has finished downloading comments.");
            }

            this.DebugLog("Blog '" + newBlog.BlogName + "' has finished downloading comments.");

            if (newBlog == CurrentBlog)
            {
                NotifyFetchComplete();
            }

            //get the posts for the new blog
            GetRecentPostsRPC recentPostsRPC = new GetRecentPostsRPC(newBlog);

            recentPostsRPC.NumberOfPosts    = CHUNK_SIZE;
            recentPostsRPC.Completed       += OnGetNewBlogRecentPostsCompleted;
            recentPostsRPC.ProgressChanged += OnGetNewBlogRecentPostsRPCProgressChanged;
            recentPostsRPC.ExecuteAsync();
        }
        private void OnFetchCurrentBlogPostsCompleted(object sender, XMLRPCCompletedEventArgs <PostListItem> args)
        {
            CurrentBlog.hideLoadingIndicator();
            CurrentBlog.IsLoadingPosts = false;

            GetRecentPostsRPC rpc = sender as GetRecentPostsRPC;

            rpc.Completed -= OnFetchCurrentBlogPostsCompleted;

            if (null == args.Error)
            {
                int prevPostsCount = CurrentBlog.PostListItems.Count;
                CurrentBlog.PostListItems.Clear();

                // If we asked for more and we got what we had, there are no more posts to load
                if (rpc.NumberOfPosts > CHUNK_SIZE && (args.Items.Count <= prevPostsCount))
                {
                    CurrentBlog.HasOlderPosts = false;
                }
                else if (rpc.NumberOfPosts == CHUNK_SIZE)
                {
                    //we should reset the flag otherwise when you refresh this blog you can't get more than CHUNK_SIZE posts
                    CurrentBlog.HasOlderPosts = true;
                }

                foreach (PostListItem item in args.Items)
                {
                    CurrentBlog.PostListItems.Add(item);
                }

                CurrentBlog.addLocalPostDraftsToPostList();

                NotifyFetchComplete();
            }
            else
            {
                NotifyExceptionOccurred(new ExceptionEventArgs(args.Error));
            }
        }