diff --git a/Demo Generator/Pkg.Json.DemoGenerator.pas b/Demo Generator/Pkg.Json.DemoGenerator.pas index e3b83ee..9938d8b 100644 --- a/Demo Generator/Pkg.Json.DemoGenerator.pas +++ b/Demo Generator/Pkg.Json.DemoGenerator.pas @@ -3,6 +3,7 @@ interface uses + System.SysUtils, Pkg.Json.Mapper; {$M+} @@ -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; @@ -115,6 +162,7 @@ procedure TDemoGenerator.ModifyDemoHelper; Free end; end; + procedure LoadText; begin with TStringList.Create do @@ -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; @@ -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. diff --git a/End To End Test/EndToEndTest.dpr b/End To End Test/EndToEndTest.dpr index bc825d4..aa32897 100644 --- a/End To End Test/EndToEndTest.dpr +++ b/End To End Test/EndToEndTest.dpr @@ -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; diff --git a/End To End Test/JSON_PAS.res b/End To End Test/JSON_PAS.res index 43d6a84..77d9252 100644 Binary files a/End To End Test/JSON_PAS.res and b/End To End Test/JSON_PAS.res differ diff --git a/Generator GUI/FMX.ConstrainedForm.pas b/Generator GUI/FMX.ConstrainedForm.pas index 80bceb9..c6d6e30 100644 --- a/Generator GUI/FMX.ConstrainedForm.pas +++ b/Generator GUI/FMX.ConstrainedForm.pas @@ -142,7 +142,6 @@ procedure TConstrainedForm.SetBounds(ALeft, ATop, AWidth, AHeight: Integer); procedure TConstrainedForm.StartWindowDrag; begin inherited; - end; procedure TConstrainedForm.StartWindowResize; diff --git a/Generator GUI/uMainForm.fmx b/Generator GUI/uMainForm.fmx index 3c646f1..af42f7f 100644 --- a/Generator GUI/uMainForm.fmx +++ b/Generator GUI/uMainForm.fmx @@ -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 @@ -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 diff --git a/Generator GUI/uMainForm.pas b/Generator GUI/uMainForm.pas index c3a2597..1e21aa7 100644 --- a/Generator GUI/uMainForm.pas +++ b/Generator GUI/uMainForm.pas @@ -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 diff --git a/Generator GUI/uSaveUnitForm.fmx b/Generator GUI/uSaveUnitForm.fmx index 668ba23..ad02a3f 100644 --- a/Generator GUI/uSaveUnitForm.fmx +++ b/Generator GUI/uSaveUnitForm.fmx @@ -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 diff --git a/Generator GUI/uSaveUnitForm.pas b/Generator GUI/uSaveUnitForm.pas index f218ee6..1974d07 100644 --- a/Generator GUI/uSaveUnitForm.pas +++ b/Generator GUI/uSaveUnitForm.pas @@ -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) @@ -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 @@ -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;