source upload
This commit is contained in:
@@ -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.
|
@@ -0,0 +1,127 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{D080C2AC-E8DE-4854-B903-873FB4745218}</ProjectGuid>
|
||||
<MainSource>ServBook.dpr</MainSource>
|
||||
<Base>True</Base>
|
||||
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||
<TargetedPlatforms>1</TargetedPlatforms>
|
||||
<AppType>Console</AppType>
|
||||
<FrameworkType>None</FrameworkType>
|
||||
<ProjectVersion>16.0</ProjectVersion>
|
||||
<Platform Condition="'$(Platform)'==''">Win32</Platform>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
|
||||
<Base_Win32>true</Base_Win32>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Base)'=='true') or '$(Base_Win64)'!=''">
|
||||
<Base_Win64>true</Base_Win64>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
|
||||
<Cfg_1>true</Cfg_1>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
|
||||
<Cfg_2>true</Cfg_2>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
|
||||
<Cfg_2_Win32>true</Cfg_2_Win32>
|
||||
<CfgParent>Cfg_2</CfgParent>
|
||||
<Cfg_2>true</Cfg_2>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Base)'!=''">
|
||||
<Manifest_File>None</Manifest_File>
|
||||
<DCC_ImageBase>00400000</DCC_ImageBase>
|
||||
<VerInfo_Locale>1033</VerInfo_Locale>
|
||||
<DCC_K>false</DCC_K>
|
||||
<DCC_S>false</DCC_S>
|
||||
<DCC_N>false</DCC_N>
|
||||
<SanitizedProjectName>ServBook</SanitizedProjectName>
|
||||
<DCC_DcuOutput>dcu</DCC_DcuOutput>
|
||||
<DCC_ExeOutput>exe</DCC_ExeOutput>
|
||||
<DCC_E>false</DCC_E>
|
||||
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=</VerInfo_Keys>
|
||||
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
|
||||
<DCC_F>false</DCC_F>
|
||||
<Icon_MainIcon>ServBook_Icon.ico</Icon_MainIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Base_Win32)'!=''">
|
||||
<VerInfo_Locale>1033</VerInfo_Locale>
|
||||
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
|
||||
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
|
||||
<Icon_MainIcon>ServBook_Icon.ico</Icon_MainIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Base_Win64)'!=''">
|
||||
<Icon_MainIcon>ServBook_Icon.ico</Icon_MainIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_1)'!=''">
|
||||
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
|
||||
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
|
||||
<DCC_DebugInformation>0</DCC_DebugInformation>
|
||||
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_2)'!=''">
|
||||
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
|
||||
<Manifest_File>None</Manifest_File>
|
||||
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<DelphiCompile Include="$(MainSource)">
|
||||
<MainSource>MainSource</MainSource>
|
||||
</DelphiCompile>
|
||||
<DCCReference Include="..\dom\DomConferenceTypes.pas"/>
|
||||
<DCCReference Include="..\dom\DomConferenceInterfaces.pas"/>
|
||||
<DCCReference Include="..\dom\DomConferenceDepend.pas"/>
|
||||
<DCCReference Include="..\dom\DomConferenceServices.pas"/>
|
||||
<DCCReference Include="..\infra\InfraConferenceRepository.pas"/>
|
||||
<DCCReference Include="ServBookMain.pas"/>
|
||||
<BuildConfiguration Include="Debug">
|
||||
<Key>Cfg_2</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
</BuildConfiguration>
|
||||
<BuildConfiguration Include="Base">
|
||||
<Key>Base</Key>
|
||||
</BuildConfiguration>
|
||||
<BuildConfiguration Include="Release">
|
||||
<Key>Cfg_1</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
</BuildConfiguration>
|
||||
</ItemGroup>
|
||||
<ProjectExtensions>
|
||||
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
|
||||
<Borland.ProjectType/>
|
||||
<BorlandProject>
|
||||
<Delphi.Personality>
|
||||
<Source>
|
||||
<Source Name="MainSource">ServBook.dpr</Source>
|
||||
</Source>
|
||||
<Excluded_Packages>
|
||||
<Excluded_Packages Name="$(BDSBIN)\bcboffice2k210.bpl">Embarcadero C++Builder Office 2000 Servers Package</Excluded_Packages>
|
||||
<Excluded_Packages Name="$(BDSBIN)\bcbofficexp210.bpl">Embarcadero C++Builder Office XP Servers Package</Excluded_Packages>
|
||||
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k210.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
|
||||
<Excluded_Packages Name="$(BDSBIN)\dclofficexp210.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
|
||||
</Excluded_Packages>
|
||||
</Delphi.Personality>
|
||||
<Platforms>
|
||||
<Platform value="OSX32">False</Platform>
|
||||
<Platform value="Win32">True</Platform>
|
||||
<Platform value="Win64">False</Platform>
|
||||
</Platforms>
|
||||
</BorlandProject>
|
||||
<ProjectFileVersion>12</ProjectFileVersion>
|
||||
</ProjectExtensions>
|
||||
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
|
||||
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
|
||||
</Project>
|
@@ -0,0 +1,84 @@
|
||||
/// Booking server implementation
|
||||
unit ServBookMain;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils,
|
||||
Classes,
|
||||
SynCommons,
|
||||
mORMot,
|
||||
SynSQLite3,
|
||||
SynTable,
|
||||
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.
|
@@ -0,0 +1,76 @@
|
||||
/// 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, b: TAttendee;
|
||||
days1, days2: TSessionDays;
|
||||
res: TRegisterAttendee;
|
||||
begin
|
||||
a := TAttendee.Create;
|
||||
b := TAttendee.Create;
|
||||
try
|
||||
days1 := TSessionDay.From([0, 1, 2]);
|
||||
res := fProcess.Booking.RegisterAttendee('abc', ' def', days1, a);
|
||||
if res = raAlreadyRegistered then // works only first time (blank DB)
|
||||
res := fProcess.Booking.RegisterAttendee(CardinalToHex(UnixTimeUTC),
|
||||
RandomIdentifier(10), days1, a);
|
||||
check(res = raSuccess);
|
||||
check(a.Name <> '');
|
||||
check(length(a.FirstName) = 10);
|
||||
check(fProcess.Booking.SearchRegistration(a.Name, a.FirstName, days2, b) = srFound);
|
||||
check(a.Name = b.Name);
|
||||
check(a.RegistrationNumber = b.RegistrationNumber);
|
||||
check(DynArrayEquals(TypeInfo(TSessionDays), days1, days2));
|
||||
finally
|
||||
a.Free;
|
||||
b.Free;
|
||||
ObjArrayClear(days1);
|
||||
ObjArrayClear(days2);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestBookingApplication.ShutdownService;
|
||||
begin
|
||||
FreeAndNil(fProcess);
|
||||
FreeAndNil(fSettings);
|
||||
end;
|
||||
|
||||
initialization
|
||||
end.
|
Reference in New Issue
Block a user