public void Load() { DateTime loadstart = DateTime.Now; List <RssFeed> newRssFeeds = new List <RssFeed>(); try { IFeedsManager fs = new FeedsManager(); IFeedFolder folder = (IFeedFolder)fs.GetFolder(Properties.Settings.Default.ImagePathOverride); foreach (IFeed feed in CommonFeedListUtils.CommonFeedList(folder)) { System.Diagnostics.Debug.Print("Found feed {0} with {1} items.", feed.Name, ((IFeedsEnum)feed.Items).Count); try { RssFeed rssFeed = RssFeed.FromApi(feed); // Only add this feed if it contains items if (rssFeed != null) { System.Diagnostics.Debug.Print("Feed has {0} items with enclosures.", rssFeed.Items.Count); if (rssFeed.Items.Count > 0) { newRssFeeds.Add(rssFeed); } } else { System.Diagnostics.Debug.Print("Feed is null."); } } catch (System.Runtime.InteropServices.COMException ex) { System.Diagnostics.Debug.Print("Failed to get RSS feed '{0}' from API; skipping feed. Error: {1} ", feed.Name, ex.ToString()); // Ignore exception, meaning ignore this feed and continue with next feed. } } } finally { // Collect garbage so that all the COM objects are released which // closes the backing structured storage files. GC.Collect(); } if (newRssFeeds.Count == 0) { // There were no suitable feeds, hence get default feeds from resources. System.Diagnostics.Debug.Print("There were no suitable feeds, hence get default feeds from resources."); RssFeed rssFeed = RssFeed.FromText(Properties.Resources.DefaultRSSText); newRssFeeds.Add(rssFeed); } this.rssFeeds = newRssFeeds; // reset current indexes currentFeedIndex = -1; currentItemIndex = -1; MoveNext(); lastRefresh = loadstart; }
} // RenameItem protected override void RemoveItem(string path, bool recurse) { path = NormalizePath(path); if (FeedsManager.ExistsFolder(path)) { IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder; if (ShouldProcess(path, "delete")) { folder.Delete(); } return; } if (FeedsManager.ExistsFeed(path)) { IFeed feed = FeedsManager.GetFeed(path) as IFeed; if (ShouldProcess(path, "delete")) { feed.Delete(); } return; } WriteError(new ErrorRecord (new ItemNotFoundException("Item not found."), "InvalidArgument", ErrorCategory.InvalidArgument, path) ); }
public static IEnumerable<IFeed> LastWriteSince(IFeedFolder folder, System.DateTime lastWriteTime) { foreach (IFeed feed in CommonFeedList(folder)) { if (feed.LastWriteTime.ToLocalTime() > lastWriteTime) yield return feed; } }
} // GetChildItems protected override string GetChildName(string path) { path = NormalizePath(path); WriteDebug("Getting name for " + path); // Checks if the path represented is a drive if (PathIsDrive(path)) { return(""); }// if (PathIsDrive... if (FeedsManager.ExistsFolder(path)) { IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder; return(folder.Name); } if (FeedsManager.ExistsFeed(path)) { IFeed feed = FeedsManager.GetFeed(path) as IFeed; return(feed.Name); } WriteDebug("Couldn't find drive, folder or feed - checking for item."); string[] chunks = ChunkPath(path); if (chunks.Length > 0) { WriteDebug("Chunks:"); foreach (string chk in chunks) { WriteDebug("chunk: " + chk); } int id; if (int.TryParse(chunks[chunks.Length - 1], out id)) { path = GetParentPath(path, ""); WriteDebug("Looking for feed " + path); if (FeedsManager.ExistsFeed(path)) { WriteDebug("Found feed - looking for item"); IFeed feed = FeedsManager.GetFeed(path) as IFeed; IFeedItem feedItem = feed.GetItem(id) as IFeedItem; if (feedItem != null) { WriteDebug("Found item - returning " + feedItem.LocalId); return(feedItem.LocalId.ToString()); } } } } return(base.GetChildName(path)); }
public static IEnumerable <IFeed> LastWriteSince(IFeedFolder folder, System.DateTime lastWriteTime) { foreach (IFeed feed in CommonFeedList(folder)) { if (feed.LastWriteTime.ToLocalTime() > lastWriteTime) { yield return(feed); } } }
public MainViewModel() { this.m_currentItemProperty = new NotifyProperty <FeedViewModel>(this, nameof(CurrentItem)); IFeedsManager feedsManager = new FeedsManager(); IFeedFolder root = ((IFeedFolder)feedsManager.GetFolder("")); FeedFolderViewModel rootWrapper = new FeedFolderViewModel(root); this.RootItems = rootWrapper.Subitems; }
public static IEnumerable<IFeed> CommonFeedList (IFeedFolder folder) { Queue<IFeedFolder> queue = new Queue<IFeedFolder>(); queue.Enqueue(folder); while (queue.Count > 0) { IFeedFolder currentFolder = queue.Dequeue(); foreach (IFeedFolder subfolder in (IFeedsEnum)currentFolder.Subfolders) queue.Enqueue(subfolder); foreach (IFeed feed in (IFeedsEnum)currentFolder.Feeds) { yield return feed; } } }
} // GetChildNames protected override void GetItem(string path) { path = NormalizePath(path); // Checks if the path represented is a drive if (PathIsDrive(path)) { WriteItemObject(FeedsManager.RootFolder, PSDriveInfo.Name + ':', true); return; }// if (PathIsDrive... if (FeedsManager.ExistsFolder(path)) { IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder; WriteItemObject(folder, folder.Path, true); return; } if (FeedsManager.ExistsFeed(path)) { IFeed feed = FeedsManager.GetFeed(path) as IFeed; WriteItemObject(feed, feed.Path, true); return; } string[] chunks = ChunkPath(path); if (chunks.Length > 0) { int id; if (int.TryParse(chunks[chunks.Length - 1], out id)) { path = GetParentPath(path, ""); if (FeedsManager.ExistsFeed(path)) { IFeed feed = FeedsManager.GetFeed(path) as IFeed; IFeedItem feedItem = feed.GetItem(id) as IFeedItem; if (feedItem != null) { WriteItemObject(feedItem, feed.Path + _pathSeparator + feedItem.LocalId, false); return; } } } } base.GetItem(path); } // GetItem
protected override bool HasChildItems(string path) { path = NormalizePath(path); if (PathIsDrive(path)) { IFeedFolder root = FeedsManager.RootFolder as IFeedFolder; IFeedsEnum subFolders = root.Subfolders as IFeedsEnum; if (subFolders.Count > 0) { return(true); } IFeedsEnum feeds = root.Feeds as IFeedsEnum; if (feeds.Count > 0) { return(true); } } else { if (FeedsManager.ExistsFolder(path)) { IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder; IFeedsEnum subFolders = folder.Subfolders as IFeedsEnum; if (subFolders.Count > 0) { return(true); } IFeedsEnum feeds = folder.Feeds as IFeedsEnum; if (feeds.Count > 0) { return(true); } } if (FeedsManager.ExistsFeed(path)) { IFeed feed = FeedsManager.GetFeed(path) as IFeed; return(feed.ItemCount > 0); } } return(false); }
protected override void RenameItem(string path, string newName) { if (newName.Contains(_pathSeparator)) { WriteError(new ErrorRecord (new ArgumentException("Cannot rename because the target specified is not a path."), "InvalidArgument", ErrorCategory.InvalidArgument, newName) ); return; } path = NormalizePath(path); if (FeedsManager.ExistsFolder(path)) { IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder; if (ShouldProcess(folder.Path, "rename")) { WriteDebug("Renaming folder " + folder.Path); folder.Rename(newName); WriteItemObject(folder, folder.Path, true); } return; } if (FeedsManager.ExistsFeed(path)) { IFeed feed = FeedsManager.GetFeed(path) as IFeed; if (Force && ShouldProcess(feed.Path, "rename")) { WriteDebug("Renaming feed " + feed.Path); feed.Rename(newName); WriteItemObject(feed, feed.Path, true); } return; } WriteError(new ErrorRecord (new NotImplementedException("Cannot rename because item specified."), "NotImplemented", ErrorCategory.NotImplemented, path) ); } // RenameItem
protected override void MoveItem(string path, string destination) { path = NormalizePath(path); destination = NormalizePath(destination); if (!FeedsManager.ExistsFolder(destination)) { WriteError(new ErrorRecord (new ArgumentException("Target feed folder not found."), "InvalidArgument", ErrorCategory.InvalidArgument, destination) ); return; } if (FeedsManager.ExistsFolder(path)) { IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder; if (ShouldProcess(folder.Path, "move")) { folder.Move(destination); WriteItemObject(folder, folder.Path, true); } return; } if (FeedsManager.ExistsFeed(path)) { IFeed feed = FeedsManager.GetFeed(path) as IFeed; if (ShouldProcess(feed.Path, "move")) { feed.Move(destination); WriteItemObject(feed, feed.Path, true); } return; } WriteError(new ErrorRecord (new ArgumentException("Item not found."), "InvalidArgument", ErrorCategory.InvalidArgument, path) ); return; }
public static IEnumerable <IFeed> CommonFeedList(IFeedFolder folder) { Queue <IFeedFolder> queue = new Queue <IFeedFolder>(); queue.Enqueue(folder); while (queue.Count > 0) { IFeedFolder currentFolder = queue.Dequeue(); foreach (IFeedFolder subfolder in (IFeedsEnum)currentFolder.Subfolders) { queue.Enqueue(subfolder); } foreach (IFeed feed in (IFeedsEnum)currentFolder.Feeds) { System.Windows.Forms.Application.DoEvents(); yield return(feed); } } }
public void Refresh() { if (lastRefresh == DateTime.MinValue) { // we never successfully loaded the CFL, so let's do it again Load(); return; } IFeedsManager fs = new FeedsManager(); try { IFeedFolder folder = (IFeedFolder)fs.GetFolder(Properties.Settings.Default.ImagePathOverride); foreach (IFeed feed in CommonFeedListUtils.LastWriteSince(folder, lastRefresh)) { RssFeed rssFeed = null; try { // This feed was updated or is new, let's get it. rssFeed = RssFeed.FromApi(feed); } catch (System.Runtime.InteropServices.COMException ex) { System.Diagnostics.Debug.Print("Failed to get RSS feed '{0}' from API; skipping feed. Error: {1} ", feed.Name, ex.ToString()); continue; // Skip this feed. } // If the feed has no items with picture enclosures then skip it. if (rssFeed == null || rssFeed.Items.Count == 0) { System.Diagnostics.Debug.Print("Feed '{0}' does not have any picture enclosures; skipping feed.", feed.Name); continue; } // Before we add it let's see if we have an old version of the feed. int index = rssFeeds.FindIndex(delegate(RssFeed f) { return(f.Path == rssFeed.Path); }); if (index == -1) { // This must be a new feed, let's append it to the list. rssFeeds.Add(rssFeed); } else { // We have an existing feed with the same path. Let's insert it // where the previous feed is at. rssFeeds.Insert(index, rssFeed); // Remove previous feed. rssFeeds.RemoveAt(index + 1); // Assure that current indexes are not out of bounds. ValidateIndexes(); } } } finally { GC.Collect(); // Release all COM objects and their file handles. lastRefresh = DateTime.Now; } }
protected override void GetChildNames(string path, ReturnContainers returnContainers) { path = NormalizePath(path); WriteDebug("Listing names in " + path); bool unreadOnly = false; RuntimeDefinedParameterDictionary dic = DynamicParameters as RuntimeDefinedParameterDictionary; if (dic != null && dic.ContainsKey("Unread")) { RuntimeDefinedParameter rdp = dic["Unread"]; unreadOnly = rdp.IsSet; } WriteDebug(unreadOnly ? "Unread items only" : "All items"); // Checks if the path represented is a drive. This means that the // children of the path are folders and feeds if (PathIsDrive(path)) { WriteDebug("Listing root folder folder names"); IFeedFolder folder = FeedsManager.RootFolder as IFeedFolder; IFeedsEnum subFolders = folder.Subfolders as IFeedsEnum; foreach (IFeedFolder subFolder in subFolders) { if (!unreadOnly || subFolder.TotalUnreadItemCount > 0) { WriteItemObject(subFolder.Name, subFolder.Path, true); } } WriteDebug("Listing root folder feed names"); IFeedsEnum feeds = folder.Feeds as IFeedsEnum; foreach (IFeed feed in feeds) { if (!unreadOnly || feed.UnreadItemCount > 0) { WriteItemObject(feed.Name, feed.Path, true); } } return; } if (FeedsManager.ExistsFolder(path)) { WriteDebug("Listing folder names in " + path); IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder; IFeedsEnum subFolders = folder.Subfolders as IFeedsEnum; foreach (IFeedFolder subFolder in subFolders) { if (!unreadOnly || subFolder.TotalUnreadItemCount > 0) { WriteItemObject(subFolder.Name, subFolder.Path, true); } } WriteDebug("Listing feed names in " + path); IFeedsEnum feeds = folder.Feeds as IFeedsEnum; foreach (IFeed feed in feeds) { if (!unreadOnly || feed.UnreadItemCount > 0) { WriteItemObject(feed.Name, feed.Path, true); } } return; } if (FeedsManager.ExistsFeed(path)) { WriteDebug("Listing names in " + path); IFeed feed = FeedsManager.GetFeed(path) as IFeed; IFeedsEnum feedItems = feed.Items as IFeedsEnum; foreach (IFeedItem feedItem in feedItems) { if (!unreadOnly || !feedItem.IsRead) { WriteItemObject(feedItem.LocalId.ToString(), feed.Path + _pathSeparator + feedItem.LocalId, false); } } return; } } // GetChildNames
protected override void NewItem(string path, string itemTypeName, object newItemValue) { path = NormalizePath(path); if (PathIsDrive(path)) { throw new ArgumentException("Path must be a a folder or feed."); } if (itemTypeName.ToLower().StartsWith("f")) { if (itemTypeName.Length == 1) { WriteError(new ErrorRecord(new ArgumentException("Ambiguous type. Only \"folder\" or \"feed\" can be specified."), "InvalidArgument", ErrorCategory.InvalidArgument, itemTypeName)); } // The leaf of the path will contain the name of the item to create string[] pathChunks = ChunkPath(path); string parentPath = GetParentPath(path, ""); // create a new folder. Let's check that we're in a folder and not a feed if (!FeedsManager.ExistsFolder(parentPath)) { WriteError(new ErrorRecord(new ArgumentException("Items can only be created within folders."), "InvalidArgument", ErrorCategory.InvalidArgument, path)); return; } IFeedFolder folder = FeedsManager.GetFolder(parentPath) as IFeedFolder; string newItemName = pathChunks[pathChunks.Length - 1]; //if (String.Compare("folder", 0, itemTypeName, 0, itemTypeName.Length, true) == 0) if (itemTypeName.Equals("folder", StringComparison.OrdinalIgnoreCase) || itemTypeName.Equals("directory", StringComparison.OrdinalIgnoreCase)) { IFeedFolder newFolder = folder.CreateSubfolder(newItemName) as IFeedFolder; WriteItemObject(newFolder, newFolder.Path, true); return; } if (String.Compare("feed", 0, itemTypeName, 0, itemTypeName.Length, true) == 0) { if (newItemValue == null || !Uri.IsWellFormedUriString(newItemValue.ToString(), UriKind.Absolute)) { WriteError(new ErrorRecord (new ArgumentException("Value must be a valid feed URI."), "InvalidArgument", ErrorCategory.InvalidArgument, newItemValue) ); return; } IFeed newFeed = folder.CreateFeed(newItemName, newItemValue.ToString()) as IFeed; WriteItemObject(newFeed, newFeed.Path, true); return; } } WriteError(new ErrorRecord(new ArgumentException("The type is not a known type for the feed store. Only \"folder\" or \"feed\" can be specified."), "InvalidArgument", ErrorCategory.InvalidArgument, itemTypeName)); return; }
public FeedFolderViewModel(IFeedFolder folder) { m_folder = folder; }