-
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sample folders rename. First version of WebStencils SSV engine
- Loading branch information
1 parent
7863944
commit 82312c6
Showing
832 changed files
with
7,386 additions
and
12,864 deletions.
There are no files selected for viewing
92 changes: 46 additions & 46 deletions
92
samples/actionfilters/ActionFilters.dpr → samples/action_filters/ActionFilters.dpr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
2,372 changes: 1,186 additions & 1,186 deletions
2,372
samples/actionfilters/ActionFilters.dproj → samples/action_filters/ActionFilters.dproj
Large diffs are not rendered by default.
Oops, something went wrong.
168 changes: 84 additions & 84 deletions
168
...ctionfilters/ActionFiltersControllerU.pas → ...tion_filters/ActionFiltersControllerU.pas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
94 changes: 47 additions & 47 deletions
94
samples/actionfilters/BusinessObjectsU.pas → samples/action_filters/BusinessObjectsU.pas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
14 changes: 7 additions & 7 deletions
14
samples/actionfilters/WebModuleU.dfm → samples/action_filters/WebModuleU.dfm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.