delphimvcframework/samples/windowsservice/ServiceU.pas

79 lines
1.6 KiB
ObjectPascal
Raw Normal View History

2019-09-25 14:55:39 +02:00
unit ServiceU;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.SvcMgr,
Vcl.Dialogs,
IdHTTPWebBrokerBridge;
type
TArticlesService = class(TService)
procedure ServiceCreate(Sender: TObject);
2019-09-26 07:04:08 +02:00
procedure ServiceExecute(Sender: TService);
2019-09-25 14:55:39 +02:00
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
private
fServer: TIdHTTPWebBrokerBridge;
public
function GetServiceController: TServiceController; override;
end;
var
ArticlesService: TArticlesService;
implementation
uses
Web.WebReq,
2020-02-05 23:46:38 +01:00
WebModuleUnit1, MVCFramework.Commons;
2019-09-25 14:55:39 +02:00
{$R *.DFM}
2020-02-05 23:46:38 +01:00
2019-09-25 14:55:39 +02:00
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
ArticlesService.Controller(CtrlCode);
end;
function TArticlesService.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TArticlesService.ServiceCreate(Sender: TObject);
begin
if WebRequestHandler <> nil then
WebRequestHandler.WebModuleClass := WebModuleClass;
end;
2019-09-26 07:04:08 +02:00
procedure TArticlesService.ServiceExecute(Sender: TService);
begin
while not Terminated do
begin
ServiceThread.ProcessRequests(True);
2019-10-10 00:19:49 +02:00
Sleep(1000);
2019-09-26 07:04:08 +02:00
end;
end;
2019-09-25 14:55:39 +02:00
procedure TArticlesService.ServiceStart(Sender: TService; var Started: Boolean);
begin
fServer := TIdHTTPWebBrokerBridge.Create(nil);
fServer.OnParseAuthentication := TMVCParseAuthentication.OnParseAuthentication;
2019-09-25 14:55:39 +02:00
fServer.DefaultPort := 8080;
fServer.Active := True;
end;
procedure TArticlesService.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
fServer.Free;
end;
end.