void Agent::Run() { Configuration* config = Configuration::Get(); Inventory inventory; if (!inventory.Initialize(config->DeviceID().c_str())) throw "Cannot initialize Inventory"; if (inventory.Build(config->DeviceID().c_str())) { if (!config->LocalInventory()) { if (inventory.Send(config->ServerURL().c_str())) return; std::cerr << "Cannot send inventory. Will try to save it locally." << std::endl; } if (!inventory.Save(config->DeviceID().c_str())) std::cerr << "Cannot save inventory file." << std::endl; } }
bool Inventory::_WriteProlog(tinyxml2::XMLDocument& document) const { Configuration* config = Configuration::Get(); tinyxml2::XMLDeclaration* declaration = document.NewDeclaration(); document.LinkEndChild(declaration); tinyxml2::XMLElement* request = document.NewElement("REQUEST"); document.LinkEndChild(request); tinyxml2::XMLElement* deviceID = document.NewElement("DEVICEID"); deviceID->LinkEndChild(document.NewText(config->DeviceID().c_str())); request->LinkEndChild(deviceID); tinyxml2::XMLElement* query = document.NewElement("QUERY"); query->LinkEndChild(document.NewText("PROLOG")); request->LinkEndChild(query); return true; }