Click or drag to resize

IModuleSetup Interface

Manage the registration of a module.

Namespace:  AskiaPortalCmn.Setup
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public interface IModuleSetup

The IModuleSetup type exposes the following members.

Properties
  NameDescription
Public propertyAuthors
Get or set the author(s) of the module.
Public propertyCategory
Get or set the category of the module.
Public propertyDescription
Get or set the description of the module.
Public propertyGuid
Indicates the module GUID that will be use for registration or update.
Public propertyIsBackground
Indicates if the module is a background module.

A background module, doesn't have a frontal User Interface.

Public propertyName
Get or set the name of the module.
Public propertyRootUrl
Get or set the root URL of the module.
Public propertyState
Get or set the state of the module (active by default).
Public propertyVersion
Indicates the module version that will be use for registration or update.
Top
Methods
  NameDescription
Public methodCode exampleSave
Save the module in the database.
Public methodCode exampleSetDefaultConfig
Set the default configuration.
Public methodSetDefaultTranslations
Set the default module translations.
Public methodCode exampleSetUrls
Set the URLs associated with the module.
Top
Examples

Register a module using his main web service (Global.asax).

using System;
using System.Web;
using System.Collections.Generic;
using AskiaPortalCmn;
using AskiaPortalCmn.Setup;
using AskiaPortalCmn.Common;

namespace MyWebModule
{
    public class Global : HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            AskiaPortalCmnApi.OnSetup += AskiaPortalCmnApi_OnSetup;
            var myWebModuleGuid = Guid.Parse("26f6ab8b-2fdb-4f4f-ad14-7507892846a5");
            var myWebModuleVersion = new Version("1.0.0.0");
            AskiaPortalCmnApi.InitializeModule(myWebModuleGuid, myWebModuleVersion);
        }

        private void AskiaPortalCmnApi_OnSetup(IModuleSetup moduleSetup, IModule currentModule)
        {
            if (currentModule != null)
            {
                // This is an update of the version:
                // currentModule.Version
                // to the current assembly version
            }
            else
            {
                // This is the first registration 
                // of the module
            }

            // Set meta information
            moduleSetup.Name = "MyWebModule";
            moduleSetup.Description = "Web module to do something...";
            moduleSetup.Authors = "Myself and Co.";
            moduleSetup.RootUrl = "MyWebModule/";
            moduleSetup.Category = ModuleCategory.SurveysCreation;

            // Set the default module configuration
            moduleSetup.SetDefaultConfig(new Dictionary<string, object>
                {
                    {"myStringKey", "default value"},
                    {"myBoolKey", false},
                    {"myIntKey", 50},
                    {"myDblKey", 50.2},
                    {"myGuidKey", Guid.Parse("26f6ab8b-2fdb-4f4f-ad14-7507892846a5"}
                }
            );

            // Set the default module translations
            moduleSetup.SetDefaultTranslations("en-GB", new Dictionary<string, string>
                {
                    {"new", "New"},
                    {"open", "Open"}
                }
            );
            moduleSetup.SetDefaultTranslations("fr-FR", new Dictionary<string, string>
                {
                    {"new", "Nouveau"},
                    {"open", "Ouvrir"}
                }
            );

            // Set URLs of the module
            moduleSetup.SetUrls(new Dictionary<ModuleUrlFor, string>
            {
                {ModuleUrlTo.ModulePage, ""},
                {ModuleUrlTo.ModuleLogo, "img/logo.svg"},
                {ModuleUrlTo.ModuleLogoHover, "img/logo-hover.svg"},
                {ModuleUrlTo.AdminUserPage, "admin/User/"},
                {ModuleUrlTo.AdminUserProfilePage, "admin/UserProfile/"},
                {ModuleUrlTo.AdminSurveyPage, "admin/Survey/"},
                {ModuleUrlTo.AdminSurveyUserPage, "admin/SurveyUser/"},
                {ModuleUrlTo.AdminSurveyGroupage, "admin/SurveyGroup/"}
            });

            // Save the module
            moduleSetup.Save();
        }
    }
}
See Also