private async Task <IEnumerable <string> > GetDbContextTypesAsync(string outputPath, Project project) { var processLauncher = new ProcessLauncher(project); var processResult = await processLauncher.GetOutputAsync(outputPath, GenerationType.DbContextList, null); if (string.IsNullOrEmpty(processResult)) { throw new InvalidOperationException(CompareLocale.UnableToCollectDbContextInformation); } if (processResult.Contains("Error:")) { throw new InvalidOperationException(processResult); } var modelResults = processLauncher.BuildModelResult(processResult); var result = new List <string>(); foreach (var modelResult in modelResults) { result.Add(modelResult.Item1); } return(result); }
private async Task <IEnumerable <string> > GetDbContextTypesAsync(string outputPath, Project project) { var processLauncher = new ProcessLauncher(project); var processResult = await processLauncher.GetOutputAsync(outputPath, GenerationType.DbContextList, null); if (string.IsNullOrEmpty(processResult)) { throw new ArgumentException("Unable to collect DbContext information", nameof(processResult)); } if (processResult.StartsWith("Error:")) { throw new ArgumentException(processResult, nameof(processResult)); } var modelResults = processLauncher.BuildModelResult(processResult); var result = new List <string>(); foreach (var modelResult in modelResults) { result.Add(modelResult.Item1); } return(result); }
private async Task <IEnumerable <CompareLogModel> > GetComparisonResultAsync(string outputPath, Project project, DatabaseConnectionModel connection, string[] contextNames) { var processLauncher = new ProcessLauncher(project); var processResult = await processLauncher.GetOutputAsync(outputPath, GenerationType.DbContextCompare, string.Join(",", contextNames), connection.ConnectionString); if (string.IsNullOrEmpty(processResult)) { throw new ArgumentException(CompareLocale.UnableToCollectSchemaCompareInformation, nameof(processResult)); } if (processResult.Contains("Error:")) { throw new ArgumentException(processResult, nameof(processResult)); } var modelResults = processLauncher.BuildModelResult(processResult); return(Newtonsoft.Json.JsonConvert.DeserializeObject <List <CompareLogModel> >(modelResults.First().Item2)); }
private async void btnApply_Click(object sender, RoutedEventArgs e) { try { StartAnimation(); btnApply.IsEnabled = false; if (btnApply.Content.ToString() == "Add Migration") { if (string.IsNullOrEmpty(txtMigrationName.Text)) { EnvDteHelper.ShowError("Migration Name required"); return; } _package.Dte2.StatusBar.Text = $"Creating Migration {txtMigrationName.Text} in DbContext {cmbDbContext.SelectedValue.ToString()}"; var processResult = await _processLauncher.GetOutputAsync(_outputPath, Path.GetDirectoryName(_project.FullName), _isNetCore, GenerationType.MigrationAdd, cmbDbContext.SelectedValue.ToString(), txtMigrationName.Text, _project.Properties.Item("DefaultNamespace").Value.ToString()); var result = BuildModelResult(processResult); if (processResult.StartsWith("Error:")) { EnvDteHelper.ShowError(processResult); return; } if (result.Count == 1) { string[] lines = result.First().Value.Split( new[] { Environment.NewLine }, StringSplitOptions.None ); if (lines.Length == 3) { _project.ProjectItems.AddFromFile(lines[1]); // migrationFile _package.Dte2.ItemOperations.OpenFile(lines[1]); // migrationFile _project.ProjectItems.AddFromFile(lines[0]); // metadataFile _project.ProjectItems.AddFromFile(lines[2]); // snapshotFile } } } if (btnApply.Content.ToString() == "Update Database") { _package.Dte2.StatusBar.Text = $"Updating Database from migrations in DbContext {cmbDbContext.SelectedValue.ToString()}"; var processResult = await _processLauncher.GetOutputAsync(_outputPath, _isNetCore, GenerationType.MigrationApply, cmbDbContext.SelectedValue.ToString()); if (processResult.StartsWith("Error:")) { EnvDteHelper.ShowError(processResult); return; } } if (btnApply.Content.ToString() == "Script Migrations") { _package.Dte2.StatusBar.Text = $"Scripting migrations in DbContext {cmbDbContext.SelectedValue.ToString()}"; var processResult = await _processLauncher.GetOutputAsync(_outputPath, _isNetCore, GenerationType.MigrationScript, cmbDbContext.SelectedValue.ToString()); if (processResult.StartsWith("Error:")) { EnvDteHelper.ShowError(processResult); return; } var modelResult = _processLauncher.BuildModelResult(processResult); var files = _project.GenerateFiles(modelResult, ".sql"); foreach (var file in files) { _package.Dte2.ItemOperations.OpenFile(file); } } await GetMigrationStatus(); } catch (Exception ex) { EnvDteHelper.ShowError(ex.ToString()); } finally { StopAnimation(); _package.Dte2.StatusBar.Text = string.Empty; btnApply.IsEnabled = true; } }