forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDSCv3ConfigurationUnitProcessor.cs
More file actions
108 lines (90 loc) · 4.74 KB
/
Copy pathDSCv3ConfigurationUnitProcessor.cs
File metadata and controls
108 lines (90 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// -----------------------------------------------------------------------------
// <copyright file="DSCv3ConfigurationUnitProcessor.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------
namespace Microsoft.Management.Configuration.Processor.DSCv3.Unit
{
using System;
using System.Collections.Generic;
using Microsoft.Management.Configuration;
using Microsoft.Management.Configuration.Processor.DSCv3.Helpers;
using Microsoft.Management.Configuration.Processor.Exceptions;
using Microsoft.Management.Configuration.Processor.Helpers;
using Microsoft.Management.Configuration.Processor.Unit;
using Windows.Foundation.Collections;
/// <summary>
/// Provides access to a specific configuration unit within the runtime.
/// </summary>
internal sealed partial class DSCv3ConfigurationUnitProcessor : ConfigurationUnitProcessorBase, IConfigurationUnitProcessor, IGetAllSettingsConfigurationUnitProcessor, IGetAllUnitsConfigurationUnitProcessor, IDiagnosticsSink
{
private readonly ProcessorSettings processorSettings;
private readonly ResourceDetails? resourceDetails;
/// <summary>
/// Initializes a new instance of the <see cref="DSCv3ConfigurationUnitProcessor"/> class.
/// </summary>
/// <param name="processorSettings">The processor settings to use.</param>
/// <param name="resourceDetails">The resource to use.</param>
/// <param name="unitInternal">Internal unit.</param>
/// <param name="isLimitMode">Whether it is under limit mode.</param>
internal DSCv3ConfigurationUnitProcessor(ProcessorSettings processorSettings, ResourceDetails? resourceDetails, ConfigurationUnitInternal unitInternal, bool isLimitMode = false)
: base(unitInternal, isLimitMode)
{
this.processorSettings = processorSettings;
this.resourceDetails = resourceDetails;
}
/// <inheritdoc />
void IDiagnosticsSink.OnDiagnostics(DiagnosticLevel level, string message)
{
this.OnDiagnostics(level, message);
}
/// <inheritdoc />
protected override ValueSet GetSettingsInternal()
{
return this.processorSettings.DSCv3.GetResourceSettings(this.UnitInternal, ProcessorRunSettings.CreateFromResourceDetails(this.resourceDetails)).Settings;
}
/// <inheritdoc />
protected override bool TestSettingsInternal()
{
return this.processorSettings.DSCv3.TestResource(this.UnitInternal, ProcessorRunSettings.CreateFromResourceDetails(this.resourceDetails)).InDesiredState;
}
/// <inheritdoc />
protected override bool ApplySettingsInternal()
{
return this.processorSettings.DSCv3.SetResourceSettings(this.UnitInternal, ProcessorRunSettings.CreateFromResourceDetails(this.resourceDetails)).RebootRequired;
}
/// <inheritdoc />
protected override IList<ValueSet>? GetAllSettingsInternal()
{
var exportResult = this.processorSettings.DSCv3.ExportResource(this.UnitInternal, ProcessorRunSettings.CreateFromResourceDetails(this.resourceDetails));
string expectedType = this.UnitInternal.QualifiedName.ToLowerInvariant();
List<ValueSet> result = new List<ValueSet>();
foreach (var exportItem in exportResult)
{
if (exportItem.Type.ToLowerInvariant() != expectedType)
{
throw new UnitPropertyUnsupportedException(typeof(IGetAllSettingsConfigurationUnitProcessor));
}
result.Add(exportItem.Settings);
}
return result;
}
/// <inheritdoc />
protected override IList<ConfigurationUnit>? GetAllUnitsInternal()
{
var exportResult = this.processorSettings.DSCv3.ExportResource(this.UnitInternal, ProcessorRunSettings.CreateFromResourceDetails(this.resourceDetails));
List<ConfigurationUnit> result = new List<ConfigurationUnit>();
foreach (var exportItem in exportResult)
{
ConfigurationUnit unit = new ConfigurationUnit();
unit.Type = exportItem.Type;
unit.Identifier = exportItem.Name;
unit.Settings = exportItem.Settings;
unit.Metadata = exportItem.Metadata;
unit.Dependencies = exportItem.Dependencies;
result.Add(unit);
}
return result;
}
}
}