#include #include #include #include "LoadFilesCommand.h" #include "MuseumDeserializer.h" #include "Exception.h" #include "FileReaderFactory.h" #include "FileReader.h" #include "ToggleMuseumPauseCommand.h" #include "ParserFactory.h" using namespace std; LoadFilesCommand::LoadFilesCommand(Museum & m, int argc, char ** argv) : museum(m) { vector files = {}; for (size_t i = 0; i < argc; i++) { files.push_back(string(argv[i])); } this->files = files; } LoadFilesCommand::LoadFilesCommand(Museum & m, vector files) : museum(m) { this->files = files; } void LoadFilesCommand::load_files() { ToggleMuseumPauseCommand(this->museum, true).execute(); MuseumDeserializer deserializer { this->museum }; ParserFactory factory {}; for (string url : files) { try { unique_ptr file = FileReaderFactory().create(url); Parser & parser = factory.get_parser(*file); parser.parse(deserializer); } catch (Exception & e) { throw Exception("%s (%s)", e.what(), url.c_str()); } } } void LoadFilesCommand::execute() { try { this->load_files(); } catch (Exception & e) { throw Exception("LoadFilesCommand: %s", e.what()); } }