From f080e27977a4ab704cb36e07534024ace3b4c2b6 Mon Sep 17 00:00:00 2001 From: Roland Bengtsson Date: Sat, 7 Dec 2024 20:51:37 +0200 Subject: [PATCH] Now uses Unloader to unload objects/members in the background. #20 --- Source/BoldSystemCopy.pas | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Source/BoldSystemCopy.pas b/Source/BoldSystemCopy.pas index 1c27c2d..2789015 100644 --- a/Source/BoldSystemCopy.pas +++ b/Source/BoldSystemCopy.pas @@ -11,6 +11,7 @@ interface BoldDomainElement, BoldDefs, BoldUMLTypes, + BoldUnloader, System.SysUtils, Winapi.Windows; @@ -53,6 +54,8 @@ TBoldSystemCopy = class(TComponent) fStopped: Integer; fStartTime: TDateTime; FMaxObjectsInMemory: integer; + fSourceUnloader, fDestinationUnloader: TBoldUnloader; + fLastCheckStop: TDateTime; function GetDestinationSystem: TBoldSystem; function GetSourceSystem: TBoldSystem; procedure CollectMembers(AClassTypeInfo: TBoldClassTypeInfo; AMemberIdList: TBoldMemberIdList; ARoleTypes: TBoldRoleSet; AAttributes: boolean; ADerived: boolean = false; ADelayedFetched: boolean = false); @@ -195,6 +198,12 @@ procedure TBoldSystemCopy.CheckStop; DoLogEvent('Use requested abort'); raise EBoldSystemCopyInterrupt.Create('Use requested abort.'); end; + if SecondsBetween(now, fLastCheckStop) > 30 then + begin + fSourceUnloader.Tick; + fDestinationUnloader.Tick; + fLastCheckStop := now; + end; end; procedure TBoldSystemCopy.CloneObject(const ASourceObject: TBoldObject; @@ -738,7 +747,17 @@ procedure TBoldSystemCopy.Report(const Msg: string; const Args: array of const); end; procedure TBoldSystemCopy.Run; +var + g: IBoldGuard; begin + g := TBoldGuard.Create(fSourceUnloader, fDestinationUnloader); + fSourceUnloader := TBoldUnloader.Create; + fDestinationUnloader := TBoldUnloader.Create; + fSourceUnloader.ScanPerTick := 500; + fDestinationUnloader.ScanPerTick := 500; + fSourceUnloader.MinAgeForUnload := 20; // 20 * 30 sec + fDestinationUnloader.MinAgeForUnload := 20; + fStopped := 0; fNewObjectsWritten := 0; if not Assigned(SourceSystemHandle) then @@ -763,12 +782,19 @@ procedure TBoldSystemCopy.Run; DestinationSystem.OnPreUpdate := PreUpdateDestination; fStartTime := now; try + fSourceUnloader.BoldSystem := SourceSystem;; + fDestinationUnloader.BoldSystem := DestinationSystem; + fLastCheckStop := now; + fSourceUnloader.Active := true; + fDestinationUnloader.Active := true; CheckStop; CheckModelCompatibility; Report('Source objects: %d Destination objects %d', [SourceAllInstanceCount, DestinationAllInstanceCount]); CheckStop; CopyInstances; UpdateLastUsedID; + fSourceUnloader.Active := false; + fDestinationUnloader.Active := false; Report('Completed succesfully, source: %d destination: %d.', [SourceAllInstanceCount, DestinationAllInstanceCount]); SourceSystemHandle.Active := false; // DestinationSystemHandle.Active := false; @@ -776,7 +802,7 @@ procedure TBoldSystemCopy.Run; on e:EBoldSystemCopyInterrupt do begin fStartTime := 0; - ; // silent + raise; end; end; end;