private async Task DeployToTarget(TargetDatabase target, IEnumerable <SqlScriptFile> scriptFiles, IProgress <ProgressEventArgs> progress) { target.DeploymentStatus = "Initiating connection..."; var couldOpen = await target.TryConnect(); target.DeploymentStatus = "Connected!"; if (couldOpen) { try { await target.DeployAsync(scriptFiles); target.DeploymentStatus = "Success"; target.State = 1; OnProgress(target, progress); } catch (Exception ex) { target.Messages.Add(new ExecutionMessage(ex)); target.DeploymentStatus = "Error"; target.State = 2; OnProgress(target, progress); } } return; }
private async Task OnEachTarget(IProgress <ProgressEventArgs> progress, TargetDatabase target) { var start = DateTime.Now; target.DeploymentStatus = "Starting.."; await DeployToTarget(target, ScriptFiles, progress); var result = (int)(DateTime.Now - start).TotalMilliseconds; target.DeploymentStatus = "Done in: " + result.ToString() + "ms"; OnProgress(target, progress); }
public async Task PopulateTargets() { Targets.Clear(); if (Type == SourceType.Direct) { var target = new TargetDatabase(Targets.Count + 1, Name, ConnectionString, ProviderName, CommandTimeout); Targets.Add(target); } else if (Type == SourceType.DataSource) { try { var result = await this.TryConnect(CancellationToken.None); if (result) { var databases = await this.Context.ExecuteAsync("SELECT * FROM sys.databases"); if (databases != null) { foreach (var db in databases) { string name = db.name as string; if (name == null) { return; } if (!string.IsNullOrEmpty(NameFilter) && !name.Contains(NameFilter)) { continue; } var target = new TargetDatabase(Targets.Count + 1, Name, ConnectionString, ProviderName, CommandTimeout, name); Targets.Add(target); } } } } finally { if (Context != null) { Context.FinishConnection(); } } } else { //throw new InvalidOperationException("Source Type should be Direct or DataSource."); } }
private async Task DeployToTarget(TargetDatabase target, IEnumerable <SqlScriptFile> scriptFiles, IProgress <ProgressEventArgs> progress, CancellationToken ct) { target.DeploymentStatusMessage = "Initiating connection..."; OnProgress(target, progress); var couldOpen = await target.TryConnect(ct).ConfigureAwait(false); if (couldOpen) { target.DeploymentStatusMessage = "Connected!"; OnProgress(target, progress); try { await target.DeployAsync(scriptFiles, ct).ConfigureAwait(false); target.DeploymentStatusMessage = "Success"; target.DeploymentState = Database.DatabaseDeploymentState.Success; OnProgress(target, progress); } catch (OperationCanceledException ex) { //Deployment.Status = DeploymentStatus.Cancelled; target.Messages.Add(new ExecutionMessage(ex)); target.DeploymentStatusMessage = "Cancelled"; target.DeploymentState = Database.DatabaseDeploymentState.Cancelled; OnProgress(target, progress); } catch (Exception ex) { target.Messages.Add(new ExecutionMessage(ex)); target.DeploymentStatusMessage = "Error"; target.DeploymentState = Database.DatabaseDeploymentState.Error; OnProgress(target, progress); } finally { target?.Dispose(); } } else { target.DeploymentState = Database.DatabaseDeploymentState.Error; OnProgress(target, progress); } }
private async Task OnEachTarget(IProgress <ProgressEventArgs> progress, TargetDatabase target, CancellationToken ct) { // await Task.Run(async () => // { var start = DateTime.Now; target.DeploymentStatusMessage = "Starting.."; target.ExecutionTime = ""; target.DeploymentState = Database.DatabaseDeploymentState.Starting; await DeployToTarget(target, ScriptFiles, progress, ct).ConfigureAwait(false); var result = (int)(DateTime.Now - start).TotalMilliseconds; target.ExecutionTime = result.ToString() + "ms"; //await Task.Delay(1); OnProgress(target, progress); // }, ct); }
private static void OnProgress(TargetDatabase target, IProgress <ProgressEventArgs> progress) { //progress?.Report(new ProgressEventArgs(target)); }