Esempio n. 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);
        }
Esempio n. 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);
        }