示例#1
0
        public static int Main(string[] args)
        {
            ConsoleApplication.WriteBanner();

            OptionCollection options = new OptionCollection();

            options.Add(new SwitchOption("?", "Show this help page."));
            options.Add(new StringOption("html", "Specify a html directory.", "htmlDirectory"));
            options.Add(new StringOption("project", "Specify a project name.", "projectName"));
            options.Add(new StringOption("toc", "Specify a toc file.", "tocFile"));
            options.Add(new StringOption("lcid", "Specify a language id.If unspecified, 1033 is used.", "languageId"));
            options.Add(new StringOption("out", "Specify an output directory. If unspecified, Chm is used.", "outputDirectory"));
            options.Add(new BooleanOption("metadata", "Specify whether output metadata or not. Default value is false."));
            options.Add(new StringOption("config", "Specify a configuration file. If unspecified, ChmBuilder.config is used", "configFilePath"));

            ParseArgumentsResult results = options.ParseArguments(args);

            if (results.Options["?"].IsPresent)
            {
                Console.WriteLine("ChmBuilder /html: /project: /toc: /out: /metadata:");
                options.WriteOptionSummary(Console.Out);
                return(0);
            }

            ChmBuilderArgs cbArgs = new ChmBuilderArgs();

            // check for invalid options
            if (!results.Success)
            {
                results.WriteParseErrors(Console.Out);
                return(1);
            }

            // check for missing or extra assembly directories
            if (results.UnusedArguments.Count != 0)
            {
                Console.WriteLine("No non-option arguments are supported.");
                return(1);
            }

            if (!results.Options["html"].IsPresent)
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, "You must specify a html directory.");
                return(1);
            }
            cbArgs.htmlDirectory = (string)results.Options["html"].Value;
            if (!Directory.Exists(cbArgs.htmlDirectory))
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("Direcotry: {0} not found.", cbArgs.htmlDirectory));
                return(1);
            }

            if (!results.Options["project"].IsPresent)
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, "You must specify a project name.");
                return(1);
            }
            cbArgs.projectName = (string)results.Options["project"].Value;

            if (results.Options["lcid"].IsPresent)
            {
                try
                {
                    cbArgs.langid = Convert.ToInt32(results.Options["lcid"].Value);
                }
                catch
                {
                    ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("{0} is not a valid integer.", results.Options["lcid"].Value));
                    return(1);
                }
            }


            if (results.Options["toc"].IsPresent)
            {
                cbArgs.tocFile = (string)results.Options["toc"].Value;
                if (!File.Exists(cbArgs.tocFile))
                {
                    ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("File: {0} not found.", cbArgs.tocFile));
                    return(1);
                }
            }

            if (!results.Options["out"].IsPresent)
            {
                cbArgs.outputDirectory = "Chm";
            }
            else
            {
                cbArgs.outputDirectory = (string)results.Options["out"].Value;
            }
            if (!Directory.Exists(cbArgs.outputDirectory))
            {
                Directory.CreateDirectory(cbArgs.outputDirectory);
                //ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("Direcotry: {0} not found.", cbArgs.outputDirectory));
                //return (1);
            }

            if (results.Options["metadata"].IsPresent && (bool)results.Options["metadata"].Value)
            {
                cbArgs.metadata = true;
            }

            if (results.Options["config"].IsPresent)
            {
                cbArgs.configFile = (string)results.Options["config"].Value;
            }
            if (!File.Exists(cbArgs.configFile))
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("Config file: {0} not found.", cbArgs.configFile));
                return(1);
            }

            try
            {
                ChmBuilder chmBuilder = new ChmBuilder(cbArgs);
                chmBuilder.Run();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(1);
            }
            return(0);
        }
