public IterationExpression(MustacheExpression expression) { Expression = expression; }
public ConditionalExpression(MustacheExpression expression) { Expression = expression; }
public MemberExpression(string name, MustacheExpression subExpression) : this(name) { SubExpression = subExpression; }
private PipelineFile <TObject> LoadFile <TObject, TConverter>(String path, IDictionary <String, Object> mustacheContext, CancellationToken cancellationToken, ref Int32 fileCount) where TConverter : IYamlTypeConverter, new() { fileCount++; if (m_options.MaxFiles > 0 && fileCount > m_options.MaxFiles) { throw new FormatException(TaskResources.YamlFileCount(m_options.MaxFiles)); } cancellationToken.ThrowIfCancellationRequested(); FileData file = m_fileProvider.GetFile(path); String mustacheReplaced; StringReader reader = null; CancellationTokenSource mustacheCancellationTokenSource = null; try { // Read front-matter IDictionary <String, Object> frontMatter = null; reader = new StringReader(file.Content); String line = reader.ReadLine(); if (!String.Equals(line, "---", StringComparison.Ordinal)) { // No front-matter. Reset the reader. reader.Dispose(); reader = new StringReader(file.Content); } else { // Deseralize front-matter. cancellationToken.ThrowIfCancellationRequested(); StringBuilder frontMatterBuilder = new StringBuilder(); while (true) { line = reader.ReadLine(); if (line == null) { throw new FormatException(TaskResources.YamlFrontMatterNotClosed(path)); } else if (String.Equals(line, "---", StringComparison.Ordinal)) { break; } else { frontMatterBuilder.AppendLine(line); } } var frontMatterDeserializer = new Deserializer(); try { frontMatter = frontMatterDeserializer.Deserialize <IDictionary <String, Object> >(frontMatterBuilder.ToString()); } catch (Exception ex) { throw new FormatException(TaskResources.YamlFrontMatterNotValid(path, ex.Message), ex); } } // Merge the mustache replace context. frontMatter = frontMatter ?? new Dictionary <String, Object>(); if (mustacheContext != null) { foreach (KeyValuePair <String, Object> pair in mustacheContext) { frontMatter[pair.Key] = pair.Value; } } // Prepare the mustache options. mustacheCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); // var mustacheOptions = new MustacheEvaluationOptions // { // CancellationToken = mustacheCancellationTokenSource.Token, // EncodeMethod = MustacheEncodeMethods.JsonEncode, // MaxResultLength = m_options.MustacheEvaluationMaxResultLength, // }; // Parse the mustache template. cancellationToken.ThrowIfCancellationRequested(); var mustacheParser = new MustacheTemplateParser(useDefaultHandlebarHelpers: true, useCommonTemplateHelpers: true); MustacheExpression mustacheExpression = mustacheParser.Parse(template: reader.ReadToEnd()); // Limit the mustache evaluation time. if (m_options.MustacheEvaluationTimeout > TimeSpan.Zero) { mustacheCancellationTokenSource.CancelAfter(m_options.MustacheEvaluationTimeout); } try { // Perform the mustache evaluation. mustacheReplaced = mustacheExpression.Evaluate( replacementObject: frontMatter, additionalEvaluationData: null, parentContext: null, partialExpressions: null //options: mustacheOptions ); } catch (System.OperationCanceledException ex) when(mustacheCancellationTokenSource.IsCancellationRequested && !cancellationToken.IsCancellationRequested) { throw new System.OperationCanceledException(TaskResources.MustacheEvaluationTimeout(path, m_options.MustacheEvaluationTimeout.TotalSeconds), ex); } m_trace.Verbose("{0}", new TraceFileContent($"{file.Name} after mustache replacement", mustacheReplaced)); } finally { reader?.Dispose(); reader = null; mustacheCancellationTokenSource?.Dispose(); mustacheCancellationTokenSource = null; } // Deserialize DeserializerBuilder deserializerBuilder = new DeserializerBuilder(); deserializerBuilder.WithTypeConverter(new TConverter()); Deserializer deserializer = deserializerBuilder.Build(); TObject obj = deserializer.Deserialize <TObject>(mustacheReplaced); m_trace.Verbose("{0}", new TraceObject <TObject, TConverter>($"{file.Name} after deserialization ", obj)); var result = new PipelineFile <TObject> { Name = file.Name, Directory = file.Directory, Object = obj }; return(result); }
public UnconvertedExpression(MustacheExpression expression) { Expression = expression; }