Exemplo n.º 1
0
        private Task ExecuteUseCase(string inputOperation, List <IUseCase> useCases, CancellationToken cancellationToken)
        {
            if (int.TryParse(inputOperation, out int index))
            {
                // An index was entered as input.
                if (useCases.Count >= index)
                {
                    return(useCases[index - 1].ExecuteAsync(cancellationToken));
                }
            }
            else
            {
                // Use case name was entered as input.
                IUseCase useCase = useCases.FirstOrDefault(u => string.Equals(u.Name, inputOperation, StringComparison.OrdinalIgnoreCase));
                if (useCase != null)
                {
                    return(useCase.ExecuteAsync(cancellationToken));
                }
            }

            // Invalid operation. Display valid operations.
            System.Console.WriteLine($"Invalid operation: {inputOperation}");
            DisplayRegisteredOperations(useCases);
            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        private Task ExecuteUseCase(IUseCase useCase, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (useCase == null)
            {
                throw new ArgumentNullException(nameof(useCase));
            }

            return(useCase.ExecuteAsync(cancellationToken));
        }