diff --git a/CalculatorCInterface.dll b/CalculatorCInterface.dll index d817d63..d268874 100644 Binary files a/CalculatorCInterface.dll and b/CalculatorCInterface.dll differ diff --git a/atbgit.pas b/atbgit.pas index 81c5a41..badf5ab 100644 --- a/atbgit.pas +++ b/atbgit.pas @@ -4,18 +4,60 @@ unit ATBGit; interface -uses - Classes, SysUtils, CTypes, fpjson, jsonparser; +uses SysUtils, fpjson, jsonparser; -type - function SetFile(const localRepository: String; const fileId: String; const json: TJSONData): Boolean; - function SetFileInternal(const localRepository: PChar; - const fileId: PChar; - const json: PChar; - size: cint32): cbool; stdcall; + // + // public interface + // + procedure SetReposRootDirectory(const rootDir: UTF8String); + function GetReposRootDirectory(): UTF8String; + function GetLocalRepositoryPath(const localrepo: UTF8String): UTF8String; + + // private c-interface + procedure SetReposRootDirectoryInternal(const rootDir: PChar); stdcall; + function GetReposRootDirectoryInternal(): PChar; stdcall; + function GetLocalRepositoryPathInternal(const localRepo: PChar): PChar; stdcall; implementation const DLLName = 'CalculatorCInterface.dll'; + /// + procedure SetReposRootDirectory(const rootDir: UTF8String); + begin + try + SetReposRootDirectoryInternal(PChar(Utf8toAnsi(rootDir))); + finally + end; + end; + + /// + function GetReposRootDirectory(): UTF8String; + begin + try + Result := UTF8String(GetReposRootDirectoryInternal()); + finally + end; + end; + + function GetLocalRepositoryPath(const localRepo: UTF8String): UTF8String; + begin + try + Result := UTF8String(GetLocalRepositoryPathInternal(PChar(Utf8toAnsi(localRepo)))); + finally + end; + end; + + // + // external c-interface + // + procedure SetReposRootDirectoryInternal(const rootDir: PChar); stdcall; + external DLLName; + + function GetReposRootDirectoryInternal(): PChar; stdcall; + external DLLName; + + function GetLocalRepositoryPathInternal(const localRepo: PChar): PChar; stdcall; + external DLLName; + end. diff --git a/atbtariffcalculator.pas b/atbtariffcalculator.pas new file mode 100644 index 0000000..df25e83 --- /dev/null +++ b/atbtariffcalculator.pas @@ -0,0 +1,99 @@ +unit ATBTariffCalculator; + +{$mode ObjFPC}{$H+} + +interface + +uses + SysUtils, CTypes, fpjson, jsonparser, ATBUtils; + +type + // Can't use the class directly, so it is treated as an opaque handle. + // THandle is guaranteed to have the right size, even on other platforms. + TariffCalculatorHandle = THandle; + //PTJSONObject = ^TJSONObject; + +function NewTariffCalculator: TariffCalculatorHandle; stdcall; +procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; + +//function GetFileMenu(const localRepository: PChar): PChar; stdcall; +//function GetFileMenuAsJson(const localRepository: String; jObj: PTJSONObject): Boolean; +//function GetFileMenuSize(const localRepository: PChar): cint32; stdcall; + +//function GetFileName(const localRepository: PChar; const fileId: PChar): PChar; stdcall; +//function GetFileNameStr(const localRepository: String; const fileId: String): String; +//function GetFileSize(const localRepository: PChar; const fileId: PChar): cint32; stdcall; +//function GetFile(const localRepository: PChar; const fileId: PChar): PChar; stdcall; + +function InitGitLibrary: cint32; stdcall; +function ShutdownGitLibrary: cint32; stdcall; +function CloneRepository(var url; var local_path) : cint32; stdcall; +function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; +function CommitFile(var local_path; var branch_name; + var file_name; var comment) : cint32; stdcall; +function PushLocalRepository(var local_path; var branch_name; + var user_name; var password) : cint32; stdcall; +implementation + +const + DLLName = 'CalculatorCInterface.dll'; + +//function GetFileNameStr(const localRepository: String; const fileId: String): String; +//var +// p: PChar; +//begin +// Result := ''; +// try +// p := GetFileName(PChar(localRepository), PChar(fileId)); +// if p <> nil then begin +// Result := String(p); +// end; +// finally +// DeleteMem(p); +// end; +//end; + +//function GetFileMenuAsJson(const localRepository: String; jObj: PTJSONObject): Boolean; +//var +// p: PChar; +// fileMenuContent: String; +//begin +// Result := false; +// try +// p := GetFileMenu(PChar(localRepository)); +// if p <> nil then begin +// fileMenuContent := String(p); +// //writeln(fileMenuContent); +// jObj^ := GetJSON(fileMenuContent) as TJSONObject; +// Result := true; +// end; +// finally +// DeleteMem(p); +// end; +//end; + +function NewTariffCalculator: TariffCalculatorHandle; stdcall; external DLLName; +procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; external DLLName; + +//function GetFileMenu(const localRepository: PChar): PChar; stdcall; external DLLName; +//function GetFileMenuSize(const localRepository: PChar): cint32; stdcall; external DLLName; +//function GetFileName(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName; +//function GetFileSize(const localRepository: PChar; const fileId: PChar): cint32; stdcall; external DLLName; +//function GetFile(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName; + +//function SetFileInternal(const localRepository: PChar; +// const fileId: PChar; +// const json: PChar; +// size: cint32): cbool; stdcall; external DLLName; + +function InitGitLibrary: cint32; stdcall; external DLLName; +function ShutdownGitLibrary: cint32; stdcall; external DLLName; +function CloneRepository(var url; var local_path) : cint32; stdcall; external DLLName; +function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; external DLLName; +function CommitFile(var local_path; var branch_name; + var file_name; var comment) : cint32; stdcall; external DLLName; +function PushLocalRepository(var local_path; var branch_name; + var user_name; var password) : cint32; stdcall; external DLLName; + +end. + diff --git a/atbutils.pas b/atbutils.pas index fe0aa6c..64ddead 100644 --- a/atbutils.pas +++ b/atbutils.pas @@ -4,7 +4,7 @@ unit ATBUtils; interface -uses Classes, SysUtils, CTypes; +uses Classes, SysUtils; procedure DeleteMem(P: PChar); stdcall; diff --git a/atbwebinterface.pas b/atbwebinterface.pas index b6b534f..f5c02c7 100644 --- a/atbwebinterface.pas +++ b/atbwebinterface.pas @@ -12,6 +12,7 @@ type // // public interface // + function GetFileMenu(const localRepository: UTF8String; jObj: PTJSONObject): Boolean; @@ -38,7 +39,6 @@ function GetFileNameInternal(const localRepository: PChar; implementation const DLLName = 'CalculatorCInterface.dll'; - /// function GetFileMenu(const localRepository: UTF8String; jObj: PTJSONObject): Boolean; var @@ -114,7 +114,10 @@ implementation end; end; + // // external c-interface + // + function GetFileInternal(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName; diff --git a/deploy/CalculatorCInterface.dll b/deploy/CalculatorCInterface.dll index cff3770..d268874 100644 Binary files a/deploy/CalculatorCInterface.dll and b/deploy/CalculatorCInterface.dll differ diff --git a/deploy/atbgit.pas b/deploy/atbgit.pas index 81c5a41..badf5ab 100644 --- a/deploy/atbgit.pas +++ b/deploy/atbgit.pas @@ -4,18 +4,60 @@ unit ATBGit; interface -uses - Classes, SysUtils, CTypes, fpjson, jsonparser; +uses SysUtils, fpjson, jsonparser; -type - function SetFile(const localRepository: String; const fileId: String; const json: TJSONData): Boolean; - function SetFileInternal(const localRepository: PChar; - const fileId: PChar; - const json: PChar; - size: cint32): cbool; stdcall; + // + // public interface + // + procedure SetReposRootDirectory(const rootDir: UTF8String); + function GetReposRootDirectory(): UTF8String; + function GetLocalRepositoryPath(const localrepo: UTF8String): UTF8String; + + // private c-interface + procedure SetReposRootDirectoryInternal(const rootDir: PChar); stdcall; + function GetReposRootDirectoryInternal(): PChar; stdcall; + function GetLocalRepositoryPathInternal(const localRepo: PChar): PChar; stdcall; implementation const DLLName = 'CalculatorCInterface.dll'; + /// + procedure SetReposRootDirectory(const rootDir: UTF8String); + begin + try + SetReposRootDirectoryInternal(PChar(Utf8toAnsi(rootDir))); + finally + end; + end; + + /// + function GetReposRootDirectory(): UTF8String; + begin + try + Result := UTF8String(GetReposRootDirectoryInternal()); + finally + end; + end; + + function GetLocalRepositoryPath(const localRepo: UTF8String): UTF8String; + begin + try + Result := UTF8String(GetLocalRepositoryPathInternal(PChar(Utf8toAnsi(localRepo)))); + finally + end; + end; + + // + // external c-interface + // + procedure SetReposRootDirectoryInternal(const rootDir: PChar); stdcall; + external DLLName; + + function GetReposRootDirectoryInternal(): PChar; stdcall; + external DLLName; + + function GetLocalRepositoryPathInternal(const localRepo: PChar): PChar; stdcall; + external DLLName; + end. diff --git a/deploy/atbtariffcalculator.pas b/deploy/atbtariffcalculator.pas new file mode 100644 index 0000000..df25e83 --- /dev/null +++ b/deploy/atbtariffcalculator.pas @@ -0,0 +1,99 @@ +unit ATBTariffCalculator; + +{$mode ObjFPC}{$H+} + +interface + +uses + SysUtils, CTypes, fpjson, jsonparser, ATBUtils; + +type + // Can't use the class directly, so it is treated as an opaque handle. + // THandle is guaranteed to have the right size, even on other platforms. + TariffCalculatorHandle = THandle; + //PTJSONObject = ^TJSONObject; + +function NewTariffCalculator: TariffCalculatorHandle; stdcall; +procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; + +//function GetFileMenu(const localRepository: PChar): PChar; stdcall; +//function GetFileMenuAsJson(const localRepository: String; jObj: PTJSONObject): Boolean; +//function GetFileMenuSize(const localRepository: PChar): cint32; stdcall; + +//function GetFileName(const localRepository: PChar; const fileId: PChar): PChar; stdcall; +//function GetFileNameStr(const localRepository: String; const fileId: String): String; +//function GetFileSize(const localRepository: PChar; const fileId: PChar): cint32; stdcall; +//function GetFile(const localRepository: PChar; const fileId: PChar): PChar; stdcall; + +function InitGitLibrary: cint32; stdcall; +function ShutdownGitLibrary: cint32; stdcall; +function CloneRepository(var url; var local_path) : cint32; stdcall; +function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; +function CommitFile(var local_path; var branch_name; + var file_name; var comment) : cint32; stdcall; +function PushLocalRepository(var local_path; var branch_name; + var user_name; var password) : cint32; stdcall; +implementation + +const + DLLName = 'CalculatorCInterface.dll'; + +//function GetFileNameStr(const localRepository: String; const fileId: String): String; +//var +// p: PChar; +//begin +// Result := ''; +// try +// p := GetFileName(PChar(localRepository), PChar(fileId)); +// if p <> nil then begin +// Result := String(p); +// end; +// finally +// DeleteMem(p); +// end; +//end; + +//function GetFileMenuAsJson(const localRepository: String; jObj: PTJSONObject): Boolean; +//var +// p: PChar; +// fileMenuContent: String; +//begin +// Result := false; +// try +// p := GetFileMenu(PChar(localRepository)); +// if p <> nil then begin +// fileMenuContent := String(p); +// //writeln(fileMenuContent); +// jObj^ := GetJSON(fileMenuContent) as TJSONObject; +// Result := true; +// end; +// finally +// DeleteMem(p); +// end; +//end; + +function NewTariffCalculator: TariffCalculatorHandle; stdcall; external DLLName; +procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; external DLLName; + +//function GetFileMenu(const localRepository: PChar): PChar; stdcall; external DLLName; +//function GetFileMenuSize(const localRepository: PChar): cint32; stdcall; external DLLName; +//function GetFileName(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName; +//function GetFileSize(const localRepository: PChar; const fileId: PChar): cint32; stdcall; external DLLName; +//function GetFile(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName; + +//function SetFileInternal(const localRepository: PChar; +// const fileId: PChar; +// const json: PChar; +// size: cint32): cbool; stdcall; external DLLName; + +function InitGitLibrary: cint32; stdcall; external DLLName; +function ShutdownGitLibrary: cint32; stdcall; external DLLName; +function CloneRepository(var url; var local_path) : cint32; stdcall; external DLLName; +function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; external DLLName; +function CommitFile(var local_path; var branch_name; + var file_name; var comment) : cint32; stdcall; external DLLName; +function PushLocalRepository(var local_path; var branch_name; + var user_name; var password) : cint32; stdcall; external DLLName; + +end. + diff --git a/deploy/atbutils.pas b/deploy/atbutils.pas index fe0aa6c..64ddead 100644 --- a/deploy/atbutils.pas +++ b/deploy/atbutils.pas @@ -4,7 +4,7 @@ unit ATBUtils; interface -uses Classes, SysUtils, CTypes; +uses Classes, SysUtils; procedure DeleteMem(P: PChar); stdcall; diff --git a/deploy/atbwebinterface.pas b/deploy/atbwebinterface.pas index b6b534f..f5c02c7 100644 --- a/deploy/atbwebinterface.pas +++ b/deploy/atbwebinterface.pas @@ -12,6 +12,7 @@ type // // public interface // + function GetFileMenu(const localRepository: UTF8String; jObj: PTJSONObject): Boolean; @@ -38,7 +39,6 @@ function GetFileNameInternal(const localRepository: PChar; implementation const DLLName = 'CalculatorCInterface.dll'; - /// function GetFileMenu(const localRepository: UTF8String; jObj: PTJSONObject): Boolean; var @@ -114,7 +114,10 @@ implementation end; end; + // // external c-interface + // + function GetFileInternal(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName; diff --git a/deploy/helloworld.lpi b/deploy/helloworld.lpi deleted file mode 100644 index ef82eec..0000000 --- a/deploy/helloworld.lpi +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - <UseAppBundle Value="False"/> - <ResourceType Value="res"/> - </General> - <BuildModes> - <Item Name="Default" Default="True"/> - </BuildModes> - <PublishOptions> - <Version Value="2"/> - <UseFileFilters Value="True"/> - </PublishOptions> - <RunParams> - <FormatVersion Value="2"/> - </RunParams> - <RequiredPackages> - <Item> - <PackageName Value="LazUtils"/> - </Item> - </RequiredPackages> - <Units> - <Unit> - <Filename Value="helloworld.lpr"/> - <IsPartOfProject Value="True"/> - </Unit> - <Unit> - <Filename Value="unit1.pas"/> - <IsPartOfProject Value="True"/> - <UnitName Value="Unit1"/> - </Unit> - <Unit> - <Filename Value="tariffcalculator.pas"/> - <IsPartOfProject Value="True"/> - <UnitName Value="TariffCalculator"/> - </Unit> - </Units> - </ProjectOptions> - <CompilerOptions> - <Version Value="11"/> - <PathDelim Value="\"/> - <Target> - <Filename Value="helloworld"/> - </Target> - <SearchPaths> - <IncludeFiles Value="$(ProjOutDir)"/> - <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> - </SearchPaths> - <Linking> - <Debugging> - <DebugInfoType Value="dsDwarf3"/> - </Debugging> - </Linking> - </CompilerOptions> - <Debugging> - <Exceptions> - <Item> - <Name Value="EAbort"/> - </Item> - <Item> - <Name Value="ECodetoolError"/> - </Item> - <Item> - <Name Value="EFOpenError"/> - </Item> - </Exceptions> - </Debugging> -</CONFIG> diff --git a/deploy/helloworld.lpr b/deploy/helloworld.lpr deleted file mode 100644 index c1bf679..0000000 --- a/deploy/helloworld.lpr +++ /dev/null @@ -1,148 +0,0 @@ - - -{%RunFlags MESSAGES+} -{$mode ObjFPC}{$H+} -program helloworld(output); - - -uses - TariffCalculator, CTypes, LazUtils, LazFileUtils, LazUtf8, SysUtils, - fpjson, jsonparser; - -type - PTJSONObject = ^TJSONObject; - -var - jData: TJSONData; - jObject, jObjTemp: TJSONObject; - - jEnum: TJSONEnum; - jArray: TJSONArray; - s: Utf8String; - fileId: String; - localRepository: String; - - //TariffCalc: TariffCalculatorHandle; - CustomerRepo: array[0..100] of char; - LocalRepo: array[0..100] of char; - LocalCustomerRepo: array[0..100] of char; - LocalBranchName: array[0..32] of char; - FileToCommit: array[0..128] of char; - CommitMessage: array[0..256] of char; - UserName: array[0..64] of char; - PassWord: array[0..64] of char; - P, R: PChar; - Q: String; - I: Integer; - -begin -// TariffCalc := NewTariffCalculator; -// DeleteTariffCalculator(TariffCalc); - try - jArray := TJSONArray.Create; - jObject := TJSONObject.Create; - - CustomerRepo := 'https://git.mimbach49.de/GerhardHoffmann/customer_999.git'; - LocalCustomerRepo := 'H:\\customer_999'; - LocalBranchName := 'zg1/zone1'; - FileToCommit := 'etc/psa_tariff/tariff01.json'; - CommitMessage := 'TEST TEST'; - UserName := 'GerhardHoffmann'; - PassWord := 'ghlinux12345'; - LocalRepo := 'customer_999'; - localRepository := 'customer_999'; - - - if GetFileMenuAsJson(localRepository, @jObject) then begin - jArray := jObject['File-Menue'] as TJSONArray; - for jEnum in jArray do begin - jObjTemp := jEnum.Value as TJSONObject; - fileId := jObjTemp.Strings['File-ID']; - writeln(); - writeLn(fileId); - s := GetFileNameStr(localRepository, fileId); - writeln(); - writeLn(s); - end; - end; - - halt; - - P := GetFileMenu(LocalRepo); - if P <> nil then - begin - jData := GetJSON(P); - s := jData.FormatJSON; - writeLn(s); - jObject := jData as TJSONObject; - writeLn(jObject['File-Menue'].Count); - - jArray := jObject['File-Menue'] as TJSONArray; - for jEnum in jArray do begin - jObjTemp := jEnum.Value as TJSONObject; - s := jObjTemp.Strings['File-ID']; - writeln(); - writeLn(s); - - end; - - for i := 0 to jObject['File-Menue'].Count-1 do - begin - jObjTemp := jObject['File-Menue'].Items[i] as TJSONObject; - s := jObjTemp.Find('File-ID').AsString; - writeLn(s); - R := GetFileName(LocalRepo, PChar(s)); - if R <> nil then - begin - writeLn(R); - writeLn(GetFileSize(LocalRepo, PChar(s))); - writeLn(GetFile(LocalRepo, PChar(s))); - DeleteMem(R); - end; - end; - //writeLn(jObject['File-Menue'].Items[0].ToString()); - //jObject := jObject['File-Menue'].Items[0] as TJSONObject; - //s := jObject.FormatJSON; - //writeLn(s); - //s := jObject.Find('File-ID').AsString; - //writeLn(s); - //Q := ':'; - //writeLn(UTF8Pos(Q, s)); - //jArray := jObject.FindPath('File-Menue') as TJSONArray; - //s := jArray[0].AsString; - //writeLn(s); - //jArray := jObject.Get('File-Menue', TJSONArray.Create); - //writeLn(jArray.Extract(0).AsString); - DeleteMem(P) - end; - //:w - //StrDispose(PChar(P)); - - //if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo)) then - // CreateDirUTF8(ExpandFilenameUtf8(LocalCustomerRepo)); - - //if InitGitLibrary() > 0 then - // Try - // writeLn('initialized git library') ; - // if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo+'\\.git')) then - // CloneRepository(CustomerRepo, LocalCustomerRepo); - // if not CheckoutLocalBranch(LocalCustomerRepo, LocalBranchName) = 0 then - // writeLn('cannot check out') ; - // if not CommitFile(LocalCustomerRepo, LocalBranchName, FileToCommit, CommitMessage) = 0 then - // writeLn('cannot commit') ; - // if not PushLocalRepository(LocalCustomerRepo, LocalBranchName, UserName, PassWord) = 0 then - // writeLn('cannot push') ; - // Finally - // if ShutdownGitLibrary() >= 0 then - // writeLn('shutdown git library') ; - // end - //else - // begin - // writeLn('initializing git library FAILED') ; - // Readln; - // end; - finally - jArray.Free; - end; -end. - diff --git a/deploy/project1.res b/deploy/project1.res deleted file mode 100644 index bb86af9..0000000 Binary files a/deploy/project1.res and /dev/null differ diff --git a/deploy/tariffcalculator.pas b/deploy/tariffcalculator.pas deleted file mode 100644 index 4b0eb86..0000000 --- a/deploy/tariffcalculator.pas +++ /dev/null @@ -1,97 +0,0 @@ -unit TariffCalculator; - -{$mode ObjFPC}{$H+} - -interface - -uses - SysUtils, CTypes, fpjson, jsonparser; - -type - // Can't use the class directly, so it is treated as an opaque handle. - // THandle is guaranteed to have the right size, even on other platforms. - TariffCalculatorHandle = THandle; - PTJSONObject = ^TJSONObject; - -function NewTariffCalculator: TariffCalculatorHandle; stdcall; -procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; - -function GetFileMenu(const localRepository: PChar): PChar; stdcall; -function GetFileMenuAsJson(const localRepository: String; jObj: PTJSONObject): Boolean; -function GetFileMenuSize(const localRepository: PChar): cint32; stdcall; -function GetFileName(const localRepository: PChar; const fileId: PChar): PChar; stdcall; -function GetFileNameStr(const localRepository: String; const fileId: String): String; -function GetFileSize(const localRepository: PChar; const fileId: PChar): cint32; stdcall; -function GetFile(const localRepository: PChar; const fileId: PChar): PChar; stdcall; - -procedure DeleteMem(P: PChar); stdcall; - -function InitGitLibrary: cint32; stdcall; -function ShutdownGitLibrary: cint32; stdcall; -function CloneRepository(var url; var local_path) : cint32; stdcall; -function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; -function CommitFile(var local_path; var branch_name; - var file_name; var comment) : cint32; stdcall; -function PushLocalRepository(var local_path; var branch_name; - var user_name; var password) : cint32; stdcall; -implementation - -const - DLLName = 'CalculatorCInterface.dll'; - -function GetFileNameStr(const localRepository: String; const fileId: String): String; -var - p: PChar; -begin - Result := ''; - try - p := GetFileName(PChar(localRepository), PChar(fileId)); - if p <> nil then begin - Result := String(p); - end; - finally - DeleteMem(p); - end; -end; - -function GetFileMenuAsJson(const localRepository: String; jObj: PTJSONObject): Boolean; -var - p: PChar; - fileMenuContent: String; -begin - Result := false; - try - p := GetFileMenu(PChar(localRepository)); - if p <> nil then begin - fileMenuContent := String(p); - writeln(fileMenuContent); - jObj^ := GetJSON(fileMenuContent) as TJSONObject; - Result := true; - end; - finally - DeleteMem(p); - end; -end; - -function NewTariffCalculator: TariffCalculatorHandle; stdcall; external DLLName; -procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; external DLLName; - -function GetFileMenu(const localRepository: PChar): PChar; stdcall; external DLLName; -function GetFileMenuSize(const localRepository: PChar): cint32; stdcall; external DLLName; -function GetFileName(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName; -function GetFileSize(const localRepository: PChar; const fileId: PChar): cint32; stdcall; external DLLName; -function GetFile(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName; - -procedure DeleteMem(P: PChar); stdcall; external DLLName; - -function InitGitLibrary: cint32; stdcall; external DLLName; -function ShutdownGitLibrary: cint32; stdcall; external DLLName; -function CloneRepository(var url; var local_path) : cint32; stdcall; external DLLName; -function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; external DLLName; -function CommitFile(var local_path; var branch_name; - var file_name; var comment) : cint32; stdcall; external DLLName; -function PushLocalRepository(var local_path; var branch_name; - var user_name; var password) : cint32; stdcall; external DLLName; - -end. - diff --git a/deploy/unit1.pas b/deploy/unit1.pas deleted file mode 100644 index 9550159..0000000 --- a/deploy/unit1.pas +++ /dev/null @@ -1,13 +0,0 @@ -unit Unit1; - -{$mode ObjFPC}{$H+} - -interface - procedure git_clone; cdecl; external 'C:\Users\G.Hoffmann\Downloads\libgit2-1.7.2\libgit2-1.7.2\build\Debug\git2.dll' name 'git_clone'; -uses - Classes, SysUtils; - -implementation - -end. - diff --git a/deploy/helloworld.exe b/deploy/webiface.exe similarity index 71% rename from deploy/helloworld.exe rename to deploy/webiface.exe index da287ad..36d2ac9 100644 Binary files a/deploy/helloworld.exe and b/deploy/webiface.exe differ diff --git a/helloworld.lpi b/deploy/webiface.lpi similarity index 63% rename from helloworld.lpi rename to deploy/webiface.lpi index ef82eec..1047b47 100644 --- a/helloworld.lpi +++ b/deploy/webiface.lpi @@ -8,12 +8,17 @@ <MainUnitHasCreateFormStatements Value="False"/> <MainUnitHasTitleStatement Value="False"/> <MainUnitHasScaledStatement Value="False"/> + <UseDefaultCompilerOptions Value="True"/> </Flags> <SessionStorage Value="InProjectDir"/> - <Title Value="helloworld"/> + <Title Value="webiface"/> <UseAppBundle Value="False"/> <ResourceType Value="res"/> </General> + <VersionInfo> + <UseVersionInfo Value="True"/> + <MajorVersionNr Value="1"/> + </VersionInfo> <BuildModes> <Item Name="Default" Default="True"/> </BuildModes> @@ -31,18 +36,27 @@ </RequiredPackages> <Units> <Unit> - <Filename Value="helloworld.lpr"/> + <Filename Value="webiface.lpr"/> <IsPartOfProject Value="True"/> </Unit> <Unit> - <Filename Value="unit1.pas"/> + <Filename Value="atbgit.pas"/> <IsPartOfProject Value="True"/> - <UnitName Value="Unit1"/> + <UnitName Value="ATBGit"/> </Unit> <Unit> - <Filename Value="tariffcalculator.pas"/> + <Filename Value="atbutils.pas"/> + <IsPartOfProject Value="True"/> + <UnitName Value="ATBUtils"/> + </Unit> + <Unit> + <Filename Value="atbwebinterface.pas"/> + <IsPartOfProject Value="True"/> + <UnitName Value="ATBWebInterface"/> + </Unit> + <Unit> + <Filename Value="atbtariffcalculator.pas"/> <IsPartOfProject Value="True"/> - <UnitName Value="TariffCalculator"/> </Unit> </Units> </ProjectOptions> @@ -50,17 +64,18 @@ <Version Value="11"/> <PathDelim Value="\"/> <Target> - <Filename Value="helloworld"/> + <Filename Value="webiface"/> </Target> <SearchPaths> <IncludeFiles Value="$(ProjOutDir)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> </SearchPaths> - <Linking> - <Debugging> - <DebugInfoType Value="dsDwarf3"/> - </Debugging> - </Linking> + <Other> + <Verbosity> + <ShoLineNum Value="True"/> + </Verbosity> + <CustomOptions Value="-FcUTF8"/> + </Other> </CompilerOptions> <Debugging> <Exceptions> diff --git a/deploy/webiface.lpr b/deploy/webiface.lpr new file mode 100644 index 0000000..ce78617 --- /dev/null +++ b/deploy/webiface.lpr @@ -0,0 +1,109 @@ + + +{%RunFlags MESSAGES+} +{$mode ObjFPC}{$H+} + +program webiface(output); + + +uses + CTypes, LazUtils, LazFileUtils, LazUtf8, SysUtils, + fpjson, jsonparser, ATBWebInterface, ATBUtils, ATBGit; + +//type +// PTJSONObject = ^TJSONObject; + +var + //jData: TJSONData; + jObject, jObjTemp: TJSONObject; + + jEnum: TJSONEnum; + jArray: TJSONArray; + + repoRootDir: UTF8String; + fileId: UTF8String; + localRepository: UTF8String; + localRepositoryDir: UTF8String; + fileName: UTF8String; + + {$R *.res} + +begin + try + jArray := TJSONArray.Create; + jObject := TJSONObject.Create; + + //CustomerRepo := 'https://git.mimbach49.de/GerhardHoffmann/customer_999.git'; + //LocalCustomerRepo := 'H:\\customer_999'; + //LocalBranchName := 'zg1/zone1'; + //FileToCommit := 'etc/psa_tariff/tariff01.json'; + //CommitMessage := 'TEST TEST'; + //UserName := 'GerhardHoffmann'; + //PassWord := 'ghlinux12345'; + //LocalRepo := 'customer_999'; + + repoRootDir := 'H:\'; + ATBGit.SetReposRootDirectory(repoRootDir); + + localRepository := 'customer_999'; + fileId := 'customer_999/etc/psa_tariff:zg1/zone1'; + //jData := GetJSON('{"F1" : "Hello"}'); + + // ATBWebInterface.SetFile(localRepository, fileId, jData); + // halt; + + if ATBWebInterface.GetFileMenu(localRepository, @jObject) then begin + jArray := jObject['File-Menue'] as TJSONArray; + for jEnum in jArray do begin + jObjTemp := jEnum.Value as TJSONObject; + fileId := jObjTemp.Strings['File-ID']; + fileName := GetFileName(localRepository, fileId); + + if fileName <> '' then begin + if FileExistsUTF8(fileName) then begin + writeln(); + writeln('file exists: ' + fileName); + if ATBWebInterface.GetFile(localRepository, fileId, @jObject) then begin + writeln(jObject.FormatJSON); + end; + end; + end; + end; + end; + + localRepositoryDir := ATBGit.GetLocalRepositoryPath(localRepository); + writeln(); + writeln('localRepositoryDir: ' + localRepositoryDir); + + if not DirectoryExistsUTF8(localRepositoryDir) then begin + writeln('create localRepositoryDir: ' + localRepositoryDir); + CreateDirUTF8(localRepositoryDir); + end; + + halt; + + //if InitGitLibrary() > 0 then + // Try + // writeLn('initialized git library') ; + // if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo+'\\.git')) then + // CloneRepository(CustomerRepo, LocalCustomerRepo); + // if not CheckoutLocalBranch(LocalCustomerRepo, LocalBranchName) = 0 then + // writeLn('cannot check out') ; + // if not CommitFile(LocalCustomerRepo, LocalBranchName, FileToCommit, CommitMessage) = 0 then + // writeLn('cannot commit') ; + // if not PushLocalRepository(LocalCustomerRepo, LocalBranchName, UserName, PassWord) = 0 then + // writeLn('cannot push') ; + // Finally + // if ShutdownGitLibrary() >= 0 then + // writeLn('shutdown git library') ; + // end + //else + // begin + // writeLn('initializing git library FAILED') ; + // Readln; + // end; + finally + jArray.Free; + end; +end. + diff --git a/deploy/webiface.res b/deploy/webiface.res new file mode 100644 index 0000000..1eb37d1 Binary files /dev/null and b/deploy/webiface.res differ diff --git a/helloworld.exe b/helloworld.exe deleted file mode 100644 index 14ccaac..0000000 Binary files a/helloworld.exe and /dev/null differ diff --git a/helloworld.lpr b/helloworld.lpr deleted file mode 100644 index ea64001..0000000 --- a/helloworld.lpr +++ /dev/null @@ -1,56 +0,0 @@ - - -{%RunFlags MESSAGES+} -{$mode ObjFPC}{$H-} -program helloworld(output); - - -uses - TariffCalculator, CTypes, LazUtils, LazFileUtils, LazUtf8; - -var - //TariffCalc: TariffCalculatorHandle; - CustomerRepo: array[0..100] of char; - LocalCustomerRepo: array[0..100] of char; - LocalBranchName: array[0..32] of char; - FileToCommit: array[0..128] of char; - CommitMessage: array[0..256] of char; - UserName: array[0..64] of char; - PassWord: array[0..64] of char; - -begin -// TariffCalc := NewTariffCalculator; -// DeleteTariffCalculator(TariffCalc); - - CustomerRepo := 'https://git.mimbach49.de/GerhardHoffmann/customer_999.git'; - LocalCustomerRepo := 'C:\\tmp\\customer_999'; - LocalBranchName := 'zg1/zone1'; - FileToCommit := 'etc/psa_tariff/tariff01.json'; - CommitMessage := 'TEST TEST'; - UserName := 'GerhardHoffmann'; - PassWord := 'ghlinux12345'; - if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo)) then - CreateDirUTF8(ExpandFilenameUtf8(LocalCustomerRepo)); - - if InitGitLibrary() > 0 then - Try - writeLn('initialized git library') ; - if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo+'\\.git')) then - CloneRepository(CustomerRepo, LocalCustomerRepo); - if not CheckoutLocalBranch(LocalCustomerRepo, LocalBranchName) = 0 then - writeLn('cannot check out') ; - if not CommitFile(LocalCustomerRepo, LocalBranchName, FileToCommit, CommitMessage) = 0 then - writeLn('cannot commit') ; - if not PushLocalRepository(LocalCustomerRepo, LocalBranchName, UserName, PassWord) = 0 then - writeLn('cannot push') ; - Finally - if ShutdownGitLibrary() >= 0 then - writeLn('shutdown git library') ; - end - else - begin - writeLn('initializing git library FAILED') ; - Readln; - end; -end. - diff --git a/tariffcalculator.pas b/tariffcalculator.pas deleted file mode 100644 index ae7a491..0000000 --- a/tariffcalculator.pas +++ /dev/null @@ -1,44 +0,0 @@ -unit TariffCalculator; - -{$mode ObjFPC}{$H+} - -interface - -uses - SysUtils, CTypes; - -type - // Can't use the class directly, so it is treated as an opaque handle. - // THandle is guaranteed to have the right size, even on other platforms. - TariffCalculatorHandle = THandle; - -function NewTariffCalculator: TariffCalculatorHandle; stdcall; -procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; - -function InitGitLibrary: cint32; stdcall; -function ShutdownGitLibrary: cint32; stdcall; -function CloneRepository(var url; var local_path) : cint32; stdcall; -function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; -function CommitFile(var local_path; var branch_name; - var file_name; var comment) : cint32; stdcall; -function PushLocalRepository(var local_path; var branch_name; - var user_name; var password) : cint32; stdcall; -implementation - -const - DLLName = 'CalculatorCInterface.dll'; - -function NewTariffCalculator: TariffCalculatorHandle; stdcall; external DLLName; -procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; external DLLName; - -function InitGitLibrary: cint32; stdcall; external DLLName; -function ShutdownGitLibrary: cint32; stdcall; external DLLName; -function CloneRepository(var url; var local_path) : cint32; stdcall; external DLLName; -function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; external DLLName; -function CommitFile(var local_path; var branch_name; - var file_name; var comment) : cint32; stdcall; external DLLName; -function PushLocalRepository(var local_path; var branch_name; - var user_name; var password) : cint32; stdcall; external DLLName; - -end. - diff --git a/webiface.lpr b/webiface.lpr new file mode 100644 index 0000000..ce78617 --- /dev/null +++ b/webiface.lpr @@ -0,0 +1,109 @@ + + +{%RunFlags MESSAGES+} +{$mode ObjFPC}{$H+} + +program webiface(output); + + +uses + CTypes, LazUtils, LazFileUtils, LazUtf8, SysUtils, + fpjson, jsonparser, ATBWebInterface, ATBUtils, ATBGit; + +//type +// PTJSONObject = ^TJSONObject; + +var + //jData: TJSONData; + jObject, jObjTemp: TJSONObject; + + jEnum: TJSONEnum; + jArray: TJSONArray; + + repoRootDir: UTF8String; + fileId: UTF8String; + localRepository: UTF8String; + localRepositoryDir: UTF8String; + fileName: UTF8String; + + {$R *.res} + +begin + try + jArray := TJSONArray.Create; + jObject := TJSONObject.Create; + + //CustomerRepo := 'https://git.mimbach49.de/GerhardHoffmann/customer_999.git'; + //LocalCustomerRepo := 'H:\\customer_999'; + //LocalBranchName := 'zg1/zone1'; + //FileToCommit := 'etc/psa_tariff/tariff01.json'; + //CommitMessage := 'TEST TEST'; + //UserName := 'GerhardHoffmann'; + //PassWord := 'ghlinux12345'; + //LocalRepo := 'customer_999'; + + repoRootDir := 'H:\'; + ATBGit.SetReposRootDirectory(repoRootDir); + + localRepository := 'customer_999'; + fileId := 'customer_999/etc/psa_tariff:zg1/zone1'; + //jData := GetJSON('{"F1" : "Hello"}'); + + // ATBWebInterface.SetFile(localRepository, fileId, jData); + // halt; + + if ATBWebInterface.GetFileMenu(localRepository, @jObject) then begin + jArray := jObject['File-Menue'] as TJSONArray; + for jEnum in jArray do begin + jObjTemp := jEnum.Value as TJSONObject; + fileId := jObjTemp.Strings['File-ID']; + fileName := GetFileName(localRepository, fileId); + + if fileName <> '' then begin + if FileExistsUTF8(fileName) then begin + writeln(); + writeln('file exists: ' + fileName); + if ATBWebInterface.GetFile(localRepository, fileId, @jObject) then begin + writeln(jObject.FormatJSON); + end; + end; + end; + end; + end; + + localRepositoryDir := ATBGit.GetLocalRepositoryPath(localRepository); + writeln(); + writeln('localRepositoryDir: ' + localRepositoryDir); + + if not DirectoryExistsUTF8(localRepositoryDir) then begin + writeln('create localRepositoryDir: ' + localRepositoryDir); + CreateDirUTF8(localRepositoryDir); + end; + + halt; + + //if InitGitLibrary() > 0 then + // Try + // writeLn('initialized git library') ; + // if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo+'\\.git')) then + // CloneRepository(CustomerRepo, LocalCustomerRepo); + // if not CheckoutLocalBranch(LocalCustomerRepo, LocalBranchName) = 0 then + // writeLn('cannot check out') ; + // if not CommitFile(LocalCustomerRepo, LocalBranchName, FileToCommit, CommitMessage) = 0 then + // writeLn('cannot commit') ; + // if not PushLocalRepository(LocalCustomerRepo, LocalBranchName, UserName, PassWord) = 0 then + // writeLn('cannot push') ; + // Finally + // if ShutdownGitLibrary() >= 0 then + // writeLn('shutdown git library') ; + // end + //else + // begin + // writeLn('initializing git library FAILED') ; + // Readln; + // end; + finally + jArray.Free; + end; +end. +