Пример #1
0
        protected override sealed void CheckValidity(string[] args, out ArgumentsValues arguments,
            out OptionsValues options)
        {
            var argumentsDictionary = new ArgumentsDictionary();
            var optionsDictionary = new OptionsDictionary();

            int j = 0;
            for (int i = 0; i < args.Length; i++)
            {
                if (Options[args[i]].HasValue)
                {
                    Option o = Options[args[i]].Value;

                    var optionArgs = new ArgumentsDictionary();
                    foreach (IArgument argument in o.Arguments)
                    {
                        i++;
                        IArgument a = argument;
                        if (!a.IsValid(args[i]))
                            throw new ArgumentNotValidException(a, j);

                        optionArgs.Add(a.Name, args[i]);
                    }
                    optionsDictionary.Add(o.Key, new ArgumentsValues(optionArgs));
                    continue;
                }

                argumentsDictionary.Add(j.ToString(CultureInfo.InvariantCulture), args[i]);
                j++;
            }

            arguments = new ArgumentsValues(argumentsDictionary);
            options = new OptionsValues(optionsDictionary);
        }
Пример #2
0
        /// <summary>
        /// Processes the command line arguments
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private static ArgumentsDictionary ProcessArguments(string[] arguments)
        {
            ArgumentSpec[] argSpecs = new ArgumentSpec[]
            {
                new ArgumentSpec(
                    "Help",
                    '?',
                    false,
                    null,
                    "Display this help message."),
                new ArgumentSpec(
                    "Log",
                    'l',
                    "-",
                    "file",
                    "Log file name ('-' for stdout)"),
                new ArgumentSpec(
                    "ConfigFile",
                    'c',
                    "Settings.xml",
                    null,
                    "Configuration file"),
            };

            ArgumentsDictionary args = new ArgumentsDictionary(arguments, argSpecs);

            if (args.AppSettingsParseError)
            {
                Console.Error.WriteLine("Error in .config file options: ignoring");
            }

            if (args.CommandLineParseError)
            {
                Console.Error.WriteLine("Error in command line arguments at {0}\n", args.ParseErrorArgument);
                Console.Error.WriteLine(args.GetUsage("homeservice"));
                System.Environment.Exit(1);
            }

            if ((bool)args["Help"])
            {
                Console.Error.WriteLine("Runs HomeService\n");
                Console.Error.WriteLine(args.GetUsage("homeservice"));
                System.Environment.Exit(0);
            }

            string configFile = ((string)args["ConfigFile"]);

            if (!File.Exists(configFile))
            {
                Console.Error.WriteLine("ConfigFile {0} not found", configFile);
                System.Environment.Exit(1);
            }

            return(args);
        }
Пример #3
0
        /// <summary>
        /// Processes the command line arguments
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private static ArgumentsDictionary ProcessArguments(string[] arguments)
        {
            ArgumentSpec[] argSpecs = new ArgumentSpec[]
            {
                new ArgumentSpec(
                    "Help",
                    '?',
                    false,
                    null,
                    "Display this help message."),
                new ArgumentSpec(
                    "Log",
                    'l',
                    "-",
                    "file",
                    "Log file name ('-' for stdout)"),
                new ArgumentSpec(
                    "ConfigFile",
                    'c',
                    "Settings.xml",
                    null,
                    "Configuration file"),
            };

            ArgumentsDictionary args = new ArgumentsDictionary(arguments, argSpecs);
            if (args.AppSettingsParseError)
            {
                Console.Error.WriteLine("Error in .config file options: ignoring");
            }

            if (args.CommandLineParseError)
            {
                Console.Error.WriteLine("Error in command line arguments at {0}\n", args.ParseErrorArgument);
                Console.Error.WriteLine(args.GetUsage("homeservice"));
                System.Environment.Exit(1);
            }

            if ((bool)args["Help"])
            {
                Console.Error.WriteLine("Runs HomeService\n");
                Console.Error.WriteLine(args.GetUsage("homeservice"));
                System.Environment.Exit(0);
            }

            string configFile = ((string)args["ConfigFile"]);

            if (!File.Exists(configFile))
            {
                Console.Error.WriteLine("ConfigFile {0} not found", configFile);
                System.Environment.Exit(1);
            }

            return args;
        }
