Jump to content

How do I get all the active sections in Hyper Server?


eduardosuruagy

Recommended Posts

for now we have this.

 

http://www.unigui.com/resources/online-documentation/developer-manual

"

Sessions

 

Another important difference from classical model is that in classical model your application is able to access all available session objects while in HyperServer each Node can only access sessions which are created by that specific Node. Needless to say that each Node holds a set of sessions which are isolated from other Nodes. If you need to query all of the sessions then you need to use different methods such as saving session information in a database table. You can simply create a row in the table when session is created and remove it when session is freed.

 

"

  • Upvote 2
Link to comment
Share on other sites

Simple sample:

procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject);
begin
  CDS.FileName := UniServerModule.StartPath + '\dados.dat';
  CDS.CreateDataSet;
  CDS.LoadFromFile(CDS.FileName);
  CDS.Open;

  CDS.Insert;
  CDS.FieldByName('SessionID').AsString := UniSession.SessionId;
  CDS.FieldByName('IP').AsString := UniSession.RemoteIP;;
  CDS.Post;
end;

procedure TUniMainModule.UniGUIMainModuleDestroy(Sender: TObject);
begin
  CDS.Locate('SessionID',UniSession.SessionId,[loCaseInsensitive]);
  CDS.First;
  while not CDS.Eof do
    CDS.Delete;
end;
  • Upvote 2
Link to comment
Share on other sites

  • Administrators

Simple sample:

procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject);
begin
  CDS.FileName := UniServerModule.StartPath + '\dados.dat';
  CDS.CreateDataSet;
  CDS.LoadFromFile(CDS.FileName);
  CDS.Open;

  CDS.Insert;
  CDS.FieldByName('SessionID').AsString := UniSession.SessionId;
  CDS.FieldByName('IP').AsString := UniSession.RemoteIP;;
  CDS.Post;
end;

procedure TUniMainModule.UniGUIMainModuleDestroy(Sender: TObject);
begin
  CDS.Locate('SessionID',UniSession.SessionId,[loCaseInsensitive]);
  CDS.First;
  while not CDS.Eof do
    CDS.Delete;
end;
Your logic is correct but CDS is a memory dataset. For real usage a file based dB is needed

 

Sent from my SM-N950F using Tapatalk

Link to comment
Share on other sites

hi..

 

if the user refresh the browser session id is change and UniGUIMainModuleDestroy never fired

i need get all active session like tradisional unigui act,coz my app limiting connected user count with check count of active session with username login

Link to comment
Share on other sites

hi..

 

if the user refresh the browser session id is change and UniGUIMainModuleDestroy never fired

i need get all active session like tradisional unigui act,coz my app limiting connected user count with check count of active session with username login

It should work even the user refresh the browser.

 

I implement it into a table : qysession :

 

procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject);
var
  formattedDateTime : String;
begin
  qysession.Open;
  qysession.append;
  qysession.FieldByName('ID').AsString := UniSession.SessionId;
  qysession.FieldByName('IP').AsString := UniSession.RemoteIP;
  DateTimeToString(formattedDateTime, 'dd/mm/yy hh:nn:ss', UniSession.LastTimeStamp);
  qysession.FieldByName('logdate').AsString := formattedDateTime;
  qysession.Post;
  qysession.Close;
end;
 
procedure TUniMainModule.UniGUIMainModuleDestroy(Sender: TObject);
begin
 qysession.Open;
 if qysession.Locate('ID',UniSession.SessionId,[loCaseInsensitive]) then
    qysession.delete;
 qysession.Close;
end;
Link to comment
Share on other sites

hi

i try on  1472 not on voyager version

i need record session on database when the user has pass the login form

so i put the record on mainform oncreate event

 

procedure TFrmMain.UniFormCreate(Sender: TObject);

begin

//INSERT SESSION

 PlayWithSession.INSERT_SESSION_DATABASE(UniSession.SessionId,
      UniMainModule.FMyStringVar_user, UniSession.UserAgent, UniPanel5.Caption,
      dm.KONEKSI.Server + ':' + dm.KONEKSI.Database, UniSession.RemoteIP,
      UniSession.RemoteIP);

end;

 

i want to delete record on database with session id

but when user refresh the browser the sessionid always change , so if i put delete session on

UniGUIMainModuleDestroy

begin

//DELETE SESSION

PlayWithSession.DELETE_SESSION_DATABASE(UniSession.SessionId
);

end;

it never find the before sessionid

Link to comment
Share on other sites

Farshad,

 

If it were possible :), my dream code would be this one.
 
A mega challenge, however, would benefit many projects :biggrin:.
var
  HS: THyperServer;
  S : TUniGUISessions;
  U : TUniGUISession;
  vI, vII: Integer;
  MyClassOrVar: TMyClassOrVar;
begin
  if NodeZero then
  begin
    HS := THyperServer.Create;
    HS.Lock;
    try
      for vI := 0 to HS.Nodes.Count -1 do
      begin
        S := HS.Nodes[vI].SessionManager.Sessions;
        for vII := 0 to S.SessionList.Count - 1 do
        begin
          U := S.SessionList[vII];
          MyClassOrVar.Add(TUniMainModule(U.UniMainModule).MyClassOrVar.Name);
        end;
      end;
    finally
      HS.UnLock;
      HS.Free;
    end;
  end;
end;
Link to comment
Share on other sites

I would rather have API REST access to the hyperserver, so I can

monitor many servers from one user interface, and purge nodes

and upload to a single server etc.

 

A restriction of the number of sessions should be set in the config file, ideally,

and also changeable through the API.

 

When I have 20 Hyperservers, it would be nice to be able to change

port settings through an API, instead of editing 20 text files.

  • Upvote 1
Link to comment
Share on other sites

With db to record session list , i can make delete user session when user log out, but if the server restart with any user still connect before the user logout

How to delete all session still exist on db session log?

I try with uniserver event on before shutdown but no success

Link to comment
Share on other sites

  • 1 month later...
On 8/20/2018 at 2:27 PM, Marlon Nardi said:

Farshad,

 

If it were possible :), my dream code would be this one.
 
A mega challenge, however, would benefit many projects :biggrin:.

var
  HS: THyperServer;
  S : TUniGUISessions;
  U : TUniGUISession;
  vI, vII: Integer;
  MyClassOrVar: TMyClassOrVar;
begin
  if NodeZero then
  begin
    HS := THyperServer.Create;
    HS.Lock;
    try
      for vI := 0 to HS.Nodes.Count -1 do
      begin
        S := HS.Nodes[vI].SessionManager.Sessions;
        for vII := 0 to S.SessionList.Count - 1 do
        begin
          U := S.SessionList[vII];
          MyClassOrVar.Add(TUniMainModule(U.UniMainModule).MyClassOrVar.Name);
        end;
      end;
    finally
      HS.UnLock;
      HS.Free;
    end;
  end;
end;

Do I understand correctly that there is no way to go through all the sessions and find out their statuses?  active/discarded

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...