TN MES101 MES Client Control - Managing Client Sessions Example
Description
The following code example can be used to keep the MES Client Control session in synch with the current owning object of an Archestra Graphic hosting the MES Client control. In the example below the owning object reference is made to an InTouch tag "ActiveLine" that corresponds to the object name that hosts the Achestra Graphic. To make this script work, replace the InTouch:ActiveLine.Value reference with a string value for hosting object name.
- Author: Michael Walker
- Published: 04/20/2015
- Applies to:
- System Platform 2014 R2 (Application Server and InTouch)
- MES 2014
Details
The code below performs four major functions:
- Sets the owning object.
- Gets the client session of the MES Client Controls.
- Logs off all Entities
- Performs logon to new entity.
A few notes:
- The embedded MES control has auto-logon enabled.
- OEE.OwningObject is used because the embedded Archestra Symbol element name is "OEE". This will most likely need to be replaced on another system.
Here is a screenshot of the code:
OEE.OwningObject = InTouch:ActiveLine.Value;
'Declarations
dim oResult as aaFactMES.Result;
dim oClientSession as aaFactMES.aaClientSession;
dim oEnt as aaFactMES.aaEnt;
dim sEntity as string;
dim iEntityID as integer;
'Set current Entity from InTouch
sEntity = InTouch:ActiveLine.Value;
'Get Client Session
oResult = aaFactMES.aaClientSession.GetInstance();
if (oResult.Success == false) then
LogMessage("WARNING -:- unable to get Client Session" );
else
oClientSession = oResult.Value;
'Logoff Entities if needed
if ( oClientSession <> null ) then
if ( oClientSession.curUser <> null) then
oResult = oClientSession.curUser.LogoffEnt( -1 );
if ( oResult.Success == true ) then
LogMessage("INFO -:- " + oClientSession.curUser.userName + " has logged off all entities" );
else
LogMessage("WARNING -:- " + oClientSession.curUser.userName + " logon attempt failed");
endif;
endif;
endif;
'Get entity ID and logon
if (oClientSession <> null and sEntity <> "") then
oResult= aaFactMES.aaEnt.EntIdFromName(sEntity.ToString());
iEntityID = oResult.Value;
oResult = oClientSession.curUser.LogonEnt(iEntityID, "", 100.0);
if (oResult.Success == true) then
LogMessage("INFO -:- " + "logon success for user:" + oClientSession.curUser.userName + " entity:" + oClientSession.curUser.curEnt.EntName.ToString());
endif;
endif;
endif;