示例#2
0
        public static int Main(string[] args)
        {
            ConsoleApplication.WriteBanner();

            OptionCollection options = new OptionCollection();
            options.Add(new SwitchOption("?", "Show this help page."));
            options.Add(new StringOption("html", "Specify a html directory.", "htmlDirectory"));
            options.Add(new StringOption("project", "Specify a project name.", "projectName"));
            options.Add(new StringOption("toc", "Specify a toc file.", "tocFile"));
            options.Add(new StringOption("lcid", "Specify a language id.If unspecified, 1033 is used.", "languageId"));
            options.Add(new StringOption("out", "Specify an output directory. If unspecified, Chm is used.", "outputDirectory"));
            options.Add(new BooleanOption("metadata", "Specify whether output metadata or not. Default value is false."));
            options.Add(new StringOption("config", "Specify a configuration file. If unspecified, ChmBuilder.config is used", "configFilePath"));

            ParseArgumentsResult results = options.ParseArguments(args);
            if (results.Options["?"].IsPresent)
            {
                Console.WriteLine("ChmBuilder /html: /project: /toc: /out: /metadata:");
                options.WriteOptionSummary(Console.Out);
                return (0);
            }

            ChmBuilderArgs cbArgs = new ChmBuilderArgs();

            // check for invalid options
            if (!results.Success)
            {
                results.WriteParseErrors(Console.Out);
                return (1);
            }

            // check for missing or extra assembly directories
            if (results.UnusedArguments.Count != 0)
            {
                Console.WriteLine("No non-option arguments are supported.");
                return (1);
            }

            if (!results.Options["html"].IsPresent)
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, "You must specify a html directory.");
                return (1);
            }
            cbArgs.htmlDirectory = (string)results.Options["html"].Value;
            if (!Directory.Exists(cbArgs.htmlDirectory))
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("Direcotry: {0} not found.", cbArgs.htmlDirectory));
                return (1);
            }

            if (!results.Options["project"].IsPresent)
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, "You must specify a project name.");
                return (1);
            }
            cbArgs.projectName = (string)results.Options["project"].Value;

            if (results.Options["lcid"].IsPresent)
            {
                try
                {
                    cbArgs.langid = Convert.ToInt32(results.Options["lcid"].Value);
                }
                catch
                {
                    ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("{0} is not a valid integer.", results.Options["lcid"].Value));
                    return (1);
                }
            }


            if (results.Options["toc"].IsPresent)
            {
                cbArgs.tocFile = (string)results.Options["toc"].Value;
                if (!File.Exists(cbArgs.tocFile))
                {
                    ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("File: {0} not found.", cbArgs.tocFile));
                    return (1);
                }
            }

            if (!results.Options["out"].IsPresent)
                cbArgs.outputDirectory = "Chm";
            else
                cbArgs.outputDirectory = (string)results.Options["out"].Value;
            if (!Directory.Exists(cbArgs.outputDirectory))
            {
                Directory.CreateDirectory(cbArgs.outputDirectory);
                //ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("Direcotry: {0} not found.", cbArgs.outputDirectory));
                //return (1);
            }

            if (results.Options["metadata"].IsPresent && (bool)results.Options["metadata"].Value)
            {
                cbArgs.metadata = true;
            }

            if (results.Options["config"].IsPresent)
            {
                cbArgs.configFile = (string)results.Options["config"].Value;
            }
            if (!File.Exists(cbArgs.configFile))
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("Config file: {0} not found.", cbArgs.configFile));
                return (1);
            }

            try
            {
                ChmBuilder chmBuilder = new ChmBuilder(cbArgs);
                chmBuilder.Run();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return (1);
            }
            return 0;
        }
示例#3
0
        /// <summary>
        /// As XmlReader is forward only and we added support for leaving xmlisland data.
        /// We have to use another xmlreader to find TocTile, keywords etc.
        /// </summary>
        /// <param name="filename"></param>
        private void ReadXmlIsland(string filename)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.IgnoreWhitespace = false;
            settings.IgnoreComments   = true;
            XmlReader reader = XmlReader.Create(filename, settings);

            //Fix TFS bug 289403: search if there is comma in k keyword except those in () or <>.
            //sample1: "StoredNumber (T1,T2) class, about StoredNumber (T1,T2) class";
            //sample2: "StoredNumber <T1,T2> class, about StoredNumber <T1,T2> class";
            Regex r = new Regex(@",([^\)\>]+|([^\<\>]*\<[^\<\>]*\>[^\<\>]*)?|([^\(\)]*\([^\(\)]*\)[^\(\)]*)?)$");

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    if (reader.Name.ToLower() == "mshelp:toctitle")
                    {
                        string titleAttr = reader.GetAttribute("Title");
                        if (!String.IsNullOrEmpty(titleAttr))
                        {
                            _currentTitle = titleAttr;
                        }
                    }

                    if (reader.Name.ToLower() == "mshelp:keyword")
                    {
                        string indexType = reader.GetAttribute("Index");
                        if (indexType == "K")
                        {
                            KKeywordInfo kkwdinfo = new KKeywordInfo();
                            string       kkeyword = reader.GetAttribute("Term");
                            if (!string.IsNullOrEmpty(kkeyword))
                            {
                                kkeyword = ChmBuilder.ReplaceMarks(kkeyword);
                                Match match = r.Match(kkeyword);
                                if (match.Success)
                                {
                                    kkwdinfo.MainEntry = kkeyword.Substring(0, match.Index);
                                    kkwdinfo.SubEntry  = kkeyword.Substring(match.Index + 1).TrimStart(new char[] { ' ' });
                                }
                                else
                                {
                                    kkwdinfo.MainEntry = kkeyword;
                                }

                                kkwdinfo.File = _currentFile;
                                _kkeywords.Add(kkwdinfo);
                            }
                        }
                    }
                }

                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.Name == "xml")
                    {
                        return;
                    }
                }
            }
        }
