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.UserList[i]);

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;

相关推荐
HyperAI超神经29 分钟前
【vLLM 学习】Aqlm 示例
java·开发语言·数据库·人工智能·学习·教程·vllm
理想奋斗中1 小时前
MYDB仿MySQL手写数据库项目总结
数据库·mysql·mydb·仿mysql
~在杰难逃~1 小时前
DB-Day10笔记-数据库事务问题补充&Python与MySQL的交互
数据库·笔记·python
小鱼学习笔记1 小时前
4.17---实现商铺和缓存与数据库双写一致以及宕机处理
数据库·缓存
{⌐■_■}2 小时前
【go】什么是Go语言中的GC,作用是什么?调优,sync.Pool优化,逃逸分析演示
java·开发语言·javascript·jvm·数据库·后端·golang
Blossom.1183 小时前
量子计算在金融领域的应用与展望
数据库·人工智能·分布式·金融·架构·量子计算·ai集成
Cachel wood3 小时前
Mysql相关知识2:Mysql隔离级别、MVCC、锁
数据库·python·sql·mysql·中间件·数据分析·django
Hello World呀3 小时前
oracle查询当前用户所有字段和表
数据库·oracle
ssauuuuuu3 小时前
Oracle高级语法篇-merge into语句
数据库·oracle
一只鹿鹿鹿3 小时前
【测试文档】项目测试文档,测试管理规程,测试计划,测试文档模版,软件测试报告书(Word)
数据库·后端·spring·单元测试