Click or drag to resize

AskiaPortal Common API Documentation

This documentation help you quick start using the AskiaPortal Common API and provide the full API reference.

This topic contains the following sections:

What's the AskiaPortal Common API?

AskiaPortal Common API (AskiaPortalCmn.dll) is a .Net library providing an access to the AskiaPortal database and managing AskiaPortal cross-modules interactions.

It's intended to be used by all of the server-side AskiaPortal modules.

Features
Code styling

Interfaces vs. Classes

Most of the objects in the AskiaPortalCmn API are only available through their interfaces.

As many as possible, it avoid to expose classes and constructors.

For several reasons we feel it's good pattern to be future-proof and to do seamless improvements.

Static factories

To instantiate an object, AskiaPortalCmn API uses static object factories such as ContextFactory, ModuleFactory, UserFactory, GroupFactory, UserProfileFactory, SurveyFactory, ShareFactory, EmailFactory, LanguageFactory, TranslatorFactory, InterpreterFactory, ...

C#
IUser user = UserFactory.FindByGuid(context, guid);

Avoid throwing exception

AskiaPortalCmn API tries as much as possible to not throw exceptions.

try{} catch {} blocks degrade performances and are necessary when an API intensively throw exceptions.

Instead of throwing, AskiaPortalCmn API will, most of the time, returns a result in form of IReturnValue or IReturnValueT.

C#
IReturnValue result = object.Method();
if (!result.Success)
{
    // Use the result.Exception,
    // result.Exception.Code,
    // result.Exception.TranslatedMessage,
    // result.Exception.Message
    // or
    // throw result.Exception;
}
C#
IReturnValue<string> result = object.Method();
if (!result.Success)
{
    // Use the result.Exception,
    // result.Exception.Code,
    // result.Exception.TranslatedMessage,
    // result.Exception.Message
    // or
    // throw result.Exception;
}
// Use the value returned by the method
string value = result.Value;