Пример #4
0
        private static void getActualConfig(ArgumentsDictionary argsDict)
        {
            string orgId = (string)argsDict["OrgID"];
            string studyId = (string)argsDict["StudyID"];
            string homeIDs = (string)argsDict["HomeIDs"];
            string container = (string)argsDict["Container"];
            string actualConfigDir = (string)argsDict["ActualConfigDir"];
            string accountName = (string)argsDict["AccountName"];

            string accountKey= null ;
            if (!String.IsNullOrEmpty((string)argsDict["AccountKey"]))
                accountKey = (string)argsDict["AccountKey"];
            else
                accountKey = PackagerHelper.ReadFile((string)argsDict["AccountKeyFile"]);

            if (string.IsNullOrEmpty(accountKey))
                Utils.die("Could not obtain AccountKey");

            string[] homeID=null;
            if (!homeIDs.Equals("*"))
            {
                homeID = homeIDs.Split(',');
            }
            else
            {

                Console.WriteLine("\nFetching list of homeIDs from container: "+container);
                Tuple<bool, List<string>> fetchHubList = AzureBlobConfigUpdate.listHubs(accountName, accountKey, container, orgId, studyId );
                if (fetchHubList.Item1)
                    homeID = fetchHubList.Item2.ToArray();
                else
                    Utils.die("ERROR! Cannot obtain hubs list! Exception : "+ fetchHubList.Item2[0]);
            }

            Console.WriteLine("HomeID list: ");
            for (int i=0; i < homeID.Count() ; i++)
            {
                homeID[i] = homeID[i].TrimEnd('/');
                Console.WriteLine("{0}", homeID[i]);
            }

            foreach (string h in homeID)
            {
                Console.WriteLine("\nFetching config for homeID:"+h );
                writeActualConfigToDisk(accountName, accountKey, container, orgId, studyId, h, actualConfigDir);
            }
        }
Пример #5
0
        /// <summary>
        /// Processes the command line arguments
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private static ArgumentsDictionary ProcessArguments(string[] arguments)
        {
            ArgumentSpec[] argSpecs = new ArgumentSpec[]
            {
                new ArgumentSpec(
                    "Help",
                    '?',
                    false,
                    null,
                    "Display this help message."),
               new ArgumentSpec(
                   "PlatformRootDir",
                   'd',
                   "output\\binaries\\Platform",
                   "directory name",
                   "Platform directory containing the binaries"),
             new ArgumentSpec(
                   "RepoDir",
                   'r',
                   "output\\HomeStore\\repository",
                   "directory name",
                   "Top-level directory where we should create the homestore repository")
            };

            ArgumentsDictionary args = new ArgumentsDictionary(arguments, argSpecs);
            if (args.AppSettingsParseError)
            {
                Console.Error.WriteLine("Error in .config file options: ignoring");
            }

            if (args.CommandLineParseError)
            {
                Console.Error.WriteLine("Error in command line arguments at {0}\n", args.ParseErrorArgument);
                Console.Error.WriteLine(args.GetUsage("PlatformPackager"));
                System.Environment.Exit(1);
            }

            if ((bool)args["Help"])
            {
                Console.Error.WriteLine("Packages platform binaries\n");
                Console.Error.WriteLine(args.GetUsage("PlatformPackager"));
                System.Environment.Exit(0);
            }

            return args;
        }
Пример #6
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public static void Main(string[] args)
        {
            ArgumentsDictionary argsDict = ProcessArguments(args);

            //this logger is not being used at the moment
            logger = new Logger((string)argsDict["Log"]);

            Settings.InitSettingsFromFile((string)argsDict["ConfigFile"]);

            HomeService homeService = new HomeService(logger);

            homeService.Start(null);

            while (!serviceExited)
            {
                System.Threading.Thread.Sleep(10000);
            }

            Environment.Exit(homeService.ExitCode);
        }
