Пример #1
0
        public async Task <bool> ImportarEncomendas(string filePath, List <Model.Encomenda> encomendas)
        {
            try
            {
                using (var reader = new StreamReader(filePath))
                {
                    while (reader.Peek() >= 0)
                    {
                        var line = await reader.ReadLineAsync();

                        var itens = line.Split(" ");

                        if (itens.Length != 2)
                        {
                            throw new Exception("Arquivo com formato inválido.");
                        }

                        encomendas.Add(new Model.Encomenda(itens[0], itens[1]));
                    }
                }

                _log.LogInformation(@$ "Foram carregados {encomendas.Count} encomendas.");
                return(true);
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                return(false);
            }
        }
Пример #2
0
 protected BaseResponse <T> Wrap <T>(Func <T> action)
 {
     try
     {
         var result = action();
         return(new BaseResponse <T>(result));
     }
     catch (ValidationException ex)
     {
         _logger?.LogError(ex.Message);
         return(new BaseResponse <T>(ex));
     }
     catch (Exception ex)
     {
         _logger?.LogError(ex.Message);
         return(new BaseResponse <T>(ex));
     }
 }
 // GET: /Store/
 public async Task <ActionResult> Index()
 {
     logger.LogError(new ApplicationException("error"), "MessageError");
     return(View(await _storeContext.Genres.ToListAsync()));
 }
Пример #4
0
 public void TratarInterrupcao(string descricao)
 {
     _logger.LogError(descricao);
     _hasError = true;
 }