Skip to content

Commit

Permalink
Added Profiler and PATREON label in Wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Apr 19, 2024
1 parent c297081 commit bdfb74a
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 75 deletions.
97 changes: 71 additions & 26 deletions ideexpert/DMVC.Expert.CodeGen.Commands.pas
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@ TUnitControllerEntityDeclarationCommand = class(TCustomCommand)
end;


TUnitControllerDeclarationCommand = class(TCustomCommand)
public
procedure ExecuteInterface(
Section: TStringBuilder;
Model: TJSONObject
); override;
end;

TUnitControllerControllerDeclarationCommand = class(TCustomCommand)
public
procedure ExecuteInterface(
Expand Down Expand Up @@ -272,7 +264,7 @@ procedure TUnitProgramCommand.ExecuteInterface(

if Model[TConfigKey.program_msheap] then
begin
Section.AppendLine(' MSHeap,');
Section.AppendLine(' {$IF Defined(MSWINDOWS)}MSHeap,{$ENDIF}');
end;

Section
Expand Down Expand Up @@ -328,16 +320,6 @@ procedure TUnitControllerCommand.ExecuteInterface(Section: TStringBuilder;
.AppendLine('type')
end;

{ TUnitControllerDeclarationCommand }

procedure TUnitControllerDeclarationCommand.ExecuteInterface(Section: TStringBuilder;
Model: TJSONObject);
begin
inherited;


end;

procedure TUnitControllerEntityDeclarationCommand.ExecuteImplementation(
Section: TStringBuilder; Model: TJsonObject);
begin
Expand Down Expand Up @@ -429,13 +411,31 @@ procedure TUnitControllerControllerDeclarationCommand.ExecuteImplementation(
Section
.AppendLine
.AppendLine('function ' + Model[TConfigKey.controller_classname] + '.Index: String;')
.AppendLine('begin')
.AppendLine('begin');
if Model.B[TConfigKey.controller_actions_profiling_generate] then
begin
Section
.AppendLine('{$IF CompilerVersion >= 34} //SYDNEY+')
.AppendLine(' var lProf := Profiler.Start(Context.ActionQualifiedName);')
.AppendLine('{$ENDIF}')
.AppendLine;
end;
Section
.AppendLine(' //use Context property to access to the HTTP request and response')
.AppendLine(' Result := ''Hello DelphiMVCFramework World'';')
.AppendLine('end;')
.AppendLine
.AppendLine('function ' + Model[TConfigKey.controller_classname] + '.GetReversedString(const Value: String): String;')
.AppendLine('begin')
.AppendLine('begin');
if Model.B[TConfigKey.controller_actions_profiling_generate] then
begin
Section
.AppendLine('{$IF CompilerVersion >= 34} //SYDNEY+')
.AppendLine(' var lProf := Profiler.Start(Context.ActionQualifiedName);')
.AppendLine('{$ENDIF}')
.AppendLine;
end;
Section
.AppendLine(' Result := System.StrUtils.ReverseString(Value.Trim);')
.AppendLine('end;')
end;
Expand All @@ -448,7 +448,16 @@ procedure TUnitControllerControllerDeclarationCommand.ExecuteImplementation(
.AppendLine('function ' + Model[TConfigKey.controller_classname] + '.GetPeople: IMVCResponse;')
.AppendLine('var')
.AppendLine(' lPeople: TObjectList<TPerson>;')
.AppendLine('begin')
.AppendLine('begin');
if Model.B[TConfigKey.controller_actions_profiling_generate] then
begin
Section
.AppendLine('{$IF CompilerVersion >= 34} //SYDNEY+')
.AppendLine(' var lProf := Profiler.Start(Context.ActionQualifiedName);')
.AppendLine('{$ENDIF}')
.AppendLine;
end;
Section
.AppendLine(' lPeople := TObjectList<TPerson>.Create(True);')
.AppendLine(' try')
.AppendLine(' lPeople.Add(TPerson.Create(1, ''Peter'',''Parker'', EncodeDate(1965, 10, 4)));')
Expand All @@ -462,24 +471,60 @@ procedure TUnitControllerControllerDeclarationCommand.ExecuteImplementation(
.AppendLine('end;')
.AppendLine
.AppendLine('function ' + Model[TConfigKey.controller_classname] + '.GetPerson(ID: Integer): TPerson;')
.AppendLine('begin')
.AppendLine('begin');
if Model.B[TConfigKey.controller_actions_profiling_generate] then
begin
Section
.AppendLine('{$IF CompilerVersion >= 34} //SYDNEY+')
.AppendLine(' var lProf := Profiler.Start(Context.ActionQualifiedName);')
.AppendLine('{$ENDIF}')
.AppendLine;
end;
Section
.AppendLine(' Result := TPerson.Create(ID, ''Daniele'', ''Teti'', EncodeDate(1979, 11, 4));')
.AppendLine('end;')
.AppendLine
.AppendLine('function ' + Model[TConfigKey.controller_classname] + '.CreatePerson([MVCFromBody] Person: TPerson): IMVCResponse;')
.AppendLine('begin')
.AppendLine('begin');
if Model.B[TConfigKey.controller_actions_profiling_generate] then
begin
Section
.AppendLine('{$IF CompilerVersion >= 34} //SYDNEY+')
.AppendLine(' var lProf := Profiler.Start(Context.ActionQualifiedName);')
.AppendLine('{$ENDIF}')
.AppendLine;
end;
Section
.AppendLine(' LogI(''Created '' + Person.FirstName + '' '' + Person.LastName);')
.AppendLine(' Result := CreatedResponse('''', ''Person created'');')
.AppendLine('end;')
.AppendLine
.AppendLine('function ' + Model[TConfigKey.controller_classname] + '.UpdatePerson(ID: Integer; [MVCFromBody] Person: TPerson): IMVCResponse;')
.AppendLine('begin')
.AppendLine('begin');
if Model.B[TConfigKey.controller_actions_profiling_generate] then
begin
Section
.AppendLine('{$IF CompilerVersion >= 34} //SYDNEY+')
.AppendLine(' var lProf := Profiler.Start(Context.ActionQualifiedName);')
.AppendLine('{$ENDIF}')
.AppendLine;
end;
Section
.AppendLine(' LogI(''Updated '' + Person.FirstName + '' '' + Person.LastName);')
.AppendLine(' Result := NoContentResponse();')
.AppendLine('end;')
.AppendLine
.AppendLine('function ' + Model[TConfigKey.controller_classname] + '.DeletePerson(ID: Integer): IMVCResponse;')
.AppendLine('begin')
.AppendLine('begin');
if Model.B[TConfigKey.controller_actions_profiling_generate] then
begin
Section
.AppendLine('{$IF CompilerVersion >= 34} //SYDNEY+')
.AppendLine(' var lProf := Profiler.Start(Context.ActionQualifiedName);')
.AppendLine('{$ENDIF}')
.AppendLine;
end;
Section
.AppendLine(' LogI(''Deleted person with id '' + ID.ToString);')
.AppendLine(' Result := NoContentResponse();')
.AppendLine('end;')
Expand Down
2 changes: 1 addition & 1 deletion ideexpert/DMVC.Expert.CodeGen.NewDMVCProject.pas
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ constructor TDMVCProjectFile.Create(const APersonality: string; const ConfigMode

function TDMVCProjectFile.GetFrameworkType: string;
begin
Result := 'VCL';
Result := 'FMX';
end;

function TDMVCProjectFile.NewProjectSource(const ProjectName: string): IOTAFile;
Expand Down
1 change: 1 addition & 0 deletions ideexpert/DMVC.Expert.Commons.pas
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ TConfigKey = class sealed
controller_index_methods_generate= 'controller.index_methods.generate';
controller_action_filters_generate= 'controller.action_filters.generate';
controller_crud_methods_generate= 'controller.crud_methods.generate';
controller_actions_profiling_generate= 'controller.actions.profiling.generate';
entity_generate= 'entity.generate';
entity_classname= 'entity.classname';
jsonrpc_generate= 'jsonrpc.generate';
Expand Down
Loading

0 comments on commit bdfb74a

Please sign in to comment.