void SearchResultPinBoundObject::HandlePinBecameFullyVisible(const MyPinModel& pinModel) { if(m_pinVendorRequiresRefreshing && !m_isCurrentlyRefreshingResult) { const int64_t timeNow(Eegeo::Helpers::Time::MillisecondsSinceEpoch()); const int64_t millisecondsSinceCreated(timeNow - m_searchResult.GetCreationTimestamp()); // Allow at least five minutes between refreshes. const int64_t millisecondsBetweenRefresh = (5 * 60 * 1000); if(millisecondsSinceCreated >= millisecondsBetweenRefresh || pinModel.Version() != MyPinModel::CurrentVersion) { m_isCurrentlyRefreshingResult = true; m_myPinsSearchResultRefreshService.RefreshPinnedSearchResult(pinModel.Identifier(), *this, m_searchResult); } } }
void MyPinsFileIO::SavePinModelToDisk(const MyPinModel& pinModel) { std::fstream stream; size_t size; if (m_fileIO.OpenFile(stream, size, MyPinsDataFilename)) { std::string json((std::istreambuf_iterator<char>(stream)), (std::istreambuf_iterator<char>())); rapidjson::Document jsonDoc; if (jsonDoc.Parse<0>(json.c_str()).HasParseError()) { Eegeo_TTY("Parse error in MyPins JSON.\n"); return; } Eegeo_ASSERT(jsonDoc.IsObject(), "JSON document is not of object type"); rapidjson::Document::AllocatorType& allocator = jsonDoc.GetAllocator(); rapidjson::Value& myPinsArray = jsonDoc[MyPinsJsonArrayName.c_str()]; rapidjson::Value pinModelJson; MyPinModelToJson(pinModel, allocator, m_myPinBoundObjectRepository, pinModelJson); myPinsArray.PushBack(pinModelJson, allocator); rapidjson::StringBuffer strbuf; rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf); jsonDoc.Accept(writer); std::string jsonString = strbuf.GetString(); if (WriteJsonToDisk(jsonString)) { m_persistentSettings.SetValue(MyPins_LastMyPinModelIdKey, pinModel.Identifier()); } } else { Eegeo_TTY("Couldn't open file:%s\n", MyPinsDataFilename.c_str()); } }