开发者

access events when running intraweb application as a service

开发者 https://www.devze.com 2023-01-23 17:02 出处:网络
I\'m running my Standalone Intraweb App as a service. Now i need to implement a function that writes a \"heartbeat\" timestamp to a database table. I\'ve done this in other service app that uses

I'm running my Standalone Intraweb App as a service. Now i need to implement a function that writes a "heartbeat" timestamp to a database table. I've done this in other service app that uses the TSe开发者_C百科rvice Classm where i can use Events like OnAfterInstall, OnExecute etc.

Is there a way i can use that events in a standalone intraweb app running as service ?

Thanks for all info

Wolfgang


I started doing exactly this in my own Intraweb application, though because the IWServiceWizard hides the service details including the main Execute loop, I did it all server-side, I was using Application Mode.

I defined a heartbeat method on my session class (RunSQL is a method on my own Data Access Layer object DBConnection, this could be a simple wrapper around TADOConnection).

function TIWUserSession.UpdateHeartbeat: boolean;
var
  sSQL : string;
begin
  sSQL := 'UPDATE Heartbeats SET LastComms = getdate()'+
          ' WHERE SessionID = '+ IntToStr(FSessionID);

  Result := DBConnection.RunSQL(sSQL);
end;

Once I'd done this it was trivial to call this method (for example) whenever a user opened a new web page.

procedure TIWMyPage.IWAppFormCreate(Sender: TObject);
begin
  inherited;

  Session.UpdateHeartbeat;
end;

This can also be used whenever the user does something that communicates with the server, even if it's an asynchronous event (AJAX).

procedure TIWMyPage.btnRefreshAsyncClick(Sender: TObject; 
  EventParams: TStringList);
begin
  Session.UpdateHeartbeat;
end;


Intraweb supports TIWTimer, so sending a timestamp to the database should be pretty straightforward. Specifics of coding depend on detailed specifications.

0

精彩评论

暂无评论...
验证码 换一张
取 消