/// <summary>The run template.</summary> public void RunTemplate() { TemplateModel templateModel = _services.Resolve <TemplateModel>(); TemplateResult templateResult = null; txtErrors.Clear(); try { string[] lines = AllText.Replace("\r", string.Empty).Split('\n'); string text; Dictionary <string, object> items = new Dictionary <string, object>(); items[TemplateModel.Extension] = templateModel.InferExtensionFromFilename(FileName, items); text = templateModel.PreProcessTemplate(lines, GetValue, items); templateResult = templateModel.ProcessTemplate(text, items); } catch (TemplateException exp) { _hostWindow.DisplaySimpleMessageBox(this, exp.Message, "Template Error"); // todo - try to get the line number and move cursor?... txtErrors.Text = exp.Message; } if (templateResult != null) { // display in new window IFileEditorResolver resolver = _services.Resolve <IFileEditorResolver>(); IEditor editor = _services.Resolve <IEditor>(resolver.ResolveEditorNameByExtension(templateResult.Extension)); editor.AllText = templateResult.Text; editor.SetSyntax(templateResult.SyntaxName); _hostWindow.DisplayDockedForm(editor as DockContent); } }
/// <summary>The lnk export script_ link clicked.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void lnkExportScript_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { DataTable dt = dataGridViewResult.DataSource as DataTable; if (dt != null) { var stringWriter = new StringWriter(); var hostWindow = _services.HostWindow; var dbModelTable = hostWindow.DatabaseInspector.DbSchema.FindTableOrView(TableName); var sqlWriter = _services.Resolve <ISqlWriter>(); sqlWriter.IncludeComments = false; sqlWriter.InsertLineBreaksBetweenColumns = false; sqlWriter.IncludeReadOnlyColumnsInExport = _settings.IncludeReadOnlyColumnsInExport; for (int i = 0; i < dt.Rows.Count; i++) { DataRow dataRow = dt.Rows[i]; foreach (var column in dbModelTable.Columns) { column.DbType.Value = dataRow[dt.Columns[column.Name]]; } sqlWriter.WriteInsert(stringWriter, dbModelTable); if (_settings.EnableQueryBatching) { stringWriter.WriteLine("GO"); } stringWriter.WriteLine(); if (i % 10 == 0) { UpdateStatus(string.Format("Processing {0} of {1} rows", i + 1, dt.Rows.Count)); } } UpdateStatus(string.Format("Processed {0} rows. Opening file...", dt.Rows.Count)); // HACK - need to clean up the values for now as the model is holding the last rows data ;-) // TODO - add a "deep clone" method to the table/columns foreach (var column in dbModelTable.Columns) { column.DbType.Value = null; } // create a new sql editor and push the sql into it IEditor editor = _services.Resolve <IQueryEditor>(); editor.AllText = stringWriter.ToString(); hostWindow.DisplayDockedForm(editor as DockContent); UpdateStatus(null); } }
/// <summary>The run template.</summary> /// <param name="fi">The fi.</param> private void RunTemplate(FileInfo fi) { TemplateResult templateResult = _model.ProcessTemplateFile(fi.FullName, GetValue); // display in new window IFileEditorResolver resolver = _services.Resolve <IFileEditorResolver>(); IEditor editor = _services.Resolve <IEditor>(resolver.ResolveEditorNameByExtension(templateResult.Extension)); editor.AllText = templateResult.Text; editor.SetSyntax(templateResult.SyntaxName); _services.HostWindow.DisplayDockedForm(editor as DockContent); }
protected void ConfigureMostRecentFileList(IApplicationServices services) { // get the files out of the settings and register them var mostRecentFilesService = services.Resolve <IMostRecentFilesService>(); if (services.Settings.MostRecentFiles != null) { foreach (string mostRecentFile in services.Settings.MostRecentFiles) { mostRecentFilesService.Filenames.Add(mostRecentFile); } } // watch for changes mostRecentFilesService.MostRecentFilesChanged += mostRecentFilesService_MostRecentFilesChanged; // need to manually call the update - only required on first load ((OpenRecentFileCommand)CommandManager.GetCommandInstance <OpenRecentFile1Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance <OpenRecentFile2Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance <OpenRecentFile3Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance <OpenRecentFile4Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance <OpenRecentFile5Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance <OpenRecentFile6Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance <OpenRecentFile7Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance <OpenRecentFile8Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance <OpenRecentFile9Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance <OpenRecentFile10Command>()).UpdateName(); }
/// <summary> /// Resolves the editor instance from the container based on the filename. /// </summary> /// <param name = "filename">The filename.</param> /// <returns>An editor.</returns> public IEditor ResolveEditorInstance(string filename) { string ext = Path.GetExtension(filename); string editorName = ResolveEditorNameByExtension(ext); return(_services.Resolve <IEditor>(editorName)); }
/// <summary>The get summary.</summary> /// <param name="column">The column.</param> /// <returns>The get summary.</returns> private string GetSummary(DbModelColumn column) { StringWriter stringWriter = new StringWriter(); if (_sqlWriter == null) { _sqlWriter = _services.Resolve <ISqlWriter>(); } _sqlWriter.WriteSummary(stringWriter, column); return(stringWriter.ToString()); }
/// <summary>The pre process template.</summary> /// <param name="lines">The lines.</param> /// <param name="getValueForParameter">The get value for parameter.</param> /// <param name="items">The items.</param> /// <returns>The pre process template.</returns> public string PreProcessTemplate( string[] lines, GetValueForParameter getValueForParameter, Dictionary <string, object> items) { int i = 0; for (; i < lines.Length; i++) { string line = lines[i]; if (line.StartsWith("#@")) { // process cmd if (line.StartsWith("#@get ", StringComparison.CurrentCultureIgnoreCase)) { string name = line.Substring("#@get ".Length); string val = getValueForParameter(name); items.Add(name, val); } else if (line.StartsWith("#@set extension ", StringComparison.CurrentCultureIgnoreCase)) { items[Extension] = line.Substring("#@set extension ".Length); } else if (line.StartsWith("#@import-plugin ", StringComparison.CurrentCultureIgnoreCase)) { string pluginKeyName = line.Substring("#@import-plugin ".Length); items[pluginKeyName.Replace(".", "_")] = _services.Resolve <IPlugIn>(pluginKeyName); } } else { break; } } string text = string.Join(Environment.NewLine, lines, i, lines.Length - i); return(text); }
/// <summary>Initializes a new instance of the <see cref="QueryForm"/> class.</summary> /// <param name="services">The services.</param> /// <param name="settings">The settings.</param> /// <param name="hostWindow">The host window.</param> public QueryForm(IApplicationServices services, IApplicationSettings settings, IHostWindow hostWindow) : this() { _services = services; _settings = settings; _hostWindow = hostWindow; var completionProvider = _services.Resolve <ICompletionProvider>(); if (completionProvider.Enabled) { _textArea.KeyEventHandler += completionProvider.KeyEventHandlerFired; } }
/// <summary>The window drag drop.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void WindowDragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); IFileEditorResolver resolver = _services.Resolve <IFileEditorResolver>(); foreach (string filename in filePaths) { // todo: check for file exist file in open windows; IEditor editor = resolver.ResolveEditorInstance(filename); editor.FileName = filename; editor.LoadFile(); DisplayDockedForm(editor as DockContent); } } }
/// <summary>The options form_ load.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void OptionsForm_Load(object sender, EventArgs e) { var cofigTypes = _services.GetConfigurationObjectTypes(); // build a list of config instances foreach (Type cofigType in cofigTypes) { _configurationObjects.Add(_services.Resolve <IConfigurationObject>(cofigType.FullName)); } // add the config editors to the list and watch them for changes foreach (var configObject in _configurationObjects) { configObject.PropertyChanged += ConfigObjectPropertyChanged; lstSettingsProviders.Items.Add(configObject.Name); } // select first if (lstSettingsProviders.Items.Count > 0) { lstSettingsProviders.SelectedIndex = 0; } }
protected void ConfigureMostRecentFileList(IApplicationServices services) { // get the files out of the settings and register them var mostRecentFilesService = services.Resolve<IMostRecentFilesService>(); if (services.Settings.MostRecentFiles != null) { foreach (string mostRecentFile in services.Settings.MostRecentFiles) { mostRecentFilesService.Filenames.Add(mostRecentFile); } } // watch for changes mostRecentFilesService.MostRecentFilesChanged += mostRecentFilesService_MostRecentFilesChanged; // need to manually call the update - only required on first load ((OpenRecentFileCommand)CommandManager.GetCommandInstance<OpenRecentFile1Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance<OpenRecentFile2Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance<OpenRecentFile3Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance<OpenRecentFile4Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance<OpenRecentFile5Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance<OpenRecentFile6Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance<OpenRecentFile7Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance<OpenRecentFile8Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance<OpenRecentFile9Command>()).UpdateName(); ((OpenRecentFileCommand)CommandManager.GetCommandInstance<OpenRecentFile10Command>()).UpdateName(); }
/// <summary>Initializes a new instance of the <see cref="QueryForm"/> class.</summary> /// <param name="services">The services.</param> /// <param name="settings">The settings.</param> /// <param name="hostWindow">The host window.</param> public QueryForm(IApplicationServices services, IApplicationSettings settings, IHostWindow hostWindow) : this() { _services = services; _settings = settings; _hostWindow = hostWindow; var completionProvider = _services.Resolve<ICompletionProvider>(); if (completionProvider.Enabled) { _textArea.KeyEventHandler += completionProvider.KeyEventHandlerFired; } }