private void OnGetApiKeyRPCCompleted(object sender, XMLRPCCompletedEventArgs <Blog> args) { //the blog is updated by the rpc. all we have to do here is unbind GetApiKeyRPC rpc = sender as GetApiKeyRPC; rpc.Completed -= OnGetApiKeyRPCCompleted; //check for empty args.Items, self-hosted blogs will return null here Blog newBlog; if (args.Items.Count == 0) { newBlog = rpc.blog; } else { newBlog = args.Items[0]; } _trackedBlogs.Add(newBlog); this.DebugLog("Blog '" + newBlog.BlogName + "' is now downloading data."); //start with the comments GetAllCommentsRPC getCommentsRPC = new GetAllCommentsRPC(newBlog); getCommentsRPC.Number = CHUNK_SIZE; getCommentsRPC.Offset = 0; getCommentsRPC.Completed += OnGetNewBlogCommentsCompleted; getCommentsRPC.ProgressChanged += OnGetCommentsRPCProgressChanged; getCommentsRPC.ExecuteAsync(); }
private void CompletionMethod(List <T> items, Exception exception, bool canceled, AsyncOperation asyncOp) { //package the results of the operation in an XMLRPCCompletedEventArgs object XMLRPCCompletedEventArgs <T> args = new XMLRPCCompletedEventArgs <T>(items, exception, canceled, asyncOp.UserSuppliedState); asyncOp.PostOperationCompleted(onCompletedDelegate, args); }
private void NotifyCompleted(object state) { XMLRPCCompletedEventArgs <T> args = state as XMLRPCCompletedEventArgs <T>; if (null != Completed) { Completed(this, 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 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 NotifyCompleted(object state) { XMLRPCCompletedEventArgs <Comment> args = state as XMLRPCCompletedEventArgs <Comment>; //modify any matches in the datastore so we can save a web call args.Items.ForEach(comment => { Comment match = DataService.Current.CurrentBlog.Comments.Single(c => c.CommentId == comment.CommentId); if (null != match) { DataService.Current.CurrentBlog.Comments.Remove(match); } }); if (null != Completed) { Completed(this, args); } }
private void OnGetCategoriesRPCCompleted(object sender, XMLRPCCompletedEventArgs <Category> args) { GetCategoriesRPC rpc = sender as GetCategoriesRPC; rpc.Completed -= OnGetCategoriesRPCCompleted; if (null == args.Error) { CurrentBlog.Categories.Clear(); args.Items.ForEach(category => { CurrentBlog.Categories.Add(category); }); NotifyFetchComplete(); } else { NotifyExceptionOccurred(new ExceptionEventArgs(args.Error)); } }
private void OnFetchOptionsRPCCompleted(object sender, XMLRPCCompletedEventArgs <Option> args) { GetOptionsRPC rpc = sender as GetOptionsRPC; rpc.Completed -= OnFetchOptionsRPCCompleted; CurrentBlog.hideLoadingIndicator(); if (null == args.Error) { CurrentBlog.Options.Clear(); args.Items.ForEach(option => { CurrentBlog.Options.Add(option); }); NotifyFetchComplete(); //Notify here the end of the synch } else { NotifyExceptionOccurred(new ExceptionEventArgs(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); } } }
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)); } }
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(); } }
//invoke the AsyncOperation.PostOperationCompleted method to signal that the task //has completed. protected void CompletionMethod(List <T> items, Exception exception, bool canceled, AsyncOperation asyncOp) { lock (_syncRoot) { if (_isFinished == true) { return; //Fix for #186 } _isFinished = true; if (!canceled) { if (userStateToLifetime.ContainsKey(asyncOp.UserSuppliedState)) { userStateToLifetime.Remove(asyncOp.UserSuppliedState); } } } //package the results of the operation in an XMLRPCCompletedEventArgs object XMLRPCCompletedEventArgs <T> args = new XMLRPCCompletedEventArgs <T>(items, exception, canceled, asyncOp.UserSuppliedState); asyncOp.PostOperationCompleted(onCompletedDelegate, args); }
private void OnFetchPostFormatsRPCCompleted(object sender, XMLRPCCompletedEventArgs <PostFormat> args) { GetPostFormatsRPC rpc = sender as GetPostFormatsRPC; rpc.Completed -= OnFetchPostFormatsRPCCompleted; if (null == args.Error) { CurrentBlog.PostFormats.Clear(); args.Items.ForEach(postFormat => { CurrentBlog.PostFormats.Add(postFormat); }); // NotifyFetchComplete(); do not notify here } else { NotifyExceptionOccurred(new ExceptionEventArgs(args.Error)); } GetOptionsRPC rpcOption = new GetOptionsRPC(CurrentBlog); rpcOption.Completed += OnFetchOptionsRPCCompleted; rpcOption.ExecuteAsync(); }
private void OnFetchCurrentBlogCommentsCompleted(object sender, XMLRPCCompletedEventArgs <Comment> args) { GetAllCommentsRPC rpc = sender as GetAllCommentsRPC; rpc.Completed -= OnFetchCurrentBlogCommentsCompleted; CurrentBlog.IsLoadingComments = false; if (null == args.Error) { int prevCommentsCount = CurrentBlog.Comments.Count; CurrentBlog.Comments.Clear(); // If we asked for more and we got what we had, there are no more posts to load if (rpc.Number > CHUNK_SIZE && (args.Items.Count <= prevCommentsCount)) { CurrentBlog.HasOlderComments = false; } else if (rpc.Number == CHUNK_SIZE) { //we should reset the flag otherwise when you refresh this blog you can't get more than CHUNK_SIZE comments CurrentBlog.HasOlderComments = true; } foreach (Comment comment in args.Items) { CurrentBlog.Comments.Add(comment); } NotifyFetchComplete(); } else { NotifyExceptionOccurred(new ExceptionEventArgs(args.Error)); } CurrentBlog.hideLoadingIndicator(); }
private void NotifyCompleted(object state) { XMLRPCCompletedEventArgs <Comment> args = state as XMLRPCCompletedEventArgs <Comment>; if (null != Completed) { Completed(this, args); } //modify any matches in the datastore so we can save a web call args.Items.ForEach(comment => { try { Comment match = DataService.Current.CurrentBlog.Comments.Single(c => c.CommentId == comment.CommentId); if (null != match) { match.CommentStatus = comment.CommentStatus; } } catch (System.InvalidOperationException) {} }); }