コード例 #1
0
        /// <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);
        }
コード例 #2
0
 /// <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);
         }
     }
 }
コード例 #3
0
        /// <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));
            }
        }
コード例 #4
0
        /// <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();
            }
        }
コード例 #5
0
        /// <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));
        }
コード例 #6
0
 /// <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));
 }