Load() protected method

* Load a template from dir or group file. Group file is given * precedence over dir with same name. name is * always fully qualified. *
protected Load ( string name ) : CompiledTemplate
name string
return Antlr4.StringTemplate.Compiler.CompiledTemplate
Exemplo n.º 1
0
        public void printReport(string filename)
        {
            string URIFilename = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase) + Path.DirectorySeparatorChar + "templates" + Path.DirectorySeparatorChar + "ST-HtmlReport" + Path.DirectorySeparatorChar;
            Uri uri = new Uri(URIFilename);
            logger.Debug("Defining Template directory for HTML report to " + uri.LocalPath);
            TemplateGroup group = new TemplateGroupDirectory(uri.LocalPath, '$', '$');

            ErrorBuffer errors = new ErrorBuffer();
            group.Listener = errors;
            group.Load();

            Template st = group.GetInstanceOf("MainTemplate");

            st.Add("Report", this);

            string result = st.Render();

            if (errors.Errors.Count > 0)
            {
                foreach (TemplateMessage m in errors.Errors)
               {
                    logger.Error(m);
                    throw new Exception(m.ToString());
                }
            }

            StreamWriter output = new StreamWriter(filename, false, Encoding.GetEncoding("UTF-8"));

            output.Write(result);
            output.Close();
        }
Exemplo n.º 2
0
        private void writeScenario()
        {
            if (alreadyGenerated) initialize();

            TemplateGroup group = new TemplateGroupDirectory(this.templatePath, '$', '$');

                ErrorBuffer errors = new ErrorBuffer();
                group.Listener = errors;
                group.Load();

                Template st = group.GetInstanceOf("MainTemplate");

                this.TSFile = genTsStructFromTestContainer(this.outFile, sequence);

                st.Add("TestStandFile", this.TSFile);

                string result = st.Render();

                if (errors.Errors.Count > 0)
                {
                    foreach (TemplateMessage m in errors.Errors)
                    {
                        logger.Error(m);
                        throw new Exception(m.ToString());
                    }
                }

                StreamWriter output = new StreamWriter(this.outFile, false, Encoding.GetEncoding("windows-1251"));

                output.Write(result);
                output.Close();

                CTsGenericInstr.resetIdCounter();
            this.alreadyGenerated = true;
        }
Exemplo n.º 3
0
 public void TestUnloadingSimpleGroup()
 {
     string dir = tmpdir;
     string a =
         "a(x) ::= <<foo>>\n";
     string b =
         "b() ::= <<bar>>\n";
     writeFile(dir, "a.st", a);
     writeFile(dir, "b.st", b);
     TemplateGroup group = new TemplateGroupDirectory(dir);
     group.Load(); // force load
     Template st = group.GetInstanceOf("a");
     int originalHashCode = RuntimeHelpers.GetHashCode(st);
     group.Unload(); // blast cache
     st = group.GetInstanceOf("a");
     int newHashCode = RuntimeHelpers.GetHashCode(st);
     Assert.AreEqual(originalHashCode == newHashCode, false); // diff objects
     string expected = "foo";
     string result = st.Render();
     Assert.AreEqual(expected, result);
     st = group.GetInstanceOf("b");
     expected = "bar";
     result = st.Render();
     Assert.AreEqual(expected, result);
 }