Skip to content

Commit

Permalink
Extend Configuration COM API for export (#3787)
Browse files Browse the repository at this point in the history
  • Loading branch information
florelis authored Oct 25, 2023
1 parent 190b812 commit 9f3511b
Show file tree
Hide file tree
Showing 25 changed files with 525 additions and 22 deletions.
3 changes: 3 additions & 0 deletions src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,9 @@ Please specify one of them using the --source option to proceed.</value>
<data name="WINGET_CONFIG_ERROR_UNIT_SETTING_CONFIG_ROOT" xml:space="preserve">
<value>A unit contains a setting that requires the config root.</value>
</data>
<data name="WINGET_CONFIG_ERROR_NOT_SUPPORTED_BY_PROCESSOR" xml:space="preserve">
<value>Operation is not supported by the configuration processor.</value>
</data>
<data name="Unavailable" xml:space="preserve">
<value>Unavailable</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerSharedLib/Errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ namespace AppInstaller
WINGET_HRESULT_INFO(WINGET_CONFIG_ERROR_UNIT_INVOKE_INVALID_RESULT, "The configuration unit returned an unexpected result during execution."),
WINGET_HRESULT_INFO(WINGET_CONFIG_ERROR_UNIT_SETTING_CONFIG_ROOT, "A unit contains a setting that requires the config root."),
WINGET_HRESULT_INFO(WINGET_CONFIG_ERROR_UNIT_IMPORT_MODULE_ADMIN, "Loading the module for the configuration unit failed because it requires administrator privileges to run."),
WINGET_HRESULT_INFO(WINGET_CONFIG_ERROR_NOT_SUPPORTED_BY_PROCESSOR, "Operation is not supported by the configuration processor."),

// Errors without the error bit set
WINGET_HRESULT_INFO(WINGET_INSTALLED_STATUS_INSTALL_LOCATION_NOT_APPLICABLE, "The install location is not applicable."),
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerSharedLib/Public/AppInstallerErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
#define WINGET_CONFIG_ERROR_UNIT_INVOKE_INVALID_RESULT ((HRESULT)0x8A15C109)
#define WINGET_CONFIG_ERROR_UNIT_SETTING_CONFIG_ROOT ((HRESULT)0x8A15C110)
#define WINGET_CONFIG_ERROR_UNIT_IMPORT_MODULE_ADMIN ((HRESULT)0x8A15C111)
#define WINGET_CONFIG_ERROR_NOT_SUPPORTED_BY_PROCESSOR ((HRESULT)0x8A15C112)

namespace AppInstaller
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

namespace Microsoft.Management.Configuration.Processor.DscModule
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Microsoft.Management.Configuration.Processor.DscResourcesInfo;
using Microsoft.Management.Configuration.Processor.Exceptions;
using Microsoft.Management.Configuration.Processor.Extensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace Microsoft.Management.Configuration.Processor.Unit
{
using System;
using System.Collections.Generic;
using Microsoft.Management.Configuration;
using Microsoft.Management.Configuration.Processor.Exceptions;
using Microsoft.Management.Configuration.Processor.Extensions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// -----------------------------------------------------------------------------
// <copyright file="GetAllSettingsResult.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------

namespace Microsoft.Management.Configuration.Processor.Unit
{
using System.Collections.Generic;
using Microsoft.Management.Configuration;
using Windows.Foundation.Collections;

/// <summary>
/// Implements IGetAllSettingsResult.
/// </summary>
internal class GetAllSettingsResult : IGetAllSettingsResult
{
/// <summary>
/// Initializes a new instance of the <see cref="GetAllSettingsResult"/> class.
/// </summary>
/// <param name="unit">The configuration unit that the result is for.</param>
public GetAllSettingsResult(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
{
get { return this.InternalResult; }
}

/// <summary>
/// Gets the implementation object for ResultInformation.
/// </summary>
public ConfigurationUnitResultInformation InternalResult { get; } = new ConfigurationUnitResultInformation();

/// <inheritdoc/>
public IList<ValueSet>? Settings { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
namespace Microsoft.Management.Configuration.UnitTests.Helpers
{
using System;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.Management.Configuration.UnitTests.Fixtures;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Windows.Storage.Streams;
using Xunit;
using Xunit.Abstractions;
Expand Down
16 changes: 16 additions & 0 deletions src/Microsoft.Management.Configuration.UnitTests/Helpers/Errors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ internal static class Errors
public static readonly int WINGET_CONFIG_ERROR_SET_DEPENDENCY_CYCLE = unchecked((int)0x8A15C00C);
public static readonly int WINGET_CONFIG_ERROR_INVALID_FIELD_VALUE = unchecked((int)0x8A15C00D);
public static readonly int WINGET_CONFIG_ERROR_MISSING_FIELD = unchecked((int)0x8A15C00E);
public static readonly int WINGET_CONFIG_ERROR_TEST_FAILED = unchecked((int)0x8A15C00F);
public static readonly int WINGET_CONFIG_ERROR_TEST_NOT_RUN = unchecked((int)0x8A15C010);

// Configuration Processor Errors
public static readonly int WINGET_CONFIG_ERROR_UNIT_NOT_INSTALLED = unchecked((int)0x8A15C101);
public static readonly int WINGET_CONFIG_ERROR_UNIT_NOT_FOUND_REPOSITORY = unchecked((int)0x8A15C102);
public static readonly int WINGET_CONFIG_ERROR_UNIT_MULTIPLE_MATCHES = unchecked((int)0x8A15C103);
public static readonly int WINGET_CONFIG_ERROR_UNIT_INVOKE_GET = unchecked((int)0x8A15C104);
public static readonly int WINGET_CONFIG_ERROR_UNIT_INVOKE_TEST = unchecked((int)0x8A15C105);
public static readonly int WINGET_CONFIG_ERROR_UNIT_INVOKE_SET = unchecked((int)0x8A15C106);
public static readonly int WINGET_CONFIG_ERROR_UNIT_MODULE_CONFLICT = unchecked((int)0x8A15C107);
public static readonly int WINGET_CONFIG_ERROR_UNIT_IMPORT_MODULE = unchecked((int)0x8A15C108);
public static readonly int WINGET_CONFIG_ERROR_UNIT_INVOKE_INVALID_RESULT = unchecked((int)0x8A15C109);
public static readonly int WINGET_CONFIG_ERROR_UNIT_SETTING_CONFIG_ROOT = unchecked((int)0x8A15C110);
public static readonly int WINGET_CONFIG_ERROR_UNIT_IMPORT_MODULE_ADMIN = unchecked((int)0x8A15C111);
public static readonly int WINGET_CONFIG_ERROR_NOT_SUPPORTED_BY_PROCESSOR = unchecked((int)0x8A15C112);

#pragma warning restore SA1025 // Code should not contain multiple whitespace in a row
#pragma warning restore SA1600 // Elements should be documented
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// -----------------------------------------------------------------------------
// <copyright file="GetAllSettingsResultInstance.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------

namespace Microsoft.Management.Configuration.UnitTests.Helpers
{
using System.Collections.Generic;
using Microsoft.Management.Configuration;
using Windows.Foundation.Collections;

/// <summary>
/// Implements IGetAllSettingsResult.
/// </summary>
internal sealed class GetAllSettingsResultInstance : IGetAllSettingsResult
{
/// <summary>
/// Initializes a new instance of the <see cref="GetAllSettingsResultInstance"/> class.
/// </summary>
/// <param name="unit">The configuration unit that the result is for.</param>
public GetAllSettingsResultInstance(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
{
get { return this.InternalResult; }
}

/// <summary>
/// Gets the implementation object for ResultInformation.
/// </summary>
public TestConfigurationUnitResultInformation InternalResult { get; } = new TestConfigurationUnitResultInformation();

/// <inheritdoc/>
public IList<ValueSet>? Settings { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ internal TestConfigurationUnitProcessor CreateTestProcessor(ConfigurationUnit un
return this.Processors[unit];
}

/// <summary>
/// Creates a new test processor that supports GetAllSettings for the given unit.
/// </summary>
/// <param name="unit">The unit.</param>
/// <returns>The configuration unit processor.</returns>
internal TestGetAllSettingsConfigurationUnitProcessor CreateGetAllSettingsTestProcessor(ConfigurationUnit unit)
{
var processor = new TestGetAllSettingsConfigurationUnitProcessor(unit);
this.Processors[unit] = processor;
return processor;
}

/// <summary>
/// Creates a new unit processor details for the given unit.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Microsoft.Management.Configuration.UnitTests.Helpers
{
using System;
using System.Collections.Generic;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// -----------------------------------------------------------------------------
// <copyright file="TestGetAllSettingsConfigurationUnitProcessor.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------

namespace Microsoft.Management.Configuration.UnitTests.Helpers
{
/// <summary>
/// A test implementation of IConfigurationProcessorFactory.
/// </summary>
internal class TestGetAllSettingsConfigurationUnitProcessor : TestConfigurationUnitProcessor, IGetAllSettingsConfigurationUnitProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="TestGetAllSettingsConfigurationUnitProcessor"/> class.
/// </summary>
/// <param name="unit">The unit.</param>
internal TestGetAllSettingsConfigurationUnitProcessor(ConfigurationUnit unit)
: base(unit)
{
}

/// <summary>
/// The delegate for GetAllSettings.
/// </summary>
/// <returns>The result.</returns>
internal delegate IGetAllSettingsResult GetAllSettingsDelegateType();

/// <summary>
/// Gets or sets the delegate object for GetAllSettings.
/// </summary>
internal GetAllSettingsDelegateType? GetAllSettingsDelegate { get; set; }

/// <summary>
/// Gets the number of times GetAllSettings is called.
/// </summary>
internal int GetAllSettingsCalls { get; private set; } = 0;

/// <summary>
/// Calls the GetAllSettingsDelegate if one is provided; returns success if not (with no settings values).
/// </summary>
/// <returns>The result.</returns>
public IGetAllSettingsResult GetAllSettings()
{
++this.GetAllSettingsCalls;
if (this.GetAllSettingsDelegate != null)
{
return this.GetAllSettingsDelegate();
}
else
{
return new GetAllSettingsResultInstance(this.Unit);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
namespace Microsoft.Management.Configuration.UnitTests.Tests
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.Management.Configuration.UnitTests.Fixtures;
using Microsoft.Management.Configuration.UnitTests.Helpers;
using Microsoft.VisualBasic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Xunit;
using Xunit.Abstractions;

/// <summary>
/// Unit tests for running test on the processor.
/// Unit tests for running apply on the processor.
/// </summary>
[Collection("UnitTestCollection")]
[OutOfProc]
Expand Down
Loading

0 comments on commit 9f3511b

Please sign in to comment.