/// <summary> /// Moves the current FeedNode from one folder to another. /// </summary> /// <param name="fnDest">Destination folder that this FeedNode will be moved to.</param> /// <returns></returns> public bool MoveTo(FeedNode fnDest, System.Windows.Forms.TreeView tvFeeds) { Debug.WriteLine(String.Format("MoveTo() {0} -> {1}", this.ToString(), fnDest.ToString())); if (fnDest.IsFolder == false) { return(false); // Can't move into anything else than a folder. } if (m_parent == fnDest) { return(false); // The FeedNode can't be moved into the same folder it already is in. } TreeNode tnOld = (TreeNode)Tag; tnOld.Remove(); // remove the treenode from the old folder m_parent.DeleteChildNode(this); // remove the feednode from this folder m_parent = fnDest; // parent this node to the destination feednode fnDest.AddChildNode(this); // add this node to the destination feednode TreeNode tnDest = (TreeNode)fnDest.Tag; // the destination folder's treenode tnDest.Nodes.Clear(); fnDest.PopulateTreeNodes(tnDest, tvFeeds); return(true); }
public Job(FeedNode fn) { if (fn != null) { m_root = fn.Duplicate(null); } }
/// <summary> /// Recursive method to duplicate (deep copy) the current node and its children. /// </summary> /// <param name="fnParent">The FeedNode to which the new node will be parented under.</param> /// <returns>The new FeedNode which contains the same information as the current node (this).</returns> public FeedNode Duplicate(FeedNode fnParent) { FeedNode fnNew = new FeedNode(Title, XmlUrl, fnParent, IsFolder); fnNew.m_strText = m_strText; fnNew.m_strHtmlUrl = m_strHtmlUrl; fnNew.m_strDescription = m_strDescription; fnNew.m_strPath = m_strPath; if (fnParent != null) { fnParent.AddChildNode(fnNew); } if (m_bFolder) { IDictionaryEnumerator enumNodes = m_listChildren.GetEnumerator(); while (enumNodes.MoveNext()) { FeedNode feedNode = (FeedNode)enumNodes.Key; if (feedNode != null) { feedNode.Duplicate(fnNew); } } } return(fnNew); }
/// <summary> /// Go through all the child nodes (leaf nodes and folder nodes), starting from the current node, and see if /// the provided FeedUrl already exists in any of the child nodes. /// </summary> /// <param name="strFeedUrl"></param> /// <returns></returns> public bool AlreadyExistsFeed(string strFeedUrl) { IDictionaryEnumerator enumNodes = m_listChildren.GetEnumerator(); while (enumNodes.MoveNext()) { FeedNode feedNode = (FeedNode)enumNodes.Key; if (feedNode != null) { if (feedNode.IsFolder) { if (feedNode.AlreadyExistsFeed(strFeedUrl)) { return(true); } } else { if (strFeedUrl.Equals(feedNode.m_strXmlUrl)) { return(true); } } } } return(false); }
private SortedList m_listChildren; // list of children of the current node public FeedNode(string strTitle, string strXmlUrl, FeedNode parent, bool bFolder) { m_strTitle = strTitle; m_strText = strTitle; m_parent = parent; m_bFolder = bFolder; if (!bFolder) { m_strXmlUrl = strXmlUrl; } else { m_listChildren = new SortedList(new FeedNodeComparer()); m_strXmlUrl = String.Empty; } if (parent != null) { m_strPath = parent.Path; if (!parent.Path.Equals("\\")) { m_strPath += "\\"; } m_strPath += m_strTitle; } else { m_strPath = "\\"; } }
/// <summary> /// Populates the tree nodes of the current FeedNode. /// Recursive method to generate the TreeView tree structure /// in accordance to the FeedNode tree structure. /// </summary> /// <param name="crtTreeNode">TreeNode with which this FeedNode is to be associated with.</param> public void PopulateTreeNodes(TreeNode crtTreeNode, System.Windows.Forms.TreeView tvFeeds) { if ((m_parent == null) && (crtTreeNode == null)) { // root node? TreeNode treeNode = tvFeeds.Nodes.Add(m_strTitle); treeNode.Tag = this; this.Tag = treeNode; crtTreeNode = treeNode; } IDictionaryEnumerator enumNodes = this.Enumerator; while (enumNodes.MoveNext()) { FeedNode feedNode = (FeedNode)enumNodes.Key; if (feedNode != null) { TreeNode treeNode = crtTreeNode.Nodes.Add(feedNode.Title); treeNode.Tag = feedNode; feedNode.Tag = treeNode; if (feedNode.IsFolder) { treeNode.ImageIndex = 0; treeNode.SelectedImageIndex = 0; feedNode.PopulateTreeNodes(treeNode, tvFeeds); } else { treeNode.ImageIndex = 1; treeNode.SelectedImageIndex = 1; } } } }
public PropertiesForm(FeedNode feedNode) { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // m_feedNode = feedNode; }
/// <summary> /// Deletes all child nodes of the current node. /// </summary> public void Clear() { FeedNode[] keys = new FeedNode[m_listChildren.Keys.Count]; m_listChildren.Keys.CopyTo(keys, 0); foreach (FeedNode key in keys) { if (key.IsFolder) { key.Clear(); } m_listChildren.Remove(key); } }
public static void QueueJob(FeedNode hierarchy) { Debug.WriteLine("--> QueueJob()"); if (Instance == null) { return; } if (!s_bEnding) { s_jobs.Enqueue(new Job(hierarchy)); s_event.Set(); // Wake the thread up, if it's sleeping. } Debug.WriteLine("<-- QueueJob()"); }
/// <summary> /// Recursively dumps the current node and its children into an OPML file. /// </summary> /// <param name="writer"></param> public void DumpAsOpml(XmlWriter writer) { // Start the element if (m_bFolder) { if (m_parent == null) { // root node writer.WriteStartElement("feeds"); } else { writer.WriteStartElement("group"); writer.WriteAttributeString("title", m_strTitle); } // Write the children IDictionaryEnumerator enumNodes = m_listChildren.GetEnumerator(); while (enumNodes.MoveNext()) { FeedNode feedNode = (FeedNode)enumNodes.Key; if (feedNode != null) { feedNode.DumpAsOpml(writer); } } } else { writer.WriteStartElement("outline"); writer.WriteAttributeString("text", m_strText); writer.WriteAttributeString("title", m_strTitle); writer.WriteAttributeString("type", "rss"); writer.WriteAttributeString("version", "RSS"); writer.WriteAttributeString("xmlUrl", m_strXmlUrl); writer.WriteAttributeString("htmlUrl", m_strHtmlUrl); writer.WriteAttributeString("description", m_strDescription); } // End the element writer.WriteEndElement(); }
/// <summary> /// Tests whether there is already a folder with the same name in the current folder. /// </summary> /// <param name="strFolderName"></param> /// <returns></returns> public bool AlreadyContainsFolder(string strFolderName) { if (!IsFolder) { return(false); } IDictionaryEnumerator enumNodes = m_listChildren.GetEnumerator(); while (enumNodes.MoveNext()) { FeedNode feedNode = (FeedNode)enumNodes.Key; if ((feedNode != null) && (feedNode.IsFolder)) { if (String.Compare(feedNode.Title, strFolderName, true, CultureInfo.InvariantCulture) == 0) { return(true); } } } return(false); }
public int Compare(object x, object y) { FeedNode f1 = x as FeedNode; FeedNode f2 = y as FeedNode; if ((f1 == null) || (f2 == null)) { return(0); } bool b1 = f1.IsFolder; bool b2 = f2.IsFolder; if (b1 && !b2) { return(-1); } else if (!b1 && b2) { return(1); } return(String.Compare(f1.Title, f2.Title, true)); }
/// <summary> /// Removes a FeedNode from the child nodes of the current node. /// </summary> /// <param name="node"></param> public void DeleteChildNode(FeedNode node) { // TODO: Make sure this Remove is okay as far as uniqueness goes. m_listChildren.Remove(node); }
//----------------------- public UpdateChannelThread(FeedReaderForm form, FeedNode feedNode) { m_form = form; m_feedNode = feedNode; m_feedFormat = FeedFormat.Rss; }
public ReadChannelThread(FeedReaderForm form, FeedNode feedNode) { m_feedNode = feedNode; m_form = form; }
/// <summary> /// The thread procedure. /// </summary> private void Run() { while (true) { s_event.WaitOne(); // Sleeping... Debug.WriteLine("WriteFeedsThread has been woken..."); int iJobs = s_jobs.Count; if (iJobs > 0) { Debug.WriteLine("...found " + iJobs.ToString() + " job(s) waiting to be executed!"); s_bBusy = true; Job job = (Job)s_jobs.Dequeue(); FeedNode root = job.Root; try { Utils.DeleteFile("feeds.xml.bak"); FileInfo fi = new FileInfo("feeds.xml"); fi.MoveTo("feeds.xml.bak"); } catch (FileNotFoundException fnfex) { Utils.DbgOutExc("WriteFeedsThread::Run()", fnfex); } catch (Exception ex) { Utils.DbgOutExc("WriteFeedsThread::Run()", ex); MessageBox.Show("Error while saving feeds:\n\n" + ex.Message, "FeedReader", MessageBoxButtons.OK, MessageBoxIcon.Error); } XmlTextWriter writer = null; try { writer = new XmlTextWriter("feeds.xml", Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.IndentChar = ' '; writer.Indentation = 4; root.DumpAsOpml(writer); } catch (Exception ex) { Utils.DbgOutExc("WriteFeedsThread::Run()", ex); MessageBox.Show("Error while saving feeds:\n\n" + ex.Message, "FeedReader", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (writer != null) { writer.Close(); } } s_bBusy = false; } s_event.Reset(); Debug.WriteLine("...Job done!"); if (s_bEnding) { // Did you wake me up to terminate? Debug.WriteLine("Ending the WriteFeeds thread..."); break; } } }
/// <summary> /// Adds a child FeedNode to the current node. /// </summary> /// <param name="node"></param> public void AddChildNode(FeedNode node) { node.m_parent = this; DumpChildren(); m_listChildren.Add(node, node.Title); }
/// <summary> /// Parses feeds.xml and constructs the tree of FeedNode's. /// </summary> public override void Run() { XmlTextReader reader = null; try { FeedNode nodeCurrent = m_form.RootFeedNode; nodeCurrent.Clear(); string strXmlUrl = String.Empty; string strFeedName = String.Empty; string strGroupName = String.Empty; string strElementName = String.Empty; reader = new XmlTextReader("feeds.xml"); reader.WhitespaceHandling = WhitespaceHandling.None; while (reader.Read()) { XmlNodeType type = reader.NodeType; if (type == XmlNodeType.Element) { strElementName = reader.Name; if (strElementName == "group" && reader.HasAttributes) { strGroupName = reader.GetAttribute("title"); FeedNode node = new FeedNode(strGroupName, null, nodeCurrent, true); nodeCurrent.AddChildNode(node); if (!reader.IsEmptyElement) { nodeCurrent = node; } } else if (strElementName == "outline" && reader.HasAttributes) { strFeedName = reader.GetAttribute("title"); strXmlUrl = reader.GetAttribute("xmlUrl"); FeedNode node = new FeedNode(strFeedName, strXmlUrl, nodeCurrent, false); node.Text = reader.GetAttribute("text"); node.HtmlUrl = reader.GetAttribute("htmlUrl"); node.Description = reader.GetAttribute("description"); nodeCurrent.AddChildNode(node); } } else if (type == XmlNodeType.EndElement) { strElementName = reader.Name; if (strElementName == "group") { nodeCurrent = nodeCurrent.Parent; } } } } catch (Exception ex) { Utils.DbgOutExc("ParseFeedsThread::Run()", ex); } finally { if (reader != null) { reader.Close(); } m_form.Invoke(new OnEndCallback(OnEnd)); } }