/// <summary> /// Start the transformation. /// </summary> /// <param name="templateSource">The template source.</param> /// <param name="arguments">The arguments.</param> /// <returns></returns> /// <exception cref="TextTransformationException">when an error has occured during transformation.</exception> protected virtual string StartTransformation(string templateSource, TemplateArgumentCollection arguments) { _host.Initialize(arguments); string result = _engine.ProcessTemplate(templateSource, _host); _host.Finish(arguments); return(result); }
/// <summary> /// Initializes the host with the specified argument dictionary. /// This will populate the CallContext with the desired arguments. /// </summary> /// <param name="arguments">The arguments.</param> public void Initialize(TemplateArgumentCollection arguments) { _compilationErrors = null; if (arguments != null) { foreach (var argument in arguments) { CallContext.LogicalSetData(argument.Name, argument.Value); } } }
/// <summary> /// Transforms the specified template using a dictionary of named arguments. /// </summary> /// <param name="templateSource">The template.</param> /// <param name="arguments">A dictionary containing named arguments used to transform the text.</param> /// <exception cref="TextTransformationException">Text transformation has failed.</exception> /// <exception cref="ArgumentNullException">template is null or empty.</exception> /// <returns>The output of the text transformation.</returns> public string Transform(string templateSource, TemplateArgumentCollection arguments) { if (arguments == null) { throw new ArgumentNullException("arguments"); } lock (_transformationLock) { return(StartTransformation(templateSource, arguments)); } }
/// <summary> /// Remove arguments from CallContet and checks whether errors have /// occured during transformation a throw exception /// when necesssary. /// </summary> /// <exception cref="TextTransformationException">when an error has occured during transformation.</exception> public void Finish(TemplateArgumentCollection arguments) { if (arguments != null) { foreach (var argument in arguments) { CallContext.FreeNamedDataSlot(argument.Name); } } if (_compilationErrors != null && _compilationErrors.HasErrors) { ThrowTransformationException(); } }
/// <summary> /// Start the transformation. /// </summary> /// <param name="template">The template.</param> /// <param name="arguments">The arguments.</param> /// <returns></returns> /// <exception cref="TextTransformationException">when an error has occured during transformation.</exception> protected override string StartTransformation( string template, TemplateArgumentCollection arguments) { CheckAutoRecycle(); if (arguments != null) { foreach (TemplateArgument pair in arguments) { AddAssemblyReference(pair.Value); } } return(base.StartTransformation(template, arguments)); }
/// <summary> /// Transforms the specified template using a dictionary of named arguments. /// </summary> /// <param name="template">The template.</param> /// <param name="arguments">A dictionary containing named arguments used to transform the text.</param> /// <exception cref="TextTransformationException">Text transformation has failed.</exception> /// <exception cref="ArgumentNullException">template is null or empty.</exception> /// <returns>The output of the text transformation.</returns> public static string Transform(string template, TemplateArgumentCollection arguments) { return(_transformer.Transform(template, arguments)); }