winget-cli

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

PSConfigurationSet.cs (4579B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="PSConfigurationSet.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace Microsoft.WinGet.Configuration.Engine.PSObjects
      8 {
      9     using System;
     10     using Microsoft.Management.Configuration;
     11 
     12     /// <summary>
     13     /// Wrapper for ConfigurationSet.
     14     /// </summary>
     15     public sealed class PSConfigurationSet
     16     {
     17         private static readonly object ProcessorLock = new ();
     18         private volatile bool hasDetails = false;
     19         private volatile bool operationInProgress = false;
     20 
     21         /// <summary>
     22         /// Initializes a new instance of the <see cref="PSConfigurationSet"/> class.
     23         /// </summary>
     24         /// <param name="psProcessor">The configuration processor wrapper.</param>
     25         /// <param name="set">The configuration set.</param>
     26         internal PSConfigurationSet(PSConfigurationProcessor psProcessor, ConfigurationSet set)
     27         {
     28             this.PsProcessor = psProcessor;
     29             this.Set = set;
     30         }
     31 
     32         /// <summary>
     33         /// Gets the name.
     34         /// </summary>
     35         public string Name
     36         {
     37             get
     38             {
     39                 return this.Set.Name;
     40             }
     41         }
     42 
     43         /// <summary>
     44         /// Gets the instance identifier.
     45         /// </summary>
     46         public Guid InstanceIdentifier
     47         {
     48             get
     49             {
     50                 return this.Set.InstanceIdentifier;
     51             }
     52         }
     53 
     54         /// <summary>
     55         /// Gets the origin.
     56         /// </summary>
     57         public string Origin
     58         {
     59             get
     60             {
     61                 return this.Set.Origin;
     62             }
     63         }
     64 
     65         /// <summary>
     66         /// Gets the source.
     67         /// </summary>
     68         public string Source
     69         {
     70             get
     71             {
     72                 return this.Set.Path;
     73             }
     74         }
     75 
     76         /// <summary>
     77         /// Gets the schema version.
     78         /// </summary>
     79         public string SchemaVersion
     80         {
     81             get
     82             {
     83                 return this.Set.SchemaVersion;
     84             }
     85         }
     86 
     87         /// <summary>
     88         /// Gets the state.
     89         /// TODO: enable once implemented.
     90         /// </summary>
     91         internal string State
     92         {
     93             get
     94             {
     95                 return this.Set.State.ToString();
     96             }
     97         }
     98 
     99         /// <summary>
    100         /// Gets or sets a value indicating whether apply ran.
    101         /// TODO: remove once State is implemented.
    102         /// </summary>
    103         internal bool ApplyCompleted { get; set; }
    104 
    105         /// <summary>
    106         /// Gets the PSConfigurationProcessor.
    107         /// </summary>
    108         internal PSConfigurationProcessor PsProcessor { get; private set; }
    109 
    110         /// <summary>
    111         /// Gets the ConfigurationSet.
    112         /// </summary>
    113         internal ConfigurationSet Set { get; private set; }
    114 
    115         /// <summary>
    116         /// Gets or sets a value indicating whether the details had been retrieved for this set.
    117         /// </summary>
    118         internal bool HasDetails
    119         {
    120             get
    121             {
    122                 lock (ProcessorLock)
    123                 {
    124                     return this.hasDetails;
    125                 }
    126             }
    127 
    128             set
    129             {
    130                 lock (ProcessorLock)
    131                 {
    132                     this.hasDetails = value;
    133                 }
    134             }
    135         }
    136 
    137         /// <summary>
    138         /// Checks if the object is being used by another cmdlet. If not, blocks it for the caller.
    139         /// </summary>
    140         /// <returns>True if no one is using me.</returns>
    141         internal bool CanProcess()
    142         {
    143             lock (ProcessorLock)
    144             {
    145                 if (!this.operationInProgress)
    146                 {
    147                     this.operationInProgress = true;
    148                     return true;
    149                 }
    150 
    151                 return false;
    152             }
    153         }
    154 
    155         /// <summary>
    156         /// The object is no longer in use by a cmdlet.
    157         /// </summary>
    158         internal void DoneProcessing()
    159         {
    160             lock (ProcessorLock)
    161             {
    162                 this.operationInProgress = false;
    163             }
    164         }
    165     }
    166 }