public async Task <GeneratedTemplateInfos> GenerateTemplateExecute(string template, IDataSourceProvider dataSourceProvider) { if (template == null) { return(null); } var parsingOptions = new ParserOptions(template, () => new MemoryStream(), Encoding.Default, false, true); parsingOptions.ValueResolver = new JObjectResolver(); //var formatterService = new MorestachioFormatterService(); //var formatters = _templateServiceProvider.ObtainFormatters(); //foreach (var formatter in formatters) //{ // var morestachioFormatterModel = formatter.CreateFormatter(); // formatterService.Add(morestachioFormatterModel.Function, morestachioFormatterModel); //} MorestachioDocumentInfo extendedParseInformation; try { extendedParseInformation = Parser.ParseWithOptions(parsingOptions); } catch (Exception e) { return(new GeneratedTemplateInfos() { Errors = new IMorestachioError[] { new MorestachioSyntaxError(new CharacterLocationExtended(), "Error ", "", "", e.Message), } }); } if (extendedParseInformation.Errors.Any()) { return(new GeneratedTemplateInfos() { InferredTemplateModel = extendedParseInformation.Document, Errors = extendedParseInformation.Errors.ToArray() }); } var result = await dataSourceProvider.Fetch(); if (result == null) { return(null); } return(new GeneratedTemplateInfos() { Result = extendedParseInformation.Create(result).Stream.Stringify(true, Encoding.Default), InferredTemplateModel = extendedParseInformation.Document }); }
public async Task <GeneratedTemplateInfos> GenerateTemplateExecute(string template, IDataSourceProvider dataSourceProvider) { if (template == null) { return(null); } var parsingOptions = new ParserOptions(template, () => new MemoryStream(), Encoding.Default, _templateServiceProvider.ParserOptions.MaxSize, _templateServiceProvider.ParserOptions.DisableContentEscaping); parsingOptions.Timeout = _templateServiceProvider.ParserOptions.Timeout; parsingOptions.Null = _templateServiceProvider.ParserOptions.NullSubstitute; parsingOptions.StackOverflowBehavior = _templateServiceProvider.ParserOptions.PartialStackOverflowBehavior; parsingOptions.PartialStackSize = _templateServiceProvider.ParserOptions.PartialStackSize; parsingOptions.ValueResolver = new JObjectResolver(); //if (_templateServiceProvider.ParserOptions.EnableExtendedMissingPathOutput) //{ // parsingOptions.UnresolvedPath += ParsingOptionsOnUnresolvedPath; //} //var formatterService = new MorestachioFormatterService(); //var formatters = _templateServiceProvider.ObtainFormatters(); //foreach (var formatter in formatters) //{ // var morestachioFormatterModel = formatter.CreateFormatter(); // formatterService.Add(morestachioFormatterModel.Function, morestachioFormatterModel); //} MorestachioDocumentInfo extendedParseInformation; try { extendedParseInformation = Parser.ParseWithOptions(parsingOptions); } catch (Exception e) { return(new GeneratedTemplateInfos() { Errors = new IMorestachioError[] { new MorestachioSyntaxError(new CharacterLocationExtended(), "Error ", "", "", e.Message), } }); } if (extendedParseInformation.Errors.Any()) { var generatedTemplateInfos = new GeneratedTemplateInfos() { InferredTemplateModel = extendedParseInformation.Document, Errors = extendedParseInformation.Errors.ToArray() }; _templateServiceProvider.OnTemplateCreated(generatedTemplateInfos); return(generatedTemplateInfos); } var result = await dataSourceProvider.Fetch(); if (result == null) { return(null); } var generateTemplateExecute = new GeneratedTemplateInfos() { Result = await extendedParseInformation.CreateAndStringifyAsync(result), InferredTemplateModel = extendedParseInformation.Document }; _templateServiceProvider.OnTemplateCreated(generateTemplateExecute); return(generateTemplateExecute); }