/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); var executed = new SqlRuner().Execute(); OpenExecuteResultDialogMessage(executed); }
private void OpenFolderRunner(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); var settings = new Settings(); var dialog = new Microsoft.Win32.SaveFileDialog(); dialog.InitialDirectory = settings.Databases.FolderPickerDefaltPath; // Use current value for initial dir dialog.Title = "Select a Directory"; // instead of default "Save As" dialog.Filter = "Directory|*.this.directory"; // Prevents displaying files dialog.FileName = "select"; // Filename will then be "select.this.directory" dialog.ShowDialog(); string path = dialog.FileName; // Remove fake filename from resulting path path = path.Replace("\\select.this.directory", ""); path = path.Replace(".this.directory", ""); // Our final value is in path var exexuted = new SqlRuner().ExecuteFromDirectoryPath(path); OpenExecuteResultDialogMessage(exexuted); }
public bool Execute(Settings.ChangeConstant changeConstants) { try { ConsoleWriteLine($"Changeing {changeConstants.Name}"); foreach (var fileDiconary in changeConstants.Files) { ConsoleWriteLine($"value: {fileDiconary.Value}"); string filepath = fileDiconary.File; if (!File.Exists(filepath)) { if (string.IsNullOrEmpty(fileDiconary.ProjectName)) { continue; } string projectDirectory = projects.ContainsKey(fileDiconary.ProjectName) ? Path.GetDirectoryName(projects[fileDiconary.ProjectName]) : null; if (string.IsNullOrEmpty(projectDirectory)) { ConsoleWriteLine($"no project by name {fileDiconary.ProjectName} on open solution"); continue; } filepath = Path.Combine(projectDirectory, fileDiconary.File); if (!File.Exists(filepath)) { ConsoleWriteLine($"no File {fileDiconary.File} in project {fileDiconary.ProjectName}"); continue; } } var fileText = File.ReadAllText(filepath); if (!Regex.IsMatch(fileText, fileDiconary.Pattern)) { ConsoleWriteLine($"no match for file {fileDiconary.Pattern} in project {fileDiconary.ProjectName}"); continue; } fileText = Regex.Replace(fileText, fileDiconary.Pattern, fileDiconary.Value); WriteAllText(filepath, fileText); ConsoleWriteLine($"File {fileDiconary.File} in project {fileDiconary.ProjectName} rewrited"); } if (!string.IsNullOrEmpty(changeConstants.Sql?.Script) && changeConstants.Sql?.Databases?.Any() == true) { var sqlScript = File.Exists(changeConstants.Sql?.Script) ? File.ReadAllText(changeConstants.Sql.Script) : changeConstants.Sql.Script; var sqlRunner = new SqlRuner(); var databases = settings.Databases.ConnectionStrings.Where(d => changeConstants.Sql.Databases.Contains(d.Name)); sqlRunner.ExecuteString(changeConstants.Sql.Script, databases); } return(true); } catch (System.Exception e) { ConsoleWriteException(e, new string[] { }); return(false); } }