/// <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> /// 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; } } }