예제 #1
0
        private void CreateHhc(TreeNodeCollection nodeCollection, Hhc hhc, Content contentDataSet)
        {
            var opened = false; // Keep track of opening or closing of TOC entries

            foreach (TreeNode node in nodeCollection)
            {
                Debug.Assert(node != null, "node is null");

                if (node.Checked)
                {
                    var mtpsNode = node.Tag as MtpsNode;

                    Debug.Assert(mtpsNode != null, "mtpsNode != null");

                    var row = contentDataSet.Tables[TableNames.ITEM].Rows.Find(mtpsNode.TargetAssetId);


                    var url = Path.Combine(CHM_SUB_DIR, row[ColumnNames.CONTENTID] + ApplicationStrings.FILE_EXTENSION_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();
                }
            }
        }
예제 #2
0
        private void CreateHhc(TreeNodeCollection nodeCollection, Hhc hhc, Content contentDataSet)
        {
            var opened = false; // Keep track of opening or closing of TOC entries

            foreach (TreeNode node in nodeCollection)
            {
                Debug.Assert(node != null, "node is null");

                if (node.Checked)
                {
                    var mtpsNode = node.Tag as MtpsNode;

                    Debug.Assert(mtpsNode != null, "mtpsNode != null");

                    var row = contentDataSet.Tables[TableNames.ITEM].Rows.Find(mtpsNode.TargetAssetId);

                    var url = Path.Combine(CHM_SUB_DIR, row[ColumnNames.CONTENTID] + ApplicationStrings.FILE_EXTENSION_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();
                }
            }
        }
예제 #3
0
        public void Create()
        {
            CreateOutputDirectoryStructure(_chmDir, _withinChmDir);

            foreach (var fileName in Directory.GetFiles(_rawDir))
            {
                File.Copy(fileName, Path.Combine(_withinChmDir, Path.GetFileName(fileName)), true);
            }

            var hhk = new Hhk(Path.Combine(_chmDir, _baseName + ".hhk"), _locale);

            foreach (DataRow row in _contentDataSet.Tables[TableNames.ITEM].Rows)
            {
                Transform(row[ColumnNames.CONTENTID].ToString(),
                          row["Metadata"].ToString(),
                          row["Annotations"].ToString(),
                          row["VersionId"].ToString(),
                          row["Title"].ToString(),
                          _contentDataSet);

                var document = new XmlDocument();
                document.LoadXml(row["Metadata"].ToString());

                var nsManager = new XmlNamespaceManager(document.NameTable);
                nsManager.AddNamespace("se", "urn:mtpg-com:mtps/2004/1/search");
                nsManager.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");

                var xmlNodes = document.SelectNodes("//xhtml:meta[@name='MSHKeywordK']/@content", nsManager);

                if (xmlNodes != null)
                {
                    foreach (XmlNode xmlNode in xmlNodes)
                    {
                        hhk.Add(xmlNode.InnerText,
                                Path.Combine(CHM_SUB_DIR, row[ColumnNames.CONTENTID].ToString() + ApplicationStrings.FILE_EXTENSION_HTM),
                                row["Title"].ToString());
                    }
                }
            }

            hhk.Save();


            // Create TOC
            using (var hhc = new Hhc(Path.Combine(_chmDir, _baseName + ".hhc"), _locale))
            {
                CreateHhc(_nodes, hhc, _contentDataSet);
            }

            var lcid = new CultureInfo(_locale).LCID;

            using (var fileStream = new FileStream(Path.Combine(_chmDir, _baseName + ".hhp"), FileMode.Create, FileAccess.Write, FileShare.None))
                using (var streamWriter = new StreamWriter(fileStream))
                {
                    streamWriter.Write(_template, _chmFile, _baseName, lcid, _defaultPage, _title);
                }


            WriteExtraFiles();

            var numFiles = Directory.GetFiles(_chmDir, "*", SearchOption.AllDirectories).Length;

            ExpectedLines = numFiles + 15;
        }
예제 #4
0
        public void Create()
        {
            CreateOutputDirectoryStructure(_chmDir, _withinChmDir);

            foreach (var fileName in Directory.GetFiles(_rawDir))
            {
                File.Copy(fileName, Path.Combine(_withinChmDir, Path.GetFileName(fileName)), true);
            }

            var hhk = new Hhk(Path.Combine(_chmDir, _baseName + ".hhk"), _locale);

            foreach (DataRow row in _contentDataSet.Tables[TableNames.ITEM].Rows)
            {
                Transform(row[ColumnNames.CONTENTID].ToString(),
                    row["Metadata"].ToString(),
                    row["Annotations"].ToString(),
                    row["VersionId"].ToString(),
                    row["Title"].ToString(),
                    _contentDataSet);

                var document = new XmlDocument();
                document.LoadXml(row["Metadata"].ToString());

                var nsManager = new XmlNamespaceManager(document.NameTable);
                nsManager.AddNamespace("se", "urn:mtpg-com:mtps/2004/1/search");
                nsManager.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");

                var xmlNodes = document.SelectNodes("//xhtml:meta[@name='MSHKeywordK']/@content", nsManager);

                if (xmlNodes != null)
                    foreach (XmlNode xmlNode in xmlNodes)
                    {
                        hhk.Add(xmlNode.InnerText,
                                Path.Combine(CHM_SUB_DIR, row[ColumnNames.CONTENTID].ToString() + ApplicationStrings.FILE_EXTENSION_HTM),
                                row["Title"].ToString());
                    }
            }

            hhk.Save();

            // Create TOC
            using (var hhc = new Hhc(Path.Combine(_chmDir, _baseName + ".hhc"), _locale))
            {
                CreateHhc(_nodes, hhc, _contentDataSet);
            }

            var lcid = new CultureInfo(_locale).LCID;

            using (var fileStream = new FileStream(Path.Combine(_chmDir, _baseName + ".hhp"), FileMode.Create, FileAccess.Write, FileShare.None))
            using (var streamWriter = new StreamWriter(fileStream))
            {
                streamWriter.Write(_template, _chmFile, _baseName, lcid, _defaultPage, _title);
            }

            WriteExtraFiles();

            var numFiles = Directory.GetFiles(_chmDir, "*", SearchOption.AllDirectories).Length;

            ExpectedLines = numFiles + 15;
        }