public async Task Process(BatchConfig batch, BatchOption option) { foreach (var command in batch.Commands) { if (command is TargetCommand targetCommand) { if (option == BatchOption.ApplyCurrentState) { await ITargetProcessor.ApplyCurrentStateAsync(targetCommand); } else if (option == BatchOption.ResetState) { await ITargetProcessor.ResetState(targetCommand); } else { await ITargetProcessor.Process(targetCommand); } } else if (command is OkCommand) { await IOkProcessor.Process(command as OkCommand); } } }
private BatchConfig ParseBatch(KeyValuePair <string, string> command, List <string> parameters, Config config) { var rawCommands = parameters .Select(x => ParsePair(x)) .ToList(); var result = new BatchConfig { Name = command.Value }; foreach (var pair in rawCommands) { if (pair.Key.EqualsIgnoreCase("target")) { var targetCommand = new TargetCommand { Name = pair.Key, Value = pair.Value, Target = config.Target.GetIfHasKey(pair.Value) }; if (targetCommand.Target == null) { throw new ConfigException($"{nameof(ParseBatch)}: {nameof(targetCommand.Target)} [{pair.Value}] not found."); } result.Commands.Add(targetCommand); } else if (pair.Key.EqualsIgnoreCase("ok")) { var okCommand = new OkCommand { Name = pair.Key, Value = pair.Value, Url = pair.Value }; result.Commands.Add(okCommand); } else { throw new ConfigException($"Unknown batch command [{pair.Key}]."); } } return(result); }