Example #1
0
        public override void Execute()
        {
            base.Execute();

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

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

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

            Terminate();
        }
Example #2
0
        private static CopySameCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
        {
            if (commandLineOptions == null)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Option used in invalid context -- {0}", "must specify a option."));
            }

            CopySameCommandLineOptions targetOptions = new CopySameCommandLineOptions();

            if (commandLineOptions.Arguments.Count >= 0)
            {
                foreach (var arg in commandLineOptions.Arguments.Keys)
                {
                    CopySameOptionType optionType = CopySameOptions.GetOptionType(arg);
                    if (optionType == CopySameOptionType.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 CopySameOptionType.Source:
                        targetOptions.IsSetSourceFolder = true;
                        targetOptions.SourceFolder      = commandLineOptions.Arguments[arg];
                        break;

                    case CopySameOptionType.Destination:
                        targetOptions.IsSetDestinationFolder = true;
                        targetOptions.DestinationFolder      = commandLineOptions.Arguments[arg];
                        break;

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

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

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

            return(targetOptions);
        }
Example #3
0
        private static void CheckOptions(CopySameCommandLineOptions checkedOptions)
        {
            if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
            {
                if (!checkedOptions.IsSetSourceFolder || string.IsNullOrEmpty(checkedOptions.SourceFolder))
                {
                    throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                                 "Option used in invalid context -- {0}", "must specify a source folder."));
                }

                if (!checkedOptions.IsSetDestinationFolder || string.IsNullOrEmpty(checkedOptions.DestinationFolder))
                {
                    throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                                 "Option used in invalid context -- {0}", "must specify a destination folder."));
                }
            }
        }
Example #4
0
    public override void Execute()
    {
      base.Execute();

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

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

      Terminate();
    }
Example #5
0
    private static void CheckOptions(CopySameCommandLineOptions checkedOptions)
    {
      if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
      {
        if (!checkedOptions.IsSetSourceFolder || string.IsNullOrEmpty(checkedOptions.SourceFolder))
        {
          throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
            "Option used in invalid context -- {0}", "must specify a source folder."));
        }

        if (!checkedOptions.IsSetDestinationFolder || string.IsNullOrEmpty(checkedOptions.DestinationFolder))
        {
          throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
            "Option used in invalid context -- {0}", "must specify a destination folder."));
        }
      }
    }
Example #6
0
    private static CopySameCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
    {
      if (commandLineOptions == null)
        throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
          "Option used in invalid context -- {0}", "must specify a option."));

      CopySameCommandLineOptions targetOptions = new CopySameCommandLineOptions();

      if (commandLineOptions.Arguments.Count >= 0)
      {
        foreach (var arg in commandLineOptions.Arguments.Keys)
        {
          CopySameOptionType optionType = CopySameOptions.GetOptionType(arg);
          if (optionType == CopySameOptionType.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 CopySameOptionType.Source:
              targetOptions.IsSetSourceFolder = true;
              targetOptions.SourceFolder = commandLineOptions.Arguments[arg];
              break;
            case CopySameOptionType.Destination:
              targetOptions.IsSetDestinationFolder = true;
              targetOptions.DestinationFolder = commandLineOptions.Arguments[arg];
              break;
            case CopySameOptionType.Recursive:
              targetOptions.IsSetRecursive = true;
              break;
            case CopySameOptionType.Help:
              targetOptions.IsSetHelp = true;
              break;
            case CopySameOptionType.Version:
              targetOptions.IsSetVersion = true;
              break;
          }
        }
      }

      return targetOptions;
    }