start testing webinterface ...

This commit is contained in:
Gerhard Hoffmann 2024-03-26 17:02:59 +01:00
parent 4501c85227
commit 6336303e45
23 changed files with 553 additions and 468 deletions

Binary file not shown.

View File

@ -4,18 +4,60 @@ unit ATBGit;
interface interface
uses uses SysUtils, fpjson, jsonparser;
Classes, SysUtils, CTypes, fpjson, jsonparser;
type //
function SetFile(const localRepository: String; const fileId: String; const json: TJSONData): Boolean; // public interface
function SetFileInternal(const localRepository: PChar; //
const fileId: PChar; procedure SetReposRootDirectory(const rootDir: UTF8String);
const json: PChar; function GetReposRootDirectory(): UTF8String;
size: cint32): cbool; stdcall; 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 implementation
const DLLName = 'CalculatorCInterface.dll'; 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. end.

99
atbtariffcalculator.pas Normal file
View File

@ -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.

View File

@ -4,7 +4,7 @@ unit ATBUtils;
interface interface
uses Classes, SysUtils, CTypes; uses Classes, SysUtils;
procedure DeleteMem(P: PChar); stdcall; procedure DeleteMem(P: PChar); stdcall;

View File

@ -12,6 +12,7 @@ type
// //
// public interface // public interface
// //
function GetFileMenu(const localRepository: UTF8String; function GetFileMenu(const localRepository: UTF8String;
jObj: PTJSONObject): Boolean; jObj: PTJSONObject): Boolean;
@ -38,7 +39,6 @@ function GetFileNameInternal(const localRepository: PChar;
implementation implementation
const DLLName = 'CalculatorCInterface.dll'; const DLLName = 'CalculatorCInterface.dll';
/// ///
function GetFileMenu(const localRepository: UTF8String; jObj: PTJSONObject): Boolean; function GetFileMenu(const localRepository: UTF8String; jObj: PTJSONObject): Boolean;
var var
@ -114,7 +114,10 @@ implementation
end; end;
end; end;
//
// external c-interface // external c-interface
//
function GetFileInternal(const localRepository: PChar; function GetFileInternal(const localRepository: PChar;
const fileId: PChar): PChar; stdcall; const fileId: PChar): PChar; stdcall;
external DLLName; external DLLName;

Binary file not shown.

View File

@ -4,18 +4,60 @@ unit ATBGit;
interface interface
uses uses SysUtils, fpjson, jsonparser;
Classes, SysUtils, CTypes, fpjson, jsonparser;
type //
function SetFile(const localRepository: String; const fileId: String; const json: TJSONData): Boolean; // public interface
function SetFileInternal(const localRepository: PChar; //
const fileId: PChar; procedure SetReposRootDirectory(const rootDir: UTF8String);
const json: PChar; function GetReposRootDirectory(): UTF8String;
size: cint32): cbool; stdcall; 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 implementation
const DLLName = 'CalculatorCInterface.dll'; 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. end.

View File

@ -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.

View File

@ -4,7 +4,7 @@ unit ATBUtils;
interface interface
uses Classes, SysUtils, CTypes; uses Classes, SysUtils;
procedure DeleteMem(P: PChar); stdcall; procedure DeleteMem(P: PChar); stdcall;

View File

@ -12,6 +12,7 @@ type
// //
// public interface // public interface
// //
function GetFileMenu(const localRepository: UTF8String; function GetFileMenu(const localRepository: UTF8String;
jObj: PTJSONObject): Boolean; jObj: PTJSONObject): Boolean;
@ -38,7 +39,6 @@ function GetFileNameInternal(const localRepository: PChar;
implementation implementation
const DLLName = 'CalculatorCInterface.dll'; const DLLName = 'CalculatorCInterface.dll';
/// ///
function GetFileMenu(const localRepository: UTF8String; jObj: PTJSONObject): Boolean; function GetFileMenu(const localRepository: UTF8String; jObj: PTJSONObject): Boolean;
var var
@ -114,7 +114,10 @@ implementation
end; end;
end; end;
//
// external c-interface // external c-interface
//
function GetFileInternal(const localRepository: PChar; function GetFileInternal(const localRepository: PChar;
const fileId: PChar): PChar; stdcall; const fileId: PChar): PChar; stdcall;
external DLLName; external DLLName;

View File

@ -1,78 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="helloworld"/>
<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>

View File

@ -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.

Binary file not shown.

View File

@ -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.

View File

@ -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.

View File

@ -8,12 +8,17 @@
<MainUnitHasCreateFormStatements Value="False"/> <MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/> <MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/> <MainUnitHasScaledStatement Value="False"/>
<UseDefaultCompilerOptions Value="True"/>
</Flags> </Flags>
<SessionStorage Value="InProjectDir"/> <SessionStorage Value="InProjectDir"/>
<Title Value="helloworld"/> <Title Value="webiface"/>
<UseAppBundle Value="False"/> <UseAppBundle Value="False"/>
<ResourceType Value="res"/> <ResourceType Value="res"/>
</General> </General>
<VersionInfo>
<UseVersionInfo Value="True"/>
<MajorVersionNr Value="1"/>
</VersionInfo>
<BuildModes> <BuildModes>
<Item Name="Default" Default="True"/> <Item Name="Default" Default="True"/>
</BuildModes> </BuildModes>
@ -31,18 +36,27 @@
</RequiredPackages> </RequiredPackages>
<Units> <Units>
<Unit> <Unit>
<Filename Value="helloworld.lpr"/> <Filename Value="webiface.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit> </Unit>
<Unit> <Unit>
<Filename Value="unit1.pas"/> <Filename Value="atbgit.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="Unit1"/> <UnitName Value="ATBGit"/>
</Unit> </Unit>
<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"/> <IsPartOfProject Value="True"/>
<UnitName Value="TariffCalculator"/>
</Unit> </Unit>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
@ -50,17 +64,18 @@
<Version Value="11"/> <Version Value="11"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Target> <Target>
<Filename Value="helloworld"/> <Filename Value="webiface"/>
</Target> </Target>
<SearchPaths> <SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/> <IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths> </SearchPaths>
<Linking> <Other>
<Debugging> <Verbosity>
<DebugInfoType Value="dsDwarf3"/> <ShoLineNum Value="True"/>
</Debugging> </Verbosity>
</Linking> <CustomOptions Value="-FcUTF8"/>
</Other>
</CompilerOptions> </CompilerOptions>
<Debugging> <Debugging>
<Exceptions> <Exceptions>

109
deploy/webiface.lpr Normal file
View File

@ -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.

BIN
deploy/webiface.res Normal file

Binary file not shown.

Binary file not shown.

View File

@ -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.

View File

@ -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.

109
webiface.lpr Normal file
View File

@ -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.