Class LicenseController
Class to handle license acquisition and release. With this a license can be acquired and released after a certain period of time.
public class LicenseController : IDisposable
- Inheritance
-
LicenseController
- Implements
- Inherited Members
Constructors
LicenseController(TimeSpan, Action<CancellationToken>, Action<CancellationToken>, ILogger, TimeProvider, CancellationToken, string)
Class to handle license acquisition and release. When this is used in a using block, the license is released based on the time span provided after the block ends. When the block ends a timer is started to release the license after the time span has elapsed.
public LicenseController(TimeSpan licenseLockTime, Action<CancellationToken> releaseLicenseFunc, Action<CancellationToken> acquireLicenseFunc, ILogger logger, TimeProvider timeProvider = null, CancellationToken cancellationToken = default, string name = "DefaultLicenseController")
Parameters
licenseLockTimeTimeSpanThe time span for which the license is locked.
releaseLicenseFuncAction<CancellationToken>The function to release the license.
acquireLicenseFuncAction<CancellationToken>The function to acquire the license.
loggerILoggerThe logger instance for logging information.
timeProviderTimeProviderThe time provider to use for all time-related operations.
cancellationTokenCancellationTokenThe cancellation token to observe while waiting for the task to complete. Optional.
namestringThe name of the license controller instance.
Exceptions
- ArgumentNullException
Thrown when
releaseLicenseFuncis null.
Properties
LicenseHeld
Gets a boolean indicating whether the license is currently held or not.
public bool LicenseHeld { get; }
Property Value
Methods
AcquireLicense(CancellationToken)
Acquires a license by invoking the license acquisition function and sets the license status to held. Also updates the release timer to ensure the license is released after a certain period.
public void AcquireLicense(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken
Exceptions
- Exception
Thrown when an error occurs while acquiring the license.
BeginUsage()
Begins usage of the license.
public IDisposable BeginUsage()
Returns
- IDisposable
An IDisposable object that can be used to end the license usage.
ClearLicenseState()
Releases the license immediately. This is used externally to reset the internal state when an external process finds out that the license is no longer held.
public void ClearLicenseState()
Dispose()
Disposes the license controller and releases the timer.
public void Dispose()
LogLicenseStatus()
Logs the current license status.
public void LogLicenseStatus()