source upload

This commit is contained in:
Razor12911
2022-01-17 22:16:47 +02:00
parent 12936d065b
commit 098e8c48de
1778 changed files with 1206749 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
program ServBook;
{$APPTYPE CONSOLE}
uses
{$I SynDprUses.inc} // includes FastMM4
SysUtils,
SynLog,
mORMot,
SynSQLite3Static,
mORMotSQLite3,
mORMotService, // cross-platform service/daemon skeleton with settings
// domain
DomConferenceTypes in '..\dom\DomConferenceTypes.pas',
DomConferenceInterfaces in '..\dom\DomConferenceInterfaces.pas',
DomConferenceDepend in '..\dom\DomConferenceDepend.pas',
DomConferenceServices in '..\dom\DomConferenceServices.pas',
// infrastructure
InfraConferenceRepository in '..\infra\InfraConferenceRepository.pas',
// servers
ServBookMain in '..\serv\ServBookMain.pas';
type
TBookSettings = class(TSynDaemonSettings)
private
fProcess: TBookProcessSettings;
public
constructor Create; override;
published
property Process: TBookProcessSettings read fProcess;
end;
TBookDaemon = class(TSynDaemon)
protected
fProcess: TBookProcess;
public
procedure Start; override;
procedure Stop; override;
end;
{ TBookDaemon }
procedure TBookDaemon.Start;
begin
if fProcess = nil then
fProcess := TBookProcess.Create((fSettings as TBookSettings).Process);
end;
procedure TBookDaemon.Stop;
begin
FreeAndNil(fProcess);
end;
{ TBookSettings }
constructor TBookSettings.Create;
begin
inherited;
fServiceDisplayName := 'My Long Name for Service';
end;
begin
with TBookDaemon.Create(TBookSettings, '', '', '') do
try
CommandLine(true);
finally
Free;
end;
end.

View File

@@ -0,0 +1,83 @@
/// Booking server implementation
unit ServBookMain;
interface
uses
SysUtils,
Classes,
SynCommons,
mORMot,
SynSQLite3,
mORMotSQLite3,
mORMotDB,
dddInfraApps,
DomConferenceTypes,
DomConferenceInterfaces,
DomConferenceServices,
DomConferenceDepend,
InfraConferenceRepository;
type
TBookProcessSettings = class(TSynAutoCreateFields)
private
fStore: TSynConnectionDefinition;
public
constructor Create; override;
published
property Store: TSynConnectionDefinition read fStore;
end;
TBookProcess = class(TSynPersistent)
protected
fSettings: TBookProcessSettings;
fRest: TSQLRest;
fBooking: IConferenceBooking;
public
constructor Create(aSettings: TBookProcessSettings); reintroduce;
destructor Destroy; override;
property Booking: IConferenceBooking read fBooking;
property Settings: TBookProcessSettings read fSettings;
end;
implementation
{ TBookProcessSettings }
constructor TBookProcessSettings.Create;
begin
inherited;
// use a local SQlite3 database file by default
fStore.Kind := 'TSQLRestServerDB'; // change Kind to switch to another engine
fStore.ServerName := ChangeFileExt(ExeVersion.ProgramFileName, '.db');
end;
{ TBookProcess }
constructor TBookProcess.Create(aSettings: TBookProcessSettings);
begin
inherited Create;
fSettings := aSettings;
fRest := TSQLRestExternalDBCreate(
TSQLModel.Create([TSQLBooking], 'book'), fSettings.Store, false, []);
fRest.Model.Owner := fRest;
if fRest is TSQLRestServerDB then
with TSQLRestServerDB(fRest) do begin // may be a client in settings :)
DB.Synchronous := smOff; // faster exclusive access to the file
DB.LockingMode := lmExclusive;
CreateMissingTables; // will create the Booking table, if necessary
end;
fBooking := TConferenceBooking.Create(TORMBookingRepository.Create(fRest));
end;
destructor TBookProcess.Destroy;
begin
inherited;
fBooking := nil; // before fRest
fRest.Free;
end;
initialization
end.

View File

@@ -0,0 +1,67 @@
/// unit tests for the Booking server
unit ServBookTest;
interface
uses
SysUtils,
Classes,
SynCommons,
SynTests,
mORMot,
DomConferenceTypes,
DomConferenceInterfaces,
DomConferenceServices,
InfraConferenceRepository,
ServBookMain;
type
TTestBookingApplication = class(TSynTestCase)
protected
fSettings: TBookProcessSettings;
fProcess: TBookProcess;
published
procedure RunService;
procedure ApplicationTest;
procedure ShutdownService;
end;
implementation
{ TTestBookingApplication }
procedure TTestBookingApplication.RunService;
begin
fSettings := TBookProcessSettings.Create;
fProcess := TBookProcess.Create(fSettings);
end;
procedure TTestBookingApplication.ApplicationTest;
var
a: TAttendee;
days: TSessionDays;
res: TRegisterAttendee;
begin
a := TAttendee.Create;
try
days := TSessionDay.From([0, 1, 2]);
res := fProcess.Booking.RegisterAttendee('abc', ' def', days, a);
if res = raAlreadyRegistered then // would works only first time
res := fProcess.Booking.RegisterAttendee(CardinalToHex(UnixTimeUTC),
RandomIdentifier(10), days, a);
check(res = raSuccess);
finally
a.Free;
ObjArrayClear(days);
end;
end;
procedure TTestBookingApplication.ShutdownService;
begin
FreeAndNil(fProcess);
FreeAndNil(fSettings);
end;
initialization
end.