project BLF > class RPCRequestService > method ValidateSession
Description
Check validity of a session id and the session current entity. Start a new session if the provided session id is zero or invalid. Switch the session to required entity if it is valid.
Parameters
| olSessionStarted | output | logical | Set to true if a new session is started. |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program1/rpcrequestservice.p)
if viBLFSessionIdRPCRS = 0
then olSessionStarted = yes.
else do:
viSession3ID = viBLFSessionIdRPCRS.
<I-59 {tFcOpenInstance
&CLASS = "Session"
&ERROR-STATEMENT = "olSessionStarted = yes."
&SESSIONID = "0"}>
if olSessionStarted = no
then do:
<M-81 run IsTimedOut
(output vlFcOk (olIsTimedOut),
output viFcReturnSuper (oiReturnStatus)) in Session>
if vlFcOk
or viFcReturnSuper < 0
then olSessionStarted = yes.
else do:
<M-69 run GetCharacterValue
(input 'CompanyCode' (icName),
output vcSessionCurrentCompany (ocValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
if viFcReturnSuper < 0
then olSessionStarted = yes.
else if vcSessionCurrentCompany = vcEntityRPCRS
then olSessionStarted = no.
else do:
<M-22 run SwitchCompany
(input vcEntityRPCRS (icCompanyCode),
input 0 (iiCompanyId),
output viFcReturnSuper (oiReturnStatus)) in Session>
if viFcReturnSuper < 0
then olSessionStarted = yes.
end.
end.
if olSessionStarted
then do:
<I-85 {tFcCloseAndStopInstance
&CLASS = "Session"
&ERROR-STATEMENT = "olSessionStarted = yes."}>
end.
else do:
<M-95 run SetDebugLevel (input viDebugLevelRPCRS (iiDebugLevel)) in Session>
<I-58 {tFcCloseInstance
&CLASS = "Session"
&ERROR-STATEMENT = "olSessionStarted = yes."}>
end.
end.
end.
if olSessionStarted
then do:
/* BLF-4122 ignore errors from starting or stopping invalid instance of session */
oiReturnStatus = 0.
<I-82 {tFcStartAndOpenInstance
&CLASS = "Session"
&ERROR-STATEMENT = "viSession3ID = 0."
&SESSIONID = "0"}>
if viSession3ID = 0
then do:
create tErrors.
assign tErrors.tcFcMessage = trim(#T-30'Unable to start a session.':255(5148)T-30#)
tErrors.tcFcMsgNumber = "BLF-RPCRS-7"
tErrors.tiFcSeverity = 3
tErrors.tcFcType = "E"
tErrors.tcFcContext = trim(#T-41'This message comes from program/RPCRequestService.p.':255(5142)T-41#)
tErrors.tcFcRowid = string(rowid(tErrors))
oiReturnStatus = -1.
return.
end.
if vcSessionIdRPCRS <> '' and
vcSessionIdRPCRS <> ?
then do:
assign vlValid = true.
<M-38 run ApplicationLogin
(input vcSessionIdRPCRS (icGlobalSessionId),
input vcEntityRPCRS (icCompanyCode),
input 'CompanyCode' + chr(2) + vcEntityRPCRS + chr(2) + 'DebugLevel' + chr(2) + string(viDebugLevelRPCRS) (icExtra),
input false (ilReturnTimeStamps),
output vcFcMaskList (ocReportTimeStamp),
output vcDummy (ocSystCacheDateTime),
output vcDummy (ocSystDateTime),
output viFcReturnSuper (oiReturnStatus)) in Session>
end.
else do:
if vlPasswordIsEncodedRPCRS
then assign vcPasswordRPCRS = string(base64-decode(vcPasswordRPCRS)).
<M-50 run Login
(input vcUserNameRPCRS (icLogin),
input vcPasswordRPCRS (icPassword),
input 'CompanyCode' + chr(2) + vcEntityRPCRS + chr(2) + 'DebugLevel' + chr(2) + string(viDebugLevelRPCRS) (icExtra),
output vlValid (olValid),
output viFcReturnSuper (oiReturnStatus)) in Session>
end.
if not vlValid or
viFcReturnSuper < 0
then do:
run GetPublictFcMessages in vhSession3Inst(output dataset tErrors, output viFcReturnSuper).
create tErrors.
assign tErrors.tcFcMessage = trim(#T-27'Unable to start a session: unable to log in.':255(5150)T-27#)
tErrors.tcFcMsgNumber = "BLF-RPCRS-8"
tErrors.tiFcSeverity = 3
tErrors.tcFcType = "E"
tErrors.tcFcContext = trim(#T-18'This message comes from program/RPCRequestService.p.':255(5142)T-18#)
tErrors.tcFcRowid = string(rowid(tErrors))
oiReturnStatus = -1.
<I-83 {tFcStopInstance
&CLASS = "Session"
&SESSIONID = "viSession3ID"}>
return.
end.
<I-51 {tFcCloseInstance
&CLASS = "Session"}>
end.