Show / Hide Table of Contents

Class LicenseManager

Inheritance
object
LicenseManager
Implements
ILicenseManager
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.License
Assembly: SoDataBase.dll
Syntax
public class LicenseManager : ILicenseManager

Constructors

LicenseManager(INSLicenseService, ILogger<LicenseManager>)

Injection constructor, perform auto-update of license if nextCheckDate has passed

Declaration
public LicenseManager(INSLicenseService licenseService, ILogger<LicenseManager> logger)
Parameters
Type Name Description
INSLicenseService licenseService
ILogger<LicenseManager> logger

Fields

SuperOfficeOwner

Declaration
public const string SuperOfficeOwner = "superoffice"
Field Value
Type Description
string

Properties

IsInitialized

Check before calling any other method. If false, call InitializeAsync().

Declaration
public bool IsInitialized { get; }
Property Value
Type Description
bool

IsUnitTesting

Turn off some checking to enable unit tests to run

Declaration
[AllowedMultitenantStatic]
public static bool IsUnitTesting { get; set; }
Property Value
Type Description
bool

Methods

ActivateLicenseInfoAsync(ExtendedLicenseInfo, bool, bool, CancellationToken)

Save a new license to the database.

Declaration
public Task ActivateLicenseInfoAsync(ExtendedLicenseInfo newLicense, bool checkSerialNumber = true, bool checkUserLicense = true, CancellationToken cancellationToken = default)
Parameters
Type Name Description
ExtendedLicenseInfo newLicense

New license to save to the database.

bool checkSerialNumber
bool checkUserLicense
CancellationToken cancellationToken
Returns
Type Description
Task
Remarks

ValidateNewLicence is called to validate the license before it is accepted and saved.

Exceptions
Type Condition
SoException

Thrown if license is not valid.

ChangeSerialNumberAsync(string, string, CancellationToken)

Change the new serial number for the installation.

Declaration
public Task ChangeSerialNumberAsync(string newCompanyName, string newSerialNumber, CancellationToken cancellationToken)
Parameters
Type Name Description
string newCompanyName

The new company name

string newSerialNumber

New serial number to change to.

CancellationToken cancellationToken
Returns
Type Description
Task

GetAssociateLicenseUsageCountAsync(AssociateType, int[], CancellationToken)

Provided an associate type and a list of module id's, count how many times each license is used. Deleted associates are not counted. License assignments with 0 license-numbers are not counted.

Declaration
public Task<Dictionary<int, int>> GetAssociateLicenseUsageCountAsync(AssociateType associateType, int[] associateModules, CancellationToken cancellationToken = default)
Parameters
Type Name Description
AssociateType associateType

Associate Type the license is relevant for (employee, external-user, anonymous).

int[] associateModules

Module License ids to count usage of

CancellationToken cancellationToken
Returns
Type Description
Task<Dictionary<int, int>>

Dictionary containing module id as a key and how many times a license is used as value.

GetCurrentLicenseAsync(string, CancellationToken)

Get the current license from a module owner.

