winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 721c81ff47c12c454c4e8d973701b7899f2f22ef
parent 8ee3db1188140b6cb71ca1b2f2328016b7470092
Author: JohnMcPMS <johnmcp@microsoft.com>
Date:   Tue,  5 Sep 2023 14:05:44 -0700

Update configuration interface for future design changes (#3584)

To better fit with future plans, the configuration interface is being updated to align.  This is mostly some name changing, but also includes a few type adjustments to better fit with a future update.
Diffstat:
M.github/actions/spelling/expect.txt | 2++
Msrc/AppInstallerCLICore/Commands/DebugCommand.cpp | 8++++----
Msrc/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp | 44++++++++++++++++++++++----------------------
Msrc/AppInstallerCLIPackage/Package.appxmanifest | 8++++----
Msrc/AppInstallerCLITests/TestConfiguration.cpp | 18+++++++++---------
Msrc/AppInstallerCLITests/TestConfiguration.h | 31+++++++++++++++++--------------
Msrc/Microsoft.Management.Configuration.Processor/Helpers/ConfigurationUnitAndResource.cs | 10+---------
Msrc/Microsoft.Management.Configuration.Processor/Helpers/ConfigurationUnitInternal.cs | 28+++++-----------------------
Msrc/Microsoft.Management.Configuration.Processor/ProcessorEnvironments/HostedEnvironment.cs | 4++--
Msrc/Microsoft.Management.Configuration.Processor/Set/ConfigurationSetProcessor.cs | 14++++++--------
Msrc/Microsoft.Management.Configuration.Processor/Unit/ApplySettingsResult.cs | 14++++++++++++++
Msrc/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessor.cs | 11+++--------
Msrc/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessorDetails.cs | 4++--
Msrc/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitSettingDetails.cs | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Msrc/Microsoft.Management.Configuration.Processor/Unit/GetSettingsResult.cs | 14++++++++++++++
Msrc/Microsoft.Management.Configuration.Processor/Unit/TestSettingsResult.cs | 14++++++++++++++
Msrc/Microsoft.Management.Configuration.UnitTests/Helpers/ApplySettingsResultInstance.cs | 14++++++++++++++
Msrc/Microsoft.Management.Configuration.UnitTests/Helpers/GetSettingsResultInstance.cs | 14++++++++++++++
Msrc/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationSetProcessor.cs | 5++---
Msrc/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessor.cs | 17+++--------------
Msrc/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessorDetails.cs | 2+-
Msrc/Microsoft.Management.Configuration.UnitTests/Helpers/TestSettingsResultInstance.cs | 14++++++++++++++
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationDetailsTests.cs | 42+++++++++++++++++++++---------------------
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationProcessorApplyTests.cs | 30+++++++++++++++---------------
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationProcessorTelemetryTests.cs | 6+++---
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationProcessorTestTests.cs | 18+++++++++---------
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationSetAuthoringTests.cs | 18+++++++++---------
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationSetProcessorTests.cs | 142++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationUnitInternalTests.cs | 35+++++++++++------------------------
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationUnitProcessorTests.cs | 5++---
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/OpenConfigurationSetTests.cs | 36+++++++++++++++++-------------------
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/ProcessorGetTests.cs | 8++++----
Msrc/Microsoft.Management.Configuration/ConfigurationProcessor.cpp | 10+++++-----
Msrc/Microsoft.Management.Configuration/ConfigurationSet.cpp | 20+++++++-------------
Msrc/Microsoft.Management.Configuration/ConfigurationSet.h | 9+++------
Msrc/Microsoft.Management.Configuration/ConfigurationSetApplyProcessor.cpp | 6+++---
Msrc/Microsoft.Management.Configuration/ConfigurationSetParser_0_1.cpp | 5++---
Msrc/Microsoft.Management.Configuration/ConfigurationSetParser_0_2.cpp | 10+++++-----
Msrc/Microsoft.Management.Configuration/ConfigurationUnit.cpp | 77+++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/Microsoft.Management.Configuration/ConfigurationUnit.h | 29++++++++++++-----------------
Msrc/Microsoft.Management.Configuration/Microsoft.Management.Configuration.idl | 114+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Msrc/Microsoft.Management.Configuration/Microsoft.Management.Configuration.vcxproj | 2--
Msrc/Microsoft.Management.Configuration/Microsoft.Management.Configuration.vcxproj.filters | 6------
Dsrc/Microsoft.Management.Configuration/MutableFlag.cpp | 12------------
Dsrc/Microsoft.Management.Configuration/MutableFlag.h | 22----------------------
Msrc/Microsoft.Management.Configuration/Telemetry/Telemetry.cpp | 2+-
Msrc/PowerShell/Microsoft.WinGet.Configuration.Engine/Commands/ConfigurationCommand.cs | 6+++---
Msrc/PowerShell/Microsoft.WinGet.Configuration.Engine/Helpers/ApplyConfigurationSetProgressOutput.cs | 2+-
Msrc/PowerShell/Microsoft.WinGet.Configuration.Engine/Helpers/ConfigurationUnitInformation.cs | 8++++----
Msrc/PowerShell/Microsoft.WinGet.Configuration.Engine/Helpers/GetConfigurationSetDetailsProgressOutput.cs | 2+-
50 files changed, 534 insertions(+), 509 deletions(-)

diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt @@ -98,6 +98,7 @@ cswinrt ctc currentuser DACL +datetimeoffset Dbg debian deigh @@ -453,6 +454,7 @@ testdata testexampleinstaller thiscouldbeapc threehundred +timespan timezone Tlg tombstoned diff --git a/src/AppInstallerCLICore/Commands/DebugCommand.cpp b/src/AppInstallerCLICore/Commands/DebugCommand.cpp @@ -84,13 +84,13 @@ namespace AppInstaller::CLI void DumpProxyStubRegistrationsCommand::ExecuteInternal(Execution::Context& context) const { + OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::ConfigurationUnit>>(context); + OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::ConfigurationSet>>(context); OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::ConfigurationConflict>>(context); - OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::ApplyConfigurationUnitResult>>(context); + OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::IConfigurationUnitSettingDetails>>(context); OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::ConfigurationConflictSetting>>(context); - OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::ConfigurationSet>>(context); - OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::ConfigurationUnit>>(context); OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::GetConfigurationUnitDetailsResult>>(context); - OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::IConfigurationUnitSettingDetails>>(context); + OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::ApplyConfigurationUnitResult>>(context); OutputProxyStubInterfaceRegistration<winrt::Windows::Foundation::Collections::IIterable<winrt::Microsoft::Management::Configuration::TestConfigurationUnitResult>>(context); // TODO: Fix the layering inversion created by the COM deployment API (probably in order to operate winget.exe against the COM server). diff --git a/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp b/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp @@ -260,19 +260,19 @@ namespace AppInstaller::CLI::Workflow void OutputConfigurationUnitInformation(OutputStream& out, const ConfigurationUnit& unit) { IConfigurationUnitProcessorDetails details = unit.Details(); - ValueSet directives = unit.Directives(); + ValueSet metadata = unit.Metadata(); if (details) { // -- Sample output when IConfigurationUnitProcessorDetails present -- - // Intent :: UnitName <from details> [Identifier] + // Intent :: UnitType <from details> [Identifier] // UnitDocumentationUri <if present> // Description <from details first, directives second> // "Module": ModuleName "by" Author / Publisher (IsLocal / ModuleSource) // "Signed by": SigningCertificateChain (leaf subject CN) // PublishedModuleUri / ModuleDocumentationUri <if present> // ModuleDescription - OutputConfigurationUnitHeader(out, unit, details.UnitName()); + OutputConfigurationUnitHeader(out, unit, details.UnitType()); auto unitDocumentationUri = details.UnitDocumentationUri(); if (unitDocumentationUri) @@ -287,7 +287,7 @@ namespace AppInstaller::CLI::Workflow } else { - auto unitDescriptionFromDirectives = GetValueSetString(directives, s_Directive_Description); + auto unitDescriptionFromDirectives = GetValueSetString(metadata, s_Directive_Description); if (unitDescriptionFromDirectives && !unitDescriptionFromDirectives.value().empty()) { out << " "_liv << unitDescriptionFromDirectives.value() << '\n'; @@ -332,18 +332,18 @@ namespace AppInstaller::CLI::Workflow else { // -- Sample output when no IConfigurationUnitProcessorDetails present -- - // Intent :: UnitName <from unit> [identifier] + // Intent :: Type <from unit> [identifier] // Description (from directives) // "Module": module <directive> - OutputConfigurationUnitHeader(out, unit, unit.UnitName()); + OutputConfigurationUnitHeader(out, unit, unit.Type()); - auto description = GetValueSetString(directives, s_Directive_Description); + auto description = GetValueSetString(metadata, s_Directive_Description); if (description && !description.value().empty()) { out << " "_liv << description.value() << '\n'; } - auto module = GetValueSetString(directives, s_Directive_Module); + auto module = GetValueSetString(metadata, s_Directive_Module); if (module && !module.value().empty()) { out << " "_liv << Resource::String::ConfigurationModuleNameOnly(module.value()) << '\n'; @@ -377,7 +377,7 @@ namespace AppInstaller::CLI::Workflow { if (FAILED(resultInformation.ResultCode())) { - AICLI_LOG(Config, Error, << "Failed to get unit details for " << Utility::ConvertToUTF8(unit.UnitName()) << " : 0x" << + AICLI_LOG(Config, Error, << "Failed to get unit details for " << Utility::ConvertToUTF8(unit.Type()) << " : 0x" << Logging::SetHRFormat << resultInformation.ResultCode() << '\n' << Utility::ConvertToUTF8(resultInformation.Description()) << '\n' << Utility::ConvertToUTF8(resultInformation.Details())); } @@ -443,7 +443,7 @@ namespace AppInstaller::CLI::Workflow { std::string description = Utility::Trim(Utility::ConvertToUTF8(resultInformation.Description())); - AICLI_LOG_LARGE_STRING(Config, Error, << "Configuration unit " << Utility::ConvertToUTF8(unit.UnitName()) << "[" << Utility::ConvertToUTF8(unit.Identifier()) << "] failed with code 0x" + AICLI_LOG_LARGE_STRING(Config, Error, << "Configuration unit " << Utility::ConvertToUTF8(unit.Type()) << "[" << Utility::ConvertToUTF8(unit.Identifier()) << "] failed with code 0x" << Logging::SetHRFormat << resultInformation.ResultCode() << " and error message:\n" << description, Utility::ConvertToUTF8(resultInformation.Details())); UnitFailedMessageData messageData = GetUnitFailedData(unit, resultInformation); @@ -665,7 +665,7 @@ namespace AppInstaller::CLI::Workflow break; case ConfigurationUnitState::Skipped: OutputUnitInProgressIfNeeded(unit); - AICLI_LOG(Config, Warning, << "Configuration unit " << Utility::ConvertToUTF8(unit.UnitName()) << "[" << Utility::ConvertToUTF8(unit.Identifier()) << "] was skipped with code 0x" + AICLI_LOG(Config, Warning, << "Configuration unit " << Utility::ConvertToUTF8(unit.Type()) << "[" << Utility::ConvertToUTF8(unit.Identifier()) << "] was skipped with code 0x" << Logging::SetHRFormat << resultInformation.ResultCode()); m_context.Reporter.Warn() << " "_liv << GetUnitSkippedMessage(resultInformation) << std::endl; MarkCompleted(unit); @@ -682,7 +682,7 @@ namespace AppInstaller::CLI::Workflow m_unitsSeen.insert(unitInstance); OutputStream out = m_context.Reporter.Info(); - OutputConfigurationUnitHeader(out, unit, unit.Details() ? unit.Details().UnitName() : unit.UnitName()); + OutputConfigurationUnitHeader(out, unit, unit.Details() ? unit.Details().UnitType() : unit.Type()); } } @@ -740,7 +740,7 @@ namespace AppInstaller::CLI::Workflow { OutputStream info = m_context.Reporter.Info(); - OutputConfigurationUnitHeader(info, unit, unit.Details() ? unit.Details().UnitName() : unit.UnitName()); + OutputConfigurationUnitHeader(info, unit, unit.Details() ? unit.Details().UnitType() : unit.Type()); } switch (testResult) @@ -875,7 +875,7 @@ namespace AppInstaller::CLI::Workflow { ConfigurationContext& configContext = context.Get<Data::ConfigurationContext>(); - if (configContext.Set().ConfigurationUnits().Size() == 0) + if (configContext.Set().Units().Size() == 0) { context.Reporter.Warn() << Resource::String::ConfigurationFileEmpty << std::endl; // This isn't an error termination, but there is no reason to proceed. @@ -954,7 +954,7 @@ namespace AppInstaller::CLI::Workflow } // Handle any units that are NOT in the results (due to an exception part of the way through) - auto allUnits = configContext.Set().ConfigurationUnits(); + auto allUnits = configContext.Set().Units(); for (unitsShown; unitsShown < allUnits.Size(); ++unitsShown) { ConfigurationUnit unit = allUnits.GetAt(unitsShown); @@ -1064,7 +1064,7 @@ namespace AppInstaller::CLI::Workflow { ConfigurationContext& configContext = context.Get<Data::ConfigurationContext>(); - if (configContext.Set().ConfigurationUnits().Size() == 0) + if (configContext.Set().Units().Size() == 0) { context.Reporter.Warn() << Resource::String::ConfigurationFileEmpty << std::endl; // This isn't an error termination, but there is no reason to proceed. @@ -1085,7 +1085,7 @@ namespace AppInstaller::CLI::Workflow ConfigurationUnit unit = unitResult.Unit(); auto out = context.Reporter.Info(); - OutputConfigurationUnitHeader(out, unit, unit.UnitName()); + OutputConfigurationUnitHeader(out, unit, unit.Type()); switch (resultCode) { @@ -1185,7 +1185,7 @@ namespace AppInstaller::CLI::Workflow AICLI_TERMINATE_CONTEXT(getCatalogHR); } - auto units = configContext.Set().ConfigurationUnits(); + auto units = configContext.Set().Units(); auto localUnitResults = getLocalResult ? getLocalResult.UnitResults() : nullptr; if (localUnitResults && units.Size() != localUnitResults.Size()) { @@ -1216,13 +1216,13 @@ namespace AppInstaller::CLI::Workflow if (needsHeader) { auto out = context.Reporter.Info(); - OutputConfigurationUnitHeader(out, unit, unit.UnitName()); + OutputConfigurationUnitHeader(out, unit, unit.Type()); needsHeader = false; foundIssue = true; } }; - if (GetValueSetString(unit.Directives(), s_Directive_Module).value_or(Utility::LocIndString{}).empty()) + if (GetValueSetString(unit.Metadata(), s_Directive_Module).value_or(Utility::LocIndString{}).empty()) { outputHeaderIfNeeded(); context.Reporter.Warn() << " "_liv << Resource::String::ConfigurationUnitModuleNotProvidedWarning << std::endl; @@ -1250,12 +1250,12 @@ namespace AppInstaller::CLI::Workflow } // If not already prerelease, try with prerelease and warn if found - std::optional<bool> allowPrereleaseDirective = GetValueSetBool(unit.Directives(), s_Directive_AllowPrerelease); + std::optional<bool> allowPrereleaseDirective = GetValueSetBool(unit.Metadata(), s_Directive_AllowPrerelease); if (!allowPrereleaseDirective || !allowPrereleaseDirective.value()) { // Check if the configuration unit is prerelease but the author forgot it ConfigurationUnit clone = unit.Copy(); - clone.Directives().Insert(s_Directive_AllowPrerelease, PropertyValue::CreateBoolean(true)); + clone.Metadata().Insert(s_Directive_AllowPrerelease, PropertyValue::CreateBoolean(true)); progressScope = context.Reporter.BeginAsyncProgress(true); progressScope->Callback().SetProgressMessage(gettingDetailString); diff --git a/src/AppInstallerCLIPackage/Package.appxmanifest b/src/AppInstallerCLIPackage/Package.appxmanifest @@ -76,13 +76,13 @@ <Extension Category="windows.activatableClass.proxyStub"> <ProxyStub ClassId="00000355-0000-0000-C000-000000000046"> <Path>Microsoft.Management.Configuration.winmd</Path> + <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.ConfigurationUnit&gt;" InterfaceId="0BB82BF3-EC6D-55DB-B399-08813A4EB204" /> + <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.ConfigurationSet&gt;" InterfaceId="6D54B059-3766-5DC9-81E3-83587EB3A58E" /> <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.ConfigurationConflict&gt;" InterfaceId="41A1F29F-518B-5776-BCF2-E42FC9DDE32A" /> - <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.ApplyConfigurationUnitResult&gt;" InterfaceId="0E2334B9-8431-5A9D-B3AA-62D4FB5B5749" /> + <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.IConfigurationUnitSettingDetails&gt;" InterfaceId="FC91924A-215F-50A7-9AEE-254B4D7A50CB" /> <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.ConfigurationConflictSetting&gt;" InterfaceId="EB1E5A3C-A444-5394-B7B3-F1593937E31E" /> - <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.ConfigurationSet&gt;" InterfaceId="070C1D82-67BC-5F8E-BE2F-F0F66E70E2CE" /> - <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.ConfigurationUnit&gt;" InterfaceId="1E33B829-D292-55A6-A7DB-2903566A0BA0" /> <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.GetConfigurationUnitDetailsResult&gt;" InterfaceId="3A034399-0F2B-51C2-A9C5-4BC6E9940068" /> - <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.IConfigurationUnitSettingDetails&gt;" InterfaceId="9901CFD7-A9E3-5D2A-A79C-72FE20513823" /> + <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.ApplyConfigurationUnitResult&gt;" InterfaceId="0E2334B9-8431-5A9D-B3AA-62D4FB5B5749" /> <Interface Name="Windows.Foundation.Collections.IIterable`1&lt;Microsoft.Management.Configuration.TestConfigurationUnitResult&gt;" InterfaceId="73848262-86D4-5FFC-8353-8408C4E649DE" /> </ProxyStub> </Extension> diff --git a/src/AppInstallerCLITests/TestConfiguration.cpp b/src/AppInstallerCLITests/TestConfiguration.cpp @@ -52,24 +52,24 @@ namespace TestCommon } } - IConfigurationUnitProcessor TestConfigurationSetProcessor::CreateUnitProcessor(const ConfigurationUnit& unit, const IMapView<winrt::hstring, IInspectable>& directivesOverlay) + IConfigurationUnitProcessor TestConfigurationSetProcessor::CreateUnitProcessor(const ConfigurationUnit& unit) { if (CreateUnitProcessorFunc) { - return CreateUnitProcessorFunc(unit, directivesOverlay); + return CreateUnitProcessorFunc(unit); } else { - return winrt::make<TestConfigurationUnitProcessor>(unit, directivesOverlay); + return winrt::make<TestConfigurationUnitProcessor>(unit); } } TestConfigurationUnitProcessorDetails::TestConfigurationUnitProcessorDetails(const ConfigurationUnit& unit) : - UnitNameValue(unit.UnitName()) + UnitTypeValue(unit.Type()) {} - TestConfigurationUnitProcessor::TestConfigurationUnitProcessor(const ConfigurationUnit& unit, const IMapView<winrt::hstring, IInspectable>& directivesOverlay) : - UnitValue(unit), DirectivesOverlayValue(directivesOverlay) + TestConfigurationUnitProcessor::TestConfigurationUnitProcessor(const ConfigurationUnit& unit) : + UnitValue(unit) {} ITestSettingsResult TestConfigurationUnitProcessor::TestSettings() @@ -80,7 +80,7 @@ namespace TestCommon } else { - return winrt::make<TestSettingsResultInstance>(); + return winrt::make<TestSettingsResultInstance>(UnitValue); } } @@ -92,7 +92,7 @@ namespace TestCommon } else { - return winrt::make<GetSettingsResultInstance>(); + return winrt::make<GetSettingsResultInstance>(UnitValue); } } @@ -104,7 +104,7 @@ namespace TestCommon } else { - return winrt::make<ApplySettingsResultInstance>(); + return winrt::make<ApplySettingsResultInstance>(UnitValue); } } } diff --git a/src/AppInstallerCLITests/TestConfiguration.h b/src/AppInstallerCLITests/TestConfiguration.h @@ -36,20 +36,18 @@ namespace TestCommon winrt::Microsoft::Management::Configuration::ConfigurationUnitDetailFlags)> GetUnitProcessorDetailsFunc; winrt::Microsoft::Management::Configuration::IConfigurationUnitProcessor CreateUnitProcessor( - const winrt::Microsoft::Management::Configuration::ConfigurationUnit& unit, - const winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Windows::Foundation::IInspectable>& directivesOverlay); + const winrt::Microsoft::Management::Configuration::ConfigurationUnit& unit); std::function<winrt::Microsoft::Management::Configuration::IConfigurationUnitProcessor( - const winrt::Microsoft::Management::Configuration::ConfigurationUnit&, - const winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Windows::Foundation::IInspectable>&)> CreateUnitProcessorFunc; + const winrt::Microsoft::Management::Configuration::ConfigurationUnit&)> CreateUnitProcessorFunc; }; struct TestConfigurationUnitProcessorDetails : winrt::implements<TestConfigurationUnitProcessorDetails, winrt::Microsoft::Management::Configuration::IConfigurationUnitProcessorDetails> { TestConfigurationUnitProcessorDetails(const winrt::Microsoft::Management::Configuration::ConfigurationUnit& unit); - winrt::hstring UnitNameValue; - winrt::hstring UnitName() const { return UnitNameValue; } + winrt::hstring UnitTypeValue; + winrt::hstring UnitType() const { return UnitTypeValue; } winrt::hstring UnitDescriptionValue; winrt::hstring UnitDescription() const { return UnitDescriptionValue; } @@ -106,15 +104,11 @@ namespace TestCommon struct TestConfigurationUnitProcessor : winrt::implements<TestConfigurationUnitProcessor, winrt::Microsoft::Management::Configuration::IConfigurationUnitProcessor> { TestConfigurationUnitProcessor( - const winrt::Microsoft::Management::Configuration::ConfigurationUnit& unit, - const winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Windows::Foundation::IInspectable>& directivesOverlay); + const winrt::Microsoft::Management::Configuration::ConfigurationUnit& unit); winrt::Microsoft::Management::Configuration::ConfigurationUnit UnitValue; winrt::Microsoft::Management::Configuration::ConfigurationUnit Unit() { return UnitValue; } - winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Windows::Foundation::IInspectable> DirectivesOverlayValue; - winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Windows::Foundation::IInspectable> DirectivesOverlay() { return DirectivesOverlayValue; } - winrt::Microsoft::Management::Configuration::ITestSettingsResult TestSettings(); std::function<winrt::Microsoft::Management::Configuration::ITestSettingsResult()> TestSettingsFunc; @@ -130,7 +124,9 @@ namespace TestCommon struct TestSettingsResultInstance : winrt::implements<TestSettingsResultInstance, winrt::Microsoft::Management::Configuration::ITestSettingsResult> { - TestSettingsResultInstance() = default; + TestSettingsResultInstance(const winrt::Microsoft::Management::Configuration::ConfigurationUnit& unit) : m_unit(unit) {} + + winrt::Microsoft::Management::Configuration::ConfigurationUnit Unit() { return m_unit; } winrt::Microsoft::Management::Configuration::ConfigurationTestResult TestResult() { return m_testResult; } void TestResult(winrt::Microsoft::Management::Configuration::ConfigurationTestResult value) { m_testResult = value; } @@ -139,13 +135,16 @@ namespace TestCommon void ResultInformation(winrt::Microsoft::Management::Configuration::IConfigurationUnitResultInformation value) { m_resultInformation = value; } private: + winrt::Microsoft::Management::Configuration::ConfigurationUnit m_unit; winrt::Microsoft::Management::Configuration::ConfigurationTestResult m_testResult = winrt::Microsoft::Management::Configuration::ConfigurationTestResult::Unknown; winrt::Microsoft::Management::Configuration::IConfigurationUnitResultInformation m_resultInformation; }; struct ApplySettingsResultInstance : winrt::implements<ApplySettingsResultInstance, winrt::Microsoft::Management::Configuration::IApplySettingsResult> { - ApplySettingsResultInstance() = default; + ApplySettingsResultInstance(const winrt::Microsoft::Management::Configuration::ConfigurationUnit& unit) : m_unit(unit) {} + + winrt::Microsoft::Management::Configuration::ConfigurationUnit Unit() { return m_unit; } bool RebootRequired() { return m_rebootRequired; } void RebootRequired(bool value) { m_rebootRequired = value; } @@ -154,13 +153,16 @@ namespace TestCommon void ResultInformation(winrt::Microsoft::Management::Configuration::IConfigurationUnitResultInformation value) { m_resultInformation = value; } private: + winrt::Microsoft::Management::Configuration::ConfigurationUnit m_unit; bool m_rebootRequired = false; winrt::Microsoft::Management::Configuration::IConfigurationUnitResultInformation m_resultInformation; }; struct GetSettingsResultInstance : winrt::implements<GetSettingsResultInstance, winrt::Microsoft::Management::Configuration::IGetSettingsResult> { - GetSettingsResultInstance() = default; + GetSettingsResultInstance(const winrt::Microsoft::Management::Configuration::ConfigurationUnit& unit) : m_unit(unit) {} + + winrt::Microsoft::Management::Configuration::ConfigurationUnit Unit() { return m_unit; } winrt::Windows::Foundation::Collections::ValueSet Settings() { return m_settings; } void Settings(winrt::Windows::Foundation::Collections::ValueSet value) { m_settings = value; } @@ -169,6 +171,7 @@ namespace TestCommon void ResultInformation(winrt::Microsoft::Management::Configuration::IConfigurationUnitResultInformation value) { m_resultInformation = value; } private: + winrt::Microsoft::Management::Configuration::ConfigurationUnit m_unit; winrt::Windows::Foundation::Collections::ValueSet m_settings; winrt::Microsoft::Management::Configuration::IConfigurationUnitResultInformation m_resultInformation; }; diff --git a/src/Microsoft.Management.Configuration.Processor/Helpers/ConfigurationUnitAndResource.cs b/src/Microsoft.Management.Configuration.Processor/Helpers/ConfigurationUnitAndResource.cs @@ -29,7 +29,7 @@ namespace Microsoft.Management.Configuration.Processor.Helpers ConfigurationUnitInternal configurationUnitInternal, DscResourceInfoInternal dscResourceInfoInternal) { - if (configurationUnitInternal.Unit.UnitName != dscResourceInfoInternal.Name) + if (configurationUnitInternal.Unit.Type != dscResourceInfoInternal.Name) { throw new ArgumentException(); } @@ -52,14 +52,6 @@ namespace Microsoft.Management.Configuration.Processor.Helpers } /// <summary> - /// Gets the directives overlay. - /// </summary> - public IReadOnlyDictionary<string, object>? DirectivesOverlay - { - get { return this.UnitInternal.DirectivesOverlay; } - } - - /// <summary> /// Gets the DSC resource name. /// </summary> /// <returns>DSC resource name.</returns> diff --git a/src/Microsoft.Management.Configuration.Processor/Helpers/ConfigurationUnitInternal.cs b/src/Microsoft.Management.Configuration.Processor/Helpers/ConfigurationUnitInternal.cs @@ -30,14 +30,11 @@ namespace Microsoft.Management.Configuration.Processor.Helpers /// </summary> /// <param name="unit">Configuration unit.</param> /// <param name="configurationFilePath">The configuration file path.</param> - /// <param name="directivesOverlay">Directives overlay.</param> public ConfigurationUnitInternal( ConfigurationUnit unit, - string configurationFilePath, - IReadOnlyDictionary<string, object>? directivesOverlay = null) + string configurationFilePath) { this.Unit = unit; - this.DirectivesOverlay = directivesOverlay; this.InitializeDirectives(); string? moduleName = this.GetDirective<string>(DirectiveConstants.Module); @@ -72,11 +69,6 @@ namespace Microsoft.Management.Configuration.Processor.Helpers public ConfigurationUnit Unit { get; } /// <summary> - /// Gets the directives overlay. - /// </summary> - public IReadOnlyDictionary<string, object>? DirectivesOverlay { get; } - - /// <summary> /// Gets the module specification. /// </summary> public ModuleSpecification? Module { get; } @@ -87,7 +79,7 @@ namespace Microsoft.Management.Configuration.Processor.Helpers /// <returns>The string that identifies this unit for diagnostics.</returns> public string ToIdentifyingString() { - return $"{this.Unit.UnitName} [{this.Module?.ToString() ?? "<no module>"}]"; + return $"{this.Unit.Type} [{this.Module?.ToString() ?? "<no module>"}]"; } /// <summary> @@ -205,7 +197,7 @@ namespace Microsoft.Management.Configuration.Processor.Helpers { if (string.IsNullOrEmpty(this.configurationFileRootPath)) { - throw new UnitSettingConfigRootException(this.Unit.UnitName, settingName); + throw new UnitSettingConfigRootException(this.Unit.Type, settingName); } if (this.configurationFileRootPath == null) @@ -222,20 +214,10 @@ namespace Microsoft.Management.Configuration.Processor.Helpers private void InitializeDirectives() { - // Overlay directives have precedence. - if (this.DirectivesOverlay is not null) - { - foreach (var directive in this.DirectivesOverlay) - { - var normalizedKey = StringHelpers.Normalize(directive.Key); - this.normalizedDirectives.Add(normalizedKey, directive.Value); - } - } - - foreach (var directive in this.Unit.Directives) + foreach (var directive in this.Unit.Metadata) { var normalizedKey = StringHelpers.Normalize(directive.Key); - _ = this.normalizedDirectives.TryAdd(normalizedKey, directive.Value); + this.normalizedDirectives.Add(normalizedKey, directive.Value); } } } diff --git a/src/Microsoft.Management.Configuration.Processor/ProcessorEnvironments/HostedEnvironment.cs b/src/Microsoft.Management.Configuration.Processor/ProcessorEnvironments/HostedEnvironment.cs @@ -131,7 +131,7 @@ namespace Microsoft.Management.Configuration.Processor.Runspaces public DscResourceInfoInternal? GetDscResource(ConfigurationUnitInternal unitInternal) { using PowerShell pwsh = PowerShell.Create(this.Runspace); - var result = this.DscModule.GetDscResource(pwsh, unitInternal.Unit.UnitName, unitInternal.Module); + var result = this.DscModule.GetDscResource(pwsh, unitInternal.Unit.Type, unitInternal.Module); this.OnDiagnostics(DiagnosticLevel.Verbose, pwsh); return result; } @@ -298,7 +298,7 @@ namespace Microsoft.Management.Configuration.Processor.Runspaces var result = this.powerShellGet.FindDscResource( pwsh, - unitInternal.Unit.UnitName, + unitInternal.Unit.Type, unitInternal.GetDirective<string>(DirectiveConstants.Module), unitInternal.GetSemanticVersion(), unitInternal.GetSemanticMinVersion(), diff --git a/src/Microsoft.Management.Configuration.Processor/Set/ConfigurationSetProcessor.cs b/src/Microsoft.Management.Configuration.Processor/Set/ConfigurationSetProcessor.cs @@ -50,15 +50,13 @@ namespace Microsoft.Management.Configuration.Processor.Set /// Creates a configuration unit processor for the given unit. /// </summary> /// <param name="unit">Configuration unit.</param> - /// <param name="directivesOverlay">Allows for the ConfigurationProcessor to alter behavior without needing to change the unit itself.</param> /// <returns>A configuration unit processor.</returns> public IConfigurationUnitProcessor CreateUnitProcessor( - ConfigurationUnit unit, - IReadOnlyDictionary<string, object>? directivesOverlay) + ConfigurationUnit unit) { try { - var configurationUnitInternal = new ConfigurationUnitInternal(unit, this.configurationSet.Path, directivesOverlay); + var configurationUnitInternal = new ConfigurationUnitInternal(unit, this.configurationSet.Path); this.OnDiagnostics(DiagnosticLevel.Verbose, $"Creating unit processor for: {configurationUnitInternal.ToIdentifyingString()}..."); var dscResourceInfo = this.PrepareUnitForProcessing(configurationUnitInternal); @@ -162,7 +160,7 @@ namespace Microsoft.Management.Configuration.Processor.Set { // Well, this is awkward. throw new InstallDscResourceException( - unit.UnitName, + unit.Type, PowerShellHelpers.CreateModuleSpecification(foundModuleInfo.Name, foundModuleInfo.Version)); } @@ -195,7 +193,7 @@ namespace Microsoft.Management.Configuration.Processor.Set foundModule = this.ProcessorEnvironment.FindModule(unitInternal); if (foundModule != null) { - resourceName = unitInternal.Unit.UnitName; + resourceName = unitInternal.Unit.Type; } } else @@ -238,7 +236,7 @@ namespace Microsoft.Management.Configuration.Processor.Set if (findUnitModuleResult is null) { - throw new FindDscResourceNotFoundException(unitInternal.Unit.UnitName, unitInternal.Module); + throw new FindDscResourceNotFoundException(unitInternal.Unit.Type, unitInternal.Module); } this.ProcessorEnvironment.InstallModule(findUnitModuleResult.Value.Module); @@ -247,7 +245,7 @@ namespace Microsoft.Management.Configuration.Processor.Set dscResourceInfo = this.ProcessorEnvironment.GetDscResource(unitInternal); if (dscResourceInfo is null) { - throw new InstallDscResourceException(unitInternal.Unit.UnitName, unitInternal.Module); + throw new InstallDscResourceException(unitInternal.Unit.Type, unitInternal.Module); } } diff --git a/src/Microsoft.Management.Configuration.Processor/Unit/ApplySettingsResult.cs b/src/Microsoft.Management.Configuration.Processor/Unit/ApplySettingsResult.cs @@ -13,6 +13,20 @@ namespace Microsoft.Management.Configuration.Processor.Unit /// </summary> internal sealed class ApplySettingsResult : IApplySettingsResult { + /// <summary> + /// Initializes a new instance of the <see cref="ApplySettingsResult"/> class. + /// </summary> + /// <param name="unit">The configuration unit that the result is for.</param> + public ApplySettingsResult(ConfigurationUnit unit) + { + this.Unit = unit; + } + + /// <summary> + /// Gets the configuration unit that the result is for. + /// </summary> + public ConfigurationUnit Unit { get; private set; } + /// <inheritdoc/> public IConfigurationUnitResultInformation ResultInformation { diff --git a/src/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessor.cs b/src/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessor.cs @@ -41,11 +41,6 @@ namespace Microsoft.Management.Configuration.Processor.Unit public ConfigurationUnit Unit => this.unitResource.Unit; /// <summary> - /// Gets the directives overlay that the processor was created with. - /// </summary> - public IReadOnlyDictionary<string, object>? DirectivesOverlay => this.unitResource.DirectivesOverlay; - - /// <summary> /// Gets or initializes the set processor factory. /// </summary> internal PowerShellConfigurationSetProcessorFactory? SetProcessorFactory { get; init; } @@ -59,7 +54,7 @@ namespace Microsoft.Management.Configuration.Processor.Unit { this.OnDiagnostics(DiagnosticLevel.Verbose, $"Invoking `Get` for resource: {this.unitResource.UnitInternal.ToIdentifyingString()}..."); - var result = new GetSettingsResult(); + var result = new GetSettingsResult(this.Unit); try { @@ -92,7 +87,7 @@ namespace Microsoft.Management.Configuration.Processor.Unit throw new NotSupportedException(); } - var result = new TestSettingsResult(); + var result = new TestSettingsResult(this.Unit); result.TestResult = ConfigurationTestResult.Failed; try { @@ -128,7 +123,7 @@ namespace Microsoft.Management.Configuration.Processor.Unit throw new NotSupportedException(); } - var result = new ApplySettingsResult(); + var result = new ApplySettingsResult(this.Unit); try { result.RebootRequired = this.processorEnvironment.InvokeSetResource( diff --git a/src/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessorDetails.cs b/src/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessorDetails.cs @@ -47,7 +47,7 @@ namespace Microsoft.Management.Configuration.Processor.Unit throw new ArgumentException(); } - this.UnitName = unitName; + this.UnitType = unitName; if (dscResourceInfo is not null) { @@ -114,7 +114,7 @@ namespace Microsoft.Management.Configuration.Processor.Unit /// <summary> /// Gets the name of the unit of configuration. /// </summary> - public string UnitName { get; private set; } + public string UnitType { get; private set; } /// <summary> /// Gets the description of the unit of configuration. diff --git a/src/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitSettingDetails.cs b/src/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitSettingDetails.cs @@ -8,6 +8,7 @@ namespace Microsoft.Management.Configuration.Processor.Unit { using Microsoft.Management.Configuration; using Microsoft.Management.Configuration.Processor.DscResourcesInfo; + using Windows.Foundation.Metadata; /// <summary> /// Provides information for a specific configuration unit setting. @@ -20,31 +21,30 @@ namespace Microsoft.Management.Configuration.Processor.Unit /// <param name="dscResourceInfo">DSC Resource info.</param> public ConfigurationUnitSettingDetails(DscResourcePropertyInfoInternal dscResourceInfo) { - this.Name = dscResourceInfo.Name; + this.Identifier = dscResourceInfo.Name; this.IsRequired = dscResourceInfo.IsMandatory; - this.Type = dscResourceInfo.PropertyType; - this.Semantics = string.Join(", ", dscResourceInfo.Values.ToArray()); - - // We don't have this information right now. - this.Description = null; - this.IsKey = false; - this.IsInformational = false; + this.Type = GetPropertyType(dscResourceInfo.PropertyType); } /// <summary> /// Gets the name of the setting. /// </summary> - public string Name { get; } + public string Identifier { get; } + + /// <summary> + /// Gets the title of the setting. + /// </summary> + public string Title { get; } = string.Empty; /// <summary> /// Gets the description of the setting. /// </summary> - public string? Description { get; } + public string Description { get; } = string.Empty; /// <summary> /// Gets a value indicating whether the setting is a key. This is used to determine if different settings are in conflict. /// </summary> - public bool IsKey { get; } + public bool IsKey { get; } = false; /// <summary> /// Gets a value indicating whether a non-empty value for the setting is required. @@ -54,17 +54,60 @@ namespace Microsoft.Management.Configuration.Processor.Unit /// <summary> /// Gets a value indicating whether the setting should be serialized in order to be applied on another system. /// </summary> - public bool IsInformational { get; } + public bool IsInformational { get; } = false; /// <summary> /// Gets the data type for the value of this setting. /// </summary> - public string Type { get; } + public Windows.Foundation.PropertyType Type { get; } /// <summary> /// Gets the semantics to be used for this setting. The goal is to enable richer conflict detection and authoring /// scenarios by having a deeper understanding of this value than "String". /// </summary> - public string? Semantics { get; } + public string Schema { get; } = string.Empty; + + private static Windows.Foundation.PropertyType GetPropertyType(string propertyType) + { + switch (propertyType.ToLowerInvariant()) + { + case "[byte]": return Windows.Foundation.PropertyType.UInt8; + case "[int16]": return Windows.Foundation.PropertyType.Int16; + case "[uint16]": return Windows.Foundation.PropertyType.UInt16; + case "[int32]": return Windows.Foundation.PropertyType.Int32; + case "[uint32]": return Windows.Foundation.PropertyType.UInt32; + case "[int64]": return Windows.Foundation.PropertyType.Int64; + case "[uint64]": return Windows.Foundation.PropertyType.UInt64; + case "[single]": return Windows.Foundation.PropertyType.Single; + case "[double]": return Windows.Foundation.PropertyType.Double; + case "[char]": return Windows.Foundation.PropertyType.Char16; + case "[bool]": return Windows.Foundation.PropertyType.Boolean; + case "[string]": return Windows.Foundation.PropertyType.String; + case "[datetime]": return Windows.Foundation.PropertyType.DateTime; + case "[datetimeoffset]": return Windows.Foundation.PropertyType.DateTime; + case "[timespan]": return Windows.Foundation.PropertyType.TimeSpan; + case "[guid]": return Windows.Foundation.PropertyType.Guid; + case "[byte[]]": return Windows.Foundation.PropertyType.UInt8Array; + case "[int16[]]": return Windows.Foundation.PropertyType.Int16Array; + case "[uint16[]]": return Windows.Foundation.PropertyType.UInt16Array; + case "[int32[]]": return Windows.Foundation.PropertyType.Int32Array; + case "[uint32[]]": return Windows.Foundation.PropertyType.UInt32Array; + case "[int64[]]": return Windows.Foundation.PropertyType.Int64Array; + case "[uint64[]]": return Windows.Foundation.PropertyType.UInt64Array; + case "[single[]]": return Windows.Foundation.PropertyType.SingleArray; + case "[double[]]": return Windows.Foundation.PropertyType.DoubleArray; + case "[char[]]": return Windows.Foundation.PropertyType.Char16Array; + case "[bool[]]": return Windows.Foundation.PropertyType.BooleanArray; + case "[string[]]": return Windows.Foundation.PropertyType.StringArray; + case "[object[]]": return Windows.Foundation.PropertyType.InspectableArray; + case "[datetime[]]": return Windows.Foundation.PropertyType.DateTimeArray; + case "[datetimeoffset[]]": return Windows.Foundation.PropertyType.DateTimeArray; + case "[timespan[]]": return Windows.Foundation.PropertyType.TimeSpanArray; + case "[guid[]]": return Windows.Foundation.PropertyType.GuidArray; + + // Everything else will just be an object... + default: return Windows.Foundation.PropertyType.Inspectable; + } + } } } diff --git a/src/Microsoft.Management.Configuration.Processor/Unit/GetSettingsResult.cs b/src/Microsoft.Management.Configuration.Processor/Unit/GetSettingsResult.cs @@ -14,6 +14,20 @@ namespace Microsoft.Management.Configuration.Processor.Unit /// </summary> internal sealed class GetSettingsResult : IGetSettingsResult { + /// <summary> + /// Initializes a new instance of the <see cref="GetSettingsResult"/> class. + /// </summary> + /// <param name="unit">The configuration unit that the result is for.</param> + public GetSettingsResult(ConfigurationUnit unit) + { + this.Unit = unit; + } + + /// <summary> + /// Gets the configuration unit that the result is for. + /// </summary> + public ConfigurationUnit Unit { get; private set; } + /// <inheritdoc/> public IConfigurationUnitResultInformation ResultInformation { diff --git a/src/Microsoft.Management.Configuration.Processor/Unit/TestSettingsResult.cs b/src/Microsoft.Management.Configuration.Processor/Unit/TestSettingsResult.cs @@ -13,6 +13,20 @@ namespace Microsoft.Management.Configuration.Processor.Unit /// </summary> internal sealed class TestSettingsResult : ITestSettingsResult { + /// <summary> + /// Initializes a new instance of the <see cref="TestSettingsResult"/> class. + /// </summary> + /// <param name="unit">The configuration unit that the result is for.</param> + public TestSettingsResult(ConfigurationUnit unit) + { + this.Unit = unit; + } + + /// <summary> + /// Gets the configuration unit that the result is for. + /// </summary> + public ConfigurationUnit Unit { get; private set; } + /// <inheritdoc/> public IConfigurationUnitResultInformation ResultInformation { diff --git a/src/Microsoft.Management.Configuration.UnitTests/Helpers/ApplySettingsResultInstance.cs b/src/Microsoft.Management.Configuration.UnitTests/Helpers/ApplySettingsResultInstance.cs @@ -13,6 +13,20 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers /// </summary> internal sealed class ApplySettingsResultInstance : IApplySettingsResult { + /// <summary> + /// Initializes a new instance of the <see cref="ApplySettingsResultInstance"/> class. + /// </summary> + /// <param name="unit">The configuration unit that the result is for.</param> + public ApplySettingsResultInstance(ConfigurationUnit unit) + { + this.Unit = unit; + } + + /// <summary> + /// Gets the configuration unit that the result is for. + /// </summary> + public ConfigurationUnit Unit { get; private set; } + /// <inheritdoc/> public IConfigurationUnitResultInformation ResultInformation { diff --git a/src/Microsoft.Management.Configuration.UnitTests/Helpers/GetSettingsResultInstance.cs b/src/Microsoft.Management.Configuration.UnitTests/Helpers/GetSettingsResultInstance.cs @@ -14,6 +14,20 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers /// </summary> internal sealed class GetSettingsResultInstance : IGetSettingsResult { + /// <summary> + /// Initializes a new instance of the <see cref="GetSettingsResultInstance"/> class. + /// </summary> + /// <param name="unit">The configuration unit that the result is for.</param> + public GetSettingsResultInstance(ConfigurationUnit unit) + { + this.Unit = unit; + } + + /// <summary> + /// Gets the configuration unit that the result is for. + /// </summary> + public ConfigurationUnit Unit { get; private set; } + /// <inheritdoc/> public IConfigurationUnitResultInformation ResultInformation { diff --git a/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationSetProcessor.cs b/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationSetProcessor.cs @@ -47,9 +47,8 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers /// Creates a new unit processor for the given unit. /// </summary> /// <param name="unit">The unit.</param> - /// <param name="directivesOverlay">Directives to override those in the unit.</param> /// <returns>The configuration unit processor.</returns> - public IConfigurationUnitProcessor CreateUnitProcessor(ConfigurationUnit unit, IReadOnlyDictionary<string, object> directivesOverlay) + public IConfigurationUnitProcessor CreateUnitProcessor(ConfigurationUnit unit) { if (this.Exceptions.ContainsKey(unit)) { @@ -58,7 +57,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers if (!this.Processors.ContainsKey(unit)) { - this.Processors.Add(unit, new TestConfigurationUnitProcessor(unit, directivesOverlay)); + this.Processors.Add(unit, new TestConfigurationUnitProcessor(unit)); } return this.Processors[unit]; diff --git a/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessor.cs b/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessor.cs @@ -24,17 +24,6 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers } /// <summary> - /// Initializes a new instance of the <see cref="TestConfigurationUnitProcessor"/> class. - /// </summary> - /// <param name="unit">The unit.</param> - /// <param name="directivesOverlay">The directives overlay.</param> - internal TestConfigurationUnitProcessor(ConfigurationUnit unit, IReadOnlyDictionary<string, object> directivesOverlay) - { - this.Unit = unit; - this.DirectivesOverlay = directivesOverlay; - } - - /// <summary> /// The delegate for ApplySettings. /// </summary> /// <returns>The result.</returns> @@ -105,7 +94,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers } else { - return new ApplySettingsResultInstance(); + return new ApplySettingsResultInstance(this.Unit); } } @@ -122,7 +111,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers } else { - return new GetSettingsResultInstance(); + return new GetSettingsResultInstance(this.Unit); } } @@ -139,7 +128,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers } else { - return new TestSettingsResultInstance { TestResult = ConfigurationTestResult.Positive }; + return new TestSettingsResultInstance(this.Unit) { TestResult = ConfigurationTestResult.Positive }; } } } diff --git a/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessorDetails.cs b/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessorDetails.cs @@ -60,7 +60,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers public Uri? UnitIconUri { get; internal set; } - public string? UnitName { get; internal set; } + public string? UnitType { get; internal set; } public string? Version { get; internal set; } diff --git a/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestSettingsResultInstance.cs b/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestSettingsResultInstance.cs @@ -13,6 +13,20 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers /// </summary> internal sealed class TestSettingsResultInstance : ITestSettingsResult { + /// <summary> + /// Initializes a new instance of the <see cref="TestSettingsResultInstance"/> class. + /// </summary> + /// <param name="unit">The configuration unit that the result is for.</param> + public TestSettingsResultInstance(ConfigurationUnit unit) + { + this.Unit = unit; + } + + /// <summary> + /// Gets the configuration unit that the result is for. + /// </summary> + public ConfigurationUnit Unit { get; private set; } + /// <inheritdoc/> public IConfigurationUnitResultInformation ResultInformation { diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationDetailsTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationDetailsTests.cs @@ -98,9 +98,9 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests getModuleInfo = this.CreateGetModuleInfo(); } - var details = new ConfigurationUnitProcessorDetails(unit.UnitName, dscResourceInfoInput, psModuleInfoInput, getModuleInfo, certsInput); + var details = new ConfigurationUnitProcessorDetails(unit.Type, dscResourceInfoInput, psModuleInfoInput, getModuleInfo, certsInput); - Assert.Equal(unit.UnitName, details.UnitName); + Assert.Equal(unit.Type, details.UnitType); if (hasDscInfo) { @@ -110,35 +110,35 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests Assert.NotNull(details.Settings); Assert.True(details.Settings.Count == 5); - var pathSetting = details.Settings.Where(s => s.Name == "Path").FirstOrDefault(); + var pathSetting = details.Settings.Where(s => s.Identifier == "Path").FirstOrDefault(); Assert.NotNull(pathSetting); - Assert.Equal("[string]", pathSetting.Type); + Assert.Equal(Windows.Foundation.PropertyType.String, pathSetting.Type); Assert.True(pathSetting.IsRequired); - Assert.Equal(string.Empty, pathSetting.Semantics); + Assert.Equal(string.Empty, pathSetting.Schema); - var contentSetting = details.Settings.Where(s => s.Name == "Content").FirstOrDefault(); + var contentSetting = details.Settings.Where(s => s.Identifier == "Content").FirstOrDefault(); Assert.NotNull(contentSetting); - Assert.Equal("[string]", contentSetting.Type); + Assert.Equal(Windows.Foundation.PropertyType.String, contentSetting.Type); Assert.False(contentSetting.IsRequired); - Assert.Equal(string.Empty, contentSetting.Semantics); + Assert.Equal(string.Empty, contentSetting.Schema); - var dependsOnSetting = details.Settings.Where(s => s.Name == "DependsOn").FirstOrDefault(); + var dependsOnSetting = details.Settings.Where(s => s.Identifier == "DependsOn").FirstOrDefault(); Assert.NotNull(dependsOnSetting); - Assert.Equal("[string[]]", dependsOnSetting.Type); + Assert.Equal(Windows.Foundation.PropertyType.StringArray, dependsOnSetting.Type); Assert.False(dependsOnSetting.IsRequired); - Assert.Equal(string.Empty, dependsOnSetting.Semantics); + Assert.Equal(string.Empty, dependsOnSetting.Schema); - var ensureSetting = details.Settings.Where(s => s.Name == "Ensure").FirstOrDefault(); + var ensureSetting = details.Settings.Where(s => s.Identifier == "Ensure").FirstOrDefault(); Assert.NotNull(ensureSetting); - Assert.Equal("[string]", ensureSetting.Type); + Assert.Equal(Windows.Foundation.PropertyType.String, ensureSetting.Type); Assert.False(ensureSetting.IsRequired); - Assert.Equal("Absent, Present", ensureSetting.Semantics); + Assert.Equal(string.Empty, ensureSetting.Schema); - var psDscRunAsCredentialSetting = details.Settings.Where(s => s.Name == "PsDscRunAsCredential").FirstOrDefault(); + var psDscRunAsCredentialSetting = details.Settings.Where(s => s.Identifier == "PsDscRunAsCredential").FirstOrDefault(); Assert.NotNull(psDscRunAsCredentialSetting); - Assert.Equal("[PSCredential]", psDscRunAsCredentialSetting.Type); + Assert.Equal(Windows.Foundation.PropertyType.Inspectable, psDscRunAsCredentialSetting.Type); Assert.False(psDscRunAsCredentialSetting.IsRequired); - Assert.Equal(string.Empty, psDscRunAsCredentialSetting.Semantics); + Assert.Equal(string.Empty, psDscRunAsCredentialSetting.Schema); } if (hasPSModuleInfo) @@ -177,9 +177,9 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests private ConfigurationUnit CreateConfigurationUnit() { var unit = new ConfigurationUnit(); - unit.UnitName = "SimpleFileResource"; - unit.Directives.Add("module", "xSimpleTestResource"); - unit.Directives.Add("version", "0.0.0.1"); + unit.Type = "SimpleFileResource"; + unit.Metadata.Add("module", "xSimpleTestResource"); + unit.Metadata.Add("version", "0.0.0.1"); return unit; } @@ -189,7 +189,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests // This is easier than trying to mock sealed class from external code... var testEnv = this.fixture.PrepareTestProcessorEnvironment(true); - var dscResourceInfo = testEnv.GetDscResource(new ConfigurationUnitInternal(unit, string.Empty, null)); + var dscResourceInfo = testEnv.GetDscResource(new ConfigurationUnitInternal(unit, string.Empty)); var psModuleInfo = testEnv.GetAvailableModule(PowerShellHelpers.CreateModuleSpecification("xSimpleTestResource", "0.0.0.1")); if (dscResourceInfo is null || psModuleInfo is null) diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationProcessorApplyTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationProcessorApplyTests.cs @@ -69,7 +69,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests string sharedIdentifier = "SameIdentifier"; configurationUnit1.Identifier = sharedIdentifier; configurationUnit2.Identifier = sharedIdentifier; - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnit1, configurationUnit2, configurationUnitDifferentIdentifier }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnit1, configurationUnit2, configurationUnitDifferentIdentifier }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); @@ -115,7 +115,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationUnit configurationUnitMissingDependency = this.ConfigurationUnit(); configurationUnit.Identifier = "Identifier"; configurationUnitMissingDependency.Dependencies = new string[] { "Dependency" }; - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnit, configurationUnitMissingDependency }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnit, configurationUnitMissingDependency }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); @@ -163,7 +163,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests configurationUnit1.Dependencies = new string[] { "Identifier3" }; configurationUnit2.Dependencies = new string[] { "Identifier1" }; configurationUnit3.Dependencies = new string[] { "Identifier2" }; - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnit1, configurationUnit2, configurationUnit3 }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnit1, configurationUnit2, configurationUnit3 }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); @@ -199,14 +199,14 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationUnit configurationUnitAssert = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Assert }); ConfigurationUnit configurationUnitInform = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Inform }); ConfigurationUnit configurationUnitApply = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Apply }); - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnitInform, configurationUnitApply, configurationUnitAssert }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnitInform, configurationUnitApply, configurationUnitAssert }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); TestConfigurationSetProcessor setProcessor = factory.CreateTestProcessor(configurationSet); TestConfigurationUnitProcessor unitProcessorAssert = setProcessor.CreateTestProcessor(configurationUnitAssert); TestConfigurationUnitProcessor unitProcessorInform = setProcessor.CreateTestProcessor(configurationUnitInform); TestConfigurationUnitProcessor unitProcessorApply = setProcessor.CreateTestProcessor(configurationUnitApply); - unitProcessorApply.TestSettingsDelegate = () => new TestSettingsResultInstance { TestResult = ConfigurationTestResult.Negative }; + unitProcessorApply.TestSettingsDelegate = () => new TestSettingsResultInstance(configurationUnitApply) { TestResult = ConfigurationTestResult.Negative }; ConfigurationProcessor processor = this.CreateConfigurationProcessorWithDiagnostics(factory); @@ -249,14 +249,14 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationSet configurationSet = this.ConfigurationSet(); ConfigurationUnit configurationUnitAssert = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Assert }); ConfigurationUnit configurationUnitApply = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Apply }); - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnitApply, configurationUnitAssert }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnitApply, configurationUnitAssert }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); TestConfigurationSetProcessor setProcessor = factory.CreateTestProcessor(configurationSet); TestConfigurationUnitProcessor unitProcessorAssert = setProcessor.CreateTestProcessor(configurationUnitAssert); unitProcessorAssert.TestSettingsDelegate = () => throw new NullReferenceException(); TestConfigurationUnitProcessor unitProcessorApply = setProcessor.CreateTestProcessor(configurationUnitApply); - unitProcessorApply.TestSettingsDelegate = () => new TestSettingsResultInstance { TestResult = ConfigurationTestResult.Negative }; + unitProcessorApply.TestSettingsDelegate = () => new TestSettingsResultInstance(configurationUnitApply) { TestResult = ConfigurationTestResult.Negative }; ConfigurationProcessor processor = this.CreateConfigurationProcessorWithDiagnostics(factory); @@ -296,14 +296,14 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationSet configurationSet = this.ConfigurationSet(); ConfigurationUnit configurationUnitAssert = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Assert }); ConfigurationUnit configurationUnitApply = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Apply }); - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnitApply, configurationUnitAssert }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnitApply, configurationUnitAssert }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); TestConfigurationSetProcessor setProcessor = factory.CreateTestProcessor(configurationSet); TestConfigurationUnitProcessor unitProcessorAssert = setProcessor.CreateTestProcessor(configurationUnitAssert); - unitProcessorAssert.TestSettingsDelegate = () => new TestSettingsResultInstance { TestResult = ConfigurationTestResult.Negative }; + unitProcessorAssert.TestSettingsDelegate = () => new TestSettingsResultInstance(configurationUnitAssert) { TestResult = ConfigurationTestResult.Negative }; TestConfigurationUnitProcessor unitProcessorApply = setProcessor.CreateTestProcessor(configurationUnitApply); - unitProcessorApply.TestSettingsDelegate = () => new TestSettingsResultInstance { TestResult = ConfigurationTestResult.Negative }; + unitProcessorApply.TestSettingsDelegate = () => new TestSettingsResultInstance(configurationUnitApply) { TestResult = ConfigurationTestResult.Negative }; ConfigurationProcessor processor = this.CreateConfigurationProcessorWithDiagnostics(factory); @@ -335,12 +335,12 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests { ConfigurationSet configurationSet = this.ConfigurationSet(); ConfigurationUnit configurationUnit = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Apply }); - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnit }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnit }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); TestConfigurationSetProcessor setProcessor = factory.CreateTestProcessor(configurationSet); TestConfigurationUnitProcessor unitProcessor = setProcessor.CreateTestProcessor(configurationUnit); - unitProcessor.TestSettingsDelegate = () => new TestSettingsResultInstance { TestResult = ConfigurationTestResult.Positive }; + unitProcessor.TestSettingsDelegate = () => new TestSettingsResultInstance(configurationUnit) { TestResult = ConfigurationTestResult.Positive }; ConfigurationProcessor processor = this.CreateConfigurationProcessorWithDiagnostics(factory); @@ -373,9 +373,9 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationUnit apply1 = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Apply, Identifier = "Apply1" }); ConfigurationUnit apply2 = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Apply, Identifier = "Apply2" }); ConfigurationUnit apply3 = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Apply, Identifier = "Apply3", Dependencies = new string[] { apply1.Identifier, apply2.Identifier } }); - ConfigurationUnit apply4 = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Apply, Identifier = "Apply4", ShouldApply = false }); + ConfigurationUnit apply4 = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Apply, Identifier = "Apply4", IsActive = false }); ConfigurationUnit apply5 = this.ConfigurationUnit().Assign(new { Intent = ConfigurationUnitIntent.Apply, Identifier = "Apply5", Dependencies = new string[] { apply4.Identifier } }); - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { assert2, assert1, inform1, apply1, apply3, apply4, apply2, apply5 }; + configurationSet.Units = new ConfigurationUnit[] { assert2, assert1, inform1, apply1, apply3, apply4, apply2, apply5 }; ManualResetEvent startProcessing = new ManualResetEvent(false); @@ -398,7 +398,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests Assert.NotNull(result.ResultCode); Assert.Equal(Errors.WINGET_CONFIG_ERROR_DEPENDENCY_UNSATISFIED, result.ResultCode.HResult); Assert.NotNull(result.UnitResults); - Assert.Equal(configurationSet.ConfigurationUnits.Count, result.UnitResults.Count); + Assert.Equal(configurationSet.Units.Count, result.UnitResults.Count); // Verify that progress events match the expected ExpectedConfigurationChangeData[] expectedProgress = new ExpectedConfigurationChangeData[] diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationProcessorTelemetryTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationProcessorTelemetryTests.cs @@ -160,7 +160,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests testObjects.Processor = this.CreateConfigurationProcessorWithDiagnostics(testObjects.Factory); testObjects.CreateDetails(); - testObjects.Unit.UnitName = "TestUnitName"; + testObjects.Unit.Type = "TestUnitName"; testObjects.UnitDetails.ModuleName = "TestModuleName"; string setting1 = "setting1"; @@ -179,7 +179,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests Assert.Equal(string.Empty, runEvent.Caller); Assert.Equal(Guid.Empty, Guid.Parse(runEvent.Properties[TelemetryEvent.SetID])); Assert.NotEqual(Guid.Empty, Guid.Parse(runEvent.Properties[TelemetryEvent.UnitID])); - Assert.Equal(testObjects.Unit.UnitName, runEvent.Properties[TelemetryEvent.UnitName]); + Assert.Equal(testObjects.Unit.Type, runEvent.Properties[TelemetryEvent.UnitName]); Assert.Equal(testObjects.UnitDetails.ModuleName, runEvent.Properties[TelemetryEvent.ModuleName]); Assert.Equal(((int)testObjects.Unit.Intent).ToString(), runEvent.Properties[TelemetryEvent.UnitIntent]); Assert.Equal(((int)ConfigurationUnitIntent.Inform).ToString(), runEvent.Properties[TelemetryEvent.RunIntent]); @@ -203,7 +203,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests if (getFails) { - var getResult = new GetSettingsResultInstance(); + var getResult = new GetSettingsResultInstance(this.Unit); getResult.InternalResult.ResultCode = new NullReferenceException(); getResult.InternalResult.ResultSource = ConfigurationUnitResultSource.UnitProcessing; this.GetResult = getResult; diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationProcessorTestTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationProcessorTestTests.cs @@ -64,7 +64,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationSet configurationSet = this.ConfigurationSet(); ConfigurationUnit configurationUnitThrows = this.ConfigurationUnit(); ConfigurationUnit configurationUnitWorks = this.ConfigurationUnit(); - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnitThrows, configurationUnitWorks }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnitThrows, configurationUnitWorks }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); TestConfigurationSetProcessor setProcessor = factory.CreateTestProcessor(configurationSet); @@ -106,7 +106,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationSet configurationSet = this.ConfigurationSet(); ConfigurationUnit configurationUnitThrows = this.ConfigurationUnit(); ConfigurationUnit configurationUnitWorks = this.ConfigurationUnit(); - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnitWorks, configurationUnitThrows }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnitWorks, configurationUnitThrows }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); TestConfigurationSetProcessor setProcessor = factory.CreateTestProcessor(configurationSet); @@ -149,12 +149,12 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationSet configurationSet = this.ConfigurationSet(); ConfigurationUnit configurationUnitThrows = this.ConfigurationUnit(); ConfigurationUnit configurationUnitWorks = this.ConfigurationUnit(); - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnitWorks, configurationUnitThrows }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnitWorks, configurationUnitThrows }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); TestConfigurationSetProcessor setProcessor = factory.CreateTestProcessor(configurationSet); TestConfigurationUnitProcessor unitProcessor = setProcessor.CreateTestProcessor(configurationUnitThrows); - TestSettingsResultInstance testResult = new TestSettingsResultInstance(); + TestSettingsResultInstance testResult = new TestSettingsResultInstance(configurationUnitThrows); testResult.TestResult = ConfigurationTestResult.Failed; testResult.InternalResult.ResultCode = new NullReferenceException(); testResult.InternalResult.Description = "Failed again"; @@ -229,13 +229,13 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); TestConfigurationSetProcessor setProcessor = factory.CreateTestProcessor(configurationSet); - TestSettingsResultInstance positiveResult = new TestSettingsResultInstance(); + TestSettingsResultInstance positiveResult = new TestSettingsResultInstance(configurationUnits[0]); positiveResult.TestResult = ConfigurationTestResult.Positive; - TestSettingsResultInstance negativeResult = new TestSettingsResultInstance(); + TestSettingsResultInstance negativeResult = new TestSettingsResultInstance(configurationUnits[0]); negativeResult.TestResult = ConfigurationTestResult.Negative; - TestSettingsResultInstance failedResult = new TestSettingsResultInstance(); + TestSettingsResultInstance failedResult = new TestSettingsResultInstance(configurationUnits[0]); failedResult.TestResult = ConfigurationTestResult.Failed; failedResult.InternalResult.ResultCode = new NullReferenceException(); failedResult.InternalResult.Description = "Failed again"; @@ -244,7 +244,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests for (int i = 0; i < resultTypes.Length; ++i) { configurationUnits[i] = this.ConfigurationUnit(); - configurationUnits[i].UnitName = $"Unit {i}"; + configurationUnits[i].Type = $"Unit {i}"; TestConfigurationUnitProcessor unitProcessor = setProcessor.CreateTestProcessor(configurationUnits[i]); switch (resultTypes[i]) @@ -264,7 +264,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests } } - configurationSet.ConfigurationUnits = configurationUnits; + configurationSet.Units = configurationUnits; ConfigurationProcessor processor = this.CreateConfigurationProcessorWithDiagnostics(factory); diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationSetAuthoringTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationSetAuthoringTests.cs @@ -52,9 +52,9 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests Assert.NotEqual(Guid.Empty, testSet.InstanceIdentifier); Assert.Equal(ConfigurationSetState.Unknown, testSet.State); - Assert.Empty(testSet.ConfigurationUnits); - testSet.ConfigurationUnits = new ConfigurationUnit[] { this.ConfigurationUnit() }; - Assert.Equal(1, testSet.ConfigurationUnits.Count); + Assert.Empty(testSet.Units); + testSet.Units = new ConfigurationUnit[] { this.ConfigurationUnit() }; + Assert.Equal(1, testSet.Units.Count); Assert.NotEqual(string.Empty, testSet.SchemaVersion); } @@ -71,8 +71,8 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationUnit testUnit = this.ConfigurationUnit(); - testUnit.UnitName = testName; - Assert.Equal(testName, testUnit.UnitName); + testUnit.Type = testName; + Assert.Equal(testName, testUnit.Type); testUnit.Identifier = testIdentifier; Assert.Equal(testIdentifier, testUnit.Identifier); @@ -86,7 +86,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests testUnit.Dependencies = new string[] { "dependency1", "dependency2" }; Assert.Equal(2, testUnit.Dependencies.Count); - Assert.Empty(testUnit.Directives); + Assert.Empty(testUnit.Metadata); Assert.Empty(testUnit.Settings); Assert.Null(testUnit.Details); @@ -94,9 +94,9 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests Assert.Null(testUnit.ResultInformation); - Assert.True(testUnit.ShouldApply); - testUnit.ShouldApply = false; - Assert.False(testUnit.ShouldApply); + Assert.True(testUnit.IsActive); + testUnit.IsActive = false; + Assert.False(testUnit.IsActive); } /// <summary> diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationSetProcessorTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationSetProcessorTests.cs @@ -56,7 +56,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(new DscResourceInfoInternal(resourceName, moduleName, version)) .Verifiable(); @@ -66,14 +66,14 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var unit = new ConfigurationUnit { - UnitName = resourceName, + Type = resourceName, }; - unit.Directives.Add("module", moduleName); - unit.Directives.Add("version", version.ToString()); + unit.Metadata.Add("module", moduleName); + unit.Metadata.Add("version", version.ToString()); - var unitProcessor = configurationSetProcessor.CreateUnitProcessor(unit, null); + var unitProcessor = configurationSetProcessor.CreateUnitProcessor(unit); Assert.NotNull(unitProcessor); - Assert.Equal(unit.UnitName, unitProcessor.Unit.UnitName); + Assert.Equal(unit.Type, unitProcessor.Unit.Type); processorEnvMock.Verify(); } @@ -90,7 +90,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(new DscResourceInfoInternal(resourceName, moduleName, version)) .Verifiable(); @@ -100,13 +100,13 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var unit = new ConfigurationUnit { - UnitName = resourceName, + Type = resourceName, }; - unit.Directives.Add("module", moduleName); + unit.Metadata.Add("module", moduleName); - var unitProcessor = configurationSetProcessor.CreateUnitProcessor(unit, null); + var unitProcessor = configurationSetProcessor.CreateUnitProcessor(unit); Assert.NotNull(unitProcessor); - Assert.Equal(unit.UnitName, unitProcessor.Unit.UnitName); + Assert.Equal(unit.Type, unitProcessor.Unit.Type); processorEnvMock.Verify(); } @@ -123,7 +123,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(new DscResourceInfoInternal(resourceName, moduleName, version)) .Verifiable(); @@ -133,12 +133,12 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var unit = new ConfigurationUnit { - UnitName = resourceName, + Type = resourceName, }; - var unitProcessor = configurationSetProcessor.CreateUnitProcessor(unit, null); + var unitProcessor = configurationSetProcessor.CreateUnitProcessor(unit); Assert.NotNull(unitProcessor); - Assert.Equal(unit.UnitName, unitProcessor.Unit.UnitName); + Assert.Equal(unit.Type, unitProcessor.Unit.Type); processorEnvMock.Verify(); } @@ -157,13 +157,13 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests DscResourceInfoInternal dscResourceInfo = new DscResourceInfoInternal(resourceName, moduleName, version); var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.SetupSequence( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(nullResource) .Returns(dscResourceInfo); PSObject findDscResourceResult = new PSObject(processorEnvMock); processorEnvMock.Setup( - m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(findDscResourceResult) .Verifiable(); @@ -177,14 +177,14 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var unit = new ConfigurationUnit { - UnitName = resourceName, + Type = resourceName, }; - unit.Directives.Add("module", moduleName); - unit.Directives.Add("version", version.ToString()); + unit.Metadata.Add("module", moduleName); + unit.Metadata.Add("version", version.ToString()); - var unitProcessor = configurationSetProcessor.CreateUnitProcessor(unit, null); + var unitProcessor = configurationSetProcessor.CreateUnitProcessor(unit); Assert.NotNull(unitProcessor); - Assert.Equal(unit.UnitName, unitProcessor.Unit.UnitName); + Assert.Equal(unit.Type, unitProcessor.Unit.Type); processorEnvMock.Verify(); } @@ -202,13 +202,13 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests DscResourceInfoInternal dscResourceInfo = new DscResourceInfoInternal(resourceName, null, version); var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.SetupSequence( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(nullResource) .Returns(dscResourceInfo); PSObject findDscResourceResult = this.CreateFindResourceInfo(); processorEnvMock.Setup( - m => m.FindDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.FindDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(findDscResourceResult) .Verifiable(); @@ -223,13 +223,13 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var unit = new ConfigurationUnit { - UnitName = resourceName, + Type = resourceName, }; - unit.Directives.Add("version", version.ToString()); + unit.Metadata.Add("version", version.ToString()); - var unitProcessor = configurationSetProcessor.CreateUnitProcessor(unit, null); + var unitProcessor = configurationSetProcessor.CreateUnitProcessor(unit); Assert.NotNull(unitProcessor); - Assert.Equal(unit.UnitName, unitProcessor.Unit.UnitName); + Assert.Equal(unit.Type, unitProcessor.Unit.Type); processorEnvMock.Verify(); } @@ -248,12 +248,12 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests DscResourceInfoInternal dscResourceInfo = new DscResourceInfoInternal(resourceName, moduleName, version); var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(nullResource); PSObject findDscResourceResult = new PSObject(processorEnvMock); processorEnvMock.Setup( - m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(findDscResourceResult) .Verifiable(); @@ -267,13 +267,13 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var unit = new ConfigurationUnit { - UnitName = resourceName, + Type = resourceName, }; - unit.Directives.Add("module", moduleName); - unit.Directives.Add("version", version.ToString()); + unit.Metadata.Add("module", moduleName); + unit.Metadata.Add("version", version.ToString()); Assert.Throws<InstallDscResourceException>( - () => configurationSetProcessor.CreateUnitProcessor(unit, null)); + () => configurationSetProcessor.CreateUnitProcessor(unit)); processorEnvMock.Verify(); } @@ -292,12 +292,12 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests DscResourceInfoInternal dscResourceInfo = new DscResourceInfoInternal(resourceName, moduleName, version); var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(nullResource); PSObject? findDscResourceResult = null; processorEnvMock.Setup( - m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => c.Unit.UnitName == resourceName))) + m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => c.Unit.Type == resourceName))) .Returns(findDscResourceResult) .Verifiable(); @@ -307,13 +307,13 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var unit = new ConfigurationUnit { - UnitName = resourceName, + Type = resourceName, }; - unit.Directives.Add("module", moduleName); - unit.Directives.Add("version", version.ToString()); + unit.Metadata.Add("module", moduleName); + unit.Metadata.Add("version", version.ToString()); Assert.Throws<FindDscResourceNotFoundException>( - () => configurationSetProcessor.CreateUnitProcessor(unit, null)); + () => configurationSetProcessor.CreateUnitProcessor(unit)); processorEnvMock.Verify(); } @@ -329,7 +329,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == resourceName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == resourceName))) .Returns(nullDscInfoInternal) .Verifiable(); @@ -339,7 +339,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var unit = new ConfigurationUnit() { - UnitName = resourceName, + Type = resourceName, }; var configurationUnitProcessorDetails = configurationSetProcessor.GetUnitProcessorDetails( @@ -363,7 +363,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == dscResourceInfo.Name))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == dscResourceInfo.Name))) .Returns(dscResourceInfo) .Verifiable(); processorEnvMock.Setup( @@ -388,7 +388,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationUnitDetailFlags.Local); Assert.NotNull(configurationUnitProcessorDetails); - Assert.Equal(dscResourceInfo.Name, configurationUnitProcessorDetails.UnitName); + Assert.Equal(dscResourceInfo.Name, configurationUnitProcessorDetails.UnitType); processorEnvMock.Verify(); } @@ -409,7 +409,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == dscResourceInfo.Name))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == dscResourceInfo.Name))) .Returns(dscResourceInfo) .Verifiable(); processorEnvMock.Setup( @@ -434,7 +434,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests detailFlags); Assert.NotNull(configurationUnitProcessorDetails); - Assert.Equal(dscResourceInfo.Name, configurationUnitProcessorDetails.UnitName); + Assert.Equal(dscResourceInfo.Name, configurationUnitProcessorDetails.UnitType); processorEnvMock.Verify(); processorEnvMock.Verify(m => m.FindDscResource(It.IsAny<ConfigurationUnitInternal>()), Times.Never()); @@ -453,7 +453,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == dscResourceInfo.Name))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == dscResourceInfo.Name))) .Returns(dscResourceInfo) .Verifiable(); processorEnvMock.Setup( @@ -481,7 +481,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationUnitDetailFlags.Load); Assert.NotNull(configurationUnitProcessorDetails); - Assert.Equal(dscResourceInfo.Name, configurationUnitProcessorDetails.UnitName); + Assert.Equal(dscResourceInfo.Name, configurationUnitProcessorDetails.UnitType); processorEnvMock.Verify(); processorEnvMock.Verify(m => m.FindDscResource(It.IsAny<ConfigurationUnitInternal>()), Times.Never()); @@ -499,11 +499,11 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == unit.UnitName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == unit.Type))) .Returns(nullDscResourceInfo) .Verifiable(); processorEnvMock.Setup( - m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => unit.UnitName == unit.UnitName))) + m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => unit.Type == unit.Type))) .Returns(nullPsModuleInfo) .Verifiable(); @@ -532,11 +532,11 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == unit.UnitName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == unit.Type))) .Returns(nullDscResourceInfo) .Verifiable(); processorEnvMock.Setup( - m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => unit.UnitName == unit.UnitName))) + m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => unit.Type == unit.Type))) .Returns(getFindResourceInfo) .Verifiable(); @@ -549,7 +549,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationUnitDetailFlags.ReadOnly); Assert.NotNull(configurationUnitProcessorDetails); - Assert.Equal("SimpleFileResource", configurationUnitProcessorDetails.UnitName); + Assert.Equal("SimpleFileResource", configurationUnitProcessorDetails.UnitType); processorEnvMock.Verify(); } @@ -567,11 +567,11 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == unit.UnitName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == unit.Type))) .Returns(nullDscResourceInfo) .Verifiable(); processorEnvMock.Setup( - m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => unit.UnitName == unit.UnitName))) + m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => unit.Type == unit.Type))) .Returns(getFindModuleInfo) .Verifiable(); processorEnvMock.Setup( @@ -595,7 +595,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationUnitDetailFlags.Download); Assert.NotNull(configurationUnitProcessorDetails); - Assert.Equal("SimpleFileResource", configurationUnitProcessorDetails.UnitName); + Assert.Equal("SimpleFileResource", configurationUnitProcessorDetails.UnitType); processorEnvMock.Verify(); @@ -615,11 +615,11 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.Setup( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == unit.UnitName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == unit.Type))) .Returns(nullDscResourceInfo) .Verifiable(); processorEnvMock.Setup( - m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => unit.UnitName == unit.UnitName))) + m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => unit.Type == unit.Type))) .Returns(getFindResourceInfo) .Verifiable(); processorEnvMock.Setup( @@ -636,7 +636,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests processorEnvMock.Verify(); processorEnvMock.Verify( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == unit.UnitName)), + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == unit.Type)), Times.Exactly(2)); } @@ -653,11 +653,11 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var processorEnvMock = new Mock<IProcessorEnvironment>(); processorEnvMock.SetupSequence( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == unit.UnitName))) + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == unit.Type))) .Returns(nullDscResourceInfo) .Returns(dscResourceInfo); processorEnvMock.Setup( - m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => unit.UnitName == unit.UnitName))) + m => m.FindModule(It.Is<ConfigurationUnitInternal>(c => unit.Type == unit.Type))) .Returns(getFindResourceInfo) .Verifiable(); processorEnvMock.Setup( @@ -680,11 +680,11 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationUnitDetailFlags.Load); Assert.NotNull(configurationUnitProcessorDetails); - Assert.Equal(dscResourceInfo.Name, configurationUnitProcessorDetails.UnitName); + Assert.Equal(dscResourceInfo.Name, configurationUnitProcessorDetails.UnitType); processorEnvMock.Verify(); processorEnvMock.Verify( - m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.UnitName == unit.UnitName)), + m => m.GetDscResource(It.Is<ConfigurationUnitInternal>(u => u.Unit.Type == unit.Type)), Times.Exactly(2)); } @@ -701,12 +701,12 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests var unit = new ConfigurationUnit { - UnitName = "SimpleTestResourceTypes", + Type = "SimpleTestResourceTypes", Intent = ConfigurationUnitIntent.Assert, }; - unit.Directives.Add("module", "xSimpleTestResource"); - unit.Directives.Add("version", "0.0.0.1"); + unit.Metadata.Add("module", "xSimpleTestResource"); + unit.Metadata.Add("version", "0.0.0.1"); var hashtableProperty = new ValueSet { @@ -720,7 +720,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests unit.Settings.Add("charProperty", 'f'); unit.Settings.Add("hashtableProperty", hashtableProperty); - var unitProcessor = setProcessor.CreateUnitProcessor(unit, null); + var unitProcessor = setProcessor.CreateUnitProcessor(unit); unitProcessor.TestSettings(); } @@ -728,9 +728,9 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests private ConfigurationUnit CreateConfigurationUnit() { var unit = new ConfigurationUnit(); - unit.UnitName = "SimpleFileResource"; - unit.Directives.Add("module", "xSimpleTestResource"); - unit.Directives.Add("version", "0.0.0.1"); + unit.Type = "SimpleFileResource"; + unit.Metadata.Add("module", "xSimpleTestResource"); + unit.Metadata.Add("version", "0.0.0.1"); return unit; } @@ -739,7 +739,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests { // This is easier than trying to mock sealed class from external code... var testEnv = this.fixture.PrepareTestProcessorEnvironment(true); - var dscResourceInfo = testEnv.GetDscResource(new ConfigurationUnitInternal(unit, string.Empty, null)); + var dscResourceInfo = testEnv.GetDscResource(new ConfigurationUnitInternal(unit, string.Empty)); var psModuleInfo = testEnv.GetAvailableModule(PowerShellHelpers.CreateModuleSpecification("xSimpleTestResource", "0.0.0.1")); if (dscResourceInfo is null || psModuleInfo is null) diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationUnitInternalTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationUnitInternalTests.cs @@ -52,10 +52,6 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests string descriptionDirective = "description"; string unitDescription = "beep beep boop i am a text"; - string overlayDescription = "beep beep boop i am an overlay text"; - - string anotherDirective = "another"; - string overlayAnother = "insert another text"; string boolDirective = "boolDirective"; bool boolDirectiveValue = true; @@ -64,31 +60,22 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests bool boolDirective2Value = false; var unit = new ConfigurationUnit(); - unit.Directives.Add(moduleDirective, unitModule); - unit.Directives.Add(versionDirective, unitVersion); - unit.Directives.Add(descriptionDirective, unitDescription); - unit.Directives.Add(boolDirective, boolDirectiveValue); - unit.Directives.Add(boolDirective2, boolDirective2Value); - - var overlays = new Dictionary<string, object>() - { - { descriptionDirective, overlayDescription }, - { anotherDirective, overlayAnother }, - }; + unit.Metadata.Add(moduleDirective, unitModule); + unit.Metadata.Add(versionDirective, unitVersion); + unit.Metadata.Add(descriptionDirective, unitDescription); + unit.Metadata.Add(boolDirective, boolDirectiveValue); + unit.Metadata.Add(boolDirective2, boolDirective2Value); - var unitInternal = new ConfigurationUnitInternal(unit, string.Empty, overlays); + var unitInternal = new ConfigurationUnitInternal(unit, string.Empty); var description = unitInternal.GetDirective<string>(descriptionDirective); - Assert.Equal(description, overlayDescription); - - var another = unitInternal.GetDirective<string>(anotherDirective); - Assert.Equal(another, overlayAnother); + Assert.Equal(description, unitDescription); var fake = unitInternal.GetDirective<string>("fake"); Assert.Null(fake); var description2 = unitInternal.GetDirective<string>("DESCRIPTION"); - Assert.Equal(description2, overlayDescription); + Assert.Equal(description2, unitDescription); Assert.Equal(unitModule, unitInternal.Module!.Name); @@ -106,11 +93,11 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests public void GetVersion_BadVersion() { var unit = new ConfigurationUnit(); - unit.Directives.Add("module", "module"); - unit.Directives.Add("version", "not a version"); + unit.Metadata.Add("module", "module"); + unit.Metadata.Add("version", "not a version"); Assert.Throws<ArgumentException>( - () => new ConfigurationUnitInternal(unit, string.Empty, null)); + () => new ConfigurationUnitInternal(unit, string.Empty)); } /// <summary> diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationUnitProcessorTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationUnitProcessorTests.cs @@ -359,11 +359,10 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests new ConfigurationUnitInternal( new ConfigurationUnit { - UnitName = resourceName, + Type = resourceName, Intent = intent, }, - string.Empty, - new Dictionary<string, object>()), + string.Empty), new DscResourceInfoInternal(resourceName, null, null)); } } diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/OpenConfigurationSetTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/OpenConfigurationSetTests.cs @@ -166,7 +166,7 @@ properties: Assert.Null(result.ResultCode); Assert.Equal(string.Empty, result.Field); - var units = result.Set.ConfigurationUnits; + var units = result.Set.Units; Assert.Equal(3, units.Count); bool sawAssert = false; bool sawInform = false; @@ -174,7 +174,7 @@ properties: foreach (var unit in units) { - Assert.Equal(unit.UnitName, unit.Intent.ToString()); + Assert.Equal(unit.Type, unit.Intent.ToString()); switch (unit.Intent) { case ConfigurationUnitIntent.Assert: sawAssert = true; break; @@ -262,13 +262,13 @@ properties: Assert.NotEqual(Guid.Empty, result.Set.InstanceIdentifier); - var units = result.Set.ConfigurationUnits; + var units = result.Set.Units; Assert.NotNull(units); Assert.Equal(1, units.Count); ConfigurationUnit unit = units[0]; Assert.NotNull(unit); - Assert.Equal("Resource", unit.UnitName); + Assert.Equal("Resource", unit.Type); Assert.NotEqual(Guid.Empty, unit.InstanceIdentifier); Assert.Equal("Identifier", unit.Identifier); Assert.Equal(ConfigurationUnitIntent.Apply, unit.Intent); @@ -279,7 +279,7 @@ properties: Assert.Contains("Dependency1", dependencies); Assert.Contains("Dependency2", dependencies); - var directives = unit.Directives; + var directives = unit.Metadata; Assert.NotNull(directives); Assert.Equal(2, directives.Count); Assert.Contains("Directive1", directives); @@ -298,7 +298,7 @@ properties: Assert.Null(unit.Details); Assert.Equal(ConfigurationUnitState.Unknown, unit.State); Assert.Null(unit.ResultInformation); - Assert.True(unit.ShouldApply); + Assert.True(unit.IsActive); } /// <summary> @@ -324,7 +324,7 @@ properties: Assert.NotNull(result.Set); Assert.Null(result.ResultCode); - var units = result.Set.ConfigurationUnits; + var units = result.Set.Units; Assert.NotNull(units); Assert.Equal(1, units.Count); @@ -366,13 +366,12 @@ properties: Assert.Null(result.ResultCode); Assert.Equal("0.1", result.Set.SchemaVersion); - Assert.Single(result.Set.ConfigurationUnits); + Assert.Single(result.Set.Units); - var unit = result.Set.ConfigurationUnits[0]; + var unit = result.Set.Units[0]; Assert.NotNull(unit); - Assert.Equal("0.1", unit.SchemaVersion); - Assert.Equal("Module/Resource", unit.UnitName); - Assert.Empty(unit.Directives); + Assert.Equal("Module/Resource", unit.Type); + Assert.Empty(unit.Metadata); } /// <summary> @@ -399,15 +398,14 @@ properties: Assert.Null(result.ResultCode); Assert.Equal("0.2", result.Set.SchemaVersion); - Assert.Single(result.Set.ConfigurationUnits); + Assert.Single(result.Set.Units); - var unit = result.Set.ConfigurationUnits[0]; + var unit = result.Set.Units[0]; Assert.NotNull(unit); - Assert.Equal("0.2", unit.SchemaVersion); - Assert.Equal("Resource", unit.UnitName); - Assert.Single(unit.Directives); - Assert.True(unit.Directives.ContainsKey(ModuleDirective)); - Assert.Equal("Module", unit.Directives[ModuleDirective]); + Assert.Equal("Resource", unit.Type); + Assert.Single(unit.Metadata); + Assert.True(unit.Metadata.ContainsKey(ModuleDirective)); + Assert.Equal("Module", unit.Metadata[ModuleDirective]); } /// <summary> diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ProcessorGetTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ProcessorGetTests.cs @@ -80,7 +80,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationSet configurationSet = this.ConfigurationSet(); ConfigurationUnit configurationUnitWorks = this.ConfigurationUnit(); ConfigurationUnit configurationUnitThrows = this.ConfigurationUnit(); - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnitWorks, configurationUnitThrows }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnitWorks, configurationUnitThrows }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); TestConfigurationSetProcessor setProcessor = factory.CreateTestProcessor(configurationSet); @@ -112,7 +112,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests ConfigurationSet configurationSet = this.ConfigurationSet(); ConfigurationUnit configurationUnit1 = this.ConfigurationUnit(); ConfigurationUnit configurationUnit2 = this.ConfigurationUnit(); - configurationSet.ConfigurationUnits = new ConfigurationUnit[] { configurationUnit1, configurationUnit2 }; + configurationSet.Units = new ConfigurationUnit[] { configurationUnit1, configurationUnit2 }; TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); @@ -158,7 +158,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); factory.NullProcessor = new TestConfigurationSetProcessor(null); TestConfigurationUnitProcessor unitProcessor = factory.NullProcessor.CreateTestProcessor(configurationUnit); - GetSettingsResultInstance getSettingsResult = new GetSettingsResultInstance(); + GetSettingsResultInstance getSettingsResult = new GetSettingsResultInstance(configurationUnit); getSettingsResult.InternalResult.ResultCode = new InvalidDataException(); getSettingsResult.InternalResult.Description = "We fail because we must"; unitProcessor.GetSettingsDelegate = () => getSettingsResult; @@ -185,7 +185,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); factory.NullProcessor = new TestConfigurationSetProcessor(null); TestConfigurationUnitProcessor unitProcessor = factory.NullProcessor.CreateTestProcessor(configurationUnit); - GetSettingsResultInstance getSettingsResult = new GetSettingsResultInstance(); + GetSettingsResultInstance getSettingsResult = new GetSettingsResultInstance(configurationUnit); getSettingsResult.Settings = new Windows.Foundation.Collections.ValueSet(); getSettingsResult.Settings.Add("key", "value"); unitProcessor.GetSettingsDelegate = () => getSettingsResult; diff --git a/src/Microsoft.Management.Configuration/ConfigurationProcessor.cpp b/src/Microsoft.Management.Configuration/ConfigurationProcessor.cpp @@ -343,7 +343,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation auto result = make_self<wil::details::module_count_wrapper<implementation::GetConfigurationSetDetailsResult>>(); progress.Result(*result); - for (const auto& unit : configurationSet.ConfigurationUnits()) + for (const auto& unit : configurationSet.Units()) { progress.ThrowIfCancelled(); @@ -483,9 +483,9 @@ namespace winrt::Microsoft::Management::Configuration::implementation try { - for (const auto& unit : configurationSet.ConfigurationUnits()) + for (const auto& unit : configurationSet.Units()) { - AICLI_LOG(Config, Info, << "Testing configuration unit: " << AppInstaller::Utility::ConvertToUTF8(unit.UnitName())); + AICLI_LOG(Config, Info, << "Testing configuration unit: " << AppInstaller::Utility::ConvertToUTF8(unit.Type())); auto testResult = make_self<wil::details::module_count_wrapper<implementation::TestConfigurationUnitResult>>(); auto unitResult = make_self<wil::details::module_count_wrapper<implementation::ConfigurationUnitResultInformation>>(); @@ -500,7 +500,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation try { // TODO: Directives overlay to prevent running elevated for test - unitProcessor = setProcessor.CreateUnitProcessor(unit, {}); + unitProcessor = setProcessor.CreateUnitProcessor(unit); } catch (...) { @@ -594,7 +594,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation try { // TODO: Directives overlay to prevent running elevated for get - unitProcessor = setProcessor.CreateUnitProcessor(unit, {}); + unitProcessor = setProcessor.CreateUnitProcessor(unit); } catch (...) { diff --git a/src/Microsoft.Management.Configuration/ConfigurationSet.cpp b/src/Microsoft.Management.Configuration/ConfigurationSet.cpp @@ -16,13 +16,13 @@ namespace winrt::Microsoft::Management::Configuration::implementation } ConfigurationSet::ConfigurationSet(const guid& instanceIdentifier) : - m_instanceIdentifier(instanceIdentifier), m_mutableFlag(false) + m_instanceIdentifier(instanceIdentifier) { } void ConfigurationSet::Initialize(std::vector<Configuration::ConfigurationUnit>&& units) { - m_configurationUnits = winrt::single_threaded_vector<Configuration::ConfigurationUnit>(std::move(units)); + m_units = winrt::single_threaded_vector<Configuration::ConfigurationUnit>(std::move(units)); } bool ConfigurationSet::IsFromHistory() const @@ -37,7 +37,6 @@ namespace winrt::Microsoft::Management::Configuration::implementation void ConfigurationSet::Name(const hstring& value) { - m_mutableFlag.RequireMutable(); m_name = value; } @@ -48,7 +47,6 @@ namespace winrt::Microsoft::Management::Configuration::implementation void ConfigurationSet::Origin(const hstring& value) { - m_mutableFlag.RequireMutable(); m_origin = value; } @@ -59,7 +57,6 @@ namespace winrt::Microsoft::Management::Configuration::implementation void ConfigurationSet::Path(const hstring& value) { - m_mutableFlag.RequireMutable(); m_path = value; } @@ -88,18 +85,15 @@ namespace winrt::Microsoft::Management::Configuration::implementation return clock::time_point{}; } - Windows::Foundation::Collections::IVectorView<Configuration::ConfigurationUnit> ConfigurationSet::ConfigurationUnits() + Windows::Foundation::Collections::IVector<Configuration::ConfigurationUnit> ConfigurationSet::Units() { - return m_configurationUnits.GetView(); + return m_units; } - void ConfigurationSet::ConfigurationUnits(const Windows::Foundation::Collections::IVectorView<ConfigurationUnit>& value) + void ConfigurationSet::Units(const Windows::Foundation::Collections::IVector<ConfigurationUnit>& value) { - m_mutableFlag.RequireMutable(); - - std::vector<ConfigurationUnit> temp{ value.Size() }; - value.GetMany(0, temp); - m_configurationUnits = winrt::single_threaded_vector<ConfigurationUnit>(std::move(temp)); + THROW_HR_IF(E_POINTER, !value); + m_units = value; } hstring ConfigurationSet::SchemaVersion() diff --git a/src/Microsoft.Management.Configuration/ConfigurationSet.h b/src/Microsoft.Management.Configuration/ConfigurationSet.h @@ -2,7 +2,6 @@ // Licensed under the MIT License. #pragma once #include "ConfigurationSet.g.h" -#include "MutableFlag.h" #include <winget/ILifetimeWatcher.h> #include <winrt/Windows.Foundation.h> #include <winrt/Windows.Foundation.Collections.h> @@ -39,8 +38,8 @@ namespace winrt::Microsoft::Management::Configuration::implementation clock::time_point ApplyBegun(); clock::time_point ApplyEnded(); - Windows::Foundation::Collections::IVectorView<ConfigurationUnit> ConfigurationUnits(); - void ConfigurationUnits(const Windows::Foundation::Collections::IVectorView<ConfigurationUnit>& value); + Windows::Foundation::Collections::IVector<ConfigurationUnit> Units(); + void Units(const Windows::Foundation::Collections::IVector<ConfigurationUnit>& value); hstring SchemaVersion(); void SchemaVersion(const hstring& value); @@ -61,11 +60,9 @@ namespace winrt::Microsoft::Management::Configuration::implementation hstring m_path; guid m_instanceIdentifier; clock::time_point m_firstApply{}; - Windows::Foundation::Collections::IVector<ConfigurationUnit> m_configurationUnits{ winrt::single_threaded_vector<ConfigurationUnit>() }; + Windows::Foundation::Collections::IVector<ConfigurationUnit> m_units{ winrt::single_threaded_vector<ConfigurationUnit>() }; hstring m_schemaVersion; winrt::event<Windows::Foundation::TypedEventHandler<WinRT_Self, ConfigurationSetChangeData>> m_configurationSetChange; - - MutableFlag m_mutableFlag; #endif }; } diff --git a/src/Microsoft.Management.Configuration/ConfigurationSetApplyProcessor.cpp b/src/Microsoft.Management.Configuration/ConfigurationSetApplyProcessor.cpp @@ -32,7 +32,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation m_progress(std::move(progress)) { // Create a copy of the set of configuration units - auto unitsView = configurationSet.ConfigurationUnits(); + auto unitsView = configurationSet.Units(); std::vector<ConfigurationUnit> unitsToProcess{ unitsView.Size() }; unitsView.GetMany(0, unitsToProcess); @@ -366,7 +366,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation // Once we get this far, consider the unit processed even if we fail to create the actual processor. unitInfo.Processed = true; - if (!unitInfo.Unit.ShouldApply()) + if (!unitInfo.Unit.IsActive()) { // If the unit is requested to be skipped, we mark it with a failure to prevent any dependency from running. // But we return true from this function to indicate a successful "processing". @@ -381,7 +381,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation try { - unitProcessor = m_setProcessor.CreateUnitProcessor(unitInfo.Unit, {}); + unitProcessor = m_setProcessor.CreateUnitProcessor(unitInfo.Unit); } catch (...) { diff --git a/src/Microsoft.Management.Configuration/ConfigurationSetParser_0_1.cpp b/src/Microsoft.Management.Configuration/ConfigurationSetParser_0_1.cpp @@ -154,7 +154,6 @@ namespace winrt::Microsoft::Management::Configuration::implementation index++; auto configurationUnit = make_self<wil::details::module_count_wrapper<ConfigurationUnit>>(); - configurationUnit->SchemaVersion(GetSchemaVersion()); ParseConfigurationUnit(configurationUnit.get(), item, intent); @@ -164,11 +163,11 @@ namespace winrt::Microsoft::Management::Configuration::implementation void ConfigurationSetParser_0_1::ParseConfigurationUnit(ConfigurationUnit* unit, const Node& unitNode, ConfigurationUnitIntent intent) { - CHECK_ERROR(GetStringValueForUnit(unitNode, GetFieldName(FieldName::Resource), true, unit, &ConfigurationUnit::UnitName)); + CHECK_ERROR(GetStringValueForUnit(unitNode, GetFieldName(FieldName::Resource), true, unit, &ConfigurationUnit::Type)); CHECK_ERROR(GetStringValueForUnit(unitNode, "id", false, unit, &ConfigurationUnit::Identifier)); unit->Intent(intent); CHECK_ERROR(GetStringArrayForUnit(unitNode, "dependsOn", unit, &ConfigurationUnit::Dependencies)); - CHECK_ERROR(GetValueSet(unitNode, "directives", false, unit->Directives())); + CHECK_ERROR(GetValueSet(unitNode, "directives", false, unit->Metadata())); CHECK_ERROR(GetValueSet(unitNode, "settings", false, unit->Settings())); } diff --git a/src/Microsoft.Management.Configuration/ConfigurationSetParser_0_2.cpp b/src/Microsoft.Management.Configuration/ConfigurationSetParser_0_2.cpp @@ -57,15 +57,15 @@ namespace winrt::Microsoft::Management::Configuration::implementation ConfigurationSetParser_0_1::ParseConfigurationUnit(unit, unitNode, intent); // Move module qualification into directives if present - QualifiedResourceName qualifiedName{ unit->UnitName() }; + QualifiedResourceName qualifiedName{ unit->Type() }; - FIELD_VALUE_ERROR_IF(qualifiedName.Resource.empty(), GetFieldName(FieldName::Resource), ConvertToUTF8(unit->UnitName()), unitNode.Mark()); + FIELD_VALUE_ERROR_IF(qualifiedName.Resource.empty(), GetFieldName(FieldName::Resource), ConvertToUTF8(unit->Type()), unitNode.Mark()); if (!qualifiedName.Module.empty()) { // If the module is provided in both the resource name and the directives, ensure that it matches hstring moduleDirectiveFieldName = GetFieldNameHString(FieldName::ModuleDirective); - auto moduleDirective = unit->Directives().TryLookup(moduleDirectiveFieldName); + auto moduleDirective = unit->Metadata().TryLookup(moduleDirectiveFieldName); if (moduleDirective) { auto moduleProperty = moduleDirective.try_as<Windows::Foundation::IPropertyValue>(); @@ -76,11 +76,11 @@ namespace winrt::Microsoft::Management::Configuration::implementation } else { - unit->Directives().Insert(moduleDirectiveFieldName, Windows::Foundation::PropertyValue::CreateString(qualifiedName.Module)); + unit->Metadata().Insert(moduleDirectiveFieldName, Windows::Foundation::PropertyValue::CreateString(qualifiedName.Module)); } // Set the unit name to be just the resource portion - unit->UnitName(qualifiedName.Resource); + unit->Type(qualifiedName.Resource); } } } diff --git a/src/Microsoft.Management.Configuration/ConfigurationUnit.cpp b/src/Microsoft.Management.Configuration/ConfigurationUnit.cpp @@ -31,6 +31,13 @@ namespace winrt::Microsoft::Management::Configuration::implementation return result; } + + Windows::Foundation::Collections::IVector<hstring> Clone(const Windows::Foundation::Collections::IVector<hstring>& value) + { + std::vector<hstring> temp{ value.Size() }; + value.GetMany(0, temp); + return winrt::single_threaded_vector<hstring>(std::move(temp)); + } } ConfigurationUnit::ConfigurationUnit() @@ -38,23 +45,21 @@ namespace winrt::Microsoft::Management::Configuration::implementation GUID instanceIdentifier; THROW_IF_FAILED(CoCreateGuid(&instanceIdentifier)); m_instanceIdentifier = instanceIdentifier; - m_schemaVersion = ConfigurationSetParser::LatestVersion(); } ConfigurationUnit::ConfigurationUnit(const guid& instanceIdentifier) : - m_instanceIdentifier(instanceIdentifier), m_mutableFlag(false) + m_instanceIdentifier(instanceIdentifier) { } - hstring ConfigurationUnit::UnitName() + hstring ConfigurationUnit::Type() { - return m_unitName; + return m_type; } - void ConfigurationUnit::UnitName(const hstring& value) + void ConfigurationUnit::Type(const hstring& value) { - m_mutableFlag.RequireMutable(); - m_unitName = value; + m_type = value; } guid ConfigurationUnit::InstanceIdentifier() @@ -69,7 +74,6 @@ namespace winrt::Microsoft::Management::Configuration::implementation void ConfigurationUnit::Identifier(const hstring& value) { - m_mutableFlag.RequireMutable(); m_identifier = value; } @@ -80,22 +84,19 @@ namespace winrt::Microsoft::Management::Configuration::implementation void ConfigurationUnit::Intent(ConfigurationUnitIntent value) { - m_mutableFlag.RequireMutable(); + THROW_HR_IF(E_INVALIDARG, value != ConfigurationUnitIntent::Assert && value != ConfigurationUnitIntent::Inform && value != ConfigurationUnitIntent::Apply); m_intent = value; } - Windows::Foundation::Collections::IVectorView<hstring> ConfigurationUnit::Dependencies() + Windows::Foundation::Collections::IVector<hstring> ConfigurationUnit::Dependencies() { - return m_dependencies.GetView(); + return m_dependencies; } - void ConfigurationUnit::Dependencies(const Windows::Foundation::Collections::IVectorView<hstring>& value) + void ConfigurationUnit::Dependencies(const Windows::Foundation::Collections::IVector<hstring>& value) { - m_mutableFlag.RequireMutable(); - - std::vector<hstring> temp{ value.Size() }; - value.GetMany(0, temp); - m_dependencies = winrt::single_threaded_vector<hstring>(std::move(temp)); + THROW_HR_IF(E_POINTER, !value); + m_dependencies = value; } void ConfigurationUnit::Dependencies(std::vector<hstring>&& value) @@ -103,9 +104,15 @@ namespace winrt::Microsoft::Management::Configuration::implementation m_dependencies = winrt::single_threaded_vector<hstring>(std::move(value)); } - Windows::Foundation::Collections::ValueSet ConfigurationUnit::Directives() + Windows::Foundation::Collections::ValueSet ConfigurationUnit::Metadata() { - return m_directives; + return m_metadata; + } + + void ConfigurationUnit::Metadata(const Windows::Foundation::Collections::ValueSet& value) + { + THROW_HR_IF(E_POINTER, !value); + m_metadata = value; } Windows::Foundation::Collections::ValueSet ConfigurationUnit::Settings() @@ -113,6 +120,12 @@ namespace winrt::Microsoft::Management::Configuration::implementation return m_settings; } + void ConfigurationUnit::Settings(const Windows::Foundation::Collections::ValueSet& value) + { + THROW_HR_IF(E_POINTER, !value); + m_settings = value; + } + IConfigurationUnitProcessorDetails ConfigurationUnit::Details() { return m_details; @@ -133,25 +146,14 @@ namespace winrt::Microsoft::Management::Configuration::implementation return nullptr; } - bool ConfigurationUnit::ShouldApply() - { - return m_shouldApply; - } - - void ConfigurationUnit::ShouldApply(bool value) - { - m_shouldApply = value; - } - - hstring ConfigurationUnit::SchemaVersion() + bool ConfigurationUnit::IsActive() { - return m_schemaVersion; + return m_isActive; } - void ConfigurationUnit::SchemaVersion(const hstring& value) + void ConfigurationUnit::IsActive(bool value) { - THROW_HR_IF(E_INVALIDARG, !ConfigurationSetParser::IsRecognizedSchemaVersion(value)); - m_schemaVersion = value; + m_isActive = value; } HRESULT STDMETHODCALLTYPE ConfigurationUnit::SetLifetimeWatcher(IUnknown* watcher) @@ -163,13 +165,12 @@ namespace winrt::Microsoft::Management::Configuration::implementation { auto result = make_self<wil::details::module_count_wrapper<ConfigurationUnit>>(); - result->m_unitName = m_unitName; + result->m_type = m_type; result->m_intent = m_intent; - result->Dependencies(m_dependencies.GetView()); - result->m_directives = Clone(m_directives); + result->m_dependencies = Clone(m_dependencies); + result->m_metadata = Clone(m_metadata); result->m_settings = Clone(m_settings); result->m_details = m_details; - result->m_schemaVersion = m_schemaVersion; return *result; } diff --git a/src/Microsoft.Management.Configuration/ConfigurationUnit.h b/src/Microsoft.Management.Configuration/ConfigurationUnit.h @@ -2,7 +2,6 @@ // Licensed under the MIT License. #pragma once #include "ConfigurationUnit.g.h" -#include "MutableFlag.h" #include <winget/ILifetimeWatcher.h> #include <winrt/Windows.Foundation.Collections.h> #include <vector> @@ -17,8 +16,8 @@ namespace winrt::Microsoft::Management::Configuration::implementation ConfigurationUnit(const guid& instanceIdentifier); #endif - hstring UnitName(); - void UnitName(const hstring& value); + hstring Type(); + void Type(const hstring& value); guid InstanceIdentifier(); @@ -28,12 +27,14 @@ namespace winrt::Microsoft::Management::Configuration::implementation ConfigurationUnitIntent Intent(); void Intent(ConfigurationUnitIntent value); - Windows::Foundation::Collections::IVectorView<hstring> Dependencies(); - void Dependencies(const Windows::Foundation::Collections::IVectorView<hstring>& value); + Windows::Foundation::Collections::IVector<hstring> Dependencies(); + void Dependencies(const Windows::Foundation::Collections::IVector<hstring>& value); - Windows::Foundation::Collections::ValueSet Directives(); + Windows::Foundation::Collections::ValueSet Metadata(); + void Metadata(const Windows::Foundation::Collections::ValueSet& value); Windows::Foundation::Collections::ValueSet Settings(); + void Settings(const Windows::Foundation::Collections::ValueSet& value); IConfigurationUnitProcessorDetails Details(); @@ -41,11 +42,8 @@ namespace winrt::Microsoft::Management::Configuration::implementation IConfigurationUnitResultInformation ResultInformation(); - bool ShouldApply(); - void ShouldApply(bool value); - - hstring SchemaVersion(); - void SchemaVersion(const hstring& value); + bool IsActive(); + void IsActive(bool value); Configuration::ConfigurationUnit Copy(); @@ -56,18 +54,15 @@ namespace winrt::Microsoft::Management::Configuration::implementation void Details(IConfigurationUnitProcessorDetails&& details); private: - hstring m_unitName; + hstring m_type; guid m_instanceIdentifier; hstring m_identifier; ConfigurationUnitIntent m_intent = ConfigurationUnitIntent::Apply; Windows::Foundation::Collections::IVector<hstring> m_dependencies{ winrt::single_threaded_vector<hstring>() }; - Windows::Foundation::Collections::ValueSet m_directives; + Windows::Foundation::Collections::ValueSet m_metadata; Windows::Foundation::Collections::ValueSet m_settings; IConfigurationUnitProcessorDetails m_details{ nullptr }; - bool m_shouldApply = true; - hstring m_schemaVersion; - - MutableFlag m_mutableFlag; + bool m_isActive = true; #endif }; } diff --git a/src/Microsoft.Management.Configuration/Microsoft.Management.Configuration.idl b/src/Microsoft.Management.Configuration/Microsoft.Management.Configuration.idl @@ -97,8 +97,10 @@ namespace Microsoft.Management.Configuration interface IConfigurationUnitSettingDetails { // The name of the setting. - String Name{ get; }; - // The description of the setting. + String Identifier{ get; }; + // A brief description of the setting. + String Title{ get; }; + // The detailed description of the setting. String Description{ get; }; // Whether the setting is a key. This is used to determine if different settings are in conflict. Boolean IsKey{ get; }; @@ -108,19 +110,31 @@ namespace Microsoft.Management.Configuration // When the current settings are retrieved from the system, this can be used to exclude settings that are not relevant to a future application of the unit of configuration. Boolean IsInformational{ get; }; // The data type for the value of this setting. - String Type{ get; }; - // The semantics to be used for this setting. - // The goal is to enable richer conflict detection and authoring scenarios by having a deeper understanding of this value than "String". - // TODO: Create the actual semantics of the semantics value... - String Semantics{ get; }; + Windows.Foundation.PropertyType Type{ get; }; + + // The schema fragment to be used for this setting. + // Using a single entry of the `properties` object from a JSON schema is suggested, for instance: + // { + // "$schema": "https://json-schema.org/draft/2020-12/schema", + // "scope": { + // "title": "Target scope", + // "description": "The scope at which the configuration should be applied.", + // "type": "string", + // "enum": [ + // "machine", + // "user" + // ] + // } + // } + String Schema{ get; }; } // Provides information for a specific configuration unit within the runtime. [contract(Microsoft.Management.Configuration.Contract, 1)] interface IConfigurationUnitProcessorDetails { - // The name of the unit of configuration. - String UnitName{ get; }; + // The type of configuration unit. + String UnitType{ get; }; // A description of the unit of configuration. String UnitDescription{ get; }; // The URI of the documentation for the unit of configuration. @@ -170,6 +184,9 @@ namespace Microsoft.Management.Configuration // The configuration unit will be used to Apply the current system state. // The configuration unit will be used to Test and Get the current system state as part of that process. Apply, + // The configuration unit's intent is unknown. + // Currently not supported. + Unknown, }; // A single unit of configuration. @@ -179,31 +196,29 @@ namespace Microsoft.Management.Configuration // Creates an empty configuration unit for authoring purposes. ConfigurationUnit(); - // The name of the unit being configured; not a name for this instance. - // Can be changed if a mutable unit. - String UnitName; + // The type of the unit being configured; not a name for this instance. + String Type; // An identifier used to uniquely identify the instance of a configuration unit on the system. - // Immutable, although the unit can be removed and an identical unit applied later with a different identifier. + // May change upon applying a configuration unit from a historical context if some part of the set changed. Guid InstanceIdentifier{ get; }; // The identifier name of this instance within the set. - // Can be changed if a mutable unit. String Identifier; // Describes how this configuration unit will be used. - // Can be changed if a mutable unit. ConfigurationUnitIntent Intent; - // The configuration units that this unit depends on. - // Can be set on a mutable configuration unit; this will copy the items into the internal storage. - Windows.Foundation.Collections.IVectorView<String> Dependencies; + // The `Identifier` values of the configuration units that this unit depends on. + Windows.Foundation.Collections.IVector<String> Dependencies; - // Contains the values that are for use by the configuration system, related to this unit. - Windows.Foundation.Collections.ValueSet Directives{ get; }; + // The metadata properties associated with the configuration unit. + // TODO: This is being used to drive processing decisions when it should not. + // There is ongoing discussion about this at https://github.com/PowerShell/DSC/issues/47 and https://github.com/PowerShell/DSC/issues/92. + Windows.Foundation.Collections.ValueSet Metadata; // Contains the values that are for use by the configuration unit itself. - Windows.Foundation.Collections.ValueSet Settings{ get; }; + Windows.Foundation.Collections.ValueSet Settings; // Contains information on the origin of the configuration unit. // May be null if ConfigurationProcessor.GetDetailsAsync has not been called yet. @@ -215,20 +230,15 @@ namespace Microsoft.Management.Configuration // Contains information on the result of the latest attempt to apply the configuration unit. IConfigurationUnitResultInformation ResultInformation{ get; }; - // Allows for control over whether this unit should be applied when the set containing it is applied. - Boolean ShouldApply; - - // The schema version to use for the unit. - // Will be set to the schema version when read in, and default to the latest if created manually. - String SchemaVersion; + // Controls whether this unit will be processed when part of a set. + Boolean IsActive; // Creates a copy of this configuration unit, with the following notes: // InstanceIdentifier will be a new value // Identifier will be empty - // Dependencies, Directives, and Settings will by new containers with identical values inside + // Dependencies, Metadata, and Settings will by new containers with identical values inside // Details will be the same value (not a copy, just another reference) // State, ResultInformation, and ShouldApply will be their default constructed state - // The returned value will be in a writable state ConfigurationUnit Copy(); } @@ -267,22 +277,19 @@ namespace Microsoft.Management.Configuration [contract(Microsoft.Management.Configuration.Contract, 1)] runtimeclass ConfigurationSet { - // Creates an empty, mutable configuration set for authoring purposes. + // Creates an empty configuration set for authoring purposes. ConfigurationSet(); - + // The name of the set; if from a file this could be the file name. - // Can be changed if a mutable set. String Name; // The origin of the set; if it came from a repository it could be the remote URL (ex. https://github.com/microsoft/winget-cli.git). - // Can be changed if a mutable set. String Origin; // The location of the configuration set on the local filesystem. // If this set is from history, the file may no longer exist or it's contents may have been changed. - // Can be changed if a mutable set. String Path; // An identifier used to uniquely identify the instance of a configuration set on the system. - // Immutable, although the set can be removed and an identical set applied later with a different identifier. + // May change upon applying a configuration set from a historical context if some part of the set changed. Guid InstanceIdentifier{ get; }; // The state that the set is in. ConfigurationSetState State{ get; }; @@ -294,8 +301,7 @@ namespace Microsoft.Management.Configuration Windows.Foundation.DateTime ApplyEnded{ get; }; // The configuration units that are part of this set. - // Can be set on a mutable configuration set; this will copy the items into the internal storage. - Windows.Foundation.Collections.IVectorView<ConfigurationUnit> ConfigurationUnits; + Windows.Foundation.Collections.IVector<ConfigurationUnit> Units; // The schema version to use for the set. // Will be set to the schema version when read in, and default to the latest if created manually. @@ -316,6 +322,9 @@ namespace Microsoft.Management.Configuration [contract(Microsoft.Management.Configuration.Contract, 1)] interface IApplySettingsResult { + // The configuration unit. + ConfigurationUnit Unit{ get; }; + // Indicates whether a reboot is required after the settings were applied. Boolean RebootRequired{ get; }; @@ -343,6 +352,9 @@ namespace Microsoft.Management.Configuration [contract(Microsoft.Management.Configuration.Contract, 1)] interface ITestSettingsResult { + // The configuration unit. + ConfigurationUnit Unit{ get; }; + // The result (if any) of running Test on the configuration unit. ConfigurationTestResult TestResult{ get; }; @@ -355,6 +367,9 @@ namespace Microsoft.Management.Configuration [contract(Microsoft.Management.Configuration.Contract, 1)] interface IGetSettingsResult { + // The configuration unit. + ConfigurationUnit Unit{ get; }; + // The current state of the system for the configuration unit. Windows.Foundation.Collections.ValueSet Settings{ get; }; @@ -370,9 +385,6 @@ namespace Microsoft.Management.Configuration // The configuration unit that the processor was created for. ConfigurationUnit Unit{ get; }; - // The directives overlay that the processor was created with. - Windows.Foundation.Collections.IMapView<String, Object> DirectivesOverlay{ get; }; - // Determines if the system is already in the state described by the configuration unit. ITestSettingsResult TestSettings(); @@ -391,9 +403,7 @@ namespace Microsoft.Management.Configuration IConfigurationUnitProcessorDetails GetUnitProcessorDetails(ConfigurationUnit unit, ConfigurationUnitDetailFlags detailFlags); // Creates a configuration unit processor for the given unit. - // The optional `directivesOverlay` parameter allows for the `ConfigurationProcessor` to alter behavior without needing to change the unit itself. - // The overlay is searched first; any value not present there will then fall back to the unit's directives. - IConfigurationUnitProcessor CreateUnitProcessor(ConfigurationUnit unit, Windows.Foundation.Collections.IMapView<String, Object> directivesOverlay); + IConfigurationUnitProcessor CreateUnitProcessor(ConfigurationUnit unit); } // The level of the diagnostic information. @@ -564,7 +574,7 @@ namespace Microsoft.Management.Configuration // Forces a new configuration set instance to be recorded when the set being applied matches a previous set's origin. // The default behavior is to assume that the incoming set is an update to the existing set and overwrite it. DoNotOverwriteMatchingOriginSet = 0x1, - // Does not apply the configuration set, instead check the configuration set for internal consistency. + // Does not apply the configuration set, only checks the configuration set for internal consistency. PerformConsistencyCheckOnly = 0x2, }; @@ -666,12 +676,12 @@ namespace Microsoft.Management.Configuration // This includes things like: creation of a new set for intent to run, start/stop of a set for application or test, deletion of a not started set. event Windows.Foundation.TypedEventHandler<ConfigurationSet, ConfigurationChangeData> ConfigurationChange; - // Gets the configuration sets that have already been applied or the intent to be applied (this may include in progress sets or those that are waiting on others). + // Gets the configuration sets that have already been applied or with the intent to be applied (this may include in progress sets or those that are waiting on others). // These configuration sets will be marked as immutable. Windows.Foundation.Collections.IVector<ConfigurationSet> GetConfigurationHistory(); Windows.Foundation.IAsyncOperation< Windows.Foundation.Collections.IVector<ConfigurationSet> > GetConfigurationHistoryAsync(); - // Loads a mutable configuration set from the given stream. + // Loads a configuration set from the given stream. OpenConfigurationSetResult OpenConfigurationSet(Windows.Storage.Streams.IInputStream stream); Windows.Foundation.IAsyncOperation<OpenConfigurationSetResult> OpenConfigurationSetAsync(Windows.Storage.Streams.IInputStream stream); @@ -707,7 +717,7 @@ namespace Microsoft.Management.Configuration // Creates an empty configuration unit. ConfigurationUnit CreateConfigurationUnit(); - // Creates an empty configuration unit. + // Creates an empty configuration set. ConfigurationSet CreateConfigurationSet(); // Creates a processor factory for the given handler. @@ -736,15 +746,15 @@ namespace Microsoft.Management.Configuration // Due to the way that metadata (WinMD) based marshalling works, in order for any of these to be IIterable<T>, they need to be // included in the manifest of the package. Update the DumpProxyStubRegistrationsCommand to add any new types to make it easier // to iterate over these collections, especially in C#. - interface Windows.Foundation.Collections.IVector<ConfigurationConflict>; + interface Windows.Foundation.Collections.IVector<ConfigurationUnit>; interface Windows.Foundation.Collections.IVector<ConfigurationSet>; - interface Windows.Foundation.Collections.IVectorView<ApplyConfigurationUnitResult>; + interface Windows.Foundation.Collections.IVector<ConfigurationConflict>; + interface Windows.Foundation.Collections.IVectorView<IConfigurationUnitSettingDetails>; interface Windows.Foundation.Collections.IVectorView<ConfigurationConflictSetting>; - interface Windows.Foundation.Collections.IVectorView<ConfigurationSet>; - interface Windows.Foundation.Collections.IVectorView<ConfigurationUnit>; interface Windows.Foundation.Collections.IVectorView<GetConfigurationUnitDetailsResult>; - interface Windows.Foundation.Collections.IVectorView<IConfigurationUnitSettingDetails>; + interface Windows.Foundation.Collections.IVectorView<ApplyConfigurationUnitResult>; interface Windows.Foundation.Collections.IVectorView<TestConfigurationUnitResult>; + interface Windows.Foundation.Collections.IVectorView<ConfigurationSet>; } // Provides a way to centralize the distribution of interfaces relevant to specific implementations of IConfigurationSetProcessorFactory. diff --git a/src/Microsoft.Management.Configuration/Microsoft.Management.Configuration.vcxproj b/src/Microsoft.Management.Configuration/Microsoft.Management.Configuration.vcxproj @@ -214,7 +214,6 @@ <ClInclude Include="GetConfigurationSetDetailsResult.h" /> <ClInclude Include="GetConfigurationUnitDetailsResult.h" /> <ClInclude Include="GetConfigurationUnitSettingsResult.h" /> - <ClInclude Include="MutableFlag.h" /> <ClInclude Include="OpenConfigurationSetResult.h" /> <ClInclude Include="pch.h" /> <ClInclude Include="Telemetry\Telemetry.h" /> @@ -243,7 +242,6 @@ <ClCompile Include="GetConfigurationSetDetailsResult.cpp" /> <ClCompile Include="GetConfigurationUnitDetailsResult.cpp" /> <ClCompile Include="GetConfigurationUnitSettingsResult.cpp" /> - <ClCompile Include="MutableFlag.cpp" /> <ClCompile Include="OpenConfigurationSetResult.cpp" /> <ClCompile Include="pch.cpp"> <PrecompiledHeader>Create</PrecompiledHeader> diff --git a/src/Microsoft.Management.Configuration/Microsoft.Management.Configuration.vcxproj.filters b/src/Microsoft.Management.Configuration/Microsoft.Management.Configuration.vcxproj.filters @@ -30,9 +30,6 @@ <ClCompile Include="GetConfigurationUnitSettingsResult.cpp"> <Filter>API Source</Filter> </ClCompile> - <ClCompile Include="MutableFlag.cpp"> - <Filter>Internals</Filter> - </ClCompile> <ClCompile Include="TestConfigurationSetResult.cpp"> <Filter>API Source</Filter> </ClCompile> @@ -111,9 +108,6 @@ <ClInclude Include="GetConfigurationUnitSettingsResult.h"> <Filter>API Headers</Filter> </ClInclude> - <ClInclude Include="MutableFlag.h"> - <Filter>Internals</Filter> - </ClInclude> <ClInclude Include="TestConfigurationSetResult.h"> <Filter>API Headers</Filter> </ClInclude> diff --git a/src/Microsoft.Management.Configuration/MutableFlag.cpp b/src/Microsoft.Management.Configuration/MutableFlag.cpp @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -#include "pch.h" -#include "MutableFlag.h" - -namespace winrt::Microsoft::Management::Configuration::implementation -{ - void MutableFlag::RequireMutable() const - { - THROW_HR_IF(E_NOT_VALID_STATE, !m_isMutable); - } -} diff --git a/src/Microsoft.Management.Configuration/MutableFlag.h b/src/Microsoft.Management.Configuration/MutableFlag.h @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -#pragma once - -namespace winrt::Microsoft::Management::Configuration::implementation -{ - // Helper to enable objects to enforce being immutable. - struct MutableFlag - { - MutableFlag(bool isMutable = true) : m_isMutable(isMutable) {} - MutableFlag(const MutableFlag&) = default; - MutableFlag& operator=(const MutableFlag&) = default; - MutableFlag(MutableFlag&&) = default; - MutableFlag& operator=(MutableFlag&&) = default; - - // If the state is not mutable, throws. - void RequireMutable() const; - - private: - bool m_isMutable; - }; -} diff --git a/src/Microsoft.Management.Configuration/Telemetry/Telemetry.cpp b/src/Microsoft.Management.Configuration/Telemetry/Telemetry.cpp @@ -282,7 +282,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation allSettingsNames.pop_back(); } - LogConfigUnitRun(setIdentifier, unit.InstanceIdentifier(), unit.UnitName(), details.ModuleName(), unit.Intent(), runIntent, action, resultInformation.ResultCode(), resultInformation.ResultSource(), allSettingsNames); + LogConfigUnitRun(setIdentifier, unit.InstanceIdentifier(), unit.Type(), details.ModuleName(), unit.Intent(), runIntent, action, resultInformation.ResultCode(), resultInformation.ResultSource(), allSettingsNames); } CATCH_LOG(); diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Commands/ConfigurationCommand.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Commands/ConfigurationCommand.cs @@ -295,7 +295,7 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands Resources.ConfigurationApply, Resources.OperationInProgress, Resources.OperationCompleted, - set.ConfigurationUnits.Count); + set.Units.Count); var applyTask = processor.ApplySetAsync(set, ApplyConfigurationSetFlags.None); applyTask.Progress = applyProgressOutput.Progress; @@ -317,7 +317,7 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands { var processor = psConfigurationSet.PsProcessor.Processor; var set = psConfigurationSet.Set; - var totalUnitsCount = set.ConfigurationUnits.Count; + var totalUnitsCount = set.Units.Count; if (totalUnitsCount == 0) { @@ -368,7 +368,7 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands { if (resultInformation.ResultCode != null) { - string errorMessage = $"Failed to get unit details for {unit.UnitName} 0x{resultInformation.ResultCode.HResult:X}" + + string errorMessage = $"Failed to get unit details for {unit.Type} 0x{resultInformation.ResultCode.HResult:X}" + $"{Environment.NewLine}Description: '{resultInformation.Description}'{Environment.NewLine}Details: '{resultInformation.Details}'"; this.WriteError( ErrorRecordErrorId.ConfigurationDetailsError, diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Helpers/ApplyConfigurationSetProgressOutput.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Helpers/ApplyConfigurationSetProgressOutput.cs @@ -119,7 +119,7 @@ namespace Microsoft.WinGet.Configuration.Engine.Helpers string description = resultInformation.Description.Trim(); var message = this.GetUnitFailedMessage(unit, resultInformation); - string errorMessage = $"Configuration unit {unit.UnitName}[{unit.Identifier}] failed with code 0x{resultInformation.ResultCode.HResult:X}" + + string errorMessage = $"Configuration unit {unit.Type}[{unit.Identifier}] failed with code 0x{resultInformation.ResultCode.HResult:X}" + $" and error message:\n{description}\n{resultInformation.Details}\n{message}"; this.cmd.WriteError( ErrorRecordErrorId.ConfigurationApplyError, diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Helpers/ConfigurationUnitInformation.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Helpers/ConfigurationUnitInformation.cs @@ -35,7 +35,7 @@ namespace Microsoft.WinGet.Configuration.Engine.Helpers /// <param name="unit">Configuration unit.</param> public ConfigurationUnitInformation(ConfigurationUnit unit) { - this.header = this.CreateHeader(unit, unit.Details != null ? unit.Details.UnitName : unit.UnitName); + this.header = this.CreateHeader(unit, unit.Details != null ? unit.Details.UnitType : unit.Type); this.information = this.CreateInformation(unit); } @@ -74,16 +74,16 @@ namespace Microsoft.WinGet.Configuration.Engine.Helpers private string CreateInformation(ConfigurationUnit unit) { IConfigurationUnitProcessorDetails details = unit.Details; - ValueSet directives = unit.Directives; + ValueSet metadata = unit.Metadata; var sb = new StringBuilder(); if (details != null) { - this.CreateInformationWithDetails(ref sb, details, directives); + this.CreateInformationWithDetails(ref sb, details, metadata); } else { - this.CreateInformationWithoutDetails(ref sb, directives); + this.CreateInformationWithoutDetails(ref sb, metadata); } // -- Sample output footer -- diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Helpers/GetConfigurationSetDetailsProgressOutput.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Helpers/GetConfigurationSetDetailsProgressOutput.cs @@ -91,7 +91,7 @@ namespace Microsoft.WinGet.Configuration.Engine.Helpers { if (resultInformation.ResultCode != null) { - string errorMessage = $"Failed to get unit details for {unit.UnitName} 0x{resultInformation.ResultCode.HResult:X}" + + string errorMessage = $"Failed to get unit details for {unit.Type} 0x{resultInformation.ResultCode.HResult:X}" + $"{Environment.NewLine}Description: '{resultInformation.Description}'{Environment.NewLine}Details: '{resultInformation.Details}'"; this.cmd.WriteError( ErrorRecordErrorId.ConfigurationDetailsError,