ConfigurationUnitAndResource.cs (3869B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="ConfigurationUnitAndResource.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.Management.Configuration.Processor.PowerShell.Helpers 8 { 9 using System; 10 using Microsoft.Management.Configuration; 11 using Microsoft.Management.Configuration.Processor.Helpers; 12 using Microsoft.Management.Configuration.Processor.PowerShell.DscResourcesInfo; 13 using Microsoft.PowerShell.Commands; 14 using Windows.Foundation.Collections; 15 16 /// <summary> 17 /// Contains information about the unit and the DSC resource that applies to it. 18 /// </summary> 19 internal class ConfigurationUnitAndResource 20 { 21 private readonly DscResourceInfoInternal dscResourceInfoInternal; 22 23 /// <summary> 24 /// Initializes a new instance of the <see cref="ConfigurationUnitAndResource"/> class. 25 /// </summary> 26 /// <param name="configurationUnitInternal">Configuration unit internal.</param> 27 /// <param name="dscResourceInfoInternal">DscResourceInfoInternal.</param> 28 public ConfigurationUnitAndResource( 29 ConfigurationUnitAndModule configurationUnitInternal, 30 DscResourceInfoInternal dscResourceInfoInternal) 31 { 32 if (!configurationUnitInternal.ResourceName.Equals(dscResourceInfoInternal.Name, StringComparison.OrdinalIgnoreCase)) 33 { 34 throw new ArgumentException(); 35 } 36 37 this.UnitInternal = configurationUnitInternal; 38 this.dscResourceInfoInternal = dscResourceInfoInternal; 39 } 40 41 /// <summary> 42 /// Gets or initializes the internal unit. 43 /// </summary> 44 public ConfigurationUnitAndModule UnitInternal { get; private init; } 45 46 /// <summary> 47 /// Gets the configuration unit. 48 /// </summary> 49 public ConfigurationUnit Unit 50 { 51 get { return this.UnitInternal.Unit; } 52 } 53 54 /// <summary> 55 /// Gets the DSC resource name. 56 /// </summary> 57 /// <returns>DSC resource name.</returns> 58 public string ResourceName 59 { 60 get { return this.dscResourceInfoInternal.Name; } 61 } 62 63 /// <summary> 64 /// Gets the module specification. 65 /// </summary> 66 public ModuleSpecification? Module 67 { 68 get { return this.UnitInternal.Module; } 69 } 70 71 /// <summary> 72 /// Gets a directive if exits. 73 /// </summary> 74 /// <param name="directiveName">Name of directive.</param> 75 /// <returns>The value of the directive. Null if doesn't exist.</returns> 76 /// <typeparam name="TType">Directive type value.</typeparam> 77 public TType? GetDirective<TType>(string directiveName) 78 where TType : class 79 { 80 return this.UnitInternal.GetDirective<TType>(directiveName); 81 } 82 83 /// <summary> 84 /// Gets a directive bool value. 85 /// </summary> 86 /// <param name="directiveName">Name of directive.</param> 87 /// <returns>The value of the directive. False if not set.</returns> 88 public bool? GetDirective(string directiveName) 89 { 90 return this.UnitInternal.GetDirective(directiveName); 91 } 92 93 /// <summary> 94 /// Gets the settings of the unit. 95 /// </summary> 96 /// <returns>ValueSet with settings.</returns> 97 public ValueSet GetSettings() 98 { 99 return this.UnitInternal.GetExpandedSettings(); 100 } 101 } 102 }