Пример #7
0
        /// <summary>
        /// Processes the command line arguments
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private static ArgumentsDictionary ProcessArguments(string[] arguments)
        {
            ArgumentSpec[] argSpecs = new ArgumentSpec[]
            {
                new ArgumentSpec(
                    "Help",
                    '?',
                    false,
                    null,
                    "Display this help message."),
                new ArgumentSpec(
                    "SmtpServer",
                    's',
                    "smtp.live.com",
                    "smtp server name",
                    "The name of the smtp server"),
                new ArgumentSpec(
                    "SmtpUser",
                    'u',
                    "*****@*****.**",
                    "smtp user name",
                    "The name of the smtp user"),
                new ArgumentSpec(
                    "SmtpPassword",
                    'p',
                    "home123$",
                    "smtp server name",
                    "password for the smtp server"),
                new ArgumentSpec(
                    "To",
                    't',
                    "*****@*****.**",
                    "whom to send email",
                    "The target of email"),
            };

            ArgumentsDictionary args = new ArgumentsDictionary(arguments, argSpecs);

            if (args.AppSettingsParseError)
            {
                Console.Error.WriteLine("Error in .config file options: ignoring");
            }

            if (args.CommandLineParseError)
            {
                Console.Error.WriteLine("Error in command line arguments at {0}\n", args.ParseErrorArgument);
                Console.Error.WriteLine(args.GetUsage("PlatformPackager"));
                System.Environment.Exit(1);
            }

            if ((bool)args["Help"])
            {
                Console.Error.WriteLine("Packages platform binaries\n");
                Console.Error.WriteLine(args.GetUsage("PlatformPackager"));
                System.Environment.Exit(0);
            }

            if ((string.IsNullOrEmpty((string)args["To"])))
            {
                Console.Error.WriteLine("You must supply a valid to address");
                Console.Error.WriteLine(args.GetUsage("EmailTester"));
                System.Environment.Exit(1);
            }

            return(args);
        }
Пример #8
0
        /// <summary>
        /// Processes the command line arguments
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private static ArgumentsDictionary ProcessArguments(string[] arguments)
        {
            //the default values are under the assumption that you run this tool from the directory where Hub.sln sits.

            ArgumentSpec[] argSpecs = new ArgumentSpec[]
            {
                new ArgumentSpec(
                    "Help",
                    '?',
                    false,
                    null,
                    "Display this help message."),
               new ArgumentSpec(
                   "ScoutsRootDir",
                   'd',
                   "output\\binaries\\Scouts",
                   "directory name",
                   "Root directory for all Scouts"),
               new ArgumentSpec(
                   "ScoutName",
                   'n',
                   "",
                   "scout name",
                   "Name of the scout. Leave empty if you want to package all scouts"),
             new ArgumentSpec(
                   "RepoDir",
                   'r',
                   "output\\HomeStore\\repository",
                   "directory name",
                   "Top-level directory where we should create the homestore repository"),
            };

            ArgumentsDictionary args = new ArgumentsDictionary(arguments, argSpecs);
            if (args.AppSettingsParseError)
            {
                Console.Error.WriteLine("Error in .config file options: ignoring");
            }

            if (args.CommandLineParseError)
            {
                Console.Error.WriteLine("Error in command line arguments at {0}\n", args.ParseErrorArgument);
                Console.Error.WriteLine(args.GetUsage("ScoutPackager"));
                System.Environment.Exit(1);
            }

            if ((bool)args["Help"])
            {
                Console.Error.WriteLine("Packages platform binaries\n");
                Console.Error.WriteLine(args.GetUsage("ScoutPackager"));
                System.Environment.Exit(0);
            }

            return args;
        }
