• unigui的session【1】


    目前是1394。

    明白session如何使用管理,看demo Session List和SessionTimeout

    unit Main;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics,
      Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses,
      uniGUIClasses, uniGUIRegClasses, uniGUIForm, uniGUIBaseClasses, uniButton,
      DB, DBClient, uniBasicGrid, uniDBGrid;
    
    type
      TUniSessionInfoRec = record
        ASessionId : string;
        AIP : string;
        AMyVar : string;
        ALastTime: TDateTime;
      end;
    
      TMainForm = class(TUniForm)
        UniButton1: TUniButton;
        ClientDataSet1: TClientDataSet;
        DataSource1: TDataSource;
        ClientDataSet1SessionId: TStringField;
        ClientDataSet1IP: TStringField;
        ClientDataSet1LastTime: TDateTimeField;
        UniDBGrid1: TUniDBGrid;
        ClientDataSet1MyVar: TStringField;
        procedure UniButton1Click(Sender: TObject);
        procedure UniFormCreate(Sender: TObject);
    
        { Private declarations }
      public
        { Public declarations }
        ASessionList : array of TUniSessionInfoRec;
      end;
    
    function MainForm: TMainForm;
    
    implementation
    
    {$R *.dfm}
    
    uses
      uniGUIVars, MainModule, uniGUIApplication, uniGUISessionManager,
      ServerModule;
    
    function MainForm: TMainForm;
    begin
      Result := TMainForm(UniMainModule.GetFormInstance(TMainForm));
    end;
    
    procedure TMainForm.UniButton1Click(Sender: TObject);
    var
      S : TUniGUISessions;
      U : TUniGUISession;
      I : Integer;
    begin
      S := UniServerModule.SessionManager.Sessions;
      S.Lock; // Using Lock on session manager should be used with extreme care.
              // We should keep the "Lock duration"  as short as we can. Session Manager stops working until lock is released.
              // Excessive use of lock/unlock or keeping the lock active for a long period will make uniGUI server slow/unresponsive.
      try
        SetLength(ASessionList, S.SessionList.Count);
    
        // Here we do a fast copy of list to another array for later use.
        for I := 0 to S.SessionList.Count - 1  do
        begin
          U := S.SessionList[I];
          ASessionList[I].ASessionId := U.SessionId;
          ASessionList[I].AIP := U.RemoteIP;
          ASessionList[I].ALastTime := U.LastTimeStamp;
          if U.UniMainModule <> nil then // Check mainModule availability. Some sessions may not have a MainModule instance
            ASessionList[I].AMyVar := (U.UniMainModule as TUniMainModule).FMyStringVar; // Access custom MainModule props
        end;
      finally
        S.Unlock; // ... and finally don't forget to release lock!
      end;
    
      ClientDataSet1.EmptyDataSet;
      for I := Low(ASessionList) to High(ASessionList) do
      begin
        ClientDataSet1.Append;
        ClientDataSet1.FieldByName('sessionid').AsString := ASessionList[I].ASessionId;
        ClientDataSet1.FieldByName('ip').AsString := ASessionList[I].AIP;
        ClientDataSet1.FieldByName('lasttime').AsDateTime := ASessionList[I].ALastTime;
        ClientDataSet1.FieldByName('myvar').AsString := ASessionList[I].AMyVar;
        ClientDataSet1.Post;
      end;
    
    end;
    
    procedure TMainForm.UniFormCreate(Sender: TObject);
    begin
      UniMainModule.FMyStringVar := TimeToStr(Now);
    end;
    
    initialization
      RegisterAppFormClass(TMainForm);
    
    end.
    View Code

    注意代码中的注释

  • 相关阅读:
    CSS基础(十七)--Padding和margin(内边距和外边距)
    tomcat动态网站
    http和nginx错误定义
    nginx动态网站
    nginx动静分离
    nginx负载均衡
    nginx介绍
    cobbler服务器
    apache网络配置
    网络源
  • 原文地址:https://www.cnblogs.com/usegear/p/8978502.html
Copyright © 2020-2023  润新知