Declaration
public Task<(LicenseInfo, DateTime)> GetCurrentLicenseAsync(string moduleOwner, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string moduleOwner

Name of the module owner

CancellationToken cancellationToken
Returns
Type Description
Task<(LicenseInfo, DateTime)>

License as stored in the database.

GetGrantedModuleLicenses(int)

Get granted module licenses for the provided associate.

Declaration
public GrantedModuleLicense[] GetGrantedModuleLicenses(int associateId)
Parameters
Type Name Description
int associateId

Associate id's of the associate to get granted module licenses for.

Returns
Type Description
GrantedModuleLicense[]

Granted module licenses

GetLicenseForAllOwnersFromDBAsync(CancellationToken)

Get all licenses, with usage, from all module owners as they are stored in the database

Declaration
public Task<ExtendedLicenseInfo[]> GetLicenseForAllOwnersFromDBAsync(CancellationToken cancellationToken = default)
Parameters
Type Name Description
CancellationToken cancellationToken
Returns
Type Description
Task<ExtendedLicenseInfo[]>

Array of licenses, with usage, as it is stored in the database.

GetLicenseFromDBAsync(string, CancellationToken)

Get license, with usage, as it is stored in the database for one particular module owner.

Declaration
public Task<ExtendedLicenseInfo> GetLicenseFromDBAsync(string ownerName, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string ownerName

Name of the module owner.

CancellationToken cancellationToken
Returns
Type Description
Task<ExtendedLicenseInfo>

License, with usage, as it is stored in the database. NULL if no license found.

GetLicenseFromFileAsync(string, CancellationToken)

Parse a license from file content for a particular module owner.

Declaration
public Task<ExtendedLicenseInfo> GetLicenseFromFileAsync(string fileContent, CancellationToken cancellationToken)
Parameters
Type Name Description
string fileContent

Content of license file.

CancellationToken cancellationToken
Returns
Type Description
Task<ExtendedLicenseInfo>

License from the database, from file and with usage.

GetLicenseFromLicenseServerAsync(string, string, CancellationToken)

Get License from the license server for a particular module owner.

Declaration
public Task<ExtendedLicenseInfo> GetLicenseFromLicenseServerAsync(string ownerName, string additionalInfo = null, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string ownerName

Name of the module owner to get license from.

string additionalInfo
CancellationToken cancellationToken
Returns
Type Description
Task<ExtendedLicenseInfo>

License from the database, from the license server and with usage.

GetLicenseFromLicenseServerWithAssignmentsAsync(string, bool, string, CancellationToken)

Get License from the license server for a particular module owner. Validates that the license is signed ok.

Declaration
public Task<ExtendedLicenseInfoWithAssignments> GetLicenseFromLicenseServerWithAssignmentsAsync(string ownerName, bool isTestUpgrade = false, string licenseUrl = null, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string ownerName

Name of the module owner to get license from.

bool isTestUpgrade

Is this a test upgrade? Default false.

string licenseUrl
CancellationToken cancellationToken
Returns
Type Description
Task<ExtendedLicenseInfoWithAssignments>

License from the database, from the license server and with new license assignments, and possibly new serial number. Possible exception if license server has not implemented method.

GetLicenseStateFromLicenseServerAsync(string, string, CancellationToken)

Ping the license server and get the current state.

Declaration
public Task<CheckLicenseStatusResult> GetLicenseStateFromLicenseServerAsync(string ownerName, string additionalInfo = null, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string ownerName

Name of the owner to ping.

string additionalInfo

Extra info - packed into NetServer version: "TestUpgrade=true"

CancellationToken cancellationToken
Returns
Type Description
Task<CheckLicenseStatusResult>

Result obtained by the license server.

GetModuleLicenseHistoryFromLicenseServerAsync(ExtendedLicenseInfo, ExtendedModuleLicense, CancellationToken)

Get details about a license from the license server.

Declaration
public Task<string> GetModuleLicenseHistoryFromLicenseServerAsync(ExtendedLicenseInfo licenseInfo, ExtendedModuleLicense moduleLicense, CancellationToken cancellationToken = default)
Parameters
Type Name Description
ExtendedLicenseInfo licenseInfo

Description of the license

ExtendedModuleLicense moduleLicense

Information about a particular module to get information for.

CancellationToken cancellationToken
Returns
Type Description
Task<string>

Information about a particular license module.

GetModuleOwnerAsync(string, CancellationToken)

Get module owner from the owners name.

Declaration
public Task<ModuleOwnerRow> GetModuleOwnerAsync(string moduleOwner, CancellationToken cancellationToken)
Parameters
Type Name Description
string moduleOwner

Name of hte module owner

CancellationToken cancellationToken
Returns
Type Description
Task<ModuleOwnerRow>

Module owner

GetModuleOwnersAsync(CancellationToken)

Get all the module owners.

Declaration
public Task<ModuleOwnerRow[]> GetModuleOwnersAsync(CancellationToken cancellationToken)
Parameters
Type Name Description
CancellationToken cancellationToken
Returns
Type Description
Task<ModuleOwnerRow[]>

Array of module owners

GetSatelliteLicenseUsageCountAsync(int[], CancellationToken)

Provided a list of module id's, count how many times each license is used.

Declaration
public Task<Dictionary<int, int>> GetSatelliteLicenseUsageCountAsync(int[] satelliteModules, CancellationToken cancellationToken = default)
Parameters
Type Name Description
int[] satelliteModules

Module id's to count usage of

CancellationToken cancellationToken
Returns
Type Description
Task<Dictionary<int, int>>

Dictionary containing module id as a key and how many times a license is used as value.

GetSatelliteLicensesAsync(int, bool, CancellationToken)

Obtain information about satellite module licenses

Declaration
public Task<SatelliteModuleLicenseOwner[]> GetSatelliteLicensesAsync(int satelliteId, bool fetchForCentralIfSatelliteIdIsZero, CancellationToken cancellationToken = default)
Parameters
Type Name Description
int satelliteId

Satellite id to check for satellite module licenses. 0 indicates central database

bool fetchForCentralIfSatelliteIdIsZero
CancellationToken cancellationToken
Returns
Type Description
Task<SatelliteModuleLicenseOwner[]>

Satellite module licenses grouped by owners.

GetShopUrlAsync(string, string, CancellationToken)

Get the shop url for a module owner, including a context string

Declaration
public Task<string> GetShopUrlAsync(string ownerName, string context, CancellationToken cancellationToken)
Parameters
Type Name Description
string ownerName
string context
CancellationToken cancellationToken
Returns
Type Description
Task<string>

GetUserLicensesAsync(int, UserType, CancellationToken)

Obtain information about associate module licenses

Declaration
public Task<AssociateModuleLicenseOwner[]> GetUserLicensesAsync(int associateId, UserType allowedType, CancellationToken cancellationToken)
Parameters
Type Name Description
int associateId

Associate id to check for associate module licenses

UserType allowedType
CancellationToken cancellationToken
Returns
Type Description
Task<AssociateModuleLicenseOwner[]>

Associate module licenses grouped by owners.

InitializeAsync()

Should be called before using the license manager.

Declaration
public Task InitializeAsync()
Returns
Type Description
Task

LicenseExists(string)

Determine if a license (owner.module) exists at all - regardsless of numbers, assignment etc

Declaration
public bool LicenseExists(string license)
Parameters
Type Name Description
string license
Returns
Type Description
bool

LoadNewLicenseFromServerIfNeededAsync(string, CancellationToken)

Check nextCheckDate on all modules, and call server for those that are in the past

Declaration
public Task LoadNewLicenseFromServerIfNeededAsync(string additionalInfo = null, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string additionalInfo

Query-string that can contain TestUpgrade=true/false and LicenseUrl=<url to use for fetching licenses>

CancellationToken cancellationToken
Returns
Type Description
Task
Remarks

The virtual SuperOffice.License.LicenseManager.AllowAutoUpdate flag can be used to inhibit auto-updating

MapAndValidateLicenseWithDbAsync(LicenseInfo, CancellationToken)

Get the current license from the database, map the incoming one on to it, and validate to see if the result is acceptable (can be Activated)

Declaration
public Task<ExtendedLicenseInfo> MapAndValidateLicenseWithDbAsync(LicenseInfo newLicense, CancellationToken cancellationToken)
Parameters
Type Name Description
LicenseInfo newLicense
CancellationToken cancellationToken
Returns
Type Description
Task<ExtendedLicenseInfo>

License including activation flags and problem tag

PopulateSignedPublicKey(LicenseInfo, Stream)

Get a SignedPublicKey from a stream

Declaration
public static void PopulateSignedPublicKey(LicenseInfo licenseInfo, Stream publicKeyStream)
Parameters
Type Name Description
LicenseInfo licenseInfo

License info object to populate with public key from stream

Stream publicKeyStream

Stream to read the signed public key from.

RemoveLicenseFromDBAsync(string, CancellationToken)

Remove all information about a licenses from a module owner from the database

Declaration
public Task RemoveLicenseFromDBAsync(string ownerName, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string ownerName
CancellationToken cancellationToken
Returns
Type Description
Task

ToInfo(ModuleLicense)

Declaration
public static string ToInfo(ModuleLicense info)
Parameters
Type Name Description
ModuleLicense info
Returns
Type Description
string

UpgradeToNewPricelistAsync(string, string, string, ProgressEstimateCallback, ProgressStepCallback, CancellationToken)

Upgrade all users in the database from their current 7.5 licenses to the new pricelist in 10.0

Declaration
public Task<bool> UpgradeToNewPricelistAsync(string systemUser, string password, string additionalInfo, ProgressEstimateCallback estimateCB, ProgressStepCallback stepCB, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string systemUser
string password
string additionalInfo
ProgressEstimateCallback estimateCB
ProgressStepCallback stepCB
CancellationToken cancellationToken
Returns
Type Description
Task<bool>

ValidateLicenseInfo(ExtendedLicenseInfo)

Validate that a license is consistent.

Declaration
public void ValidateLicenseInfo(ExtendedLicenseInfo licenseInfo)
Parameters
Type Name Description
ExtendedLicenseInfo licenseInfo

License to validate consistance for

Exceptions
Type Condition
SoException

Thrown if license is not valid.

ValidateLicenseInfo(LicenseInfo, bool)

Validate that a license is consistent.

Declaration
public void ValidateLicenseInfo(LicenseInfo licenseInfo, bool checkSerialNumber = true)
Parameters
Type Name Description
LicenseInfo licenseInfo

License to validate consistancy for

bool checkSerialNumber

Check that Serial Number is consistent. Throws exception if serial number is inconsistent if true. Default = true.

Exceptions
Type Condition
SoException

Thrown if license is not valid.

ValidatePublicKey(SignedPublicKey)

Validate a Public Key

Declaration
public static void ValidatePublicKey(SignedPublicKey publicKey)
Parameters
Type Name Description
SignedPublicKey publicKey

Public key to validate

Exceptions
Type Condition
SoException

Throw if failed to validate public key.

Implements

ILicenseManager

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top