Esempio n. 1
0
        public async Task <ResultArray <StockInfoResponseDto> > GetStockInfos(string symbol)
        {
            var clients = _factory.GetAllClients();

            if (!clients.Any())
            {
                return(ResultExtensions.FailureArray <StockInfoResponseDto>("Unexpected exception"));
            }

            var clientTasks = await LaunchClientsCall(clients, symbol);

            var finishedTasks = clientTasks.Cast <Task <Result <StockInfoClientResponseDto> > >();

            var results = new List <StockInfoResponseDto>();

            foreach (var finshedTask in finishedTasks)
            {
                var instance = HandleClientResponse(finshedTask.Result);

                if (instance == null)
                {
                    var dto = _mapper.Map <StockInfoResponseDto>(instance);
                    results.Add(dto);
                }
            }

            return(ResultExtensions.Success(instances: results));
        }