/// <summary> /// De-provision the database. /// </summary> /// <returns> /// <c>true</c>, if the database was successfully de-provisioned; otherwise, <c>false<c/>. /// </returns> async Task <bool> Deprovision() { Log.Info("De-provisioning database {DatabaseId} in server {ServerId}...", ActiveProvisioner.State.Id, ActiveProvisioner.State.ServerId ); DataAccess.Tell( new DatabaseDeprovisioning(ActiveProvisioner.State.Id) ); try { if (!await ActiveProvisioner.DoesDatabaseExist()) { Log.Info("Database {DatabaseName} not found; will treat as deprovisioned.", ActiveProvisioner.State.Id, ActiveProvisioner.State.Name ); } else { await ActiveProvisioner.DropDatabase(); } DataAccess.Tell( new DatabaseDeprovisioned(ActiveProvisioner.State.Id) ); return(true); } catch (ProvisioningException dropDatabaseFailed) { Log.Error(dropDatabaseFailed, "Unexpected error dropping database {DatabaseName} (Id:{DatabaseId}).", ActiveProvisioner.State.Name, ActiveProvisioner.State.Id ); return(false); } }
/// <summary> /// Provision the database. /// </summary> /// <returns> /// A <see cref="Task"/> representing the operation. /// </returns> async Task Provision() { Log.Info("Provisioning database {DatabaseId} in server {ServerId}...", ActiveProvisioner.State.Id, ActiveProvisioner.State.ServerId ); DataAccess.Tell( new DatabaseProvisioning(ActiveProvisioner.State.Id) ); try { if (await ActiveProvisioner.DoesDatabaseExist()) { Log.Info("Database {DatabaseName} already exists; will treat as provisioned.", ActiveProvisioner.State.Id, ActiveProvisioner.State.Name ); } else { await ActiveProvisioner.CreateDatabase(); } DataAccess.Tell( new DatabaseProvisioned(ActiveProvisioner.State.Id) ); } catch (ProvisioningException createDatabaseFailed) { Log.Error(createDatabaseFailed, "Unexpected error creating database {DatabaseName} (Id:{DatabaseId}).", ActiveProvisioner.State.Name, ActiveProvisioner.State.Id ); DataAccess.Tell( new DatabaseProvisioningFailed(ActiveProvisioner.State.Id) ); } }