Skip to content

Commit

Permalink
Sample folders rename. First version of WebStencils SSV engine
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Oct 11, 2024
1 parent 7863944 commit 82312c6
Show file tree
Hide file tree
Showing 832 changed files with 7,386 additions and 12,864 deletions.
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
program ActionFilters;
{$APPTYPE CONSOLE}


uses
System.SysUtils,
MVCFramework.Logger,
Winapi.Windows,
IdHTTPWebBrokerBridge,
Web.WebReq,
Web.WebBroker,
WebModuleU in 'WebModuleU.pas' {WebModule1: TWebModule} ,
ActionFiltersControllerU in 'ActionFiltersControllerU.pas',
BusinessObjectsU in 'BusinessObjectsU.pas';

{$R *.res}


procedure RunServer(APort: Integer);
var
LServer: TIdHTTPWebBrokerBridge;
begin
Writeln(Format('Starting HTTP Server or port %d', [APort]));
LServer := TIdHTTPWebBrokerBridge.Create(nil);
try
LServer.DefaultPort := APort;
LServer.Active := True;
LogI(Format('Server started on port %d', [APort]));
Writeln('Press RETURN to stop the server');
ReadLn;
finally
LServer.Free;
end;
end;

begin
try
if WebRequestHandler <> nil then
WebRequestHandler.WebModuleClass := WebModuleClass;
RunServer(8080);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end

end.
program ActionFilters;
{$APPTYPE CONSOLE}


uses
System.SysUtils,
MVCFramework.Logger,
Winapi.Windows,
IdHTTPWebBrokerBridge,
Web.WebReq,
Web.WebBroker,
WebModuleU in 'WebModuleU.pas' {WebModule1: TWebModule} ,
ActionFiltersControllerU in 'ActionFiltersControllerU.pas',
BusinessObjectsU in 'BusinessObjectsU.pas';

{$R *.res}


procedure RunServer(APort: Integer);
var
LServer: TIdHTTPWebBrokerBridge;
begin
Writeln(Format('Starting HTTP Server or port %d', [APort]));
LServer := TIdHTTPWebBrokerBridge.Create(nil);
try
LServer.DefaultPort := APort;
LServer.Active := True;
LogI(Format('Server started on port %d', [APort]));
Writeln('Press RETURN to stop the server');
ReadLn;
finally
LServer.Free;
end;
end;

begin
try
if WebRequestHandler <> nil then
WebRequestHandler.WebModuleClass := WebModuleClass;
RunServer(8080);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end

end.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
unit ActionFiltersControllerU;

interface

uses
MVCFramework, MVCFramework.Commons;

type

[MVCPath('/')]
TActionFiltersController = class(TMVCController)
protected
procedure MVCControllerAfterCreate; override;
procedure MVCControllerBeforeDestroy; override;

procedure OnBeforeAction(Context: TWebContext; const AActionNAme: string;
var Handled: Boolean); override;
procedure OnAfterAction(Context: TWebContext; const AActionNAme: string);
override;

