Class SoContext
Class holding context information about the currently logged on user.
Namespace: SuperOffice
Assembly: SoCore.dll
Syntax
public sealed class SoContext : Object
Examples
Log in and get the users home country:
SoSession session = SoSession.Authenticate("user", "password");
int countryId = SoContext.CurrentPrincipal.HomeCountryId;
session.Close();
Constructors
SoContext()
Class holding context information about the currently logged on user.
Declaration
public SoContext()
Examples
Log in and get the users home country:
SoSession session = SoSession.Authenticate("user", "password");
int countryId = SoContext.CurrentPrincipal.HomeCountryId;
session.Close();
Properties
CurrentIdentity
Obtain the current identity
Declaration
public static ISoIdentity CurrentIdentity { get; }
Property Value
Type | Description |
---|---|
ISoIdentity |
Examples
Log in and get the users home country:
SoSession session = SoSession.Authenticate("user", "password");
int countryId = SoContext.CurrentPrincipal.HomeCountryId;
session.Close();
CurrentPrincipal
Obtain the current principal
Declaration
public static SoPrincipal CurrentPrincipal { get; }
Property Value
Type | Description |
---|---|
SoPrincipal |
Examples
Log in and get the users home country:
SoSession session = SoSession.Authenticate("user", "password");
int countryId = SoContext.CurrentPrincipal.HomeCountryId;
session.Close();
CurrentRealPrincipal
Root principal. Impersonated users will yield the principal of the user impersonating.
Declaration
public static SoPrincipal CurrentRealPrincipal { get; }
Property Value
Type | Description |
---|---|
SoPrincipal |
Examples
Log in and get the users home country:
SoSession session = SoSession.Authenticate("user", "password");
int countryId = SoContext.CurrentPrincipal.HomeCountryId;
session.Close();
IsAuthenticated
True if authenticated
Declaration
public static bool IsAuthenticated { get; }
Property Value
Type | Description |
---|---|
Boolean |
Examples
Log in and get the users home country:
SoSession session = SoSession.Authenticate("user", "password");
int countryId = SoContext.CurrentPrincipal.HomeCountryId;
session.Close();
IsUdefAvailable
Should archive providers add Udefs
Declaration
public static bool IsUdefAvailable { get; }
Property Value
Type | Description |
---|---|
Boolean |
Examples
Log in and get the users home country:
SoSession session = SoSession.Authenticate("user", "password");
int countryId = SoContext.CurrentPrincipal.HomeCountryId;
session.Close();
Methods
CloseCurrentSession()
Close any open session. Does nothing if the current session is already closed.
Declaration
public static void CloseCurrentSession()
Remarks
Will no longer throw an exception if called twice.
Examples
Log in and get the users home country:
SoSession session = SoSession.Authenticate("user", "password");
int countryId = SoContext.CurrentPrincipal.HomeCountryId;
session.Close();
SpawnThread<TArgument>(AsyncOperation<TArgument>, TArgument)
Spawn a new thread in the same SoContext as the currently executed thread.
Declaration
public static AsyncContext SpawnThread<TArgument>(AsyncOperation<TArgument> asyncOperation, TArgument argument)
Parameters
Type | Name | Description |
---|---|---|
AsyncOperation<TArgument> | asyncOperation | Operation executed in the new thread. |
TArgument | argument | Argument passed to the operation executing the thread. |
Returns
Type | Description |
---|---|
AsyncContext | Information about the async operation. |
Type Parameters
Name | Description |
---|---|
TArgument |
Remarks
If the number of threads currently executing in parallel is less then the currently configured maximum allowed threads for parallel execution, a thread is spawned. If the number of threads exceeds this limitation, the current thread is blocked until the number of threads currently executing in parallel is less then the currently configured maximum allowed threads for parallel execution.
Maximum parallel connections are read from the MaxParellalThreads property of the configuration file
Examples
The method implementing the asynchronous operation needs to implement the delegate AsyncOperation:
private void MyAsyncOperation(AsyncContext context, object argument)
{
// Do some stuff...
}
The argument passed to the method is an optional argument selected when spawning off the asynchronous task:
AsyncContext ctx = ThreadManager.SpawnThread(new AsyncOperation(MyAsyncOperation), argument );
SpawnThread<TArgument>(AsyncOperation<TArgument>, TArgument, String)
Spawn a new thread in the same SoContext as the currently executed thread.
Declaration
public static AsyncContext SpawnThread<TArgument>(AsyncOperation<TArgument> asyncOperation, TArgument argument, string threadName)
Parameters
Type | Name | Description |
---|---|---|
AsyncOperation<TArgument> | asyncOperation | Operation executed in the new thread. |
TArgument | argument | Argument passed to the operation executing the thread. |
String | threadName | Thread name, for debugging purposes |
Returns
Type | Description |
---|---|
AsyncContext | Information about the async operation. |
Type Parameters
Name | Description |
---|---|
TArgument |
Remarks
If the number of threads currently executing in parallel is less then the currently configured maximum allowed threads for parallel execution, a thread is spawned. If the number of threads exceeds this limitation, the current thread is blocked until the number of threads currently executing in parallel is less then the currently configured maximum allowed threads for parallel execution.
Maximum parallel connections are read from the MaxParellalThreads property of the configuration file
Examples
The method implementing the asynchronous operation needs to implement the delegate AsyncOperation:
private void MyAsyncOperation(AsyncContext context, object argument)
{
// Do some stuff...
}
The argument passed to the method is an optional argument selected when spawning off the asynchronous task:
AsyncContext ctx = ThreadManager.SpawnThread(new AsyncOperation(MyAsyncOperation), argument, "MyThread");
SpawnThread<TArgument>(AsyncOperation<TArgument>, TArgument, String, Boolean)
Spawn a new thread in the same SoContext as the currently executed thread.
Declaration
public static AsyncContext SpawnThread<TArgument>(AsyncOperation<TArgument> asyncOperation, TArgument argument, string threadName, bool breakOnError)
Parameters
Type | Name | Description |
---|---|---|
AsyncOperation<TArgument> | asyncOperation | Operation executed in the new thread. |
TArgument | argument | Argument passed to the operation executing the thread. |
String | threadName | Thread name, for debugging purposes |
Boolean | breakOnError | Shall the attached debugger break on errors executing the thread. |
Returns
Type | Description |
---|---|
AsyncContext | Information about the async operation. |
Type Parameters
Name | Description |
---|---|
TArgument |
Remarks
If the number of threads currently executing in parallel is less then the currently configured maximum allowed threads for parallel execution, a thread is spawned. If the number of threads exceeds this limitation, the current thread is blocked until the number of threads currently executing in parallel is less then the currently configured maximum allowed threads for parallel execution.
Maximum parallel connections are read from the MaxParellalThreads property of the configuration file
Examples
The method implementing the asynchronous operation needs to implement the delegate AsyncOperation:
private void MyAsyncOperation(AsyncContext context, object argument)
{
// Do some stuff...
}
The argument passed to the method is an optional argument selected when spawning off the asynchronous task:
AsyncContext ctx = ThreadManager.SpawnThread(new AsyncOperation(MyAsyncOperation), argument );
ToString()
If there is a valid principal, return his ToString() - generally for debug purposes. An empty string is returned if there is no valid principal (_currentPrincipal returned null).
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | Current principal's ToString, or string.Empty if the current SoPrincipal is null |
Examples
Log in and get the users home country:
SoSession session = SoSession.Authenticate("user", "password");
int countryId = SoContext.CurrentPrincipal.HomeCountryId;
session.Close();