Volk65 Posted November 30, 2017 Share Posted November 30, 2017 Hi! I need to track the closing/termination of the session. As I understand the session can be closed: 1) timeout 2) if the user closed the browser 3) if the "Close;" in the main window 4) other... Where better to catch the event "Session closed" (before closing the session) to record information in the database? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 1, 2017 Share Posted December 1, 2017 Hi, You can use UniMainModule -> OnDestroy event for this Best regards, 1 Quote Link to comment Share on other sites More sharing options...
freedowsRoO Posted January 9, 2020 Share Posted January 9, 2020 Hello!! I made a function to not permit the same user login in two different PCs, so when i detect that same user in another PC i want to kill the old session. Here is the question: How can i kill the session manually, without use "timeout"? I searched in another topics for this and did not find the answer. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 9, 2020 Share Posted January 9, 2020 9 minutes ago, freedowsRoO said: Here is the question: How can i kill the session manually, without use "timeout"? Hello, You can also analyze this demo example I think: \FMSoft\Framework\uniGUI\Demos\Desktop\Session List 1 Quote Link to comment Share on other sites More sharing options...
freedowsRoO Posted January 9, 2020 Share Posted January 9, 2020 2 minutes ago, Sherzod said: Hello, You can also analyze this demo example I think: \FMSoft\Framework\uniGUI\Demos\Desktop\Session List I'm already looked at this demo, this demo show how to get the sessions not how kill them. i'm already use the demo example to save the sessions im my DB. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 9, 2020 Share Posted January 9, 2020 2 minutes ago, freedowsRoO said: this demo show how to get the sessions not how kill them. procedure TMainForm.UniButton2Click(Sender: TObject); var SId : string; SS : TUniGUISession; begin SId := ClientDataSet1.FieldByName('sessionid').AsString; if (SId <> '') and (SId <> UniSession.SessionId) then begin SS := UniServerModule.GetSession(SId); if Assigned(SS) then try SS.TerminateAfterSecs(1); finally SS.UnBusy; end; end; end; 2 Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 9, 2020 Share Posted January 9, 2020 This is what I do on Server Shut Down (UniGUIServerModuleBeforeShutdown), modify my code and use elsewhere by filtering the SessionID in question. Remember that Browsers still open (UniGUIMainModuleSessionTimeout) will force the Server to try and reconnect, so after running my code below on shutdown and subsequent restart you will still get:- "EUniSessionException : Invalid session or session Timeout. (Session not found: ..." error messages in the Server Log until the Browser is closed -or- the session in question is let go of by the Browser. procedure TUniServerModule.UniGUIServerModuleBeforeShutdown(Sender: TObject); var I, p: Integer; S: TUniGUISessions; U: TUniGUISession; begin S:= UniServerModule.SessionManager.Sessions; S.Lock; try for I:= 0 to S.SessionList.Count - 1 do begin U:= S.SessionList; if U.UniMainModule <> nil then begin try U.ReleaseSession; U.Terminate('Closed !'); except end; end; // nil end; // for except end; S.Unlock; end; procedure TUniMainModule.UniGUIMainModuleSessionTimeout(ASession: TObject; var ExtendTimeOut: Integer); var Cmp: TComponent; s, s0, s1, s2: String; begin Inc(SessionMinutesCounter); if UniMainModule.TracePulse = True then begin s:= 'http'; if SecureFlag = True then begin s:= 'HTTPS'; end; DateTimeToString(formattedDateTime, 'dd/mm/yyyy hh:nn:ss.z', Now()); s0:= formattedDateTime; if EditedBy <> '' then begin s0:= EditedBy + ' ' + formattedDateTime; end; ////////////////////////////////////////////////////////////////////////////// try Cmp:= TUniGUIApplication(UniApplication).UniSession.CurrentComponent; if Assigned(Cmp) then begin s1:= Cmp.Name + ' (' + Cmp.ClassName + ')'; if Cmp is TUniControl then s2:= TUniControl(Cmp).OwnerForm.Name else if Cmp is TUniComponent then s2:= TUniComponent(Cmp).OwnerForm.Name else s2:= ''; uniServerModule.Logger.AddLog('ANDY-M', s+' "Session.TimeOut ('+s0+', '+IntToStr(SessionMinutesCounter)+' mins, SessionID:' + SessionIDstr + ', ' + UniMainModule.EditedBy + ', Component ' + s1 + ', Extended 3mins)"'); end else begin uniServerModule.Logger.AddLog('ANDY-M', s+' "Session.TimeOut ('+s0+', '+IntToStr(SessionMinutesCounter)+' mins, SessionID:' + SessionIDstr + ', ' + UniMainModule.EditedBy + ', Extended 3mins)"'); end; except end; end; // TracePulse ////////////////////////////////////////////////////////////////////////////// ExtendTimeOut:= (1000 * 180); // 3mins end; 1 Quote Link to comment Share on other sites More sharing options...
freedowsRoO Posted January 9, 2020 Share Posted January 9, 2020 Thats it! Thank you guys! You are awesome! 1 Quote Link to comment Share on other sites More sharing options...
Freeman35 Posted January 13, 2020 Share Posted January 13, 2020 Hi, @Sherzod TUniGUISession.UnBusy; This procedure not in old version. I have 1484. Is there a aqual code(s) ? thanx 1 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 13, 2020 Share Posted January 13, 2020 Hi, Can you please upgrade to the latest build? Quote Link to comment Share on other sites More sharing options...
Freeman35 Posted January 14, 2020 Share Posted January 14, 2020 I wish, but I can not my money tree died. But I can accept gift Quote Link to comment Share on other sites More sharing options...
MAPS2 Posted March 3, 2021 Share Posted March 3, 2021 On 1/9/2020 at 5:15 PM, Sherzod said: procedure TMainForm.UniButton2Click(Sender: TObject); var SId : string; SS : TUniGUISession; begin SId := ClientDataSet1.FieldByName('sessionid').AsString; if (SId <> '') and (SId <> UniSession.SessionId) then begin SS := UniServerModule.GetSession(SId); if Assigned(SS) then try SS.TerminateAfterSecs(1); finally SS.UnBusy; end; end; end; This code doesn't work with HyperServer, what do you need to adapt to make it work? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.