Пример #9
0
        /// <summary>
        /// Processes the command line arguments
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private static ArgumentsDictionary ProcessArguments(string[] arguments)
        {
            //the default values are under the assumption that you run this tool from the directory where Hub.sln sits.

            ArgumentSpec[] argSpecs = new ArgumentSpec[]
            {
                new ArgumentSpec(
                    "Help",
                    '?',
                    false,
                    null,
                    "Display this help message."),
               new ArgumentSpec(
                   "AddInRoot",
                   'd',
                   "output\\binaries\\Pipeline",
                   "directory name",
                   "Root directory for AddIns (i.e., the parent directory of AddIns, under which modules are present)"),
               new ArgumentSpec(
                   "ModuleName",
                   'n',
                   "",
                   "module name",
                   "Name of the module. Leave empty if you want to package all modules"),
             new ArgumentSpec(
                   "RepoDir",
                   'r',
                   "output\\HomeStore\\repository",
                   "directory name",
                   "Top-level directory where we should create the homestore repository"),
            };

            ArgumentsDictionary args = new ArgumentsDictionary(arguments, argSpecs);
            if (args.AppSettingsParseError)
            {
                Console.Error.WriteLine("Error in .config file options: ignoring");
            }

            if (args.CommandLineParseError)
            {
                Console.Error.WriteLine("Error in command line arguments at {0}\n", args.ParseErrorArgument);
                Console.Error.WriteLine(args.GetUsage("ModulePackager"));
                System.Environment.Exit(1);
            }

            if ((bool)args["Help"])
            {
                Console.Error.WriteLine("Packages platform binaries\n");
                Console.Error.WriteLine(args.GetUsage("ModulePackager"));
                System.Environment.Exit(0);
            }

            //if (string.IsNullOrWhiteSpace((string)args["AddInRoot"]))
            //{
            //    Console.Error.WriteLine("AddInRoot not supplied\n");
            //    Console.Error.WriteLine(args.GetUsage("ModulePackager"));
            //    System.Environment.Exit(1);
            //}

            //if (string.IsNullOrWhiteSpace((string) args["ModuleName"]))
            //{
            //    Console.Error.WriteLine("Module name not supplied\n");
            //    Console.Error.WriteLine(args.GetUsage("ModulePackager"));
            //    System.Environment.Exit(1);
            //}

            //if (string.IsNullOrWhiteSpace((string)args["RepoDir"]))
            //{
            //    Console.Error.WriteLine("Repository directory name not supplied\n");
            //    Console.Error.WriteLine(args.GetUsage("ModulePackager"));
            //    System.Environment.Exit(1);
            //}

            return args;
        }
Пример #10
0
        public static void printArgumentsDictionary(ArgumentsDictionary dict)
        {
            foreach (string key in dict.Keys)
            {
                Console.WriteLine(key + " : " + dict[key]);
            }

        }
