public IConfig GetConfig(string fileName)
        {
            if (!System.IO.File.Exists(fileName))
            {
                throw new System.IO.FileNotFoundException(string.Format("Config file not found: {0}", fileName), fileName);
            }

            var lines = System.IO.File.ReadAllLines(fileName).Where(x => (!string.IsNullOrEmpty(x)) && (!x.StartsWith("#")));

            var config = GetNameValueCollection(lines);

            var skipDestinationCheck = GetBoolOption(config, "skipDestinationCheck");
            var parallelGetLists     = GetBoolOption(config, "parallel");
            var forceAllContents     = GetBoolOption(config, "all");

            var args =
                SplitArgs(
                    "--from", config["from"],
                    "--to", config["to"],
                    "--maxContentNumber", config["maxContentNumber"],
                    "--maxConnectionNumber", config["maxConnectionNumber"],
                    (skipDestinationCheck ? "--skipDestinationCheck" : null),
                    (parallelGetLists ? "--parallel" : null),
                    (forceAllContents ? "--all" : null),
                    "--log", FormatLogFileName(config["log"]));

            if (!string.IsNullOrEmpty(config["hashCheckMoment"]))
            {
                args = args.Concat(SplitArgs("--hashCheckMoment", config["hashCheckMoment"]));
            }

            return(_commandLineArgsConfigProvider.GetConfig(args));
        }
Exemple #2
0
        public IConfig GetConfig()
        {
            var args = Environment.GetCommandLineArgs();

            var options = new CommandLineOptions();

            using (var parser = new CommandLine.Parser((settings) => { settings.HelpWriter = null; }))
            {
                parser.ParseArguments <CommandLineOptions>(args)
                .WithParsed(opts => { options = opts; })
                .WithNotParsed(errors => { });
            }

            var configFileConfig  = (string.IsNullOrEmpty(options.ConfigFileName) ? null : _fileConfigProvider.GetConfig(options.ConfigFileName));
            var commandLineConfig = _commandLineArgsConfigProvider.GetConfig(args);

            return(_mergeConfigProvider.GetConfig(configFileConfig, commandLineConfig));
        }