Sample folders rename. First version of WebStencils SSV engine
@ -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.
|
@ -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.
|
@ -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.
|
@ -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
|
@ -1,33 +1,33 @@
|
||||
unit WebModuleU;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
System.SysUtils, System.Classes,
|
||||
Web.HTTPApp, MVCFramework;
|
||||
|
||||
type
|
||||
TWebModule1 = class(TWebModule)
|
||||
procedure WebModuleCreate(Sender: TObject);
|
||||
private
|
||||
DMVC: TMVCEngine;
|
||||
end;
|
||||
|
||||
var
|
||||
WebModuleClass: TComponentClass = TWebModule1;
|
||||
|
||||
implementation
|
||||
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
|
||||
uses ActionFiltersControllerU;
|
||||
|
||||
procedure TWebModule1.WebModuleCreate(Sender: TObject);
|
||||
begin
|
||||
DMVC := TMVCEngine.Create(self);
|
||||
DMVC.AddController(TActionFiltersController);
|
||||
end;
|
||||
|
||||
end.
|
||||
unit WebModuleU;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
System.SysUtils, System.Classes,
|
||||
Web.HTTPApp, MVCFramework;
|
||||
|
||||
type
|
||||
TWebModule1 = class(TWebModule)
|
||||
procedure WebModuleCreate(Sender: TObject);
|
||||
private
|
||||
DMVC: TMVCEngine;
|
||||
end;
|
||||
|
||||
var
|
||||
WebModuleClass: TComponentClass = TWebModule1;
|
||||
|
||||
implementation
|
||||
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
|
||||
uses ActionFiltersControllerU;
|
||||
|
||||
procedure TWebModule1.WebModuleCreate(Sender: TObject);
|
||||
begin
|
||||
DMVC := TMVCEngine.Create(self);
|
||||
DMVC.AddController(TActionFiltersController);
|
||||
end;
|
||||
|
||||
end.
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 306 B After Width: | Height: | Size: 306 B |
Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B |
Before Width: | Height: | Size: 293 B After Width: | Height: | Size: 293 B |
Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 247 B |
Before Width: | Height: | Size: 314 B After Width: | Height: | Size: 314 B |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 260 KiB After Width: | Height: | Size: 260 KiB |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 216 B After Width: | Height: | Size: 216 B |
Before Width: | Height: | Size: 308 B After Width: | Height: | Size: 308 B |
Before Width: | Height: | Size: 233 B After Width: | Height: | Size: 233 B |
Before Width: | Height: | Size: 298 B After Width: | Height: | Size: 298 B |