private async Task <string> OutputFromTemplate(string templateName) { var stubble = _stubbleBuilder .Configure(StubbleBuilderSettings) .Build(); return(await stubble.RenderAsync(_templateLoader.GetTemplate(templateName), _variableProvider.GetVariableValues(), TemplateRenderSettings())); }
/// <summary> /// Check is template with specified language exist. /// </summary> /// <param name="templateId">Email template identifier.</param> /// <param name="languageId">Communication language identifier.</param> /// <param name="templateLoader">Loader for email templates.</param> /// <returns>Is template exist.</returns> protected bool IsTemplateValid(Guid templateId, Guid languageId, ITemplateLoader templateLoader) { if (templateLoader == null) { templateLoader = GetEmailTemplateStore(); } Entity template = templateLoader.GetTemplate(templateId, languageId); return(template != null && !string.IsNullOrEmpty(template.GetTypedColumnValue <string>("Subject")) && !string.IsNullOrEmpty(template.GetTypedColumnValue <string>("Body"))); }
public void Edit(string path, ITemplateLoader loader, UIContentPresenter presenter) { this.path = path; this.loader = loader; this.presenter = presenter; result = loader.GetTemplate(presenter.DataTemplateName, path); if (result != null) { codeTextBox.Text = result.Code; } this.Show(); }
/// <summary> /// Select a datatemplate /// </summary> /// <param name="item">Viewmodel instance</param> /// <param name="container"></param> /// <returns></returns> public override DataTemplate SelectTemplate(object item, DependencyObject container) { var presenter = SearchCustomContentPresenter(container); if (presenter != null) { // Contains all possible UITemplates UITemplate template = null; if (presenter.Templates == null) { throw new Exception($"Templates list can not be null. UIContentPresenter: {presenter.Name ?? "<No name set>"}"); } // Copy template list var templates = presenter.Templates.OfType <UITemplate>().ToList(); // Add dynamic templates if (UITemplateManager.DynamicResolverFactories != null) { foreach (var factory in UITemplateManager.DynamicResolverFactories) { var resolver = factory.Create(presenter.GetType().Namespace, presenter.DataTemplateName); if (resolver != null) { // Add all dynamically resolved templates var tmpls = resolver.ResolveDynamicTemplates(presenter.GetType().Namespace, presenter.DataTemplateName); if (tmpls != null) { templates.AddRange(tmpls); } } } } // Find all templates that are selectable if (templates != null) { foreach (var _template in templates) { // Select a template if it has no selector and there is no template set yet // or select a template if there is already a selected template but that has not selector if ((_template.Selector == null && template == null) || (template != null && template.Selector == null)) { template = _template; } else if (_template.Selector != null && _template.Selector.SelectTemplate(_template, presenter.DataContext)) { template = _template; } } } if (presenter.IsSelectedTemplateRequired && template == null && !DesignerProperties.GetIsInDesignMode(presenter)) { throw new Exception($"A template is required for the given UIContentPresenter, but there is no selectable uitemplate {presenter.Name ?? "<No name set>"}"); } if (template != null) { foreach (var loader in loaders) { var rd = Cache.TemplateCache.Get(presenter.DataTemplateName, template.TemplatePath); if (rd != null) { if (rd.Contains(presenter.DataTemplateName)) { this.loader = loader; presenter.SelectedTemplate = template; return((DataTemplate)rd[presenter.DataTemplateName]); } } var result = loader.GetTemplate(presenter.DataTemplateName, template.TemplatePath); if (result != null && !string.IsNullOrWhiteSpace(result.Code)) { using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(result.Code))) { try { var resourceDict = (ResourceDictionary)System.Windows.Markup.XamlReader.Load(stream); Cache.TemplateCache.Add(presenter.DataTemplateName, template.TemplatePath, resourceDict); if (resourceDict != null) { if (resourceDict.Contains(presenter.DataTemplateName)) { this.loader = loader; presenter.SelectedTemplate = template; return((DataTemplate)resourceDict[presenter.DataTemplateName]); } } } catch (Exception ex) { if (UITemplateManager.LoadExceptionHandler != null) { // Handle excetpion presenter.Dispatcher.BeginInvoke(new Action(() => { // Set loader to be able to fix the template error using the editor this.loader = loader; presenter.SelectedTemplate = template; if (!UITemplateManager.LoadExceptionHandler.Handle(ex)) { throw ex; } })); } else { throw ex; } } } } } } } return(new DataTemplate()); }
public Task FromTemplate(string templateName, string destinationPath, Encoding encoding) => FromTemplate(templateName, _templateLoader.GetTemplate(templateName), destinationPath, encoding);