Пример #11
0
        /// <summary>
        /// Processes the command line arguments
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private ArgumentsDictionary ProcessArguments(string[] arguments)
        {
            ArgumentSpec[] argSpecs = new ArgumentSpec[]
            {
                new ArgumentSpec(
                    "Help",
                    '?',
                    false,
                    null,
                    "Display this help message."),
                new ArgumentSpec(
                    "LogFile",
                    'l',
                    DEFAULT_COMMAND_LINE_ARG_VAL,
                    "file name",
                    "Log file name ('-' for stdout)"),
                new ArgumentSpec(
                    "ConfigDir",
                    'c',
                    DEFAULT_COMMAND_LINE_ARG_VAL,
                    "directory",
                    "Configuration directory"),
                new ArgumentSpec(
                    "RunningMode",
                    'r',
                     DEFAULT_COMMAND_LINE_ARG_VAL,
                    "string",
                    "Running Mode"),
                new ArgumentSpec(
                    "EnforcePolicies",
                    'p',
                    DEFAULT_COMMAND_LINE_ARG_VAL,
                    "true/false",
                    "Turn policy enforcement on/off"),
                new ArgumentSpec(
                    "StayOffline",
                    'o',
                    DEFAULT_COMMAND_LINE_ARG_VAL,
                    "true/false",
                    "Whether we should stay offline")
            };

            ArgumentsDictionary args = new ArgumentsDictionary(arguments, argSpecs);
            if (args.AppSettingsParseError)
            {
                Console.Error.WriteLine("Error in .config file options: ignoring");
            }

            if (args.CommandLineParseError)
            {
                Console.Error.WriteLine("Error in command line arguments at {0}\n", args.ParseErrorArgument);
                Console.Error.WriteLine(args.GetUsage("homeos"));
                System.Environment.Exit(1);
            }

            if ((bool)args["Help"])
            {
                Console.Error.WriteLine("Runs HomeOS\n");
                Console.Error.WriteLine(args.GetUsage("homeos"));
                System.Environment.Exit(0);
            }

            //if the supplied config path is relative, make it absolute
            if (!DEFAULT_COMMAND_LINE_ARG_VAL.Equals((string)args["ConfigDir"]))
            {
                string configDir = (string)args["ConfigDir"];

                if (!Directory.Exists(configDir))
                {
                    Console.Error.WriteLine("Configuration directory does not exist: " + configDir);
                    System.Environment.Exit(1);
                }

                args["ConfigDir"] = Path.GetFullPath(configDir);
            }


           // if ((string)args["ConfigDir"] != "\\Config")
         //   {
             //  Settings.SetParameter("ConfigDir", Environment.CurrentDirectory + "\\" + (string)args["ConfigDir"]);
            //}

            //Settings.RunningMode = (string) args["RunningMode"];

            if (Settings.RunningMode.Equals("unittesting"))
            {
                // need to set the global switch here since doing it in Configured Start is too late as Logger
                // settings for unittesting do not get affected correctly
                //Settings.UnitTestingEnabled = true;

                // Current directory is not the output directory when platform is launched from the unit tests,
                // this is needed because we don't want to set the output directory in the unit test project to the
                // global output dir.
                // ....
                // evgeni -- per my email, this should be needed any more -- ratul
                // if true please delete all this code
                // ....
                //Constants.AddInRoot = Environment.CurrentDirectory + "\\..\\..\\..\\output\\binaries\\Pipeline"; 
                //Constants.ScoutRoot = Environment.CurrentDirectory + "\\..\\..\\..\\output\\binaries\\Scouts";
                //Settings.ConfigDir = Environment.CurrentDirectory + "\\..\\..\\..\\output\\Configs\\Config";
                
                //Constants.LocationsFileName = Environment.CurrentDirectory + "\\..\\..\\..\\output\\Configs\\Config\\" + Constants.LocationsFileName;
            }

            //Settings.EnforcePolicies = !(bool)args["NoPolicyEnforcement"];
            
            return args;
        }
Пример #12
0
        /// <summary>
        /// Processes the command line arguments
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private static ArgumentsDictionary ProcessArguments(string[] arguments)
        {
            ArgumentSpec[] argSpecs = new ArgumentSpec[]
            {
                new ArgumentSpec(
                    "Help",
                    '?',
                    false,
                    null,
                    "Display this help message."),
               new ArgumentSpec(
                   "SmtpServer",
                   's',
                   "smtp.live.com",
                   "smtp server name",
                   "The name of the smtp server"),
               new ArgumentSpec(
                   "SmtpUser",
                   'u',
                   "*****@*****.**",
                   "smtp user name",
                   "The name of the smtp user"),
               new ArgumentSpec(
                   "SmtpPassword",
                   'p',
                   "home123$",
                   "smtp server name",
                   "password for the smtp server"),
               new ArgumentSpec(
                   "To",
                   't',
                   "*****@*****.**",
                   "whom to send email",
                   "The target of email"),
            };

            ArgumentsDictionary args = new ArgumentsDictionary(arguments, argSpecs);
            if (args.AppSettingsParseError)
            {
                Console.Error.WriteLine("Error in .config file options: ignoring");
            }

            if (args.CommandLineParseError)
            {
                Console.Error.WriteLine("Error in command line arguments at {0}\n", args.ParseErrorArgument);
                Console.Error.WriteLine(args.GetUsage("PlatformPackager"));
                System.Environment.Exit(1);
            }

            if ((bool)args["Help"])
            {
                Console.Error.WriteLine("Packages platform binaries\n");
                Console.Error.WriteLine(args.GetUsage("PlatformPackager"));
                System.Environment.Exit(0);
            }

            if ((string.IsNullOrEmpty((string) args["To"])))
            {
                Console.Error.WriteLine("You must supply a valid to address");
                Console.Error.WriteLine(args.GetUsage("EmailTester"));
                System.Environment.Exit(1);
            }

              return args;
        }
