diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2b6d34c7b4..b537d79578 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -345,7 +345,7 @@ jobs: testSelector: 'testAssemblies' testAssemblyVer2: '**\Microsoft.Management.Configuration.UnitTests.dll' searchFolder: '$(buildOutDir)\Microsoft.Management.Configuration.UnitTests' - codeCoverageEnabled: true + codeCoverageEnabled: false platform: '$(buildPlatform)' configuration: '$(BuildConfiguration)' diagnosticsEnabled: true diff --git a/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.cpp b/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.cpp index 215ac30e52..a73bd5496a 100644 --- a/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.cpp +++ b/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.cpp @@ -28,7 +28,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation // TODO: Consider having the version/uri/type information all together in the future if (schemaVersion.PartAt(0).Integer == 0 && schemaVersion.PartAt(1).Integer == 1) { - throw E_NOTIMPL; + THROW_HR(E_NOTIMPL); } else if (schemaVersion.PartAt(0).Integer == 0 && schemaVersion.PartAt(1).Integer == 2) { @@ -36,22 +36,31 @@ namespace winrt::Microsoft::Management::Configuration::implementation } else if (schemaVersion.PartAt(0).Integer == 0 && schemaVersion.PartAt(1).Integer == 3) { - throw E_NOTIMPL; + THROW_HR(E_NOTIMPL); } else { AICLI_LOG(Config, Error, << "Unknown configuration version: " << schemaVersion.ToString()); - throw E_UNEXPECTED; + THROW_HR(E_UNEXPECTED); } } - void ConfigurationSetSerializer::WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet) + void ConfigurationSetSerializer::WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet, std::initializer_list exclusions) { + // Create a sorted list of the field names to exclude + std::vector exclusionStrings; + for (ConfigurationField field : exclusions) + { + exclusionStrings.emplace_back(GetConfigurationFieldNameHString(field)); + } + std::sort(exclusionStrings.begin(), exclusionStrings.end()); + emitter << BeginMap; for (const auto& [key, value] : valueSet) { - if (value != nullptr) + if (value != nullptr && + !std::binary_search(exclusionStrings.begin(), exclusionStrings.end(), key)) { std::string keyName = winrt::to_string(key); emitter << Key << keyName << Value; diff --git a/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.h b/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.h index 3c7e94223f..5dea31e523 100644 --- a/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.h +++ b/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.h @@ -2,9 +2,11 @@ // Licensed under the MIT License. #pragma once #include "ConfigurationSetSerializer.h" +#include "ConfigurationSetUtilities.h" #include "ConfigurationSet.h" #include +#include namespace winrt::Microsoft::Management::Configuration::implementation { @@ -26,7 +28,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation ConfigurationSetSerializer() = default; void WriteYamlConfigurationUnits(AppInstaller::YAML::Emitter& emitter, const std::vector& units); - void WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet); + void WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet, std::initializer_list exclusions = {}); void WriteYamlValue(AppInstaller::YAML::Emitter& emitter, const winrt::Windows::Foundation::IInspectable& value); void WriteYamlValueSetAsArray(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSetArray); winrt::hstring GetSchemaVersionComment(winrt::hstring version); diff --git a/src/Microsoft.Management.Configuration/ConfigurationSetSerializer_0_2.cpp b/src/Microsoft.Management.Configuration/ConfigurationSetSerializer_0_2.cpp index 1d7293f88e..aafc1a8c41 100644 --- a/src/Microsoft.Management.Configuration/ConfigurationSetSerializer_0_2.cpp +++ b/src/Microsoft.Management.Configuration/ConfigurationSetSerializer_0_2.cpp @@ -73,15 +73,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation void ConfigurationSetSerializer_0_2::WriteResourceDirectives(AppInstaller::YAML::Emitter& emitter, const ConfigurationUnit& unit) { - auto metadata = unit.Metadata(); - - const auto moduleKey = GetConfigurationFieldNameHString(ConfigurationField::ModuleDirective); - if (metadata.HasKey(moduleKey)) - { - metadata.Remove(moduleKey); - } - emitter << Key << GetConfigurationFieldName(ConfigurationField::Directives); - WriteYamlValueSet(emitter, metadata); + WriteYamlValueSet(emitter, unit.Metadata(), { ConfigurationField::ModuleDirective }); } }