public static FeedSubscriptionTree GetFeedSubscriptionTreeFromOpmlFile(string filepath) { XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Auto; settings.CloseInput = true; settings.IgnoreComments = true; settings.IgnoreProcessingInstructions = true; settings.IgnoreWhitespace = true; settings.ValidationType = ValidationType.None; XmlDocument xmlDoc; using (TextReader tr = new StreamReader(filepath)) { XmlReader xr = XmlReader.Create(tr, settings); xmlDoc = new XmlDocument(); xmlDoc.Load(xr); } FeedSubscriptionTree fst = new FeedSubscriptionTree(); foreach (XmlNode node in xmlDoc.ChildNodes) { processOpmlNode(fst, node, null); } return fst; }
public static void ExportAsOpml(FeedSubscriptionTree fst, string filepath) { XElement root = new XElement("opml", new XElement("head")); XElement body = new XElement("body"); root.Add(body); addNodesToParentNode(fst.RootLevelNodes, body); root.Save(filepath); }
public FeedSubTreeManager(string lFeedSubsFilePath, FeedsTreeView lFeedsTreeView, ToolStripButton lHideReadFeedsBTN) { feedSubsFilepath = lFeedSubsFilePath; feedsTreeView = lFeedsTreeView; hideReadFeedsBTN = lHideReadFeedsBTN; feedsNormalFont = feedsTreeView.Font; feedsBoldFont = new Font(feedsNormalFont, FontStyle.Bold); if (File.Exists(feedSubsFilepath)) { fst = FeedSubscriptionTree.GetFromFeedSubscriptionsFile(feedSubsFilepath); BindTreeView(); } else { fst = new FeedSubscriptionTree(); } }
internal void ImportOpml(string filepath) { fst = Opml.GetFeedSubscriptionTreeFromOpmlFile(filepath); fst.SaveAsFeedSubscriptionsFile(feedSubsFilepath); BindTreeView(); }
internal void AddNewFolder(TreeNode parentNode) { FeedFolder parentFolder; TreeNode newNode; FeedFolder newFolder = new FeedFolder(); newFolder.Name = "New Folder"; if (fst == null) { //this is most likely a new user with no subscriptions who has chosen to start //with a new folder fst = new FeedSubscriptionTree(); } if (parentNode == null) { newFolder.ParentFolder = null; fst.RootLevelNodes.Add(newFolder); newNode = feedsTreeView.Nodes.Add(newFolder.Name); } else { parentFolder = (FeedFolder)parentNode.Tag; newFolder.ParentFolder = parentFolder; parentFolder.ChildNodes.Add(newFolder); newNode = parentNode.Nodes.Add(newFolder.Name); } newNode.Tag = newFolder; SaveFeedSubTree(); }
private static void processOpmlNode(FeedSubscriptionTree fst, XmlNode node, FeedFolder currentParentFolder) { if (node.Name == null && node.Name.Length < 1) { return; } switch (node.Name.ToLower()) { case "body": case "opml": case "xml": foreach (XmlNode childNode in node.ChildNodes) { processOpmlNode(fst, childNode, currentParentFolder); } break; case "outline": processOpmlOutlineNode(fst, node, currentParentFolder); break; case "head": return; } }
private static void processOpmlOutlineNode(FeedSubscriptionTree fst, XmlNode node, FeedFolder currentParentFolder) { FeedSubTreeNodeBase fstnb = FeedSubTreeNodeBase.GetFromOpmlXmlNode(node); Type nodeType = fstnb.GetType(); if (nodeType == typeof(FeedSubscription)) { FeedSubscription fs = fstnb as FeedSubscription; fs.ParentFolder = currentParentFolder; if (currentParentFolder == null) { //this feed sub is at the root level of the tree fst.RootLevelNodes.Add(fs); } else { currentParentFolder.ChildNodes.Add(fs); } //Debug.WriteLine("Processed Sub Node: " + fs.DisplayName + ":" + currentParentFolder == null ? "root" : currentParentFolder.Name); } else if (nodeType == typeof(FeedFolder)) { FeedFolder ff = fstnb as FeedFolder; ff.ParentFolder = currentParentFolder; if (currentParentFolder == null) { //this feed folder is at the root level of the tree fst.RootLevelNodes.Add(ff); } else { currentParentFolder.ChildNodes.Add(ff); } foreach (XmlNode childNode in node.ChildNodes) { processOpmlNode(fst, childNode, ff); } } else { throw new Exception("FeedSubscriptionTree.processOpmlOutlineNode error: Unrecognized node type: " + nodeType.ToString()); } }