Exemple #1
0
        public string RunTemplate(Interfaces.ITemplateManager manager, string templateName, IDictionary <string, object> context)
        {
            string retStr = "";

            for (int i = 0; i < 1; i++)
            {
                var template = manager.RenderTemplate(templateName, context);
                retStr = template.ReadToEnd();
            }
            return(retStr);
        }
        public string runTemplate(Interfaces.ITemplateManager manager, string templateName, IDictionary <string, object> context)
        {
            Stopwatch stopwatch = new Stopwatch();
            string    retStr    = "";

            stopwatch.Start();
            for (int i = 0; i < 1; i++)
            {
                var template = manager.RenderTemplate(templateName, context);
                retStr = template.ReadToEnd();
            }
            using (TextWriter stream = System.IO.File.AppendText("Timers.txt"))
                stream.WriteLine(Name + "," + stopwatch.ElapsedTicks);
            return(retStr);
        }
Exemple #3
0
        private static string Render(string template, Lazy <TagDictionary> values, Interfaces.ITemplateManager templateManager)
        {
            lock (Error)
            {
                if (!template.Contains("{{") && !template.Contains("{%"))
                {
                    //Use an empty tag dictionary because we don't have tags
                    //For some reason, this "fixes" something in files...but i have no idea what!
                    values = new Lazy <TagDictionary>(TagDictionary.Empty);
                }

                Exception exception = null;
                string    replacementValue;

                try
                {
                    Error.Invoked    = false;
                    replacementValue = templateManager.RenderTemplate(StringProvider + template, values.Value).ReadToEnd();
                }
                catch (Exception ex)
                {
                    exception        = ex;
                    replacementValue = string.Empty;
                    Error.Invoked    = true;
                }

                if (Error.Invoked)
                {
                    if (string.IsNullOrWhiteSpace(replacementValue) || !replacementValue.Contains(Error.ToString()))
                    {
                        throw new ArgumentException($"Tag substitution errored on template string:\n{template}", exception);
                    }

                    var attemptedRender = replacementValue.Replace(Error.ToString(), "[ERROR OCCURRED HERE]");
                    throw new ArgumentException($"Tag substitution failed on template string:\n{template}\n\nAttempted rendering was:\n{attemptedRender}", exception);
                }

                return(replacementValue);
            }
        }