Click or drag to resize

Module centric context

Many methods in AskiaPortalCmn API optionally require the GUID of the module ( IConfigItem, ITranslatorTranslate, ShareFactory methods...).

This is extremely useful when you want to use data from a different module.

For convenient usage, the API will use the GUID of the current module by default.

This topic contains the following sections:

Initialization of the module

To provide the most friendly usage of the library, AskiaPortalCmn API needs to know which module is currently using it.

Except the call to set the environment mode, the first API calls are done to initialize the current module.

C#
// Entry point of the module
private void Main()
{
  Guid myModuleGuid = Guid.Parse("6d26aeb0-e17d-46d2-a97f-f946c7d88c31");
  Version myModuleVersion = new Version("1.0.0.0");
  AskiaPortalCmnApi.InitializeModule(myModuleGuid, myModuleVersion);
}

Also see the examples of the method AskiaPortalCmnApiInitializeModule

Module setup

A module must be referenced into the database to be available through the API.

In regular usage, the method AskiaPortalCmnApiInitializeModule will throw an exception ExceptionCodeUnableToInitNotFoundModule when the module is not present into the database.
However when you listen for the event AskiaPortalCmnApiOnSetup, the API will then allow you to setup or update the module in the database.

C#
  AskiaPortalCmnApi.OnSetup += AskiaPortalCmnApi_OnSetup;
  Guid myModuleGuid = Guid.Parse("6d26aeb0-e17d-46d2-a97f-f946c7d88c31");
  Version myModuleVersion = new Version("1.0.0.0");
  AskiaPortalCmnApi.InitializeModule(myModuleGuid, myModuleVersion);

// ...
private void AskiaPortalCmnApi_OnSetup(IModuleSetup moduleSetup, IModule currentModule)
{
  // rest of the code to setup or update the module
}

The first line of the above example register a delegate to the OnSetup event in order to setup or update a module.

The delegate SetupHandler, provide two arguments:

IModuleSetup moduleSetup

This object is use to collect all required information about the module (name, description, configuration, translations...), and to save them into the database.

IModule module

This object provide the information of the module currently register. It's null when the module has never been registered in AskiaPortal, or not null when an update is require.

It provide useful information such as the version number of current installed module.

Setup or update

Caution note Caution

The API will trigger the AskiaPortalCmnApiOnSetup in two occasions:

Setup

The module to initialize is not present in the database.
In such case, the second argument of the delegate SetupHandler will be null.

Update

The module to initialize is present in the database, but the version number provided in AskiaPortalCmnApiInitializeModule is higher than the one in the database.

Important note Important
See Also