public
[MVCHTTPMethod([httpGet])]
[MVCPath('/people/($id)')]
[MVCProduces('application/json')]
{ This action cannot be called by a browser address bar because requires the
ACCEPT header to be application/json. Use Postman or RAD Studio's RESTDebugger. }
procedure GetPerson(id: Integer);

end;

implementation

uses
System.SysUtils, BusinessObjectsU, Data.DBXJSON, MVCFramework.Logger;

{ TActionFiltersController }

procedure TActionFiltersController.GetPerson(id: Integer);
var
P: TPerson;
begin
{
Use ID to load the person from a database...
In this example, we're creating a fake person
}
P := TPerson.Create;
P.FirstName := 'Daniele';
P.LastName := 'Teti';
P.DOB := EncodeDate(1975, 5, 2);
P.Married := True;
Render(P);
end;

procedure TActionFiltersController.MVCControllerAfterCreate;
begin
inherited;
// raise Exception.Create('Error Message');
Log.Info('MVCControllerAfterCreate', 'ACTIONFILTERS');
end;

procedure TActionFiltersController.MVCControllerBeforeDestroy;
begin
inherited;
end;

procedure TActionFiltersController.OnAfterAction(Context: TWebContext;
const AActionNAme: string);
begin
inherited;
Log.Info('ACTION CALLED: ' + AActionNAme +
' mapped to ' + Context.Request.PathInfo +
' from ' + Context.Request.ClientIP, 'ACTIONFILTERS');
end;

procedure TActionFiltersController.OnBeforeAction(Context: TWebContext;
const AActionNAme: string; var Handled: Boolean);
begin
inherited;
if DayOfWeek(date) in [1, 7] then
raise Exception.Create('You cannot use this service in the WeekEnd');
// if handled = true (or exception raised) then actual action will not be called
end;

end.
unit ActionFiltersControllerU;

interface

uses
MVCFramework, MVCFramework.Commons;

type

[MVCPath('/')]
TActionFiltersController = class(TMVCController)
protected
procedure MVCControllerAfterCreate; override;
procedure MVCControllerBeforeDestroy; override;

procedure OnBeforeAction(Context: TWebContext; const AActionNAme: string;
var Handled: Boolean); override;
procedure OnAfterAction(Context: TWebContext; const AActionNAme: string);
override;

public
[MVCHTTPMethod([httpGet])]
[MVCPath('/people/($id)')]
[MVCProduces('application/json')]
{ This action cannot be called by a browser address bar because requires the
ACCEPT header to be application/json. Use Postman or RAD Studio's RESTDebugger. }
procedure GetPerson(id: Integer);

end;

implementation

uses
System.SysUtils, BusinessObjectsU, Data.DBXJSON, MVCFramework.Logger;

{ TActionFiltersController }

procedure TActionFiltersController.GetPerson(id: Integer);
var
P: TPerson;
begin
{
Use ID to load the person from a database...
In this example, we're creating a fake person
}
P := TPerson.Create;
P.FirstName := 'Daniele';
P.LastName := 'Teti';
P.DOB := EncodeDate(1975, 5, 2);
P.Married := True;
Render(P);
end;

procedure TActionFiltersController.MVCControllerAfterCreate;
begin
inherited;
// raise Exception.Create('Error Message');
Log.Info('MVCControllerAfterCreate', 'ACTIONFILTERS');
end;

procedure TActionFiltersController.MVCControllerBeforeDestroy;
begin
inherited;
end;

procedure TActionFiltersController.OnAfterAction(Context: TWebContext;
const AActionNAme: string);
begin
inherited;
Log.Info('ACTION CALLED: ' + AActionNAme +
' mapped to ' + Context.Request.PathInfo +
' from ' + Context.Request.ClientIP, 'ACTIONFILTERS');
end;

procedure TActionFiltersController.OnBeforeAction(Context: TWebContext;
const AActionNAme: string; var Handled: Boolean);
begin
inherited;
if DayOfWeek(date) in [1, 7] then
raise Exception.Create('You cannot use this service in the WeekEnd');
// if handled = true (or exception raised) then actual action will not be called
end;

end.
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
unit BusinessObjectsU;

interface

type
TPerson = class
private
FLastName: String;
FDOB: TDate;
FFirstName: String;
FMarried: boolean;
procedure SetDOB(const Value: TDate);
procedure SetFirstName(const Value: String);
procedure SetLastName(const Value: String);
procedure SetMarried(const Value: boolean);
public
property FirstName: String read FFirstName write SetFirstName;
property LastName: String read FLastName write SetLastName;
property DOB: TDate read FDOB write SetDOB;
property Married: boolean read FMarried write SetMarried;
end;

implementation

{ TPerson }

procedure TPerson.SetDOB(const Value: TDate);
begin
FDOB := Value;
end;

procedure TPerson.SetFirstName(const Value: String);
begin
FFirstName := Value;
end;

procedure TPerson.SetLastName(const Value: String);
begin
FLastName := Value;
end;

procedure TPerson.SetMarried(const Value: boolean);
begin
FMarried := Value;
end;

end.
unit BusinessObjectsU;

interface

type
TPerson = class
private
FLastName: String;
FDOB: TDate;
FFirstName: String;
FMarried: boolean;
procedure SetDOB(const Value: TDate);
procedure SetFirstName(const Value: String);
procedure SetLastName(const Value: String);
procedure SetMarried(const Value: boolean);
public
property FirstName: String read FFirstName write SetFirstName;
property LastName: String read FLastName write SetLastName;
property DOB: TDate read FDOB write SetDOB;
property Married: boolean read FMarried write SetMarried;
end;

implementation

{ TPerson }

procedure TPerson.SetDOB(const Value: TDate);
begin
FDOB := Value;
end;

procedure TPerson.SetFirstName(const Value: String);
begin
FFirstName := Value;
end;

procedure TPerson.SetLastName(const Value: String);
begin
FLastName := Value;
end;

procedure TPerson.SetMarried(const Value: boolean);
begin
FMarried := Value;
end;

end.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object WebModule1: TWebModule1
OldCreateOrder = False
OnCreate = WebModuleCreate
Actions = <>
Height = 230
Width = 415
end
object WebModule1: TWebModule1
OldCreateOrder = False
OnCreate = WebModuleCreate
Actions = <>
Height = 230
Width = 415
end
Loading

0 comments on commit 82312c6

Please sign in to comment.