public void CreateHhc(TreeNodeCollection nodeCollection, Hhc hhc, Content contentDataSet) { bool opened = false; // Keep track of opening or closing of TOC entries foreach (TreeNode node in nodeCollection) { if (node.Checked == true) { MtpsNode mtpsNode = node.Tag as MtpsNode; DataRow row = contentDataSet.Tables["Item"].Rows.Find(mtpsNode.targetAssetId); string Url; if (Int32.Parse(row["Size"].ToString()) == 0) { Url = null; } else { Url = Path.Combine(chmSubDir, row["ContentId"].ToString() + ".htm"); // Save the first page we see in the TOC as the default page as required // by the chm. if (defaultPage == null) { defaultPage = Url; } } hhc.WriteStartNode(mtpsNode.title, Url); opened = true; } if (node.Nodes.Count != 0 || node.Tag != null) { CreateHhc(node.Nodes, hhc, contentDataSet); } if (opened) { opened = false; hhc.WriteEndNode(); } } }
public void CreateHhc(TreeNodeCollection nodeCollection, Hhc hhc, Content contentDataSet) { bool opened = false; // Keep track of opening or closing of TOC entries foreach (TreeNode node in nodeCollection) { if (node.Checked == true) { MtpsNode mtpsNode = node.Tag as MtpsNode; DataRow row = contentDataSet.Tables["Item"].Rows.Find(mtpsNode.targetAssetId); string Url; //RWC: Now include phantom pages //if (Int32.Parse(row["Size"].ToString()) == 0) // Url = null; //else //{ Url = Path.Combine(chmSubDir, row["ContentId"].ToString() + ".htm"); // Save the first page we see in the TOC as the default page as required // by the chm. if(defaultPage == null) defaultPage = Url; //} hhc.WriteStartNode(mtpsNode.title, Url); opened = true; } if (node.Nodes.Count != 0 || node.Tag != null) { CreateHhc(node.Nodes, hhc, contentDataSet); } if (opened) { opened = false; hhc.WriteEndNode(); } } }
public void Create() { if (Directory.Exists(chmDir) == true) { Directory.Delete(chmDir, true); } Directory.CreateDirectory(chmDir); Directory.CreateDirectory(withinChmDir); foreach (string file in Directory.GetFiles(rawDir)) { File.Copy(file, Path.Combine(withinChmDir, Path.GetFileName(file)), true); } Hhk hhk = new Hhk(Path.Combine(chmDir, baseName + ".hhk"), locale); foreach (DataRow row in contentDataSet.Tables["Item"].Rows) { if (Int32.Parse(row["Size"].ToString()) != 0) { Transform(row["ContentId"].ToString(), row["Metadata"].ToString(), row["Annotations"].ToString(), row["VersionId"].ToString(), contentDataSet); XmlDocument document = new XmlDocument(); document.LoadXml(row["Metadata"].ToString()); XmlNamespaceManager nsManager = new XmlNamespaceManager(document.NameTable); nsManager.AddNamespace("se", "urn:mtpg-com:mtps/2004/1/search"); nsManager.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml"); XmlNodeList xmlNodes = document.SelectNodes("//xhtml:meta[@name='MSHKeywordK']/@content", nsManager); foreach (XmlNode xmlNode in xmlNodes) { hhk.Add(xmlNode.InnerText, Path.Combine(chmSubDir, row["ContentId"].ToString() + ".htm"), row["Title"].ToString()); } } } hhk.Save(); int lcid = new CultureInfo(locale).LCID; // Create TOC Hhc hhc = new Hhc(Path.Combine(chmDir, baseName + ".hhc"), locale); CreateHhc(nodes, hhc, contentDataSet); hhc.Close(); using (FileStream fileStream = new FileStream(Path.Combine(chmDir, baseName + ".hhp"), FileMode.Create, FileAccess.Write, FileShare.None)) { using (StreamWriter streamWriter = new StreamWriter(fileStream)) { streamWriter.Write(template, chmFile, baseName, lcid, defaultPage, title); } } WriteExtraFiles(); int numFiles = Directory.GetFiles(chmDir, "*", SearchOption.AllDirectories).Length; expectedLines = numFiles + 15; }
public void Create() { if (Directory.Exists(chmDir) == true) { Directory.Delete(chmDir, true); } Directory.CreateDirectory(chmDir); Directory.CreateDirectory(withinChmDir); foreach (string file in Directory.GetFiles(rawDir)) { File.Copy(file, Path.Combine(withinChmDir, Path.GetFileName(file)), true); } Hhk hhk = new Hhk(Path.Combine(chmDir, baseName + ".hhk"), locale); foreach (DataRow row in contentDataSet.Tables["Item"].Rows) { //RWC: Now include phantom nodes //if (Int32.Parse(row["Size"].ToString()) != 0) //{ Transform(row["ContentId"].ToString(), row["Metadata"].ToString(), row["Annotations"].ToString(), row["VersionId"].ToString(), row["Title"].ToString(), contentDataSet); XmlDocument document = new XmlDocument(); document.LoadXml(row["Metadata"].ToString()); XmlNamespaceManager nsManager = new XmlNamespaceManager(document.NameTable); nsManager.AddNamespace("se", "urn:mtpg-com:mtps/2004/1/search"); nsManager.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml"); XmlNodeList xmlNodes = document.SelectNodes("//xhtml:meta[@name='MSHKeywordK']/@content", nsManager); foreach (XmlNode xmlNode in xmlNodes) { hhk.Add(xmlNode.InnerText, Path.Combine(chmSubDir, row["ContentId"].ToString() + ".htm"), row["Title"].ToString()); } //} } hhk.Save(); int lcid = new CultureInfo(locale).LCID; // Create TOC Hhc hhc = new Hhc(Path.Combine(chmDir, baseName + ".hhc"), locale); CreateHhc(nodes, hhc, contentDataSet); hhc.Close(); using (FileStream fileStream = new FileStream(Path.Combine(chmDir, baseName + ".hhp"), FileMode.Create, FileAccess.Write, FileShare.None)) { using (StreamWriter streamWriter = new StreamWriter(fileStream)) { streamWriter.Write(template, chmFile, baseName, lcid, defaultPage, title); } } WriteExtraFiles(); int numFiles = Directory.GetFiles(chmDir, "*", SearchOption.AllDirectories).Length; expectedLines = numFiles + 15; }