Click or drag to resize

ContextFactory Class

Factory to create a new context of execution

A context of execution is almost require to instantiate all objects.
Consider the creation of context the entry point of the AskiaPortalCmn usage.

According to the AuthenticationType of the context, the API will be restricted.
For example, a context created for registration (ForRegistration) will only allow the creation of a new user and send to him email(s) to activate the user account.

Inheritance Hierarchy
SystemObject
  AskiaPortalCmnContextFactory

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public static class ContextFactory

The ContextFactory type exposes the following members.

Methods
  NameDescription
Public methodStatic memberCode exampleCreateByLoginOrEmailAndPassword

Creates a new context of execution for the user with the specified login (or email) and password.

Public methodStatic memberCode exampleCreateBySessionKey

Creates a new context of execution for the user behind the session key.

Public methodStatic memberCode exampleCreateByUserEmail

Creates a new context of execution for the user with the specified email address.

Public methodStatic memberCode exampleCreateByUserEncryptedKey

Creates a context using the encryption key of a user.

Public methodStatic memberCode exampleCreateByUserGuid

Creates a new context of execution for the user with the specified GUID.

Public methodStatic memberCode exampleCreateByUserToken

Creates a new context of execution for the user with the specified user token.

Public methodStatic memberCode exampleCreateForRegistration

Creates a special restricted context of execution to register a user account.

Public methodStatic memberCode exampleCreateForSuperAdmin

Creates a new context of execution for the super administrator.

Top
Examples

This example shows how to create a context to register a user.
The created context will restrict the usage of API methods.
It only allow creation of account and send emails to activate it.

using system;
using AskiaPortalCmn;

namespace MyApp 
{
    class Program
    {
         static void Main(string[] args)
         {
                var context = ContextFactory.CreateForRegistration();
                context.User.FirstName = "John";
                context.User.LastName = "Doe";
                context.User.Email = "johndoe@anonymous.com";
                var saveResult = context.User.Save();
                if (saveResult.Success)
                {
                    Console.WriteLine("The account for the user `{0} {1}` was successfully created. An email has been sent to `{2}`",
                                        context.User.FirstName, context.User.LastName, context.User.Email);
                }
                else
                {
                    Console.Error.WriteLine("Unable to create the user account");
                    Console.Error.Write(saveResult.Exception.Message);
                }
         }
    }
}
See Also