Exemplo n.º 1
0
        public override void Execute()
        {
            base.Execute();

            List <string>      singleOptionList = ExtractOptions.GetSingleOptions();
            CommandLineOptions cloptions        = CommandLineParser.Parse(Arguments.ToArray <string>(), singleOptionList.ToArray());

            options = ParseOptions(cloptions);
            CheckOptions(options);

            if (options.IsSetHelp)
            {
                RaiseCommandLineUsage(this, ExtractOptions.Usage);
            }
            else if (options.IsSetVersion)
            {
                RaiseCommandLineUsage(this, Version);
            }
            else
            {
                StartExtract();
            }

            Terminate();
        }
Exemplo n.º 2
0
 private static void CheckOptions(ExtractCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
     {
         if (string.IsNullOrEmpty(checkedOptions.RegexPattern))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a regex pattern."));
         }
         if (!checkedOptions.RegexPattern.Contains("(") ||
             !checkedOptions.RegexPattern.Contains(")"))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "regex pattern must contain a pair of '()'."));
         }
         if (string.IsNullOrEmpty(checkedOptions.InputDirectory))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a input directory."));
         }
         if (!Directory.Exists(checkedOptions.InputDirectory))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "no such input directory."));
         }
         if (string.IsNullOrEmpty(checkedOptions.OutputDirectory))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a output directory."));
         }
         if (!Directory.Exists(checkedOptions.OutputDirectory))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "no such output directory."));
         }
         if (!checkedOptions.OutputFileExtension.StartsWith(".", StringComparison.CurrentCulture))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "output file extension must start with '.'."));
         }
         foreach (var filter in checkedOptions.InputFileExtensionFilter)
         {
             if (!filter.StartsWith(".", StringComparison.CurrentCulture))
             {
                 throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                              "Option used in invalid context -- {0}", "input file extension filter item must start with '.'."));
             }
         }
     }
 }
Exemplo n.º 3
0
        public override void Execute()
        {
            base.Execute();

              List<string> singleOptionList = ExtractOptions.GetSingleOptions();
              CommandLineOptions cloptions = CommandLineParser.Parse(Arguments.ToArray<string>(), singleOptionList.ToArray());
              options = ParseOptions(cloptions);
              CheckOptions(options);

              if (options.IsSetHelp)
              {
            RaiseCommandLineUsage(this, ExtractOptions.Usage);
              }
              else if (options.IsSetVersion)
              {
            RaiseCommandLineUsage(this, Version);
              }
              else
              {
            StartExtract();
              }

              Terminate();
        }
Exemplo n.º 4
0
        private static ExtractCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
        {
            if (commandLineOptions == null)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Option used in invalid context -- {0}", "must specify a option."));
            }

            ExtractCommandLineOptions targetOptions = new ExtractCommandLineOptions();

            if (commandLineOptions.Arguments.Count >= 0)
            {
                foreach (var arg in commandLineOptions.Arguments.Keys)
                {
                    ExtractOptionType optionType = ExtractOptions.GetOptionType(arg);
                    if (optionType == ExtractOptionType.None)
                    {
                        throw new CommandLineException(
                                  string.Format(CultureInfo.CurrentCulture, "Option used in invalid context -- {0}",
                                                string.Format(CultureInfo.CurrentCulture, "cannot parse the command line argument : [{0}].", arg)));
                    }

                    switch (optionType)
                    {
                    case ExtractOptionType.RegexPattern:
                        targetOptions.RegexPattern = commandLineOptions.Arguments[arg];
                        break;

                    case ExtractOptionType.InputDirectory:
                        targetOptions.InputDirectory = commandLineOptions.Arguments[arg];
                        break;

                    case ExtractOptionType.Recursive:
                        targetOptions.IsSetRecursive = true;
                        break;

                    case ExtractOptionType.InputFileExtensionFilter:
                        targetOptions.InputFileExtensionFilter.AddRange(
                            commandLineOptions.Arguments[arg].Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList());
                        break;

                    case ExtractOptionType.OutputDirectory:
                        targetOptions.OutputDirectory = commandLineOptions.Arguments[arg];
                        break;

                    case ExtractOptionType.OutputFileExtension:
                        targetOptions.OutputFileExtension = commandLineOptions.Arguments[arg].Trim();
                        break;

                    case ExtractOptionType.Exclude:
                        targetOptions.Excludes.AddRange(
                            commandLineOptions.Arguments[arg].Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList());
                        break;

                    case ExtractOptionType.Help:
                        targetOptions.IsSetHelp = true;
                        break;

                    case ExtractOptionType.Version:
                        targetOptions.IsSetVersion = true;
                        break;
                    }
                }
            }

            return(targetOptions);
        }
