Пример #1
0
        /// <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);
            }
        }