Checkpoint.h (2951B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <winget/CheckpointDatabase.h> 5 #include <guiddef.h> 6 7 using namespace AppInstaller::Repository::Microsoft; 8 9 namespace AppInstaller::Checkpoints 10 { 11 enum AutomaticCheckpointData 12 { 13 ClientVersion, 14 Command, 15 Arguments, 16 ResumeCount 17 }; 18 19 struct CheckpointManager; 20 21 // A representation of a row in the Checkpoint table. 22 template <typename T> 23 struct Checkpoint 24 { 25 static_assert(std::is_enum<T>::value); 26 friend CheckpointManager; 27 28 std::vector<T> GetCheckpointDataTypes() 29 { 30 return m_checkpointDatabase->GetDataTypes(m_checkpointId); 31 } 32 33 // Returns a boolean value indicating whether the field name exists. 34 bool Has(T dataType, const std::string& fieldName) 35 { 36 return m_checkpointDatabase->HasDataField(m_checkpointId, dataType, fieldName); 37 } 38 39 // Gets all available field names. 40 std::vector<std::string> GetFieldNames(T dataType) 41 { 42 return m_checkpointDatabase->GetDataFieldNames(m_checkpointId, dataType); 43 } 44 45 // Sets a single field value for a data type. 46 void Set(T dataType, const std::string& fieldName, const std::string& value) 47 { 48 m_checkpointDatabase->SetDataValue(m_checkpointId, dataType, fieldName, { value }); 49 } 50 51 // Sets multiple field values for a data type. 52 void SetMany(T dataType, const std::string& fieldName, const std::vector<std::string>& values) 53 { 54 m_checkpointDatabase->SetDataValue(m_checkpointId, dataType, fieldName, values); 55 } 56 57 // Update a single existing field value for a data type. 58 void Update(T dataType, const std::string& fieldName, const std::string& value) 59 { 60 m_checkpointDatabase->UpdateDataValue(m_checkpointId, dataType, fieldName, { value }); 61 } 62 63 // Gets a single field value for a data type. 64 std::string Get(T dataType, const std::string& fieldName) 65 { 66 return m_checkpointDatabase->GetDataFieldSingleValue(m_checkpointId, dataType, fieldName); 67 } 68 69 // Gets multiple field values for a data type. 70 std::vector<std::string> GetMany(T dataType, const std::string& fieldName) 71 { 72 return m_checkpointDatabase->GetDataFieldMultiValue(m_checkpointId, dataType, fieldName); 73 } 74 75 private: 76 Checkpoint(std::shared_ptr<AppInstaller::Repository::Microsoft::CheckpointDatabase> checkpointDatabase, AppInstaller::Repository::Microsoft::CheckpointDatabase::IdType checkpointId) : 77 m_checkpointDatabase(checkpointDatabase), m_checkpointId(checkpointId){}; 78 79 AppInstaller::Repository::Microsoft::CheckpointDatabase::IdType m_checkpointId; 80 std::shared_ptr<CheckpointDatabase> m_checkpointDatabase; 81 }; 82 }