Exemplo n.º 5
0
 private static void CheckOptions(ExtractCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
       {
     if (string.IsNullOrEmpty(checkedOptions.RegexPattern))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "must specify a regex pattern."));
     }
     if (!checkedOptions.RegexPattern.Contains("(")
       || !checkedOptions.RegexPattern.Contains(")"))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "regex pattern must contain a pair of '()'."));
     }
     if (string.IsNullOrEmpty(checkedOptions.InputDirectory))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "must specify a input directory."));
     }
     if (!Directory.Exists(checkedOptions.InputDirectory))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "no such input directory."));
     }
     if (string.IsNullOrEmpty(checkedOptions.OutputDirectory))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "must specify a output directory."));
     }
     if (!Directory.Exists(checkedOptions.OutputDirectory))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "no such output directory."));
     }
     if (!checkedOptions.OutputFileExtension.StartsWith(".", StringComparison.CurrentCulture))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "output file extension must start with '.'."));
     }
     foreach (var filter in checkedOptions.InputFileExtensionFilter)
     {
       if (!filter.StartsWith(".", StringComparison.CurrentCulture))
       {
     throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
       "Option used in invalid context -- {0}", "input file extension filter item must start with '.'."));
       }
     }
       }
 }
Exemplo n.º 6
0
        private static ExtractCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
        {
            if (commandLineOptions == null)
            throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
              "Option used in invalid context -- {0}", "must specify a option."));

              ExtractCommandLineOptions targetOptions = new ExtractCommandLineOptions();

              if (commandLineOptions.Arguments.Count >= 0)
              {
            foreach (var arg in commandLineOptions.Arguments.Keys)
            {
              ExtractOptionType optionType = ExtractOptions.GetOptionType(arg);
              if (optionType == ExtractOptionType.None)
            throw new CommandLineException(
              string.Format(CultureInfo.CurrentCulture, "Option used in invalid context -- {0}",
              string.Format(CultureInfo.CurrentCulture, "cannot parse the command line argument : [{0}].", arg)));

              switch (optionType)
              {
            case ExtractOptionType.RegexPattern:
              targetOptions.RegexPattern = commandLineOptions.Arguments[arg];
              break;
            case ExtractOptionType.InputDirectory:
              targetOptions.InputDirectory = commandLineOptions.Arguments[arg];
              break;
            case ExtractOptionType.Recursive:
              targetOptions.IsSetRecursive = true;
              break;
            case ExtractOptionType.InputFileExtensionFilter:
              targetOptions.InputFileExtensionFilter.AddRange(
                commandLineOptions.Arguments[arg].Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList());
              break;
            case ExtractOptionType.OutputDirectory:
              targetOptions.OutputDirectory = commandLineOptions.Arguments[arg];
              break;
            case ExtractOptionType.OutputFileExtension:
              targetOptions.OutputFileExtension = commandLineOptions.Arguments[arg].Trim();
              break;
            case ExtractOptionType.Exclude:
              targetOptions.Excludes.AddRange(
                commandLineOptions.Arguments[arg].Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList());
              break;
            case ExtractOptionType.Help:
              targetOptions.IsSetHelp = true;
              break;
            case ExtractOptionType.Version:
              targetOptions.IsSetVersion = true;
              break;
              }
            }
              }

              return targetOptions;
        }