public async Task AwaitReadiness() { using (await SyncLock.Lock()) { switch (Status) { case TempDatabaseCreationStatus.Created: break; case TempDatabaseCreationStatus.Failed: case TempDatabaseCreationStatus.NotCreated: Status = TempDatabaseCreationStatus.Creating; await Create(); break; case TempDatabaseCreationStatus.Creating: await Task.Delay(100); await AwaitReadiness(); break; default: throw new NotSupportedException(Status + " is not handled"); } } }
public async Task Create(bool dropExisting = false) { try { var generator = new TestDatabaseGenerator(DatabaseManager) { DropExisting = dropExisting }; if (generator.Process()) { try { await ReferenceData.Create(); } catch (Exception ex) { throw new Exception("Failed to run the reference data.", ex); } } Status = TempDatabaseCreationStatus.Created; } catch { Status = TempDatabaseCreationStatus.Failed; throw; } finally { DatabaseChangeWatcher.Restart(); } }
public async Task Restart() { using (await SyncLock.Lock()) { Status = TempDatabaseCreationStatus.Creating; await Create(dropExisting : true); } }