2017-01-29 16:11:04 +01:00
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Delphi MVC Framework
|
|
|
|
//
|
2024-01-02 17:04:27 +01:00
|
|
|
// Copyright (c) 2010-2024 Daniele Teti and the DMVCFramework Team
|
2017-01-29 16:11:04 +01:00
|
|
|
//
|
|
|
|
// https://github.com/danieleteti/delphimvcframework
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// This IDE expert is based off of the one included with the DUnitX
|
|
|
|
// project. Original source by Robert Love. Adapted by Nick Hodges.
|
|
|
|
//
|
|
|
|
// The DUnitX project is run by Vincent Parrett and can be found at:
|
|
|
|
//
|
|
|
|
// https://github.com/VSoftTechnologies/DUnitX
|
|
|
|
// ***************************************************************************
|
2016-02-23 01:41:13 +01:00
|
|
|
|
|
|
|
unit DMVC.Expert.CodeGen.Templates;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
2021-01-05 17:01:08 +01:00
|
|
|
{$I ..\sources\dmvcframework.inc}
|
2019-08-02 12:32:23 +02:00
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
resourcestring
|
|
|
|
|
2016-09-20 11:10:40 +02:00
|
|
|
{ Delphi template code }
|
|
|
|
// 0 - project name
|
|
|
|
// 1 - http/s port
|
2023-10-23 11:05:07 +02:00
|
|
|
// 2 - UseMSHeapOnWindows
|
2017-04-14 17:28:18 +02:00
|
|
|
sDMVCDPR =
|
|
|
|
'program %0:s;' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
sLineBreak +
|
2019-07-24 03:29:10 +02:00
|
|
|
'{$APPTYPE CONSOLE}' + sLineBreak +
|
|
|
|
sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
'uses' + sLineBreak +
|
2023-10-23 11:05:07 +02:00
|
|
|
' %2:s' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' System.SysUtils,' + sLineBreak +
|
2022-08-13 00:21:00 +02:00
|
|
|
' MVCFramework,' + sLineBreak +
|
2016-11-27 23:17:20 +01:00
|
|
|
' MVCFramework.Logger,' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' MVCFramework.DotEnv,' + sLineBreak +
|
2017-01-29 16:11:04 +01:00
|
|
|
' MVCFramework.Commons,' + sLineBreak +
|
2022-07-25 15:32:31 +02:00
|
|
|
' MVCFramework.Signal,' + sLineBreak +
|
2019-08-02 12:32:23 +02:00
|
|
|
{$IF Defined(SeattleOrBetter)}
|
2019-07-24 03:29:10 +02:00
|
|
|
' Web.ReqMulti, //If you have problem with this unit, see https://quality.embarcadero.com/browse/RSP-17216' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' Web.WebReq,' + sLineBreak +
|
|
|
|
' Web.WebBroker,' + sLineBreak +
|
2019-08-02 12:32:23 +02:00
|
|
|
{$ELSE}
|
|
|
|
' ReqMulti, //If you have problem with this unit, see https://quality.embarcadero.com/browse/RSP-17216' + sLineBreak +
|
|
|
|
' WebReq,' + sLineBreak +
|
|
|
|
' WebBroker,' + sLineBreak +
|
|
|
|
{$ENDIF}
|
2019-07-24 03:29:10 +02:00
|
|
|
' IdContext,' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' IdHTTPWebBrokerBridge;' + sLineBreak +
|
2019-07-24 03:29:10 +02:00
|
|
|
sLineBreak +
|
|
|
|
'{$R *.res}' + sLineBreak +
|
|
|
|
sLineBreak +
|
|
|
|
sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
'procedure RunServer(APort: Integer);' + sLineBreak +
|
|
|
|
'var' + sLineBreak +
|
2019-07-24 03:29:10 +02:00
|
|
|
' LServer: TIdHTTPWebBrokerBridge;' + sLineBreak +
|
2024-01-24 00:14:26 +01:00
|
|
|
'begin' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' LServer := TIdHTTPWebBrokerBridge.Create(nil);' + sLineBreak +
|
|
|
|
' try' + sLineBreak +
|
2019-07-24 20:48:22 +02:00
|
|
|
' LServer.OnParseAuthentication := TMVCParseAuthentication.OnParseAuthentication;' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' LServer.DefaultPort := APort;' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' LServer.KeepAlive := True;' + sLineBreak +
|
|
|
|
' LServer.MaxConnections := dotEnv.Env(''dmvc.webbroker.max_connections'', 0);' + sLineBreak +
|
|
|
|
' LServer.ListenQueue := dotEnv.Env(''dmvc.indy.listen_queue'', 500);' + sLineBreak + sLineBreak +
|
2022-07-25 15:32:31 +02:00
|
|
|
' LServer.Active := True;' + sLineBreak +
|
2024-01-24 00:14:26 +01:00
|
|
|
' LogI(''Listening on port '' + APort.ToString);' + sLineBreak +
|
2024-01-25 19:32:04 +01:00
|
|
|
' LogI(''Application started. Press Ctrl+C to shut down.'');' + sLineBreak +
|
2022-07-25 15:32:31 +02:00
|
|
|
' WaitForTerminationSignal; ' + sLineBreak +
|
2022-08-13 00:21:00 +02:00
|
|
|
' EnterInShutdownState; ' + sLineBreak +
|
|
|
|
' LServer.Active := False; ' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' finally' + sLineBreak +
|
|
|
|
' LServer.Free;' + sLineBreak +
|
|
|
|
' end;' + sLineBreak +
|
2019-07-24 03:29:10 +02:00
|
|
|
'end;' + sLineBreak +
|
|
|
|
sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
'begin' + sLineBreak +
|
2023-06-06 17:33:37 +02:00
|
|
|
' { Enable ReportMemoryLeaksOnShutdown during debug }' + sLineBreak +
|
|
|
|
' // ReportMemoryLeaksOnShutdown := True;' + sLineBreak +
|
|
|
|
' IsMultiThread := True;' + sLineBreak + sLineBreak +
|
2023-01-28 23:31:00 +01:00
|
|
|
' // DMVCFramework Specific Configuration ' + sLineBreak +
|
|
|
|
' // When MVCSerializeNulls = True empty nullables and nil are serialized as json null.' + sLineBreak +
|
|
|
|
' // When MVCSerializeNulls = False empty nullables and nil are not serialized at all.' + sLineBreak +
|
2024-01-24 00:14:26 +01:00
|
|
|
' MVCSerializeNulls := True;' + sLineBreak +
|
|
|
|
' UseConsoleLogger := True;' + sLineBreak + sLineBreak +
|
|
|
|
' LogI(''** DMVCFramework Server ** build '' + DMVCFRAMEWORK_VERSION);' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' try' + sLineBreak +
|
|
|
|
' if WebRequestHandler <> nil then' + sLineBreak +
|
|
|
|
' WebRequestHandler.WebModuleClass := WebModuleClass;' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
'' + sLineBreak +
|
2023-06-14 17:57:33 +02:00
|
|
|
' dotEnvConfigure(' + sLineBreak +
|
|
|
|
' function: IMVCDotEnv' + sLineBreak +
|
|
|
|
' begin' + sLineBreak +
|
|
|
|
' Result := NewDotEnv' + sLineBreak +
|
2023-11-01 23:10:39 +01:00
|
|
|
' .UseStrategy(TMVCDotEnvPriority.FileThenEnv)' + sLineBreak +
|
2023-06-14 17:57:33 +02:00
|
|
|
' //if available, by default, loads default environment (.env)' + sLineBreak +
|
|
|
|
' .UseProfile(''test'') //if available loads the test environment (.env.test)' + sLineBreak +
|
|
|
|
' .UseProfile(''prod'') //if available loads the prod environment (.env.prod)' + sLineBreak +
|
|
|
|
' .UseLogger(procedure(LogItem: String)' + sLineBreak +
|
|
|
|
' begin' + sLineBreak +
|
2024-01-24 00:14:26 +01:00
|
|
|
' LogD(''dotEnv: '' + LogItem);' + sLineBreak +
|
2023-06-14 17:57:33 +02:00
|
|
|
' end)' + sLineBreak +
|
|
|
|
' .Build(); //uses the executable folder to look for .env* files' + sLineBreak +
|
|
|
|
' end);' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
'' + sLineBreak +
|
2023-06-06 17:33:37 +02:00
|
|
|
' WebRequestHandlerProc.MaxConnections := dotEnv.Env(''dmvc.handler.max_connections'', 1024);' + sLineBreak +
|
2023-10-04 23:13:49 +02:00
|
|
|
'' + sLineBreak +
|
|
|
|
' if dotEnv.Env(''dmvc.profiler.enabled'', false) then' + sLineBreak +
|
|
|
|
' begin' + sLineBreak +
|
|
|
|
' Profiler.ProfileLogger := Log;' + sLineBreak +
|
|
|
|
' Profiler.WarningThreshold := dotEnv.Env(''dmvc.profiler.warning_threshold'', 2000);' + sLineBreak +
|
|
|
|
' end;' + sLineBreak +
|
|
|
|
'' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' RunServer(dotEnv.Env(''dmvc.server.port'', %1:d));' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' except' + sLineBreak +
|
|
|
|
' on E: Exception do' + sLineBreak +
|
2024-01-24 00:14:26 +01:00
|
|
|
' LogF(E.ClassName + '': '' + E.Message);' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' end;' + sLineBreak +
|
|
|
|
'end.' + sLineBreak;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
2016-09-20 11:10:40 +02:00
|
|
|
// 0 - Unit Name
|
|
|
|
// 1 - Class Name
|
|
|
|
// 2 - Sample Methods - Interface
|
|
|
|
// 3 - Sample Methods - Implementation
|
|
|
|
// 4 - Action Filters - Interface
|
|
|
|
// 5 - Action Filters - Implementation
|
2023-08-03 17:05:04 +02:00
|
|
|
// 8 - BO - Interface
|
|
|
|
// 9 - BO - Implementation
|
|
|
|
|
2016-09-20 11:10:40 +02:00
|
|
|
sControllerUnit = 'unit %0:s;' + sLineBreak +
|
|
|
|
sLineBreak +
|
|
|
|
'interface' + sLineBreak +
|
|
|
|
sLineBreak +
|
|
|
|
'uses' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' MVCFramework, MVCFramework.Commons, MVCFramework.Serializer.Commons, System.Generics.Collections;' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
sLineBreak +
|
|
|
|
'type' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
'%8:s' + sLineBreak +
|
2018-08-05 20:31:33 +02:00
|
|
|
' [MVCPath(''/api'')]' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' %1:s = class(TMVCController) ' + sLineBreak +
|
|
|
|
' public' + sLineBreak +
|
|
|
|
'%2:s' +
|
|
|
|
'%4:s' +
|
2017-05-17 22:32:45 +02:00
|
|
|
'%6:s' +
|
2016-09-20 11:10:40 +02:00
|
|
|
' end;' + sLineBreak +
|
|
|
|
sLineBreak +
|
2017-01-18 21:53:53 +01:00
|
|
|
'implementation' + sLineBreak + sLineBreak +
|
2016-12-07 12:34:51 +01:00
|
|
|
'uses' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
' System.SysUtils, MVCFramework.Logger, System.StrUtils;' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
sLineBreak +
|
|
|
|
'%3:s' + sLineBreak +
|
|
|
|
'%5:s' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
'%7:s' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
'%9:s' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
'end.' + sLineBreak;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
2016-09-20 11:10:40 +02:00
|
|
|
sIndexMethodIntf =
|
2020-02-03 10:51:40 +01:00
|
|
|
' [MVCPath]' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' [MVCHTTPMethod([httpGET])]' + sLineBreak +
|
2024-01-25 19:32:04 +01:00
|
|
|
' function Index: String;' + sLineBreak + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
' [MVCPath(''/reversedstrings/($Value)'')]' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' [MVCHTTPMethod([httpGET])]' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' [MVCProduces(TMVCMediaType.TEXT_PLAIN)]' + sLineBreak +
|
2024-01-25 19:32:04 +01:00
|
|
|
' function GetReversedString(const Value: String): String;' + sLineBreak;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
2016-09-20 11:10:40 +02:00
|
|
|
// 0 - Class Name
|
|
|
|
sIndexMethodImpl =
|
2024-01-25 19:32:04 +01:00
|
|
|
'function %0:s.Index: String;' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
'begin' + sLineBreak +
|
|
|
|
' //use Context property to access to the HTTP request and response ' + sLineBreak +
|
2024-01-25 19:32:04 +01:00
|
|
|
' Result := ''Hello DelphiMVCFramework World'';' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
'end;' + sLineBreak + sLineBreak +
|
2024-01-25 19:32:04 +01:00
|
|
|
'function %0:s.GetReversedString(const Value: String): String;' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
'begin' + sLineBreak +
|
2024-01-25 19:32:04 +01:00
|
|
|
' Result := System.StrUtils.ReverseString(Value.Trim);' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
'end;' + sLineBreak;
|
2016-09-05 16:19:15 +02:00
|
|
|
|
2017-05-17 22:32:45 +02:00
|
|
|
sCRUDMethodsIntf =
|
|
|
|
sLineBreak +
|
2017-10-09 16:17:12 +02:00
|
|
|
' public' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' //Sample CRUD Actions for a "People" entity' + sLineBreak +
|
|
|
|
' [MVCPath(''/people'')]' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
' [MVCHTTPMethod([httpGET])]' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' function GetPeople: TObjectList<TPerson>;' + sLineBreak + sLineBreak +
|
|
|
|
' [MVCPath(''/people/($ID)'')]' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
' [MVCHTTPMethod([httpGET])]' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' function GetPerson(ID: Integer): TPerson;' + sLineBreak + sLineBreak +
|
|
|
|
' [MVCPath(''/people'')]' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
' [MVCHTTPMethod([httpPOST])]' + sLineBreak +
|
2023-09-04 17:09:41 +02:00
|
|
|
' function CreatePerson([MVCFromBody] Person: TPerson): IMVCResponse;' + sLineBreak + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' [MVCPath(''/people/($ID)'')]' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
' [MVCHTTPMethod([httpPUT])]' + sLineBreak +
|
2023-09-04 17:09:41 +02:00
|
|
|
' function UpdatePerson(ID: Integer; [MVCFromBody] Person: TPerson): IMVCResponse;' + sLineBreak + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' [MVCPath(''/people/($ID)'')]' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
' [MVCHTTPMethod([httpDELETE])]' + sLineBreak +
|
2023-09-04 17:09:41 +02:00
|
|
|
' function DeletePerson(ID: Integer): IMVCResponse;' + sLineBreak + sLineBreak;
|
2017-05-17 22:32:45 +02:00
|
|
|
|
|
|
|
sCRUDMethodsImpl =
|
2023-08-03 17:05:04 +02:00
|
|
|
'//Sample CRUD Actions for a "People" entity' + sLineBreak +
|
|
|
|
'function %0:s.GetPeople: TObjectList<TPerson>;' + sLineBreak +
|
|
|
|
'var' + sLineBreak +
|
|
|
|
' lPeople: TObjectList<TPerson>;' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
'begin' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' lPeople := TObjectList<TPerson>.Create(True);' + sLineBreak +
|
|
|
|
' try' + sLineBreak +
|
|
|
|
' lPeople.Add(TPerson.Create(''Peter'',''Parker'', EncodeDate(1965, 10, 4)));' + sLineBreak +
|
|
|
|
' lPeople.Add(TPerson.Create(''Bruce'',''Banner'', EncodeDate(1945, 9, 6)));' + sLineBreak +
|
|
|
|
' lPeople.Add(TPerson.Create(''Reed'',''Richards'', EncodeDate(1955, 3, 7)));' + sLineBreak +
|
|
|
|
' Result := lPeople;' + sLineBreak +
|
|
|
|
' except' + sLineBreak +
|
|
|
|
' lPeople.Free;' + sLineBreak +
|
|
|
|
' raise;' + sLineBreak +
|
|
|
|
' end;' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
'end;' + sLineBreak + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
'function %0:s.GetPerson(ID: Integer): TPerson;' + sLineBreak +
|
|
|
|
'var' + sLineBreak +
|
|
|
|
' lPeople: TObjectList<TPerson>;' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
'begin' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' lPeople := GetPeople;' + sLineBreak +
|
|
|
|
' try' + sLineBreak +
|
|
|
|
' Result := lPeople.ExtractAt(ID mod lPeople.Count);' + sLineBreak +
|
|
|
|
' finally' + sLineBreak +
|
|
|
|
' lPeople.Free;' + sLineBreak +
|
|
|
|
' end;' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
'end;' + sLineBreak + sLineBreak +
|
2023-09-04 17:09:41 +02:00
|
|
|
'function %0:s.CreatePerson([MVCFromBody] Person: TPerson): IMVCResponse;' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
'begin' + sLineBreak +
|
2023-09-04 17:09:41 +02:00
|
|
|
' LogI(''Created '' + Person.FirstName + '' '' + Person.LastName);' + sLineBreak +
|
|
|
|
' Result := MVCResponseBuilder' + sLineBreak +
|
|
|
|
' .StatusCode(HTTP_STATUS.Created)' + sLineBreak +
|
|
|
|
' .Body(''Person created'')' + sLineBreak +
|
|
|
|
' .Build;' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
'end;' + sLineBreak + sLineBreak +
|
2023-09-04 17:09:41 +02:00
|
|
|
'function %0:s.UpdatePerson(ID: Integer; [MVCFromBody] Person: TPerson): IMVCResponse;' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
'begin' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' LogI(''Updated '' + Person.FirstName + '' '' + Person.LastName);' + sLineBreak +
|
2023-09-04 17:09:41 +02:00
|
|
|
' Result := MVCResponseBuilder' + sLineBreak +
|
|
|
|
' .StatusCode(HTTP_STATUS.NoContent)' + sLineBreak +
|
|
|
|
' .Build;' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
'end;' + sLineBreak + sLineBreak +
|
2023-09-04 17:09:41 +02:00
|
|
|
'function %0:s.DeletePerson(ID: Integer): IMVCResponse;' + sLineBreak +
|
2017-05-17 22:32:45 +02:00
|
|
|
'begin' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
' LogI(''Deleted person with id '' + ID.ToString);' + sLineBreak +
|
2023-09-04 17:09:41 +02:00
|
|
|
' Result := MVCResponseBuilder' + sLineBreak +
|
|
|
|
' .StatusCode(HTTP_STATUS.NoContent)' + sLineBreak +
|
|
|
|
' .Build;' + sLineBreak +
|
2023-08-03 17:05:04 +02:00
|
|
|
'end;' + sLineBreak;
|
2017-05-17 22:32:45 +02:00
|
|
|
|
2016-09-20 11:10:40 +02:00
|
|
|
sActionFiltersIntf =
|
2017-01-18 21:53:53 +01:00
|
|
|
' protected' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' procedure OnBeforeAction(Context: TWebContext; const AActionName: string; var Handled: Boolean); override;'
|
|
|
|
+ sLineBreak +
|
|
|
|
' procedure OnAfterAction(Context: TWebContext; const AActionName: string); override;' +
|
|
|
|
sLineBreak;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
2016-09-20 11:10:40 +02:00
|
|
|
sActionFiltersImpl =
|
|
|
|
'procedure %0:s.OnAfterAction(Context: TWebContext; const AActionName: string); ' + sLineBreak +
|
|
|
|
'begin' + sLineBreak +
|
|
|
|
' { Executed after each action }' + sLineBreak +
|
|
|
|
' inherited;' + sLineBreak +
|
|
|
|
'end;' + sLineBreak +
|
|
|
|
sLineBreak +
|
|
|
|
'procedure %0:s.OnBeforeAction(Context: TWebContext; const AActionName: string; var Handled: Boolean);'
|
|
|
|
+ sLineBreak +
|
|
|
|
'begin' + sLineBreak +
|
|
|
|
' { Executed before each action' + sLineBreak +
|
|
|
|
' if handled is true (or an exception is raised) the actual' + sLineBreak +
|
|
|
|
' action will not be called }' + sLineBreak +
|
|
|
|
' inherited;' + sLineBreak +
|
|
|
|
'end;' + sLineBreak;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
2023-08-03 17:05:04 +02:00
|
|
|
sBOClassesIntf =
|
|
|
|
' [MVCNameCase(ncCamelCase)]' + sLineBreak +
|
|
|
|
' TPerson = class' + sLineBreak +
|
|
|
|
' private' + sLineBreak +
|
|
|
|
' fFirstName: String;' + sLineBreak +
|
|
|
|
' fLastName: String;' + sLineBreak +
|
|
|
|
' fDOB: TDate;' + sLineBreak +
|
|
|
|
' public' + sLineBreak +
|
|
|
|
' property FirstName: String read fFirstName write fFirstName;' + sLineBreak +
|
|
|
|
' property LastName: String read fLastName write fLastName;' + sLineBreak +
|
|
|
|
' property DOB: TDate read fDOB write fDOB; ' + sLineBreak +
|
|
|
|
' constructor Create(FirstName, LastName: String; DOB: TDate);' + sLineBreak +
|
|
|
|
' end;' + sLineBreak;
|
|
|
|
|
|
|
|
sBOClassesImpl =
|
|
|
|
sLineBreak +
|
|
|
|
'constructor %0:s.Create(FirstName, LastName: String; DOB: TDate);' + sLineBreak +
|
|
|
|
'begin' + sLineBreak +
|
|
|
|
' inherited Create;' + sLineBreak +
|
|
|
|
' fFirstName := FirstName;' + sLineBreak +
|
|
|
|
' fLastName := LastName;' + sLineBreak +
|
|
|
|
' fDOB := DOB;' + sLineBreak +
|
|
|
|
'end;' + sLineBreak;
|
|
|
|
|
2016-09-20 11:10:40 +02:00
|
|
|
sDefaultControllerName = 'TMyController';
|
|
|
|
sDefaultWebModuleName = 'TMyWebModule';
|
|
|
|
sDefaultServerPort = '8080';
|
2016-02-24 22:37:13 +01:00
|
|
|
|
2016-09-20 11:10:40 +02:00
|
|
|
// 0 = unit name
|
|
|
|
// 1 = webmodule classname
|
|
|
|
// 2 = controller unit
|
|
|
|
// 3 - controller class name
|
2022-07-25 10:36:30 +02:00
|
|
|
// 4 - middlewares
|
|
|
|
// 5 - jsonrpc registration code
|
2023-10-21 23:46:12 +02:00
|
|
|
// 6 - jsonrpc class unit
|
2016-09-20 11:10:40 +02:00
|
|
|
sWebModuleUnit =
|
|
|
|
'unit %0:s;' + sLineBreak +
|
|
|
|
'' + sLineBreak +
|
|
|
|
'interface' + sLineBreak +
|
|
|
|
sLineBreak +
|
2020-04-29 17:53:29 +02:00
|
|
|
'uses ' + sLineBreak +
|
2022-07-25 10:36:30 +02:00
|
|
|
' System.SysUtils,' + sLineBreak +
|
2020-04-29 17:53:29 +02:00
|
|
|
' System.Classes,' + sLineBreak +
|
|
|
|
' Web.HTTPApp,' + sLineBreak +
|
|
|
|
' MVCFramework;' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
sLineBreak +
|
|
|
|
'type' + sLineBreak +
|
|
|
|
' %1:s = class(TWebModule)' + sLineBreak +
|
|
|
|
' procedure WebModuleCreate(Sender: TObject);' + sLineBreak +
|
|
|
|
' procedure WebModuleDestroy(Sender: TObject);' + sLineBreak +
|
|
|
|
' private' + sLineBreak +
|
|
|
|
' FMVC: TMVCEngine;' + sLineBreak +
|
|
|
|
' public' + sLineBreak +
|
|
|
|
' { Public declarations }' + sLineBreak +
|
|
|
|
' end;' + sLineBreak +
|
|
|
|
sLineBreak +
|
|
|
|
'var' + sLineBreak +
|
|
|
|
' WebModuleClass: TComponentClass = %1:s;' + sLineBreak +
|
|
|
|
sLineBreak +
|
|
|
|
'implementation' + sLineBreak +
|
|
|
|
sLineBreak +
|
|
|
|
'{$R *.dfm}' + sLineBreak +
|
|
|
|
sLineBreak +
|
2020-04-29 17:53:29 +02:00
|
|
|
'uses ' + sLineBreak +
|
2022-07-25 10:36:30 +02:00
|
|
|
' %2:s, ' + sLineBreak +
|
|
|
|
' %6:s ' + sLineBreak +
|
|
|
|
' System.IOUtils, ' + sLineBreak +
|
2020-04-29 17:53:29 +02:00
|
|
|
' MVCFramework.Commons, ' + sLineBreak +
|
2022-08-13 16:10:19 +02:00
|
|
|
' MVCFramework.Middleware.ActiveRecord, ' + sLineBreak +
|
2020-04-29 17:53:29 +02:00
|
|
|
' MVCFramework.Middleware.StaticFiles, ' + sLineBreak +
|
2022-08-13 00:21:00 +02:00
|
|
|
' MVCFramework.Middleware.Analytics, ' + sLineBreak +
|
|
|
|
' MVCFramework.Middleware.Trace, ' + sLineBreak +
|
|
|
|
' MVCFramework.Middleware.CORS, ' + sLineBreak +
|
2022-08-13 10:35:53 +02:00
|
|
|
' MVCFramework.Middleware.ETag, ' + sLineBreak +
|
2020-04-29 17:53:29 +02:00
|
|
|
' MVCFramework.Middleware.Compression;' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
sLineBreak +
|
|
|
|
'procedure %1:s.WebModuleCreate(Sender: TObject);' + sLineBreak +
|
|
|
|
'begin' + sLineBreak +
|
|
|
|
' FMVC := TMVCEngine.Create(Self,' + sLineBreak +
|
|
|
|
' procedure(Config: TMVCConfig)' + sLineBreak +
|
|
|
|
' begin' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config.dotEnv := dotEnv; ' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' // session timeout (0 means session cookie)' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.SessionTimeout] := dotEnv.Env(''dmvc.session_timeout'', ''0'');' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' //default content-type' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.DefaultContentType] := dotEnv.Env(''dmvc.default.content_type'', TMVCConstants.DEFAULT_CONTENT_TYPE);' +
|
2016-09-20 11:10:40 +02:00
|
|
|
sLineBreak +
|
|
|
|
' //default content charset' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.DefaultContentCharset] := dotEnv.Env(''dmvc.default.content_charset'', TMVCConstants.DEFAULT_CONTENT_CHARSET);' +
|
2016-09-20 11:10:40 +02:00
|
|
|
sLineBreak +
|
|
|
|
' //unhandled actions are permitted?' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.AllowUnhandledAction] := dotEnv.Env(''dmvc.allow_unhandled_actions'', ''false'');' + sLineBreak +
|
2020-04-29 18:45:01 +02:00
|
|
|
' //enables or not system controllers loading (available only from localhost requests)' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.LoadSystemControllers] := dotEnv.Env(''dmvc.load_system_controllers'', ''true'');' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' //default view file extension' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.DefaultViewFileExtension] := dotEnv.Env(''dmvc.default.view_file_extension'', ''html'');' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' //view path' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.ViewPath] := dotEnv.Env(''dmvc.view_path'', ''templates'');' + sLineBreak +
|
2023-09-25 23:55:28 +02:00
|
|
|
' //use cache for server side views (use "false" in debug and "true" in production for faster performances' + sLineBreak +
|
|
|
|
' Config[TMVCConfigKey.ViewCache] := dotEnv.Env(''dmvc.view_cache'', ''false'');' + sLineBreak +
|
2018-10-23 16:18:34 +02:00
|
|
|
' //Max Record Count for automatic Entities CRUD' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.MaxEntitiesRecordCount] := dotEnv.Env(''dmvc.max_entities_record_count'', IntToStr(TMVCConstants.MAX_RECORD_COUNT));' + sLineBreak +
|
2023-03-24 17:52:32 +01:00
|
|
|
' //Enable Server Signature in response' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.ExposeServerSignature] := dotEnv.Env(''dmvc.expose_server_signature'', ''false'');' + sLineBreak +
|
2023-03-24 17:52:32 +01:00
|
|
|
' //Enable X-Powered-By Header in response' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.ExposeXPoweredBy] := dotEnv.Env(''dmvc.expose_x_powered_by'', ''true'');' + sLineBreak +
|
2018-12-17 00:39:29 +01:00
|
|
|
' // Max request size in bytes' + sLineBreak +
|
2023-06-06 13:00:21 +02:00
|
|
|
' Config[TMVCConfigKey.MaxRequestSize] := dotEnv.Env(''dmvc.max_request_size'', IntToStr(TMVCConstants.DEFAULT_MAX_REQUEST_SIZE));' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
' end);' + sLineBreak +
|
2020-09-21 12:42:38 +02:00
|
|
|
' FMVC.AddController(%3:s);' + sLineBreak + sLineBreak +
|
2022-07-25 10:36:30 +02:00
|
|
|
' %4:s ' + sLineBreak +
|
|
|
|
' %5:s ' + sLineBreak +
|
2023-03-24 17:52:32 +01:00
|
|
|
' ' + sLineBreak +
|
|
|
|
' {' + sLineBreak +
|
|
|
|
' FMVC.OnWebContextCreate( ' + sLineBreak +
|
|
|
|
' procedure(const Context: TWebContext) ' + sLineBreak +
|
|
|
|
' begin ' + sLineBreak +
|
|
|
|
' // Initialize services to make them accessibile from Context ' + sLineBreak +
|
|
|
|
' // Context.CustomIntfObject := TMyService.Create; ' + sLineBreak +
|
|
|
|
' end); ' + sLineBreak +
|
|
|
|
' ' + sLineBreak +
|
|
|
|
' FMVC.OnWebContextDestroy(' + sLineBreak +
|
|
|
|
' procedure(const Context: TWebContext)' + sLineBreak +
|
|
|
|
' begin' + sLineBreak +
|
|
|
|
' //Cleanup services, if needed' + sLineBreak +
|
|
|
|
' end);' + sLineBreak +
|
|
|
|
' }' + sLineBreak +
|
2016-09-20 11:10:40 +02:00
|
|
|
'end;' + sLineBreak +
|
|
|
|
sLineBreak +
|
|
|
|
'procedure %1:s.WebModuleDestroy(Sender: TObject);' + sLineBreak +
|
|
|
|
'begin' + sLineBreak +
|
|
|
|
' FMVC.Free;' + sLineBreak +
|
|
|
|
'end;' + sLineBreak +
|
|
|
|
sLineBreak +
|
|
|
|
'end.' + sLineBreak;
|
2016-02-24 22:37:13 +01:00
|
|
|
|
2016-09-20 11:10:40 +02:00
|
|
|
sWebModuleDFM =
|
|
|
|
'object %0:s: %1:s' + sLineBreak +
|
|
|
|
' OldCreateOrder = False' + sLineBreak +
|
|
|
|
' OnCreate = WebModuleCreate' + sLineBreak +
|
|
|
|
' OnDestroy = WebModuleDestroy' + sLineBreak +
|
|
|
|
' Height = 230' + sLineBreak +
|
|
|
|
' Width = 415' + sLineBreak +
|
|
|
|
'end';
|
2016-02-23 01:41:13 +01:00
|
|
|
|
2022-07-25 10:36:30 +02:00
|
|
|
|
|
|
|
//0 - unit name
|
|
|
|
//1 - class name
|
|
|
|
sJSONRPCUnit =
|
|
|
|
'unit %0:s; ' + sLineBreak + sLineBreak +
|
|
|
|
'interface' + sLineBreak + sLineBreak +
|
|
|
|
'type ' + sLineBreak +
|
|
|
|
' %1:s = class' + sLineBreak +
|
|
|
|
' public' + sLineBreak +
|
|
|
|
' function ReverseString(const Value: String): String;' + sLineBreak +
|
|
|
|
' end;' + sLineBreak + sLineBreak +
|
|
|
|
'implementation' + sLineBreak + sLineBreak +
|
|
|
|
'uses System.StrUtils;' + sLineBreak + sLineBreak +
|
|
|
|
'function %1:s.ReverseString(const Value: String): String;' + sLineBreak +
|
|
|
|
'begin' + sLineBreak +
|
|
|
|
' Result := System.StrUtils.ReverseString(Value);' + sLineBreak +
|
|
|
|
'end;' + sLineBreak + sLineBreak +
|
|
|
|
'end.' + sLineBreak;
|
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
implementation
|
|
|
|
|
|
|
|
end.
|