Пример #13
0
        private static void setDesiredConfig(ArgumentsDictionary argsDict)
        {
            string orgId = (string)argsDict["OrgID"];
            string studyId = (string)argsDict["StudyID"];
            string homeIDs = (string)argsDict["HomeIDs"];
            string container = (string)argsDict["Container"];
            string actualConfigDir = (string)argsDict["ActualConfigDir"];
            string desiredConfigDir = (string)argsDict["DesiredConfigDir"];
            string accountName = (string)argsDict["AccountName"];

            string accountKey = null;
            if (!String.IsNullOrEmpty((string)argsDict["AccountKey"]))
                accountKey = (string)argsDict["AccountKey"];
            else
                accountKey = PackagerHelper.ReadFile((string)argsDict["AccountKeyFile"]);

            if (string.IsNullOrEmpty(accountKey))
                Utils.die("Could not obtain AccountKey");

            if(!Directory.Exists(desiredConfigDir+"/"+orgId))
                Utils.die("ERROR! Directory "+desiredConfigDir+"/"+orgId+" corresponding to given orgID: "+orgId+" does not exist.");

            if (!Directory.Exists(desiredConfigDir + "/" + orgId + "/" + studyId))
                Utils.die("ERROR! Directory " + desiredConfigDir + "/" + orgId + "/" + studyId + " corresponding to given studyID: " + studyId + " does not exist.");

            string[] homeID = null;
            if (!homeIDs.Equals("*"))
            {
                homeID = homeIDs.Split(',');
            }
            else
            {
                Console.WriteLine("\nFetching list of homeIDs from "+desiredConfigDir);
                homeID = PackagerHelper.ListDirectories(desiredConfigDir + "/" + orgId + "/" + studyId+"/").ToArray();
            }

            Console.WriteLine("HomeID list: ");
            for (int i = 0; i < homeID.Count(); i++)
            {
                homeID[i] = homeID[i].TrimEnd('/');
                Console.WriteLine("{0}", homeID[i]);
            }

            foreach (string h in homeID)
            {
                Console.WriteLine("\nSetting desired config for homeID:" + h);
                writeDesiredConfigToAzure(accountName, accountKey, container, orgId, studyId, h, actualConfigDir, desiredConfigDir);
            }
        }