示例#4
0
        public static int Main(string[] args)
        {
            ConsoleApplication.WriteBanner();

            OptionCollection options = new OptionCollection();

            options.Add(new SwitchOption("?", "Show this help page."));
            options.Add(new StringOption("html", "Specify an HTML directory.", "htmlDirectory")
                { RequiredMessage = "You must specify an HTML directory" });
            options.Add(new StringOption("project", "Specify a project name.", "projectName")
                { RequiredMessage = "You must specify a project name" });
            options.Add(new StringOption("toc", "Specify a TOC file.", "tocFile"));
            options.Add(new StringOption("lcid", "Specify a language id.  If unspecified, 1033 (en-US) is used.",
                "languageId"));
            options.Add(new StringOption("out", "Specify an output directory. If unspecified, Chm is used.",
                "outputDirectory"));
            options.Add(new BooleanOption("metadata", "Specify whether to output metadata or not. Default " +
                "value is false."));
            options.Add(new StringOption("config", "Specify a configuration file. If unspecified, " +
                "ChmBuilder.config is used.", "configFilePath"));

            ParseArgumentsResult results = options.ParseArguments(args);

            if(results.Options["?"].IsPresent)
            {
                Console.WriteLine("ChmBuilder /html: /project: /toc: /out: /metadata:");
                options.WriteOptionSummary(Console.Out);
                return 0;
            }

            // Check for invalid options
            if(!results.Success)
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, "Unable to parse command line options.");
                results.WriteParseErrors(Console.Out);
                return 1;
            }

            // Check for unused arguments
            if(results.UnusedArguments.Count != 0)
            {
                Console.WriteLine("No non-option arguments are supported.");
                return 1;
            }

            ChmBuilderArgs cbArgs = new ChmBuilderArgs();

            cbArgs.HtmlDirectory = (string)results.Options["html"].Value;

            if(!Directory.Exists(cbArgs.HtmlDirectory))
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, String.Format(CultureInfo.CurrentCulture,
                    "Direcotry: {0} not found.", cbArgs.HtmlDirectory));
                return 1;
            }

            cbArgs.ProjectName = (string)results.Options["project"].Value;

            if(results.Options["lcid"].IsPresent)
            {
                try
                {
                    cbArgs.LanguageId = Convert.ToInt32(results.Options["lcid"].Value, CultureInfo.CurrentCulture);
                }
                catch
                {
                    ConsoleApplication.WriteMessage(LogLevel.Error, String.Format(CultureInfo.CurrentCulture,
                        "{0} is not a valid integer.", results.Options["lcid"].Value));
                    return 1;
                }
            }

            if(results.Options["toc"].IsPresent)
            {
                cbArgs.TocFile = (string)results.Options["toc"].Value;

                if(!File.Exists(cbArgs.TocFile))
                {
                    ConsoleApplication.WriteMessage(LogLevel.Error, String.Format(CultureInfo.CurrentCulture,
                        "File: {0} not found.", cbArgs.TocFile));
                    return 1;
                }
            }

            if(!results.Options["out"].IsPresent)
                cbArgs.OutputDirectory = "Chm";
            else
                cbArgs.OutputDirectory = (string)results.Options["out"].Value;

            if(!Directory.Exists(cbArgs.OutputDirectory))
                Directory.CreateDirectory(cbArgs.OutputDirectory);

            if(results.Options["metadata"].IsPresent && (bool)results.Options["metadata"].Value)
            {
                cbArgs.OutputMetadata = true;
            }

            if(results.Options["config"].IsPresent)
            {
                cbArgs.ConfigurationFile = (string)results.Options["config"].Value;
            }

            if(!File.Exists(cbArgs.ConfigurationFile))
            {
                ConsoleApplication.WriteMessage(LogLevel.Error, String.Format(CultureInfo.CurrentCulture,
                    "Config file: {0} not found.", cbArgs.ConfigurationFile));
                return 1;
            }

            try
            {
                ChmBuilder chmBuilder = new ChmBuilder(cbArgs);
                chmBuilder.Run();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return (1);
            }
            return 0;
        }