winget-cli

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

ConfigurationEnvironmentData.cs (3082B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="ConfigurationEnvironmentData.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace Microsoft.Management.Configuration.UnitTests.Helpers
      8 {
      9     using System;
     10     using System.Collections.Generic;
     11 
     12     /// <summary>
     13     /// Contains the data defining a configuration environment.
     14     /// </summary>
     15     internal class ConfigurationEnvironmentData
     16     {
     17         /// <summary>
     18         /// Initializes a new instance of the <see cref="ConfigurationEnvironmentData"/> class.
     19         /// </summary>
     20         internal ConfigurationEnvironmentData()
     21         {
     22         }
     23 
     24         /// <summary>
     25         /// Gets or sets the security context.
     26         /// </summary>
     27         internal SecurityContext Context { get; set; } = SecurityContext.Current;
     28 
     29         /// <summary>
     30         /// Gets or sets the processor identifier.
     31         /// </summary>
     32         internal string ProcessorIdentifier { get; set; } = string.Empty;
     33 
     34         /// <summary>
     35         /// Gets or sets the processor properties.
     36         /// </summary>
     37         internal Dictionary<string, string> ProcessorProperties { get; set; } = new ();
     38 
     39         /// <summary>
     40         /// Applies this environment to the given unit.
     41         /// </summary>
     42         /// <param name="unit">The unit to apply to.</param>
     43         /// <returns>The given unit.</returns>
     44         internal ConfigurationUnit ApplyToUnit(ConfigurationUnit unit)
     45         {
     46             var environment = unit.Environment;
     47 
     48             environment.Context = this.Context;
     49             environment.ProcessorIdentifier = this.ProcessorIdentifier;
     50             environment.ProcessorProperties.Clear();
     51             foreach (var property in this.ProcessorProperties)
     52             {
     53                 environment.ProcessorProperties.Add(property.Key, property.Value);
     54             }
     55 
     56             return unit;
     57         }
     58 
     59         /// <summary>
     60         /// Tests whether the given properties match this object's properties.
     61         /// </summary>
     62         /// <param name="properties">The properties to test.</param>
     63         /// <returns>True if the properties match; false if not.</returns>
     64         internal bool PropertiesEqual(IDictionary<string, string> properties)
     65         {
     66             if (properties.Count != this.ProcessorProperties.Count)
     67             {
     68                 return false;
     69             }
     70 
     71             foreach (var property in properties)
     72             {
     73                 string? value = null;
     74                 if (!this.ProcessorProperties.TryGetValue(property.Key, out value))
     75                 {
     76                     return false;
     77                 }
     78 
     79                 if (property.Value != value)
     80                 {
     81                     return false;
     82                 }
     83             }
     84 
     85             return true;
     86         }
     87     }
     88 }