Skip to content

Commit

Permalink
Merge branch 'Feature/uGitHUB' into Development
Browse files Browse the repository at this point in the history
  • Loading branch information
JensBorrisholt committed Aug 1, 2020
2 parents f4587f1 + fe75b4a commit a0f9ad6
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 37 deletions.
86 changes: 72 additions & 14 deletions Demo Generator/Pkg.Json.DemoGenerator.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
interface

uses
System.SysUtils,
Pkg.Json.Mapper;

{$M+}
Expand All @@ -12,41 +13,87 @@ interface

TDemoGenerator = class
private
FDestinationDirectory: string;
FRootDirectory: string;
FJsonMapper: TPkgJsonMapper;
FTDestinationFrameWork: TDestinationFrameWork;
FDestinationClassName: string;
FDestinationUnitName: string;
FJson: string;
FFileName: TFilename;
FDestinationDirectory: string;
procedure Validate;
procedure ExtractZipFile;
procedure GenerateFrameWorkINC;
procedure UpdateDemoProject;
procedure ModifyDemoHelper;
procedure SetDestinationDirectory(const Value: string);
procedure SetRootDirectory(const Value: string);
published
property DestinationDirectory: string read FDestinationDirectory write SetDestinationDirectory;
property RootDirectory: string read FRootDirectory write SetRootDirectory;
property DestinationDirectory : string read FDestinationDirectory;
property DestinationFrameWork: TDestinationFrameWork read FTDestinationFrameWork write FTDestinationFrameWork;
property DestinationClassName: string read FDestinationClassName write FDestinationClassName;
property DestinationUnitName: string read FDestinationUnitName write FDestinationUnitName;
property Json: string read FJson write FJson;
public
constructor Create(aJsonMapper: TPkgJsonMapper); reintroduce;
constructor Create; overload;
constructor Create(aFileName: TFilename); overload;
destructor Destroy; override;
procedure Execute;
end;

implementation

uses
System.Classes, System.Zip, System.SysUtils, System.IOUtils, System.RTLConsts;
System.Classes, System.Zip, System.IOUtils, System.RTLConsts;

{ TDemoGenerator }

constructor TDemoGenerator.Create(aJsonMapper: TPkgJsonMapper);
constructor TDemoGenerator.Create;
begin
inherited Create;

FJsonMapper := TPkgJsonMapper.Create;;
FDestinationClassName := '';
FDestinationUnitName := '';
FJson := '';
FRootDirectory := '';
FTDestinationFrameWork := TDestinationFrameWork.dfBoth;
FFileName := '';
end;

constructor TDemoGenerator.Create(aFileName: TFilename);
begin
inherited Create;
FJsonMapper := aJsonMapper;
FDestinationDirectory := '';

FJsonMapper := TPkgJsonMapper.Create;;
FFileName := aFileName;
FDestinationClassName := '';
FDestinationUnitName := '';
FJson := '';
FRootDirectory := '';
FTDestinationFrameWork := TDestinationFrameWork.dfBoth;
end;

destructor TDemoGenerator.Destroy;
begin
FreeAndNil(FJsonMapper);
inherited;
end;

procedure TDemoGenerator.Execute;
begin
Validate;

FJsonMapper.DestinationClassName := FDestinationClassName;
FJsonMapper.DestinationUnitName := FDestinationUnitName;
FDestinationDirectory := FRootDirectory + FJsonMapper.DestinationClassName + TPath.DirectorySeparatorChar;
TDirectory.CreateDirectory(FDestinationDirectory);

if FFileName = '' then
FJsonMapper.Parse(FJson)
else
FJsonMapper.LoadFormFile(FFileName);

ExtractZipFile;
UpdateDemoProject;
end;
Expand Down Expand Up @@ -115,6 +162,7 @@ procedure TDemoGenerator.ModifyDemoHelper;
Free
end;
end;

procedure LoadText;
begin
with TStringList.Create do
Expand All @@ -136,9 +184,9 @@ procedure TDemoGenerator.ModifyDemoHelper;
SaveText;
end;

procedure TDemoGenerator.SetDestinationDirectory(const Value: string);
procedure TDemoGenerator.SetRootDirectory(const Value: string);
begin
FDestinationDirectory := IncludeTrailingPathDelimiter(Value);
FRootDirectory := IncludeTrailingPathDelimiter(Value);
end;

procedure TDemoGenerator.UpdateDemoProject;
Expand All @@ -158,11 +206,21 @@ procedure TDemoGenerator.UpdateDemoProject;

procedure TDemoGenerator.Validate;
begin
if FDestinationDirectory.Trim = string.empty then
raise EIntError.Create('DestinationDirectory can not be empty');
if FRootDirectory.Trim = string.empty then
raise EPathNotFoundException.Create('RootDirectory can not be empty');

if not TDirectory.Exists(FRootDirectory) then
raise EPathNotFoundException.CreateRes(@SDirectoryInvalid);

if FDestinationClassName = '' then
raise EArgumentException.Create('DestinationClassName must be provided');

if FDestinationUnitName = '' then
raise EArgumentException.Create('DestinationUnitName must be provided');

