Example #1
0
        private XmlHelper loadXml(String fileName, _ImportFlags flags = _ImportFlags.UseFlagsFromXml)
        {
            XmlHelper tmp = new XmlHelper(fileName);

            if (TemplateFactory == null)
            {
                String factoryClass = tmp.ReadStr("@templatefactory", typeof(TemplateFactory).FullName);
                TemplateFactory = CreateObject <ITemplateFactory>(factoryClass, this, tmp);
            }
            _ImportFlags flagsFromXml = tmp.ReadEnum("@importflags", (_ImportFlags)0);

            if (((ImportFlags | flagsFromXml) & _ImportFlags.DebugTemplate) != 0)
            {
                TemplateFactory.AutoWriteGenerated = true;
            }

            ImportLog.Log("Flags before load={0}", ImportFlags);

            XmlHelper       xml = new XmlHelper();
            ITemplateEngine eng = TemplateFactory.CreateEngine();

            eng.Variables.Set("IMPORT_ROOT", Path.GetDirectoryName(tmp.FileName));
            tmp = null;

            eng.LoadFromFile(fileName);
            MainVariables = eng.Variables;
            FileVariables = eng.FileVariables;
            TemplateFactory.InitialVariables = FileVariables;

            xml.Load(eng.ResultAsReader(), fileName);

            return(xml);
        }
Example #2
0
        private String load(String fn, ITemplateFactory templatefactory)
        {
            Regex refExpr  = new Regex("^//@ref=(.*)$", RegexOptions.IgnoreCase | RegexOptions.IgnoreCase);
            Regex inclExpr = new Regex("^//@incl=(.*)$", RegexOptions.IgnoreCase | RegexOptions.IgnoreCase);

            ITemplateEngine template = templatefactory.CreateEngine();

            template.LoadFromFile(fn);
            String outputFile = template.WriteGeneratedOutput();
            var    rdr        = template.ResultAsReader();

            String dir = Path.GetDirectoryName(fn);

            while (true)
            {
                String line = rdr.ReadLine();
                String val1;
                if (line == null)
                {
                    break;
                }

                if (line.Length < 5)
                {
                    continue;
                }
                if (line[0] != '/')
                {
                    continue;
                }
                if (refExpr.IsMatch(line))
                {
                    val1 = refExpr.Replace(line, "$1");
                    ScriptHost.logger.Log("handling REF: '{0}'", val1);
                    if (!String.IsNullOrEmpty(val1))
                    {
                        References.Add(val1);
                    }
                    continue;
                }
                if (inclExpr.IsMatch(line))
                {
                    val1 = inclExpr.Replace(line, "$1");
                    ScriptHost.logger.Log("handling INCL: '{0}'", val1);
                    if (!String.IsNullOrEmpty(val1))
                    {
                        Includes.Add(IOUtils.FindFileToRoot(dir, val1, FindToTootFlags.Except));
                    }
                    continue;
                }
            }
            return(outputFile);
        }
Example #3
0
        public void TestVarRecursionToDeep()
        {
            var factory = new TemplateFactory();

            factory.AutoWriteGenerated = true;
            factory.DebugLevel         = 10;
            ITemplateEngine eng = factory.CreateEngine();
            var             v   = eng.Variables;

            v.Set("boe", "bah");
            v.Set("var", "Dit is $$var$$");
            eng.LoadFromFile(root + "templates\\simple.txt");
            Assert.AreEqual(" included regel met 'abc'| this line is in between| included regel met 'Dit is bah'| ", resultAsString(eng));
        }
Example #4
0
        private JObject _loadConfig(ESIndexDefinition index, String fn, out DateTime fileUtcDate)
        {
            if (fn == null)
            {
                fileUtcDate = DateTime.MinValue;
                return(null);
            }
            Engine.ImportLog.Log("Loading config via template. fn={0}", fn);
            fileUtcDate = File.GetLastWriteTimeUtc(fn);
            ITemplateEngine template = Engine.TemplateFactory.CreateEngine();

            template.LoadFromFile(fn);
            var rdr = template.ResultAsStream().CreateJsonReader();

            return(JObject.Load(rdr));
        }