/// <summary>The process template.</summary> /// <param name="text">The text.</param> /// <param name="items">The items.</param> /// <returns></returns> public TemplateResult ProcessTemplate(string text, Dictionary<string, object> items) { if (items == null) { items = new Dictionary<string, object>(); } TemplateResult result; using (TemplateHost host = _services.Resolve<TemplateHost>()) { host.Data = _templateData; items.Add("Host", host); items.Add("Data", host.Data); result = new TemplateResult(); result.Text = _formatter.Format(text, items); result.Extension = "sql"; if (items.ContainsKey(Extension)) { result.Extension = (string)items[Extension]; } } return result; }
/// <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 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); }
/// <summary>The process template.</summary> /// <param name="text">The text.</param> /// <param name="items">The items.</param> /// <returns></returns> public TemplateResult ProcessTemplate(string text, Dictionary<string, object> items) { if (items == null) { items = new Dictionary<string, object>(); } TemplateResult result; using (TemplateHost host = _services.Resolve<TemplateHost>()) { host.Data = _templateData; items.Add("Host", host); items.Add("Data", host.Data); result = new TemplateResult(); result.Text = _formatter.Format(text, items); result.Extension = "sql"; if (items.ContainsKey(Extension)) { result.Extension = (string)items[Extension]; } } return result; }