Пример #1
0
        public override void Execute()
        {
            base.Execute();

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

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

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

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

            SplitCommandLineOptions targetOptions = new SplitCommandLineOptions();

            if (commandLineOptions.Arguments.Count >= 0)
            {
                foreach (var arg in commandLineOptions.Arguments.Keys)
                {
                    SplitOptionType optionType = SplitOptions.GetOptionType(arg);
                    if (optionType == SplitOptionType.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 SplitOptionType.File:
                        targetOptions.IsSetFile = true;
                        targetOptions.File      = commandLineOptions.Arguments[arg];
                        break;

                    case SplitOptionType.Prefix:
                        targetOptions.IsSetPrefix = true;
                        targetOptions.Prefix      = commandLineOptions.Arguments[arg];
                        break;

                    case SplitOptionType.SuffixLength:
                        int suffixLength = 0;
                        if (!int.TryParse(commandLineOptions.Arguments[arg], out suffixLength))
                        {
                            throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                                         "Option used in invalid context -- {0}", "invalid suffix length."));
                        }
                        if (suffixLength <= 0 || suffixLength > 10)
                        {
                            throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                                         "Option used in invalid context -- {0}", "invalid suffix length."));
                        }
                        targetOptions.SuffixLength = suffixLength;
                        break;

                    case SplitOptionType.Bytes:
                        targetOptions.Bytes = GetBytesSize(commandLineOptions.Arguments[arg]);
                        break;

                    case SplitOptionType.Directory:
                        targetOptions.Directory = commandLineOptions.Arguments[arg];
                        break;

                    case SplitOptionType.Timestamp:
                        targetOptions.IsSetTimestamp = true;
                        break;

                    case SplitOptionType.Overwrite:
                        targetOptions.IsSetOverwrite = true;
                        break;

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

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

            if (commandLineOptions.Parameters.Count > 0)
            {
                if (!targetOptions.IsSetFile)
                {
                    targetOptions.IsSetFile = true;
                    targetOptions.File      = commandLineOptions.Parameters.First();
                }
            }

            return(targetOptions);
        }