示例#1
0
        static void Main(string[] args)
        {
            //args check
            //==============================================================
            if (args.Length < 2)
            {
                Console.WriteLine("TextConv [-p PATTERN] [-r REPLACEMENT] [-d srcfolder] [-f srcfile]");
                Console.WriteLine("TextConv [-c COMMAND_KEY] [-x XPATH] [-d srcfolder] [-f srcfile]");
                return;
            }
            string cmd = getValue("-c", args);

            string srcfolder = getValue("-d", args);

            if (string.IsNullOrEmpty(srcfolder))
            {
                srcfolder = Config.GetAppSettingValue("srcfolder");
            }
            resultFolder = UtilWxg.GetMatchGroup(srcfolder, @"(\w+)\\*$", 1);

            string srcFile = getValue("-f", args);

            if (string.IsNullOrEmpty(srcfolder) && string.IsNullOrEmpty(srcFile))
            {
                Console.WriteLine("App.config setting srcfolder is required.");
                return;
            }

            //==============================================================
            if (args.Contains("-x"))
            {
                List <XPathRuleItem> rules = new List <XPathRuleItem>();
                string ruleFolderPath      = Config.GetAppSettingValue("xpath.rule.yml");
                LoadYmlRules(rules, ruleFolderPath, cmd);
                HtmlParseFolder(srcfolder, rules);
                HtmlParseFile(srcFile, rules);
            }

            //==============================================================
            if (args.Contains("-c") || args.Contains("-p"))
            {
                List <ReplaceRule> repRules       = new List <ReplaceRule>();
                string             ruleFolderPath = Config.GetAppSettingValue("replace.rule.yml");
                LoadYmlRules(repRules, ruleFolderPath, cmd);

                ReplaceRuleItem ri = new ReplaceRuleItem();
                ri.pattern     = getValue("-p", args);
                ri.replacement = getValue("-r", args);
                if (!string.IsNullOrEmpty(ri.pattern))
                {
                    string content = getValue("-input", args);
                    if (!string.IsNullOrEmpty(content))
                    {
                        Console.WriteLine(ri.replaceText(content));
                    }
                    else
                    {
                        ReplaceRule rule = new ReplaceRule();
                        rule.rules.Add(ri);
                        repRules.Add(rule);
                    }
                }
                ReplaceFolder(srcfolder, repRules);
                ReplaceFile(srcfolder, repRules);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            //args check
            //==============================================================
            if (args.Length < 2)
            {
                Console.WriteLine("TextConv [-p PATTERN] [-r REPLACEMENT] [-d srcfolder] [-f srcfile]");
                Console.WriteLine("TextConv [-c COMMAND_KEY] [-x XPATH] [-d srcfolder] [-f srcfile]");
                return;
            }
            string cmd = StringUtils.GetArgValue("-c", args);

            string srcfolder = string.Empty;

            if (args.Contains("-d"))
            {
                srcfolder = StringUtils.GetArgValue("-d", args);
                if (string.IsNullOrEmpty(srcfolder))
                {
                    srcfolder = Config.GetAppSettingValue("srcfolder");
                }
                resultFolder = StringUtils.GetMatchGroup(srcfolder, @"(\w+)\\*$", 1);
            }
            string srcFile = string.Empty;

            if (args.Contains("-f"))
            {
                srcFile = StringUtils.GetArgValue("-f", args);
            }
            if (string.IsNullOrEmpty(srcfolder) && string.IsNullOrEmpty(srcFile))
            {
                Console.WriteLine("App.config setting srcfolder is required.");
                return;
            }
            //==============================================================
            if (args.Contains("-web"))
            {
                WebRunner wr = new WebRunner();
                if (!string.IsNullOrEmpty(srcFile))
                {
                    wr.Run(srcFile);
                }
                else if (!string.IsNullOrEmpty(srcfolder))
                {
                    wr.RunBatch(srcfolder);
                }
            }
            //==============================================================
            if (args.Contains("-x"))
            {
                List <XPathRuleItem> rules = new List <XPathRuleItem>();
                string ruleFolderPath      = Config.GetAppSettingValue("xpath.rule.yml");
                YmlLoader.Load(rules, ruleFolderPath, cmd);
                HtmlParseFolder(srcfolder, rules);
                HtmlParseFile(srcFile, rules);
            }

            //==============================================================
            if (args.Contains("-c"))
            {
                List <ReplaceRule> repRules       = new List <ReplaceRule>();
                string             ruleFolderPath = Config.GetAppSettingValue("replace.rule.yml");
                YmlLoader.Load(repRules, ruleFolderPath, cmd);

                if (args.Contains("-p"))
                {
                    ReplaceRuleItem ri = new ReplaceRuleItem();
                    ri.pattern     = StringUtils.GetArgValue("-p", args);
                    ri.replacement = StringUtils.GetArgValue("-r", args);
                    if (!string.IsNullOrEmpty(ri.pattern))
                    {
                        string content = StringUtils.GetArgValue("-input", args);
                        if (!string.IsNullOrEmpty(content))
                        {
                            Console.WriteLine(ri.replaceText(content));
                        }
                        else
                        {
                            ReplaceRule rule = new ReplaceRule();
                            rule.rules.Add(ri);
                            //コマンドより-p -r 指定する場合、コマンド優先とする
                            repRules.Clear();
                            repRules.Add(rule);
                        }
                    }
                }

                ReplaceFolder(srcfolder, repRules);
                ReplaceFile(srcFile, repRules);
            }
            //==============================================================
            if (args.Contains("-rename"))
            {
                if (args.Contains("-p") && args.Contains("-r"))
                {
                    ReplaceRuleItem ri = new ReplaceRuleItem();
                    ri.pattern     = StringUtils.GetArgValue("-p", args);
                    ri.replacement = StringUtils.GetArgValue("-r", args);
                    ri.Rename(srcfolder);
                }
            }
        }