/// <summary> /// Enqueues a task to rename the specified category in NewsGator Online /// </summary> /// <remarks>This method assumes that the caller will rename categories on INewsFeed instances directly instead /// of having this method do it automatically.</remarks> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="oldName">The old name of the category</param> /// <param name="newName">The new name of the category</param> public void RenameFolderInNewsGatorOnline(string newsgatorUserID, string oldName, string newName) { lock (this.pendingNewsGatorOperations) { //don't bother adding a folder that was later renamed, simply add the final named folder PendingNewsGatorOperation addFolderOp = this.pendingNewsGatorOperations.Find(oldOp => oldOp.Action == NewsGatorOperation.AddFolder && oldName.Equals(oldOp.Parameters[0])); if (addFolderOp == null) { //also check if category was renamed then renamed again PendingNewsGatorOperation renameOp = this.pendingNewsGatorOperations.Find(oldOp => oldOp.Action == NewsGatorOperation.RenameFolder && oldName.Equals(oldOp.Parameters[1])); if (renameOp == null) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.RenameFolder, new object[] { oldName, newName }, newsgatorUserID); this.pendingNewsGatorOperations.Add(op); } else { this.pendingNewsGatorOperations.Remove(renameOp); this.pendingNewsGatorOperations.Add(new PendingNewsGatorOperation(NewsGatorOperation.RenameFolder, new object[] { renameOp.Parameters[0], newName }, newsgatorUserID)); } } else { this.pendingNewsGatorOperations.Remove(addFolderOp); this.pendingNewsGatorOperations.Add(new PendingNewsGatorOperation(NewsGatorOperation.AddFolder, new object[] { newName }, newsgatorUserID)); } } }
/// <summary> /// Deletes the folder in NewsGator Online /// </summary> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="folderId">The ID of the folder to delete</param> public void DeleteFolderFromNewsGatorOnline(string newsgatorUserID, string folderId) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.DeleteFolder, new object[] { folderId }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { this.pendingNewsGatorOperations.Add(op); } }
/// <summary> /// Enqueues a task to move a folder in NewsGator Online /// </summary> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="folderId">The ID of the folder to move</param> /// <param name="parentId">The ID of the new parent folder</param> public void MoveFolderInNewsGatorOnline(string newsgatorUserID, string folderId, string parentId) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.MoveFolder, new object[] { folderId, parentId }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { this.pendingNewsGatorOperations.Add(op); } }
/// <summary> /// Adds the specified feed in NewsGator Online /// </summary> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="feedUrl">The URL of the feed to add</param> /// <param name="cat">The name of the category</param> public void ChangeFolderInNewsGatorOnline(string newsgatorUserID, string feedUrl, string cat) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.MoveFeed, new object[] { feedUrl, cat }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { this.pendingNewsGatorOperations.Add(op); } }
/// <summary> /// Changes the title of a subscribed feed in NewsGator Online /// </summary> /// <remarks>This method does nothing if the new title is empty or null</remarks> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="url">The feed URL</param> /// <param name="title">The new title</param> public void RenameFeedInNewsGatorOnline(string newsgatorUserID, string url, string title) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.RenameFeed, new object[] { url, title }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { this.pendingNewsGatorOperations.Add(op); } }
/// <summary> /// Enqueus a task that adds the specified feed in NewsGator Online /// </summary> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="feedUrl">The URL of the feed to add</param> public void AddFeedInNewsGatorOnline(string newsgatorUserID, string feedUrl) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.AddFeed, new object[] { feedUrl }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { this.pendingNewsGatorOperations.Add(op); } }
/// <summary> /// Enqueues a task that adds the folder in NewsGator Online /// </summary> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="name">The name of the folder to add</param> public void AddFolderInNewsGatorOnline(string newsgatorUserID, string name) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.AddFolder, new object[] { name }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { this.pendingNewsGatorOperations.Add(op); } }
/// <summary> /// Marks an item as flagged or unflagged in NewsGator Online /// </summary> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="itemId">The NewsGator ID of the news item</param> /// <param name="feedUrl">The URL of the feed the item belongs to</param> /// <param name="state">Indicates the flag status of the item</param> public void ChangeItemStateInNewsGatorOnline(string newsgatorUserID, string itemId, string feedUrl, NewsGatorFlagStatus state) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.MarkSingleItemFlagged, new object[] { itemId, feedUrl, state }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { this.pendingNewsGatorOperations.Add(op); } }
/// <summary> /// Enqueues a task to clip or unclip a post in NewsGator Online /// </summary> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="itemId">The ID of the news item to clip or unclip</param> /// <param name="clipped">Indicates whether the item is being clipped or unclipped</param> public void ChangeItemClippedStateInNewsGatorOnline(string newsgatorUserID, string itemId, bool clipped) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.MarkSingleItemClipped, new object[] { itemId, clipped }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { this.pendingNewsGatorOperations.Add(op); } }
/// <summary> /// Enqueues a task to mark all items as read in NewsGatorOnline /// </summary> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="feedUrl">The feed URL</param> /// <param name="syncToken">The synchronization token that identifies which items should be marked as read</param> public void MarkAllItemsAsReadInNewsGatorOnline(string newsgatorUserID, string feedUrl, string syncToken) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.MarkAllItemsRead, new object[] { feedUrl, syncToken }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { this.pendingNewsGatorOperations.Add(op); } }
/// <summary> /// Enqueues a task to marks an item as read, unread or deleted in NewsGator Online /// </summary> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="itemId">The NewsGator ID of the news item</param> /// <param name="state">Indicates whether the item was marked as read, unread or deleted</param> public void ChangeItemStateInNewsGatorOnline(string newsgatorUserID, string itemId, NewsGatorItemState state) { PendingNewsGatorOperation op = new PendingNewsGatorOperation(NewsGatorOperation.MarkSingleItemReadOrDeleted, new object[] { itemId, state }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { this.pendingNewsGatorOperations.Add(op); } }
/// <summary> /// Enqueues a task that deletes a feed from the list of user's subscriptions in NewsGator Online /// </summary> /// <param name="newsgatorUserID">The NewsGator User ID of the account under which this operation will be performed.</param> /// <param name="feedUrl">The URL of the feed to delete. </param> public void DeleteFeedFromNewsGatorOnline(string newsgatorUserID, string feedUrl) { PendingNewsGatorOperation deleteOp = new PendingNewsGatorOperation(NewsGatorOperation.DeleteFeed, new object[] { feedUrl }, newsgatorUserID); lock (this.pendingNewsGatorOperations) { //remove all pending operations related to the feed since it is going to be unsubscribed IEnumerable <PendingNewsGatorOperation> ops2remove = pendingNewsGatorOperations.Where(op => op.NewsGatorUserName.Equals(deleteOp.NewsGatorUserName) && op.Parameters.Contains(feedUrl)); var ops2remove_array = ops2remove.ToArray(); //prevent collection modified Exceptions foreach (PendingNewsGatorOperation op2remove in ops2remove_array) { pendingNewsGatorOperations.Remove(op2remove); } pendingNewsGatorOperations.Add(deleteOp); } }
/// <summary> /// Performs a set of pending network operations from the pendingGoogleReaderOperations queue on the /// Google Reader service. /// </summary> /// <param name="batchedItemsAmount">The number of operations that should be performed.</param> private void FlushPendingOperations(int batchedItemsAmount) { try { this.flushInprogress = true; do { PendingNewsGatorOperation pendingOp = null; //perform all queued operations on the index lock (this.pendingNewsGatorOperations) { if (this.pendingNewsGatorOperations.Count > 0) { pendingOp = this.pendingNewsGatorOperations[0]; } } //lock //Optimizing the index is an expensive operation so we don't want to //call it if the queue is being flushed since it may delay application exit. if (pendingOp != null) { this.PerformOperation(pendingOp); this.pendingNewsGatorOperations.RemoveAt(0); } batchedItemsAmount--; //potential race condition on this.pendingIndexOperations.Count but chances are very low } while (this.pendingNewsGatorOperations.Count > 0 && batchedItemsAmount >= 0); } finally { this.flushInprogress = false; } }
/// <summary> /// Performs the specified PendingNewsGatorOperation. /// </summary> /// <param name="current">The operation to perform</param> private void PerformOperation(PendingNewsGatorOperation current) { NewsGatorFeedSource source; this.FeedSources.TryGetValue(current.NewsGatorUserName, out source); if (source == null) { return; } try { switch (current.Action) { case NewsGatorOperation.AddFeed: source.AddFeedInNewsGatorOnline(current.Parameters[0] as string); break; case NewsGatorOperation.AddFolder: source.AddFolderInNewsGatorOnline(current.Parameters[0] as string); break; case NewsGatorOperation.DeleteFeed: source.DeleteFeedFromNewsGatorOnline(current.Parameters[0] as string); break; case NewsGatorOperation.DeleteFolder: source.DeleteFolderFromNewsGatorOnline(current.Parameters[0] as string); break; case NewsGatorOperation.MarkSingleItemFlagged: source.ChangeItemStateInNewsGatorOnline(current.Parameters[0] as string, current.Parameters[1] as string, (NewsGatorFlagStatus)current.Parameters[2]); break; case NewsGatorOperation.MarkSingleItemClipped: source.ChangeItemClippedStateInNewsGatorOnline(current.Parameters[0] as string, (bool)current.Parameters[1]); break; case NewsGatorOperation.MarkSingleItemReadOrDeleted: source.ChangeItemStateInNewsGatorOnline(current.Parameters[0] as string, (NewsGatorItemState)current.Parameters[1]); break; case NewsGatorOperation.MarkAllItemsRead: source.MarkAllItemsAsReadInNewsGatorOnline(current.Parameters[0] as string, current.Parameters[1] as string); break; case NewsGatorOperation.MoveFeed: source.ChangeFolderInNewsGatorOnline(current.Parameters[0] as string, current.Parameters[1] as string); break; case NewsGatorOperation.MoveFolder: source.MoveFolderInNewsGatorOnline(current.Parameters[0] as string, current.Parameters[1] as string); break; case NewsGatorOperation.RenameFeed: source.RenameFeedInNewsGatorOnline(current.Parameters[0] as string, current.Parameters[1] as string); break; case NewsGatorOperation.RenameFolder: source.RenameFolderInNewsGatorOnline(current.Parameters[0] as string, current.Parameters[1] as string); break; default: Debug.Assert(false, "Unknown NewsGator Online operation: " + current.Action); return; } } catch (Exception e) { //TODO: Rethrow to handle time outs and connections cancelled by host _log.Error("Error in NewsGatorModifier.PerformOperation:", e); }; }