Esempio n. 1
0
        private async void btnLoadTemplate_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            _templateModel = await _templateLoader.LoadTemplate(txtTemplate.Text);

            lstTemplate.Items.Clear();
            foreach (var template in _templateModel.Templates)
            {
                lstTemplate.Items.Add(new ListViewItem(new string[] { template.Key }));
            }
            Cursor.Current = Cursors.Default;
        }
Esempio n. 2
0
        public string Execute(string name, object model)
        {
            var    isTemplated = Engine.Razor.IsTemplateCached(name, null);
            string result      = null;

            if (isTemplated)
            {
                result = Engine.Razor.Run(name, null, model);
            }
            else
            {
                var template = templateLoader.LoadTemplate(name);
                result = Engine.Razor.RunCompile(template, name, null, model);
            }

            return(result);
        }
Esempio n. 3
0
        public LoadResult Load([NotNull] Stream templateStream)
        {
            if (templateStream == null)
            {
                throw new ArgumentNullException(nameof(templateStream));
            }
            if (_loadedTemplate != null)
            {
                throw new InvalidOperationException("Load can only be called once");
            }

            if (!templateStream.CanRead || !templateStream.CanSeek)
            {
                throw new ArgumentException("The supplied stream must be readable and seekable", nameof(templateStream));
            }

            _xmlDeclarationInfo = _xmlDeclarationParser.Parse(templateStream);

            XmlTemplateLoadResults xmlTemplateLoadResults = _templateLoader.LoadTemplate(templateStream);

            if (xmlTemplateLoadResults.Success)
            {
                _loadedTemplate = xmlTemplateLoadResults.LoadedTemplate;

                IEnumerable <Error> preferencesLoadErrors = _templatePreferencesLoader.LoadPreferences(_loadedTemplate);

                if (preferencesLoadErrors.Any())
                {
                    return(LoadResult.CreateFailResult(preferencesLoadErrors));
                }
            }

            //TODO: make result returning more general - this is just another mapping from one result to another
            return(xmlTemplateLoadResults.TemplateLoadErrors.Any()
                ? LoadResult.CreateFailResult(xmlTemplateLoadResults.TemplateLoadErrors)
                : LoadResult.CreateSuccessResult());
        }
 public string Parse(string templateName, CultureInfo culture, FogBugzCase parameters)
 {
     return(RazorEngine.Razor.Parse(templateLoader.LoadTemplate(templateName, culture), parameters));
 }
Esempio n. 5
0
        public ITemplateSource Resolve(ITemplateKey key)
        {
            var template = templateLoader.LoadTemplate(key.Name);

            return(new LoadedTemplateSource(template));
        }