Class LicenseEventArgs
Provides data for the LicenseChanged event.
Namespace: Sartorius.SAF.Licensing
Assembly: Sartorius.SAF.Licensing.dll
Syntax
public class LicenseEventArgs : EventArgs
Examples
The following example shows how to use the LicenseChanged event to handle license changes.
[ImportingConstructor]
public LicenseConsumer(ILicenseProvider licenseProvider)
{
this.licenseProvider = licenseProvider ?? throw new ArgumentNullException(nameof(licenseProvider));
this.licenseProvider.LicenseChanged += OnLicenseChanged;
}
private void OnLicenseChanged(Object sender, LicenseEventArgs licenseEventArgs)
{
switch (licenseEventArgs.Action)
{
case LicenseEventAction.Expired:
// one or more feature licenses have expired
// this is called from a worker thread
// remove the features from the application
RemoveFeatures(licenseEventArgs.Removed);
// Show information to the user about the expired features
ShowInfo(licenseEventArgs.Removed);
break;
case LicenseEventAction.Changed:
// a change of license occured. This happens when keys are applied.
// add the feature functionality to the application
AddFeatures(licenseEventArgs.Added);
// remove features that are no longer available
RemoveFeatures(licenseEventArgs.Removed);
// update feature functionality for changed features (e.g. expiration date has been updated, license count has been updated)
ChangeFeatures(licenseEventArgs.Changed);
break;
case LicenseEventAction.Error:
// an error occured when there was a timed check for expired modules
// throw the exception in the UI thread and let the global exception handler take care of application shutdown.
Application.Current.Dispatcher.BeginInvoke(new Action(((ErrorLicenseEventArgs) licenseEventArgs).Throw));
// or use ErrorLicenseEventArgs::Exception to handle the exception here.
// keep in mind this runs on a background thread.
break;
default:
throw new ArgumentOutOfRangeException(nameof(licenseEventArgs));
}
}
Constructors
View SourceLicenseEventArgs(LicenseEventAction, IEnumerable<FeatureInfo>)
Initializes a new instance of the LicenseEventArgs class with the specified action and changed feature infos.
Declaration
public LicenseEventArgs(LicenseEventAction action, IEnumerable<FeatureInfo> changed)
Parameters
Type | Name | Description |
---|---|---|
LicenseEventAction | action | The action. |
System.Collections.Generic.IEnumerable<FeatureInfo> | changed | The changed features. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Constructor only supports the 'Expired' action |
LicenseEventArgs(IEnumerable<FeatureInfo>, IEnumerable<FeatureInfo>)
Initializes a new instance of the LicenseEventArgs class with the specified action and previous and current feature infos.
Declaration
public LicenseEventArgs(IEnumerable<FeatureInfo> previous, IEnumerable<FeatureInfo> current)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<FeatureInfo> | previous | The feature infos that represent the state previous the change. |
System.Collections.Generic.IEnumerable<FeatureInfo> | current | The current. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Constructor only supports the 'Changed' action |
Properties
View SourceAction
Gets the action these event args represent.
Declaration
public LicenseEventAction Action { get; }
Property Value
Type | Description |
---|---|
LicenseEventAction | The action. |
Added
Gets the added feature infos which have been newly licensed.
Declaration
public IReadOnlyList<FeatureInfo> Added { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<FeatureInfo> | The added feature infos which have been newly licensed. |
Changed
Gets the changed feature infos which have changes in the license (e.g. changed count).
Declaration
public IReadOnlyList<FeatureInfo> Changed { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<FeatureInfo> | The added feature infos which have changed in the license. |
Removed
Gets the changed feature infos which have their license revoked or have expired.
Declaration
public IReadOnlyList<FeatureInfo> Removed { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<FeatureInfo> | The changed feature infos which have their license revoked or have expired |
Methods
View SourceFilterExpired(IEnumerable<FeatureInfo>)
Filters for the expired items.
Declaration
[Pure]
protected virtual IEnumerable<FeatureInfo> FilterExpired(IEnumerable<FeatureInfo> changed)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<FeatureInfo> | changed | The changed feature infos. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<FeatureInfo> | All items that have just expired. |
Remarks
The base implementation filters for all FeatureInfos that have a ExpirationDate on the previous day.
This method is used in the constructor of LicenseEventArgs. Do not use instance variables when overriding in a derived class or make your derived class sealed.
GetChanges(IEnumerable<FeatureInfo>, IEnumerable<FeatureInfo>)
Gets the changes between the specified previous state and the specified current state.
Declaration
[Pure]
protected virtual LicenseEventArgs.ChangeInfo GetChanges(IEnumerable<FeatureInfo> previous, IEnumerable<FeatureInfo> current)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<FeatureInfo> | previous | The previous state. |
System.Collections.Generic.IEnumerable<FeatureInfo> | current | The current state. |
Returns
Type | Description |
---|---|
LicenseEventArgs.ChangeInfo | A LicenseEventArgs.ChangeInfo describing the state change. |
Remarks
This method is used in the constructor of LicenseEventArgs. Do not use instance variables when overriding in a derived class or make your derived class sealed.