public XmlTemplate( [NotNull] XmlDeclarationParser xmlDeclarationParser, [NotNull] ITemplateLoader templateLoader, [NotNull] ITemplatePreprocessor templatePreprocessor, [NotNull] ITokenReplacer tokenReplacer, [NotNull] TemplatePreferencesLoader templatePreferencesLoader) { if (xmlDeclarationParser == null) { throw new ArgumentNullException(nameof(xmlDeclarationParser)); } if (templateLoader == null) { throw new ArgumentNullException(nameof(templateLoader)); } if (templatePreprocessor == null) { throw new ArgumentNullException(nameof(templatePreprocessor)); } if (tokenReplacer == null) { throw new ArgumentNullException(nameof(tokenReplacer)); } if (templatePreferencesLoader == null) { throw new ArgumentNullException(nameof(templatePreferencesLoader)); } _xmlDeclarationParser = xmlDeclarationParser; _templateLoader = templateLoader; _templatePreprocessor = templatePreprocessor; _tokenReplacer = tokenReplacer; _templatePreferencesLoader = templatePreferencesLoader; }
public EmailSender( IEnumerable <IEmailProviderType> emailProviderTypes, IOptions <EmailOptions> options, IStorageFactory storageFactory, ITemplateLoaderFactory templateLoaderFactory) { this.options = options.Value; var providerType = emailProviderTypes .FirstOrDefault(x => x.Name == this.options.Provider.Type); if (providerType == null) { throw new ArgumentNullException("ProviderType", $"The provider type {this.options.Provider.Type} does not exist. Maybe you are missing a reference or an Add method call in your Startup class."); } this.provider = providerType.BuildProvider(this.options.Provider); if (!string.IsNullOrWhiteSpace(this.options.TemplateStorage)) { var store = storageFactory.GetStore(this.options.TemplateStorage); if (store == null) { throw new ArgumentNullException("TemplateStorage", $"There is no file store configured with name {this.options.TemplateStorage}. Unable to initialize email templating."); } this.templateLoader = templateLoaderFactory.Create(store); } }
/// <param name="fileController"></param> /// <param name="progressHelper">The TaskProgressHelper to use to report progress and cancel the operation.</param> /// <param name="projectInfo">The Project we are generating files from.</param> /// <param name="loader"></param> public GenerationHelper(ITaskProgressHelper <GenerateFilesProgress> progressHelper, ITemplateLoader loader, IWorkbenchProject projectInfo, IFileController fileController) { _Loader = loader; _ProgressHelper = progressHelper; _Project = projectInfo; _FileController = fileController; }
/// <summary> /// Notifies contacts via multilanguage templates. /// </summary> /// <param name="userConnection">User connection.</param> /// <param name="parameters">Parameters.</param> public virtual void Execute(UserConnection userConnection, IDictionary <string, object> parameters) { if (EmailWithMacrosManager == null) { EmailWithMacrosManager = new EmailWithMacrosManager(userConnection); } EmailData emailData = new EmailData(); emailData.ParseParameters(parameters); if (userConnection.GetIsFeatureEnabled("EmailMessageMultiLanguageV2")) { SendEmail(emailData, emailData.TplId); } else { if (TemplateLoader == null) { TemplateLoader = new EmailTemplateStore(userConnection); } if (EmailTemplateLanguageHelper == null) { EmailTemplateLanguageHelper = new EmailTemplateLanguageHelper(emailData.CaseId, userConnection); } Guid languageId = EmailTemplateLanguageHelper.GetLanguageId(emailData.TplId, TemplateLoader); Entity templateEntity = TemplateLoader.GetTemplate(emailData.TplId, languageId); SendEmail(emailData, templateEntity.PrimaryColumnValue); } }
public void Load(ITemplateLoader loader, string templateName, string templatePath, DependencyObject content) { if (content is Label) { ((Label)content).Background = new SolidColorBrush(Colors.Red); } }
/// <summary> /// Constructs a TemplateCompiler. /// </summary> /// <param name="templateLoader">ITemplateLoader to load templates by name.</param> /// <param name="messageHandler">IMessageHandler to report messges to the user.</param> /// <param name="referencedAssemblies">Additional assemblied to include in template compilation.</param> public TemplateCompiler(ITemplateLoader templateLoader, IMessageHandler messageHandler, List <string> referencedAssemblies) { if (templateLoader == null) { throw new ArgumentNullException(nameof(templateLoader)); } if (messageHandler == null) { throw new ArgumentNullException(nameof(messageHandler)); } this.TemplateLoader = templateLoader; this.MessageHandler = messageHandler; this.ReferencedAssemblies = referencedAssemblies; var parserRules = new Dictionary <char, IParserRule> { { '\\', new InterpolationRule() }, { '|', new InterpolationLineRule() }, { '=', new CallRule() }, { '#', new PreprocessorRule() }, }; this.TemplateParser = new TemplateParser(parserRules, new PassThroughRule(), this.MessageHandler); }
public TextGenerator( ITemplateLoader templateLoader, IVirtualFileProvider virtualFileProvider) { _templateLoader = templateLoader; _virtualFileProvider = virtualFileProvider; }
public Generator( ITaskProgressHelper<GenerateFilesProgress> progressHelper, ITemplateLoader loader) { _Loader = loader; _ProgressHelper = progressHelper; }
private ImmutableList <ITemplate> LoadTemplates(IFileSystem fileSystem, ITemplateLoader templateLoader, ILogger <RepositoryLoader> logger) { var templates = ImmutableList.CreateBuilder <ITemplate>(); var templatePaths = fileSystem.Directory. EnumerateDirectories(this.RootPath.Join("templates").ToString()). Select(path => PurePath.Create(path)); foreach (var templatePath in templatePaths) { try { var templateFolderName = templatePath.Basename; ValidateTemplateFolderName(templateFolderName); var p = PurePath.Create("/opt/stamp/repos/TestRepo/templates/TestTemplate@1"); var template = templateLoader.LoadFromTemplateDirectory(templatePath); ValidateTemplateAgainstTemplateFolderName(template, templateFolderName); templates.Add(template); } catch (Exception ex) { logger.LogWarning(ex, $"Failed to load template from {templatePath}."); throw; } } return(templates.ToImmutable()); }
public void should_load_default_templates_from_template_directory( ITemplateLoader templateLoader, DirectoryInfo root, ICraneContext context, IFileManager fileManager, IEnumerable <ITemplate> result) { "Given I have a project root folder" ._(() => { context = ServiceLocator.Resolve <ICraneContext>(); fileManager = ServiceLocator.Resolve <IFileManager>(); context.ProjectRootDirectory = new DirectoryInfo(fileManager.GetTemporaryDirectory()); }); "And a template loader" ._(() => templateLoader = ServiceLocator.Resolve <ITemplateLoader>()); "When I call load" ._(() => result = templateLoader.Load()); "It should load the default source template" ._( () => result.Any( item => item.Name.Equals(CraneConfiguration.DefaultSourceProviderName) && item.TemplateType == TemplateType.Source)); "It should load the default build template" ._( () => result.Any( item => item.Name.Equals(CraneConfiguration.DefaultBuildProviderName) && item.TemplateType == TemplateType.Build)); }
public Engine(ITemplateLoader templateLoader, IMessageHandler messageHandler, params string[] referencedAssemblies) { this.TemplateLoader = templateLoader; this.MessageHandler = messageHandler; this.ReferencedAssemblies = new List <string>(); this.ReferencedAssemblies.AddRange(referencedAssemblies); }
public static void LoadTemplates() { foreach (var clazz in ClassLoaderUtils.GetClassesForPackage()) { ITemplateLoader templateLoader = (ITemplateLoader)Activator.CreateInstance(clazz); templateLoader.Load(); } }
public Form1() { InitializeComponent(); _databaseLoader = ServiceLocator.GetInstance <IDatabaseLoader>(); _templateLoader = ServiceLocator.GetInstance <ITemplateLoader>(); _templateTranslator = ServiceLocator.GetInstance <ITemplateTranslator>(); txtTemplate.Text = @"F:\Projects2\CodeGen\CodeGen\CodeGen.Templates\ProductMS"; }
internal IRepository Build(IFileSystem fileSystem, ITemplateLoader templateLoader, IStampConfig stampConfig, ILogger <RepositoryLoader> logger) => new Repository(this.Name, this.Description, stampConfig.GetRepositoryPath(this.Name), fileSystem, templateLoader, logger);
internal Repository(string name, string description, IPurePath rootPath, IFileSystem fileSystem, ITemplateLoader templateLoader, ILogger <RepositoryLoader> logger) { this.Name = name; this.Description = description; this.RootPath = rootPath; _templates = new Lazy <ImmutableList <ITemplate> >(() => LoadTemplates(fileSystem, templateLoader, logger)); }
/// <summary> /// Initializes a new instance of <see cref="TemplateFormatter">TemplateFormatter</see> with specified template loader. /// </summary> /// <param name="loader">Template loader.</param> public TemplateFormatter(ITemplateLoader loader) { if (loader == null) { throw new ArgumentNullException(nameof(loader)); } _loader = loader; }
public RepositoryLoader(IFileSystem fileSystem, ITemplateLoader templateLoader, IStampConfig stampConfig, ILogger <RepositoryLoader> logger) { this.FileSystem = fileSystem; this.TemplateLoader = templateLoader; this.StampConfig = stampConfig; this.Logger = logger; }
internal ScriptingPlugin(SiteObject site) : base(site) { unauthorizedTemplateLoader = new TemplateLoaderUnauthorized(Site); Builtins = TemplateContext.GetDefaultBuiltinObject(); SiteFunctions = new ScriptGlobalFunctions(this); // Add default scriban frontmatter parser FrontMatterParsers = new OrderedList <IFrontMatterParser> { new ScribanFrontMatterParser(this) }; }
/// <summary> /// Entry point for language searching. /// </summary> /// <param name="templateId">Email template identifier.</param> /// <param name="templateLoader">Email template store.</param> /// <returns>Language identifier for email template.</returns> public override Guid Handle(Guid templateId, ITemplateLoader templateLoader) { Guid languageId = GetLanguageId(templateId, templateLoader); if (languageId != default(Guid)) { return(languageId); } return(Successor != null?Successor.Handle(templateId, templateLoader) : Guid.Empty); }
public FileGenerator( IVariableProvider variableProvider, ITemplateLoader templateLoader, StubbleBuilder stubbleBuilder, IConsoleWriter consoleWriter) { _variableProvider = variableProvider; _templateLoader = templateLoader; _stubbleBuilder = stubbleBuilder; _consoleWriter = consoleWriter; }
/// <summary> /// Tests for the existance of a path. /// </summary> /// <param name="context">The template context.</param> /// <param name="span">The source span.</param> /// <param name="path">The path to test.</param> /// <param name="type">The type of path to test. May be one of the following: "leaf", "container" or "any". Defaults to "any".</param> /// <returns>If the path exists, `true`. Otherwise, `false`.</returns> /// <remarks> /// ```template-text /// {{ '.\foo.txt' | fs.test }} /// ``` /// ```html /// true /// ``` /// </remarks> public static bool Test(TemplateContext context, SourceSpan span, string path, string type = "any") { if (string.IsNullOrEmpty(path)) { throw new ScriptRuntimeException(span, string.Format(RS.FSPathRequired, "fs.test")); } PathType pathType = PathType.Any; if (string.IsNullOrEmpty(type)) { type = "any"; } else { type = type.ToLowerInvariant(); } switch (type) { case "any": break; case "container": pathType = PathType.Container; break; case "leaf": pathType = PathType.Leaf; break; default: throw new ScriptRuntimeException(span, string.Format(RS.FSUnsupportedType, "fs.test", type)); } ITemplateLoader templateLoader = context.TemplateLoader; if (templateLoader == null) { throw new ScriptRuntimeException(span, string.Format(RS.NoTemplateLoader, "fs.test")); } bool pathExists = false; try { pathExists = templateLoader.PathExists(context, span, path, pathType); } catch (Exception ex) when(!(ex is ScriptRuntimeException)) { } return(pathExists); }
/// <summary> /// Entry point for language searching. /// </summary> /// <param name="templateId">Email template identifier.</param> /// <param name="templateLoader">Email template store.</param> /// <returns>Language identifier for email template.</returns> public override Guid Handle(Guid templateId, ITemplateLoader templateLoader) { var contactId = CaseEntity.GetTypedColumnValue <Guid>("ContactId"); Guid contactLanguageId = _commLang.Get(contactId); if (contactLanguageId != default(Guid) && IsTemplateValid(templateId, contactLanguageId, templateLoader)) { return(contactLanguageId); } return(Successor != null?Successor.Handle(templateId, templateLoader) : Guid.Empty); }
/// <summary> /// Entry point for language searching. /// </summary> /// <param name="templateId">Email template identifier.</param> /// <param name="templateLoader">Email template store.</param> /// <returns>Language identifier for email template.</returns> public override Guid Handle(Guid templateId, ITemplateLoader templateLoader) { string supportServiceEmail = SystemSettings.GetValue(UserConnection, "SupportServiceEmail", string.Empty); Guid languageId = GetCommunicationLanguageId(supportServiceEmail); if (languageId != default(Guid) && IsTemplateValid(templateId, languageId, templateLoader)) { return(languageId); } return(Successor != null?Successor.Handle(templateId, templateLoader) : Guid.Empty); }
/// <summary> /// Entry point for language searching. /// </summary> /// <param name="templateId">Email template identifier.</param> /// <param name="templateLoader">Email template store.</param> /// <returns>Language identifier for email template.</returns> public override Guid Handle(Guid templateId, ITemplateLoader templateLoader) { Guid defaultLanguageMessageId = SystemSettings.GetValue(UserConnection, DefaultMessageLanguageCode, default(Guid)); if (defaultLanguageMessageId != default(Guid) && IsTemplateValid(templateId, defaultLanguageMessageId, templateLoader)) { return(defaultLanguageMessageId); } return(Successor != null?Successor.Handle(templateId, templateLoader) : Guid.Empty); }
/// <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 Setup() { mocks = new MockRepository(); progressHelper = mocks.DynamicMock <ITaskProgressHelper <GenerateFilesProgress> >(); projectInfo = mocks.DynamicMock <IWorkbenchProject>(); folder = mocks.DynamicMock <IFolder>(); scriptObject = mocks.DynamicMock <IScriptBaseObject>(); loader = mocks.DynamicMock <ITemplateLoader>(); controller = mocks.DynamicMock <IController>(); fileController = mocks.DynamicMock <IFileController>(); }
public void Setup() { mocks = new MockRepository(); progressHelper = mocks.DynamicMock<ITaskProgressHelper<GenerateFilesProgress>>(); projectInfo = mocks.DynamicMock<IWorkbenchProject>(); folder = mocks.DynamicMock<IFolder>(); scriptObject = mocks.DynamicMock<IScriptBaseObject>(); loader = mocks.DynamicMock<ITemplateLoader>(); controller = mocks.DynamicMock<IController>(); fileController = mocks.DynamicMock<IFileController>(); }
public static CompiledTemplateData LoadPrecompiledTemplates(TemplateSettings templateSettings) { Assembly assembly = AppDomain.CurrentDomain.GetAssemblyByName(templateSettings.assemblyName); Type type = assembly.GetType("UIForia.Generated.UIForiaGeneratedTemplates_" + templateSettings.StrippedApplicationName); if (type == null) { throw new ArgumentException("Trying to use precompiled templates for " + templateSettings.StrippedApplicationName + " but couldn't find the type. Maybe you need to regenerate the code?"); } CompiledTemplateData compiledTemplateData = new CompiledTemplateData(templateSettings); compiledTemplateData.styleImporter.importResolutionPath = Path.Combine(UnityEngine.Application.streamingAssetsPath, "UIForia", compiledTemplateData.templateSettings.StrippedApplicationName); ITemplateLoader loader = (ITemplateLoader)Activator.CreateInstance(type); string[] files = loader.StyleFilePaths; compiledTemplateData.styleImporter.Reset(); // reset because in testing we will already have parsed files, nuke these LightList <UIStyleGroupContainer> styleList = new LightList <UIStyleGroupContainer>(128); Dictionary <string, StyleSheet> styleSheetMap = new Dictionary <string, StyleSheet>(128); MaterialDatabase materialDatabase = loader.GetMaterialDatabase(); for (int i = 0; i < files.Length; i++) { StyleSheet sheet = compiledTemplateData.styleImporter.ImportStyleSheetFromFile(files[i], materialDatabase); styleList.EnsureAdditionalCapacity(sheet.styleGroupContainers.Length); for (int j = 0; j < sheet.styleGroupContainers.Length; j++) { styleList.array[styleList.size++] = sheet.styleGroupContainers[j]; } styleSheetMap.Add(sheet.path, sheet); } compiledTemplateData.templates = loader.LoadTemplates(); compiledTemplateData.slots = loader.LoadSlots(); compiledTemplateData.bindings = loader.LoadBindings(); compiledTemplateData.templateMetaData = loader.LoadTemplateMetaData(styleSheetMap, styleList.array); for (int i = 0; i < compiledTemplateData.templateMetaData.Length; i++) { compiledTemplateData.templateMetaData[i].compiledTemplateData = compiledTemplateData; } compiledTemplateData.constructElement = loader.ConstructElement; compiledTemplateData.dynamicTemplates = loader.DynamicTemplates; return(compiledTemplateData); }
/// <summary> /// Get default language for sending email template. /// </summary> /// <param name="templateId">Email template id.</param> /// <param name="templateLoader">Email template store.</param> /// <returns>Return language id.</returns> public virtual Guid GetLanguageId(Guid templateId, ITemplateLoader templateLoader) { var contactHandler = new ContactLangEmailTemplateHandler(CaseEntity, UserConnection); var mailboxHandler = new MailboxLangEmailTemplateHandler(CaseEntity, UserConnection); var supportServiceHandler = new SupportServiceLangEmailTemplateHandler(CaseEntity, UserConnection); var defaultMessageHandler = new DefaultMessageLangEmailTemplateHandler(CaseEntity, UserConnection); contactHandler.Successor = mailboxHandler; mailboxHandler.Successor = supportServiceHandler; supportServiceHandler.Successor = defaultMessageHandler; return(contactHandler.Handle(templateId, templateLoader)); }
public FileManipulator( IVariableProvider variableProvider, ITemplateLoader templateLoader, StubbleBuilder stubbleBuilder, ISolutionLoader solutionLoader, IConsoleWriter consoleWriter) { _variableProvider = variableProvider; _templateLoader = templateLoader; _stubbleBuilder = stubbleBuilder; _solutionLoader = solutionLoader; _consoleWriter = consoleWriter; }
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> /// Returns items in a container path. /// </summary> /// <param name="context">The template context.</param> /// <param name="span">The source span.</param> /// <param name="path">The path to query. Wildcard is supported. For recursive search, use the syntax `**\foo.txt`.</param> /// <param name="type">The type of children items to return. May be one of the following: "leaf", "container" or "any". Defaults to "any".</param> /// <returns>A list of children items under the path specified.</returns> /// <remarks> /// ```template-text /// {{ '**\fo?.txt' | fs.dir }} /// ``` /// ```html /// [C:\foo.txt, C:\temp\foa.txt] /// ``` /// </remarks> public static IEnumerable Dir(TemplateContext context, SourceSpan span, string path, string type = "any") { if (string.IsNullOrEmpty(path)) { throw new ScriptRuntimeException(span, string.Format(RS.FSPathRequired, "fs.dir")); } PathType pathType = PathType.Any; if (string.IsNullOrEmpty(type)) { type = "any"; } else { type = type.ToLowerInvariant(); } switch (type) { case "any": break; case "container": pathType = PathType.Container; break; case "leaf": pathType = PathType.Leaf; break; default: throw new ScriptRuntimeException(span, string.Format(RS.FSUnsupportedType, "fs.dir")); } ITemplateLoader templateLoader = context.TemplateLoader; if (templateLoader == null) { throw new ScriptRuntimeException(span, string.Format(RS.NoTemplateLoader, "fs.dir")); } return(templateLoader.Enumerate(context, span, path, pathType)); }
/// <summary> /// Get mailbox language identifier. /// </summary> /// <param name="templateId">Email template identifier.</param> /// <param name="templateLoader">Email template store.</param> /// <returns>Mailbox language identifier</returns> private Guid GetLanguageId(Guid templateId, ITemplateLoader templateLoader) { var recipients = GetRecipientMailboxes(); if (recipients.Length > 0) { string languageIdColumnName; var mailboxes = GetMailboxCollection(recipients, out languageIdColumnName); foreach (Entity mailbox in mailboxes) { var mailboxLanguageId = mailbox.GetTypedColumnValue <Guid>(languageIdColumnName); if (mailboxLanguageId != default(Guid) && IsTemplateValid(templateId, mailboxLanguageId, templateLoader)) { return(mailboxLanguageId); } } } return(Guid.Empty); }
/// <param name="fileController"></param> /// <param name="progressHelper">The TaskProgressHelper to use to report progress and cancel the operation.</param> /// <param name="projectInfo">The Project we are generating files from.</param> /// <param name="loader"></param> public GenerationHelper(ITaskProgressHelper<GenerateFilesProgress> progressHelper, ITemplateLoader loader, IWorkbenchProject projectInfo, IFileController fileController) { _Loader = loader; _ProgressHelper = progressHelper; _Project = projectInfo; _FileController = fileController; }
public ResourceTemplateManager(ITemplateLoader templateLoader) { this.templateLoader = templateLoader; }
public SubTemplateValueProcessor( ITemplateEngine engine, ITemplateLoader loader ) { this.Engine = engine; this.Loader = loader; }