if FFileName + FJson = '' then
raise EArgumentException.Create('Json must be provided');

if not TDirectory.Exists(FDestinationDirectory) then
raise EInOutError.CreateRes(@SDirectoryInvalid);
end;

end.
14 changes: 6 additions & 8 deletions End To End Test/EndToEndTest.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,16 @@ begin

FileName := TPath.GetFileName(FullFileName).Replace('.json', '');
Console.Write('* Building E2E Test for %s ... ', [FileName]);
JsonMapper.DestinationClassName := string(FileName).Replace(#32, '');
JsonMapper.DestinationUnitName := JsonMapper.DestinationClassName;
JsonMapper.LoadFormFile(FullFileName);

OutputDirectory := OutputDirectory + JsonMapper.DestinationClassName + TPath.DirectorySeparatorChar;
TDirectory.CreateDirectory(OutputDirectory);

with TDemoGenerator.Create(JsonMapper) do
with TDemoGenerator.Create(FullFileName) do
try
DestinationDirectory := OutputDirectory;
DestinationClassName := string(FileName).Replace(#32, '');
DestinationUnitName := JsonMapper.DestinationClassName;

RootDirectory := OutputDirectory;
DestinationFrameWork := TDestinationFrameWork.dfVCL;
Execute;
OutputDirectory := DestinationDirectory;
finally
Free;
end;
Expand Down
Binary file modified End To End Test/JSON_PAS.res
Binary file not shown.
1 change: 0 additions & 1 deletion Generator GUI/FMX.ConstrainedForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ procedure TConstrainedForm.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
procedure TConstrainedForm.StartWindowDrag;
begin
inherited;

end;

procedure TConstrainedForm.StartWindowResize;
Expand Down
8 changes: 4 additions & 4 deletions Generator GUI/uMainForm.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -1552,8 +1552,8 @@ object MainForm: TMainForm
Size.PlatformDefault = False
StyleLookup = 'Memo1Style1'
TabOrder = 0
Viewport.Width = 836.000000000000000000
Viewport.Height = 444.000000000000000000
Viewport.Width = 840.000000000000000000
Viewport.Height = 448.000000000000000000
end
object Label4: TLabel
Align = Top
Expand Down Expand Up @@ -1737,8 +1737,8 @@ object MainForm: TMainForm
TabOrder = 0
OnDblClick = TreeViewDblClick
OnKeyDown = TreeViewKeyDown
Viewport.Width = 329.000000000000000000
Viewport.Height = 450.000000000000000000
Viewport.Width = 333.000000000000000000
Viewport.Height = 454.000000000000000000
end
object Label3: TLabel
Align = Top
Expand Down
4 changes: 3 additions & 1 deletion Generator GUI/uMainForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@ procedure TMainForm.ActDemoExecute(Sender: TObject);
FJsonMapper.DestinationUnitName := Edit2.Text;
FJsonMapper.Parse(Memo1.Lines.Text);

with TDemoGenerator.Create(FJsonMapper) do
with TDemoGenerator.Create do
try
DestinationClassName := Edit1.Text;
DestinationUnitName := Edit2.Text;
DestinationDirectory := Destination;
Execute;
finally
Expand Down
4 changes: 2 additions & 2 deletions Generator GUI/uSaveUnitForm.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ object SaveUnitForm: TSaveUnitForm
Size.PlatformDefault = False
StyleLookup = 'Memo1Style1'
TabOrder = 1
Viewport.Width = 917.000000000000000000
Viewport.Height = 551.000000000000000000
Viewport.Width = 913.000000000000000000
Viewport.Height = 547.000000000000000000
end
object Panel1: TPanel
Align = Bottom
Expand Down
12 changes: 5 additions & 7 deletions Generator GUI/uSaveUnitForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox,
FMX.Memo.Types;
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.StdCtrls, FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo.Types;

type
TSaveUnitForm = class(TForm)
Expand All @@ -30,7 +28,7 @@ TSaveUnitForm = class(TForm)
public
{ Public declarations }
property FileName: string read GetFileName write SetFileName;
property Json : string read FJson write SetJson;
property Json: string read FJson write SetJson;
end;

implementation
Expand All @@ -53,14 +51,14 @@ procedure TSaveUnitForm.btnSaveClick(Sender: TObject);
if not sd.Execute then
exit;

Memo1.Lines.SaveToFile(sd.FileName);
Memo1.Lines.SaveToFile(FileName);

Buffer := TStringList.Create;
ResourceStream := TResourceStream.Create(HInstance, 'JsonDTO', 'PAS');
try
ResourceStream.Position := 0;
Buffer.LoadFromStream(ResourceStream);
Buffer.SaveToFile(TPath.GetDirectoryName(sd.FileName) + TPath.DirectorySeparatorChar + 'Pkg.Json.DTO.pas');
Buffer.SaveToFile(TPath.GetDirectoryName(FileName) + TPath.DirectorySeparatorChar + 'Pkg.Json.DTO.pas');
finally
ResourceStream.Free;
Buffer.Free;
Expand Down

0 comments on commit a0f9ad6

Please sign in to comment.