UniGUI Session管理說明

UniGUI Session管理說明

每一個Session對應一個UniMainModule,一個MainForm

因此Session+UniMainModule就可以得到所有Session+使用者的資料

以做管理之用

UniServerModule

Public區定義

UserList:TList; //登入Session List

//事件

procedure TUniServerModule.UniGUIServerModuleCreate(Sender: TObject);

begin

UserList:=UniServerModule.SessionManager.Sessions.SessionList;

end;

//---------------------------------------------------------------------------------

UniMainModule

Public //定義,由設計者自行決

UserID:String; //登入使用者ID

LoginTime:TDateTime; //登入時間

Msg:String; //做Session間訊息傳遞

BrowserType:String; //Session之瀏覽器類別

BrowserVersion:integer; //Session之瀏覽器版本

OSType:String;

IsMobile:Boolean; //Session是否Mobile

RType:Integer; //OnHandleRequest執行類別

//事件,此處可處理Session間的訊息

//只要使用者在瀏覽器有動作,會觸發本事件

//UniGUI的Session接受其他Session的訊息,無法主動顯示,

procedure TUniMainModule.UniGUIMainModuleHandleRequest(ASession: TObject;var Handled: Boolean);

var Session:TUniGUISession;

MF:TMainForm;

begin

Session:=TUniGUISession(ASession);

MF:=TMainForm( Session.UniMainModule.MainForm ); //Session對應的MainForm

case Self.RType of

1:begin

MF.UniLabel1.Caption:='TEST訊息'; //

Session.ShowAlert('OK');

end;

2:begin

end;

3:begin

end;

end;

Self.RType:=-1; //

end;

//---------------------------------------------------------------------------------

LoginForm

//事件,設定Session沒定義的資料

procedure TLoginForm.BtnLoginClick(Sender: TObject);

var ok:Boolean;

C:TUniClientInfoRec; //uniGUIApplication.pas

m:TuniMainModule;

begin

m:=UniMainModule; //

//--處理可否登錄 Ok=True可登入

m.UserID:=Self.EdUser.Text; //UserID在Session沒有,是自行加入

C:=UniApplication.ClientInfoRec;

m.SessionID:=UniSession.SessionID;

m.LoginTime:=Now;

m.BrowserType:=C.BrowserType;

m.BrowserVersion:=C.BrowserVersion;

m.OSType:=C.OSType;

m.IsMobile:=UniSession.IsMobile;

Ok:=True; //自行決定如此處理Ok

//記錄登入使用者處理

if Ok then

begin

ModalResult:=mrOK; // Login is valid so proceed to MainForm ,執行段 Login form會Destory

end;

end;

//---------------------------------------------------------------------------------

MainForm

//事件,列出Session一覽表

procedure TMainForm.UniButton7Click(Sender: TObject);

var i:integer;

Session:TUniGUISession;

m:TUniMainModule; //Session對應的UniMainModule

begin

Self.PageControl.ActivePageIndex:=0;

Self.MLog.Clear;

for i:=0 to UniServerModule.UserList.Count-1 do

begin

Session:= TUniGUISession( UniServerModule.UserListi);

m:=TUniMainModule(Session.UniMainModule);

Self.MLog.Lines.Add( Session.SessionId +','+

m.UserID +','+

FormatDateTime('yyyy.mm.dd-hh:nn:ss.zzz',LoginTime:TDateTime; )+','+

m.BrowserType+','+

inttostr(m.BrowserVersion)+','+

m.OSType+','+

inttostr(ord(m.IsMobile))

);

end;

end;

相关推荐
先吃饱再说1 天前
存储的进化:从 MySQL 到浏览器缓存,数据到底住在哪?
数据库
Nturmoils1 天前
字段太多看不全,ksql 的展开模式和输出控制怎么用
数据库·后端
Databend1 天前
Agent 轨迹分析与归因的数据工程实践
大数据·数据库·agent
这个DBA有点耶1 天前
SQL改写进阶:标量子查询的“隐形代价”与消除实战
数据库·mysql·架构
smallyoung1 天前
数据库乐观锁深度解析:MySQL、PostgreSQL 实战 + Spring Boot 集成指南
数据库·mysql·postgresql
parade岁月1 天前
MySQL JOIN解析:朴实无华但食之有味
数据库·后端
用户3169353811831 天前
MySQL服务无法启动问题解决全记录
数据库
vivo互联网技术1 天前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
倔强的石头_2 天前
《Kingbase护城河》——猎捕慢查询:执行计划的微观解析与索引调优实战
数据库
SelectDB2 天前
Apache Doris Python UDF:让 SQL 直接调用 Python 生态,支撑 Agent 时代复杂业务逻辑
大数据·数据库·python