private static void ProcessArgument(Argument argument) { switch (argument.ArgumentType) { case ArgumentType.OneToOne: oneToOneMigrationService.Migrate(argument.AvailableValues); break; case ArgumentType.Entities: entityMigrationService.Migrate(); break; case ArgumentType.Products: productMigrationService.Migrate(argument.AvailableValues); break; default: break; } }
private static IEnumerable<Argument> ValidateArguments(string[] args) { var possibleArguments = JsonConvert.DeserializeObject<List<Argument>>(File.ReadAllText(Properties.Settings.Default.ArgumentMappingFilePath)); var currentArguments = new List<Argument>(); // Iterate the input arguments; for (int i = 0; i < args.Length; i++) { var arg = args[i]; // If the argument is an available option of the configured Arguments if (IsArgumentOption(possibleArguments, arg)) { var possibleArgument = possibleArguments.First(x => x.ArgumentOption == arg); var currentArgument = new Argument(possibleArgument.ArgumentOption, possibleArgument.ArgumentType); // If the argument option is not already in the current execution Arguments if (!IsArgumentOption(currentArguments, arg)) { // Iterate the available Values of the current Argument for (int j = i + 1; j < args.Length; j++) { var valueArg = args[j]; // if the current argument is an option if (IsArgumentOption(possibleArguments, valueArg)) { break; } else { // Is the Argument is an available value if (IsArgumentAvailableValue(possibleArgument, valueArg)) { var availableValue = possibleArgument.AvailableValues.First(x => x.Name == valueArg); currentArgument.AvailableValues.Add(availableValue); } else { throw new Exception("The value '" + arg + "' is not available in for the option '" + valueArg + "'."); } } i = j; } } else { throw new Exception("The option '" + arg + "' appears more than once."); } currentArguments.Add(currentArgument); } else { throw new Exception("The option '" + arg + "' is not available."); } } return currentArguments; }
private static bool IsArgumentAvailableValue(Argument argument, string valueArg) { return argument.AvailableValues.Any(x => x.Name == valueArg); }