/// <summary> /// Compile the file provided and its dependencies. Dependencies may be compiled /// conditionally if out of date or unconditionally. /// </summary> /// <param name="srcInfo">The source file info.</param> /// <param name="srcText">The source file text.</param> /// <param name="compileAll">Compile dependencies unconditionally if true.</param> /// <returns>True if the action completed successfully.</returns> public bool Compile(FileInfo srcInfo, string srcText, bool compileAll) { if (_output == null) { return(false); } _output.ClearOutputViews(); _mainForm.SetStatusBarMessage(Resources.BuildStarted); _mainForm.StatusBar.Refresh(); if (srcInfo == null || String.IsNullOrEmpty(srcText)) { _output.AddLineToOutputView(String.Format( "------ {0}: {1}", Resources.BuildErrors, Resources.ErrorSourceInvalid)); _output.AdjustOutputWidth(); _mainForm.SetStatusBarMessage(Resources.BuildErrors); return(false); } if (!CompileDependencies(srcText, compileAll)) { return(false); } BuildCommand compileCommand = GetBuildCommand(srcInfo, Constants.ACTION_COMPILE); return(CompileFile(compileCommand)); }
private void RunSqlMetal(string filename) { string sqlMetalArgs; if (_useCompactEdition) { string dbname = _sqlConnectionManager. GetSqlServrCeDbName(_connectionString, true); dbname = Path.ChangeExtension(dbname, ".sdf"); if (!File.Exists(dbname)) { MessageBox.Show(String.Format("{0}: {1}", Resources.DbFileNotFoundMessage, dbname), Resources.DbFileNotFoundTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } sqlMetalArgs = String.Format("/dbml:\"{0}\" \"{1}\"", filename, dbname); } else { sqlMetalArgs = String.Format("/conn:\"{0}\" /dbml:\"{1}\"", _connectionString, filename); } if (_viewsCheckBox.Checked) { sqlMetalArgs += " /views"; } if (_functionsCheckBox.Checked) { sqlMetalArgs += " /functions"; } if (_sprocsCheckBox.Checked) { sqlMetalArgs += " /sprocs"; } RunProcessContext context = new RunProcessContext(); context.ExePath = _sqlMetalPath; context.ProcessArgs = sqlMetalArgs; context.HeaderText = String.Format("{0}: ", Resources.SqlMetalStarted); context.FooterText = String.Format("{0}: ", Resources.SqlMetalComplete); _output.ClearOutputViews(); _output.Text = Resources.OutputWindowRunSqlMetal; _output.RunProcessInternal(context); _applicationManager.NotifyFileSystemChange(); }
private void ActivatePlugin() { _findTextHistory = new List <String>(); _replaceTextHistory = new List <String>(); _fileSpecHistory = new List <String>(); /* * Access the output window. */ _output = ApplicationManager.GetInstance().GetDockedForm( QuickSharp.Output.Constants.DOCKED_FORM_KEY) as OutputForm; if (_output == null) { return; } _output.ClearOutputViews(); /* * Create the menu items. */ ToolStripMenuItem editMenu = _mainForm.GetMenuItemByName( QuickSharp.Editor.Constants.UI_EDIT_MENU); if (editMenu == null) { return; } int index = editMenu.DropDownItems.IndexOfKey( QuickSharp.Editor.Constants.UI_EDIT_MENU_REPLACE); if (index == -1) { return; } ToolStripMenuItem findMenu = MenuTools.CreateMenuItem( Constants.UI_EDIT_MENU_FIND_IN_FILES, Resources.MainEditMenuFindInFiles, null, Keys.Control | Keys.Shift | Keys.F, null, delegate { FindInFiles(true); }); ToolStripMenuItem replaceMenu = MenuTools.CreateMenuItem( Constants.UI_EDIT_MENU_REPLACE_IN_FILES, Resources.MainEditMenuReplaceInFiles, null, Keys.Control | Keys.Shift | Keys.H, null, delegate { FindInFiles(false); }, true); editMenu.DropDownItems.Insert(index + 1, replaceMenu); editMenu.DropDownItems.Insert(index + 1, findMenu); }
public void Find(string findText, string replaceText, string filePattern, bool searchSubFolders, bool useRegex, bool matchCase, bool findOnly) { /* * Prepare the output view. */ _outputForm.ClearOutputViews(); _outputForm.Text = String.Format(findOnly ? Resources.OutputTitleFind : Resources.OutputTitleReplace, filePattern); /* * Find all the matching files. */ string[] files = Directory.GetFiles( ".", filePattern, searchSubFolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); if (files.Length == 0) { _outputForm.AddLineToOutputView( Resources.FindMessageNoMatchingFiles); _outputForm.AdjustOutputWidth(); return; } /* * Prepare the regular expression if required. */ Regex regex = null; if (useRegex) { try { regex = new Regex(findText); } catch (ArgumentException ex) { _outputForm.AddLineToOutputView( String.Format(Resources.FindError, ex.Message), System.Drawing.Color.Red); _outputForm.AdjustOutputWidth(); return; } } /* * Search. File is ".\filename.ext" so we use Substring(2) for the name. */ if (findOnly) { int lineCount = 0; foreach (string file in files) { if (useRegex) { lineCount += FindInFileRE(file.Substring(2), regex); } else { lineCount += FindInFile(file.Substring(2), findText, matchCase); } } _outputForm.AddLineToOutputView( String.Format(lineCount == 1 ? Resources.FindMessageMatchCountSingle : Resources.FindMessageMatchCountMulti, lineCount)); } else { int fileCount = 0; foreach (string file in files) { bool updated = false; if (useRegex) { updated = ReplaceInFileRE(file.Substring(2), replaceText, regex); } else { updated = ReplaceInFile(file.Substring(2), findText, replaceText); } if (updated) { fileCount++; } } _outputForm.AddLineToOutputView( String.Format(fileCount == 1 ? Resources.FindMessageReplaceCountSingle : Resources.FindMessageReplaceCountMulti, fileCount)); } _outputForm.AdjustOutputWidth(); }
private void RunQuery() { SqlEditForm activeDocument = GetActiveDocument(); if (activeDocument == null) { return; } string dataSetName = Path.GetFileNameWithoutExtension(activeDocument.FileName); if (String.IsNullOrEmpty(dataSetName)) { dataSetName = Resources.QueryDataSetName; } activeDocument.ClearData(); _output.ClearOutputViews(); _output.Text = Resources.OutputWindowRunQuery; _mainForm.SetStatusBarMessage(String.Empty); List <string> commands = GetCommands(); if (commands == null) { return; } SqlConnection activeConnection = _sqlConnectionManager.SelectedConnection; if (activeConnection == null) { return; } _output.Text = String.Format("{0}: {1}", Resources.OutputWindowRunQuery, activeConnection.Name); DbConnection cnn = null; DbTransaction trx = null; DbCommand cmd = null; DbDataAdapter dataAdapter = null; DataSet dataSet = new DataSet(dataSetName); WriteLog(String.Format("------ {0}: {1}", Resources.QueryStarted, activeDocument.FileName)); _mainForm.SetStatusBarMessage(Resources.StatusBarQueryStarted); _mainForm.StatusBar.Refresh(); string logMessage = Resources.QueryUnknownCommand; bool useTransaction = (commands.Count > 1); try { DbProviderFactory factory = DbProviderFactories.GetFactory( activeConnection.Provider.InvariantName); cnn = factory.CreateConnection(); cnn.ConnectionString = activeConnection.ConnectionString; cnn.Open(); cmd = factory.CreateCommand(); cmd.Connection = cnn; cmd.CommandText = String.Empty; if (useTransaction) { trx = cnn.BeginTransaction(); cmd.Transaction = trx; WriteLog(Resources.QueryBeginTransaction); } dataAdapter = factory.CreateDataAdapter(); dataAdapter.SelectCommand = cmd; int commandCount = 1; foreach (string command in commands) { cmd.CommandText = command; string commandType = GetCommandName(command); logMessage = commandType; if (commandType == Resources.QuerySelectCommand) { int res = dataAdapter.Fill(dataSet, String.Format( Resources.QueryDataRowName, commandCount++)); if (res < 0) { res = 0; } WriteLog(String.Format( Resources.QuerySelectSuccess, logMessage, res, res == 1 ? Resources.QueryRowSingular : Resources.QueryRowPlural)); } else { int res = cmd.ExecuteNonQuery(); if (res < 0) { res = 0; } WriteLog(String.Format( Resources.QueryNonSelectSuccess, logMessage, res, res == 1 ? Resources.QueryRowSingular : Resources.QueryRowPlural)); } } if (useTransaction) { trx.Commit(); WriteLog(Resources.QueryCommitTransaction); } _mainForm.SetStatusBarMessage( Resources.StatusBarQuerySuccess); activeDocument.DataSet = dataSet; activeDocument.ShowTable(); } catch (Exception ex) { string errorMessage = ex.Message.Replace("\r\n", " "); WriteError(String.Format( Resources.QueryErrors, logMessage, errorMessage)); _mainForm.SetStatusBarMessage(Resources.StatusBarQueryError); if (useTransaction && trx != null) { trx.Rollback(); WriteLog(Resources.QueryRollbackTransaction); } } finally { if (cnn != null) { cnn.Dispose(); } } WriteLog(String.Format("------ {0}", Resources.QueryComplete)); }