Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
        }