2using System.Collections.Generic;
 
    3using System.Globalization;
 
    4using System.Runtime.CompilerServices;
 
    6using System.Threading.Tasks;
 
    8using Microsoft.Extensions.Logging;
 
   37        readonly HashSet<DmbLock> 
locks;
 
   66        static string GetFullLockDescriptor(
DmbLock dmbLock) => $
"{dmbLock.LockID} {dmbLock.EngineVersion} {dmbLock.Descriptor} (Created at {dmbLock.LockTime}){(dmbLock.KeptAlive ? " (RELEASED)
" : String.Empty)}";
 
   80            this.logger = 
logger ?? 
throw new ArgumentNullException(nameof(
logger));
 
   83            locks = 
new HashSet<DmbLock>();
 
 
   98        public IDmbProvider AddLock(
string reason, [CallerFilePath] 
string? callerFile = 
null, [CallerLineNumber]
int callerLine = 
default)
 
  100            ArgumentNullException.ThrowIfNull(reason);
 
  103                if (
locks.Count == 0)
 
  104                    throw new InvalidOperationException($
"No locks exist on the DmbProvider for CompileJob {dmbProvider.CompileJob.Id}!");
 
  106                return CreateLock(reason, callerFile!, callerLine);
 
 
  116            ArgumentNullException.ThrowIfNull(stringBuilder);
 
  118            stringBuilder.AppendLine(CultureInfo.InvariantCulture, $
"Compile Job #{CompileJob.Id}: {CompileJob.DirectoryName}");
 
  120                foreach (var dmbLock 
in locks)
 
  121                    stringBuilder.AppendLine(CultureInfo.InvariantCulture, $
"\t-{GetFullLockDescriptor(dmbLock)}");
 
 
  135            string? descriptor = 
null;
 
  136            ValueTask LockCleanupAction()
 
  138                ValueTask disposeTask = ValueTask.CompletedTask;
 
  141                    logger.LogTrace(
"Removing .dmb Lock: {descriptor}", descriptor);
 
  143                    if (
locks.Remove(newLock!))
 
  144                        logger.LogTrace(
"Lock was removed from list successfully");
 
  146                        logger.LogError(
"A .dmb lock was disposed more than once: {descriptor}", descriptor);
 
  148                    if (
locks.Count == 0)
 
  151                        logger.LogDebug(
"First lock on CompileJob #{compileJobId} removed, it must cleanup {remaining} remaining locks to be cleaned", 
CompileJob.
Id, 
locks.Count);
 
  157            newLock = 
new DmbLock(LockCleanupAction, 
dmbProvider, $
"{callerFile}#{callerLine}: {reason}");
 
  161            logger.LogTrace(
"Created .dmb Lock: {descriptor}", descriptor);
 
 
 
 
virtual ? long Id
The ID of the entity.
 
Manages locks on a given IDmbProvider.
 
readonly DmbLock firstLock
The first lock acquired by the DeploymentLockManager.
 
static string GetFullLockDescriptor(DmbLock dmbLock)
Generates a verbose description of a given dmbLock .
 
IDmbProvider AddLock(string reason, [CallerFilePath] string? callerFile=null, [CallerLineNumber]int callerLine=default)
Add a lock to the managed IDmbProvider.
 
static DeploymentLockManager Create(IDmbProvider dmbProvider, ILogger logger, string initialLockReason, out IDmbProvider firstLock, [CallerFilePath] string? callerFile=null, [CallerLineNumber] int callerLine=default)
Create a DeploymentLockManager.
 
readonly ILogger logger
The ILogger for the DeploymentLockManager.
 
void LogLockStats(StringBuilder stringBuilder)
Add lock stats to a given stringBuilder .
 
readonly HashSet< DmbLock > locks
The DmbLocks on the dmbProvider.
 
readonly IDmbProvider dmbProvider
The IDmbProvider the DeploymentLockManager is managing.
 
DmbLock CreateLock(string reason, string callerFile, int callerLine)
Creates a DmbLock and adds it to locks.
 
DeploymentLockManager(IDmbProvider dmbProvider, ILogger logger, string initialLockReason, string callerFile, int callerLine)
Initializes a new instance of the DeploymentLockManager class.
 
Represents a lock on a given IDmbProvider.
 
Provides absolute paths to the latest compiled .dmbs.
 
Models.CompileJob CompileJob
The CompileJob of the .dmb.