/// <summary> /// Processa o comando: DataLoadFromFile /// </summary> /// <param name="request">Comando</param> /// <param name="cancellationToken">CancellationToken</param> /// <returns>Task</returns> public async Task <Unit> Handle(DataLoadFromFile request, CancellationToken cancellationToken) { try { var data = _dataManipulation.LoadFromFile(); if (data != null) { Log.Debug("Application data was loaded from: {Path}", _dataManipulation.Path); await _messageBus.Publish(new DataLoadedFromFile(request), cancellationToken); await _messageBus.Send(new DataUpdate(data, DataSection.All, true), cancellationToken); } else { Log.Debug("Application data cannot be loaded because the file does not exist in: {Path}", _dataManipulation.Path); data = Program.Data; await _messageBus.Send(new DataSaveToFile { SaveImmediately = true }, cancellationToken); await _messageBus.Send(new DataUpdate(data, DataSection.All, true), cancellationToken); } } catch (Exception exception) { Log.Error(exception, "Application data cannot load from: {Path}", _dataManipulation.Path); } return(Unit.Value); }