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

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

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

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

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

            SyncCopyCommandLineOptions targetOptions = new SyncCopyCommandLineOptions();

            if (commandLineOptions.Arguments.Count >= 0)
            {
                foreach (var arg in commandLineOptions.Arguments.Keys)
                {
                    SyncCopyOptionType optionType = SyncCopyOptions.GetOptionType(arg);
                    if (optionType == SyncCopyOptionType.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 SyncCopyOptionType.FromDirectory:
                        targetOptions.FromDirectory = commandLineOptions.Arguments[arg];
                        break;

                    case SyncCopyOptionType.ToDirectory:
                        targetOptions.ToDirectory = commandLineOptions.Arguments[arg];
                        break;

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

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

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

            return(targetOptions);
        }
Example #3
0
 private static void CheckOptions(SyncCopyCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
     {
         if (string.IsNullOrEmpty(checkedOptions.FromDirectory))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a source directory."));
         }
         if (string.IsNullOrEmpty(checkedOptions.ToDirectory))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a target directory."));
         }
     }
 }
Example #4
0
        public override void Execute()
        {
            base.Execute();

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

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

              Terminate();
        }
Example #5
0
 private static void CheckOptions(SyncCopyCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
       {
     if (string.IsNullOrEmpty(checkedOptions.FromDirectory))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "must specify a source directory."));
     }
     if (string.IsNullOrEmpty(checkedOptions.ToDirectory))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "must specify a target directory."));
     }
       }
 }
Example #6
0
        private static SyncCopyCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
        {
            if (commandLineOptions == null)
            throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
              "Option used in invalid context -- {0}", "must specify a option."));

              SyncCopyCommandLineOptions targetOptions = new SyncCopyCommandLineOptions();

              if (commandLineOptions.Arguments.Count >= 0)
              {
            foreach (var arg in commandLineOptions.Arguments.Keys)
            {
              SyncCopyOptionType optionType = SyncCopyOptions.GetOptionType(arg);
              if (optionType == SyncCopyOptionType.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 SyncCopyOptionType.FromDirectory:
              targetOptions.FromDirectory = commandLineOptions.Arguments[arg];
              break;
            case SyncCopyOptionType.ToDirectory:
              targetOptions.ToDirectory = commandLineOptions.Arguments[arg];
              break;
            case SyncCopyOptionType.Recursive:
              targetOptions.IsSetRecursive = true;
              break;
            case SyncCopyOptionType.Help:
              targetOptions.IsSetHelp = true;
              break;
            case SyncCopyOptionType.Version:
              targetOptions.IsSetVersion = true;
              break;
              }
            }
              }

              return targetOptions;
        }