Пример #14
0
        /// <summary>
        /// Processes the command line arguments
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private static ArgumentsDictionary ProcessArguments(string[] arguments)
        {
            ArgumentSpec[] argSpecs = new ArgumentSpec[]
            {
                    new ArgumentSpec(
                    "Help",
                    '?',
                    false,
                    null,
                    "Display this help message."),

                    new ArgumentSpec(
                   "AccountKey",
                   'k',
                   "",
                   "Azure account key",
                   "Azure account key"),

                    new ArgumentSpec(
                   "AccountKeyFile",
                   '\0',
                   "",
                   "file containing Azure account key",
                   "file containing Azure account key"),

                   new ArgumentSpec(
                   "AccountName",
                   'n',
                   "homelab",
                   "Azure account name",
                   "Azure account name"),

                   new ArgumentSpec(
                   "Container",
                   'c',
                   "configs",
                   "Config storage container name",
                   "Config storage container name"),

                   new ArgumentSpec(
                   "OrgID",
                   'o',
                   "Default",
                   "Organization ID or OrgID",
                   "Organization ID or OrgID"),

                   new ArgumentSpec(
                   "StudyID",
                   's',
                   "Default",
                   "StudyID",
                   "StudyID"),

                   new ArgumentSpec(
                   "HomeIDs",
                   'h',
                   "*",
                   "HomeIDs",
                   "single HomeID or comma-separated multiple HomeIDs"),

                   new ArgumentSpec(
                   "ActualConfigDir",
                   'a',
                   "",
                   "Actual Configs Directory",
                   "Directory for reading or writing actual/current Hub configs"),

                   new ArgumentSpec(
                   "DesiredConfigDir",
                   'd',
                   "",
                   "Desired Configs Directory",
                   "Directory for reading desired Hub configs"),

                    new ArgumentSpec(
                   "Function",
                   'f',
                   "",
                   "function to get performed",
                   "function to get performed"),

            };

            ArgumentsDictionary args = new ArgumentsDictionary(arguments, argSpecs);
            if (args.AppSettingsParseError)
            {
                Console.Error.WriteLine("Error in .config file options: ignoring");
            }

            if (args.CommandLineParseError)
            {
                Console.Error.WriteLine("Error in command line arguments at {0}\n", args.ParseErrorArgument);
                Console.Error.WriteLine(args.GetUsage("ConfigPackager"));
                System.Environment.Exit(1);
            }

            if ((bool)args["Help"])
            {
                Console.Error.WriteLine("Downloads current Hub configs, and uploads desired configs for deployment on hubs\n");
                Console.Error.WriteLine(args.GetUsage("ConfigPackager"));
                System.Environment.Exit(0);
            }

            return args;
        }
Пример #15
0
        protected override sealed void CheckValidity(string[] args, out ArgumentsValues arguments,
            out OptionsValues options)
        {
            var argumentsDictionary = new ArgumentsDictionary();
            var optionsDictionary = new OptionsDictionary();

            int argsCount = 0;
            for (int i = 0; i < args.Length; i++)
            {
                if (Options[args[i]].HasValue)
                {
                    i += Options[args[i]].Value.Arguments.Count;
                    continue;
                }

                argsCount++;
            }

            if (argsCount < RequiredArguments.Count)
                throw new NumberOfArgumentsException(argsCount, RequiredArguments.Count);

            if (argsCount > RequiredArguments.Count + OptionalArguments.Count)
                throw new NumberOfArgumentsException(argsCount, RequiredArguments.Count + OptionalArguments.Count);

            int j = 0;
            int k = 0;
            for (int i = 0; i < args.Length; i++)
            {
                if (Options[args[i]].HasValue)
                {
                    Option o = Options[args[i]].Value;

                    var optionArgs = new ArgumentsDictionary();
                    foreach (IArgument argument in o.Arguments)
                    {
                        i++;
                        IArgument a = argument;
                        if (!a.IsValid(args[i]))
                            throw new ArgumentNotValidException(a, j);

                        optionArgs.Add(a.Name, args[i]);
                    }
                    optionsDictionary.Add(o.Key, new ArgumentsValues(optionArgs));
                    continue;
                }

                if (j < RequiredArguments.Count)
                {
                    if (!RequiredArguments[j].IsValid(args[i]))
                        throw new ArgumentNotValidException(RequiredArguments[j], j);

                    argumentsDictionary.Add(RequiredArguments[j].Name, args[i]);
                    j++;
                }
                else
                {
                    if (!OptionalArguments[k].IsValid(args[i]))
                        throw new ArgumentNotValidException(OptionalArguments[k], j + k);

                    argumentsDictionary.Add(OptionalArguments[k].Name, args[i]);
                    k++;
                }
            }

            arguments = new ArgumentsValues(argumentsDictionary);
            options = new OptionsValues(optionsDictionary);
        }