private void OnGetNewBlogPagesProgressChanged(object sender, ProgressChangedEventArgs args) { GetPageListRPC rpc = sender as GetPageListRPC; Blog newBlog = _trackedBlogs.Where(blog => blog.BlogId == rpc.BlogId).FirstOrDefault(); if (null != newBlog) { this.DebugLog("OnGetNewBlogPagesProgressChanged-- Blog: " + newBlog.BlogName); } this.DebugLog("OnGetNewBlogPagesProgressChanged-- Progress: " + args.ProgressPercentage.ToString()); this.DebugLog("OnGetNewBlogPagesProgressChanged-- UserState: " + args.UserState); }
public bool FetchCurrentBlogPagesAsync(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 numerberOfPages = 0; if (more) { numerberOfPages = Math.Max(CurrentBlog.PageListItems.Count, CHUNK_SIZE); if (CurrentBlog.HasOlderPages) { numerberOfPages += CHUNK_SIZE; } else { //removing this block you will enable the refresh of pages when reached the end of the list and no more pages are available CurrentBlog.hideLoadingIndicator(); return(false); } } else { numerberOfPages = CHUNK_SIZE; } CurrentBlog.IsLoadingPages = true; GetPageListRPC rpc = new GetPageListRPC(CurrentBlog); rpc.NumberOfPages = numerberOfPages; rpc.Completed += OnFetchCurrentBlogPagesCompleted; rpc.ExecuteAsync(); return(true); }
private void OnGetNewBlogOptionsCompleted(object sender, XMLRPCCompletedEventArgs <Option> args) { GetOptionsRPC rpc = sender as GetOptionsRPC; rpc.Completed -= OnGetNewBlogOptionsCompleted; 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("OnGetNewBlogOptionsCompleted: Exception occurred (" + newBlog.BlogName + ")"); this.DebugLog(args.Error.ToString()); NotifyExceptionOccurred(new ExceptionEventArgs(args.Error)); } else { newBlog.Options.Clear(); args.Items.ForEach(option => { newBlog.Options.Add(option); }); } this.DebugLog("Blog '" + newBlog.BlogName + "' has finished downloading Options."); if (newBlog == CurrentBlog) { NotifyFetchComplete(); } //get the pages for the new blog GetPageListRPC pageListRPC = new GetPageListRPC(newBlog); pageListRPC.Completed += OnGetNewBlogPagesCompleted; pageListRPC.ProgressChanged += OnGetNewBlogPagesProgressChanged; pageListRPC.ExecuteAsync(); }
private void OnFetchCurrentBlogPagesCompleted(object sender, XMLRPCCompletedEventArgs <PageListItem> args) { CurrentBlog.IsLoadingPages = false; CurrentBlog.hideLoadingIndicator(); GetPageListRPC rpc = sender as GetPageListRPC; rpc.Completed -= OnFetchCurrentBlogPagesCompleted; if (null == args.Error) { int prevPagesCount = CurrentBlog.PageListItems.Count; CurrentBlog.PageListItems.Clear(); // If we asked for more and we got what we had, there are no more posts to load if (rpc.NumberOfPages > CHUNK_SIZE && (args.Items.Count <= prevPagesCount)) { CurrentBlog.HasOlderPages = false; } else if (rpc.NumberOfPages == CHUNK_SIZE) { //we should reset the flag otherwise when you refresh this blog you can't get more than CHUNK_SIZE posts CurrentBlog.HasOlderPages = true; } foreach (PageListItem item in args.Items) { CurrentBlog.PageListItems.Add(item); } CurrentBlog.addLocalPageDraftsToPostList(); NotifyFetchComplete(); } else { NotifyExceptionOccurred(new ExceptionEventArgs(args.Error)); } }
private void OnGetNewBlogPagesCompleted(object sender, XMLRPCCompletedEventArgs <PageListItem> args) { GetPageListRPC rpc = sender as GetPageListRPC; rpc.Completed -= OnGetNewBlogPagesCompleted; rpc.ProgressChanged -= OnGetNewBlogPagesProgressChanged; Blog newBlog = _trackedBlogs.Where(blog => blog.BlogId == rpc.BlogId).FirstOrDefault(); if (null == newBlog) { return; } if (null != args.Error) { this.DebugLog("OnGetNewBlogPagesCompleted: Exception occurred (" + newBlog.BlogName + ")"); this.DebugLog(args.Error.ToString()); NotifyExceptionOccurred(new ExceptionEventArgs(args.Error)); } else { foreach (PageListItem item in args.Items) { newBlog.PageListItems.Add(item); } } _trackedBlogs.Remove(newBlog); newBlog.hideLoadingIndicator(); if (newBlog == CurrentBlog) { NotifyFetchComplete(); } }