private static CreateCommand ParseCreateCommand(string[] args) { var command = new CreateCommand(); for (var i = 1; i < args.Length; i++) { switch (args[i]) { case "--start": case "-s": command.StartUponCreation = true; break; case "--in": case "-i": if (i + 1 == args.Length) { throw new CommandParseException("Unexpected command end"); } int delay; if (int.TryParse(args[i + 1], out delay)) { command.DelayInSeconds = delay; i++; continue; } throw new CommandParseException($"Cannot parse start delay: {args[i + 1]}"); case "--after": case "-a": if (i + 1 == args.Length) { throw new CommandParseException("Unexpected command end"); } int taskId; if (int.TryParse(args[i + 1], out taskId)) { command.DependentTaskIds.Add(taskId); i++; continue; } throw new CommandParseException($"Cannot parse dependent task id: {args[i]}"); default: int iterations; if (int.TryParse(args[i], out iterations)) { command.Iterations = iterations; continue; } throw new CommandParseException($"Cannot parse parameter: {args[i]}"); } } return command; }
private void ProcessCommand(CreateCommand command) { var jobToCreate = new StandaloneJob { Id = Interlocked.Increment(ref _lastTaskId), Iterations = command.Iterations, DelayInSeconds = command.DelayInSeconds }; jobToCreate.RequiredJobs.AddRange(command.DependentTaskIds.Select(id => _allJobs.Single(t => t.Id == id))); _allJobs.Add(jobToCreate); if (command.StartUponCreation) { StartJob(jobToCreate); } }