Skip to content

Commit

Permalink
Added lock to prevent parallel checks attempting to create database a…
Browse files Browse the repository at this point in the history
…t same time
  • Loading branch information
tznind committed Mar 16, 2021
1 parent 011ef97 commit b130034
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions Rdmp.Dicom/Extraction/FoDicomBased/FoDicomAnonymiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,54 +184,55 @@ public void PreInitialize(IExtractCommand value, IDataLoadEventListener listener
_extractCommand = value as IExtractDatasetCommand;
}

private static object CreateServersOneAtATime = new object();

public void Check(ICheckNotifier notifier)
{
if(UIDMappingServer == null)
lock(CreateServersOneAtATime)
{
throw new Exception($"{nameof(UIDMappingServer)} not set, set it existing UID mapping server or to an empty database to create a new one");
}
if (UIDMappingServer == null)
{
throw new Exception($"{nameof(UIDMappingServer)} not set, set it existing UID mapping server or to an empty database to create a new one");
}

var patcher = new SMIDatabasePatcher();
var patcher = new SMIDatabasePatcher();

if(!UIDMappingServer.WasCreatedBy(patcher))
{
if (string.IsNullOrWhiteSpace(UIDMappingServer.CreatedByAssembly))
if (!UIDMappingServer.WasCreatedBy(patcher))
{
bool create = notifier.OnCheckPerformed(new CheckEventArgs($"{nameof(UIDMappingServer)} is not set up yet", CheckResult.Warning, null, "Attempt to create UID mapping schema"));

if(create)
if (string.IsNullOrWhiteSpace(UIDMappingServer.CreatedByAssembly))
{
var db = UIDMappingServer.Discover(ReusableLibraryCode.DataAccess.DataAccessContext.DataExport);
bool create = notifier.OnCheckPerformed(new CheckEventArgs($"{nameof(UIDMappingServer)} is not set up yet", CheckResult.Warning, null, "Attempt to create UID mapping schema"));

if (!db.Exists())
if (create)
{
notifier.OnCheckPerformed(new CheckEventArgs($"About to create {db}", CheckResult.Success));
db.Create();
}
var db = UIDMappingServer.Discover(ReusableLibraryCode.DataAccess.DataAccessContext.DataExport);

notifier.OnCheckPerformed(new CheckEventArgs($"Creating UID Mapping schema in {db}", CheckResult.Success));
if (!db.Exists())
{
notifier.OnCheckPerformed(new CheckEventArgs($"About to create {db}", CheckResult.Success));
db.Create();
}

var scripter = new MasterDatabaseScriptExecutor(db);
scripter.CreateAndPatchDatabase(patcher, new AcceptAllCheckNotifier());
notifier.OnCheckPerformed(new CheckEventArgs($"Creating UID Mapping schema in {db}", CheckResult.Success));

UIDMappingServer.CreatedByAssembly = patcher.Name;
UIDMappingServer.SaveToDatabase();
var scripter = new MasterDatabaseScriptExecutor(db);
scripter.CreateAndPatchDatabase(patcher, new AcceptAllCheckNotifier());

UIDMappingServer.CreatedByAssembly = patcher.Name;
UIDMappingServer.SaveToDatabase();
}
else
{
return;
}
}
else
{
notifier.OnCheckPerformed(new CheckEventArgs($"{nameof(UIDMappingServer)} '{UIDMappingServer}' was created by '{UIDMappingServer.CreatedByAssembly}' not a UID patcher. Try creating a new server reference to a blank database", CheckResult.Fail));
return;
}
}
else
{
notifier.OnCheckPerformed(new CheckEventArgs($"{nameof(UIDMappingServer)} '{UIDMappingServer}' was created by '{UIDMappingServer.CreatedByAssembly}' not a UID patcher. Try creating a new server reference to a blank database",CheckResult.Fail));
return;
}
}




}
}
}

0 comments on commit b130034

Please sign in to comment.