PackageCatalogProgress.h (3550B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "AppInstallerProgress.h" 5 #include <unordered_map> 6 #include <functional> 7 8 namespace winrt::Microsoft::Management::Deployment 9 { 10 namespace ProgressSinkFactory 11 { 12 /// <summary> 13 /// Creates a progress sink for package catalog operations based on sourceType. 14 /// </summary> 15 /// <param name="sourceType">sourceType.</param> 16 /// <param name="progressReporter">callback function that reports progress to caller.</param> 17 /// <param name="removeOperation"> Default value is false. Identifies if the operation is a PackageCatalog removal and requests the ProgressSink.</param> 18 /// <returns>IProgressSink.</returns> 19 std::shared_ptr<AppInstaller::IProgressSink> CreatePackageCatalogProgressSink(std::string sourceType, std::function<void(double)> progressReporter, bool removeOperation = false); 20 } 21 22 /// <summary> 23 /// Progress sink that only reports start and completion to caller. 24 /// </summary> 25 struct CompletionOnlyProgressSink : AppInstaller::IProgressSink 26 { 27 /// <summary> 28 /// Constructor. 29 /// </summary> 30 /// <param name="progressReporter">callback that reports progress to caller.</param> 31 CompletionOnlyProgressSink(std::function<void(double)> progressReporter); 32 33 void OnProgress(uint64_t current, uint64_t maximum, AppInstaller::ProgressType type) override; 34 void SetProgressMessage(std::string_view message) override; 35 void BeginProgress() override; 36 void EndProgress(bool hideProgressWhenDone) override; 37 38 private: 39 std::function<void(double)> m_progressReporter; 40 }; 41 42 /// <summary> 43 /// Progress sink for pre-indexed package catalog operations. 44 /// capable of reporting progress for download and installation of index. 45 /// Add/update operation has two progress types: Bytes for downloading index and Percent for index installation. 46 /// Remove operation has only percentage based progress. 47 /// </summary> 48 struct PreIndexedPackageCatalogProgressSink : AppInstaller::IProgressSink 49 { 50 /// <summary> 51 /// Constructor. 52 /// </summary> 53 /// <param name="progressWeights">ProgressType weight map.</param> 54 /// <param name="progressReporter">Callback function that reports progress to caller.</param> 55 PreIndexedPackageCatalogProgressSink(std::vector<std::pair<AppInstaller::ProgressType, double>> progressWeights, std::function<void(double)> progressReporter); 56 57 /// <summary> 58 /// Reports combined progress to caller when configured for multiple progress types. 59 /// </summary> 60 /// <param name="current">The current progress value.</param> 61 /// <param name="maximum">The maximum progress value.</param> 62 /// <param name="type">ProgressType for which progress is applicable.</param> 63 void OnProgress(uint64_t current, uint64_t maximum, AppInstaller::ProgressType type) override; 64 void SetProgressMessage(std::string_view message) override; 65 void BeginProgress() override; 66 void EndProgress(bool hideProgressWhenDone) override; 67 68 private: 69 std::vector<std::pair<AppInstaller::ProgressType, double>> m_progressWeights; 70 std::function<void(double)> m_progressReporter; 71 std::unordered_map<AppInstaller::ProgressType, double> m_progressValues; 72 }; 73 }