public override void ExecuteProfile(Parser parser)
        {
            string file = Path.Combine(Program.Configuration.Output, OutPutPath, GetRelativePath(parser.Filename), Path.GetFileNameWithoutExtension(parser.Filename));
            var xmlMessage = Program.Configuration.XmlMessagesProfile.SearchXmlPattern(Path.GetFileNameWithoutExtension(parser.Filename));

            if (xmlMessage == null)
                Program.Shutdown(string.Format("File {0} not found", file));

            var engine = new Engine();
            var host = new TemplateHost(TemplatePath);
            host.Session["Message"] = xmlMessage;
            host.Session["Profile"] = this;
            var output = engine.ProcessTemplate(File.ReadAllText(TemplatePath), host);

            foreach (CompilerError error in host.Errors)
            {
                Console.WriteLine(error.ErrorText);
            }

            if (host.Errors.Count > 0)
                Program.Shutdown();

            File.WriteAllText(file + host.FileExtension, output);

            Console.WriteLine("Wrote {0}", file);
        }
        public override void ExecuteProfile(Parser parser)
        {
            string file = Path.Combine(Program.Configuration.Output, OutPutPath, GetRelativePath(parser.Filename),
                                       Path.GetFileNameWithoutExtension(parser.Filename));

            string moduleFile =
                parser.Fields.Where(entry => entry.Name == "MODULE").Select(entry => entry.Value).SingleOrDefault();

            var engine = new Engine();
            var host = new TemplateHost(TemplatePath);
            host.Session["Parser"] = parser;
            host.Session["Profile"] = this;
            string output = engine.ProcessTemplate(File.ReadAllText(TemplatePath), host);

            foreach (CompilerError error in host.Errors)
            {
                Console.WriteLine(error.ErrorText);
            }

            if (host.Errors.Count > 0)
                Program.Shutdown();

            File.WriteAllText(file + host.FileExtension, output);

            Console.WriteLine("Wrote {0}", file + host.FileExtension);
        }
        public override void ExecuteProfile(Parser parser)
        {
            string relativePath = GetRelativePath(parser.Filename);

            string xmlfile = Path.Combine(Program.Configuration.Output, OutPutPath, relativePath, Path.GetFileNameWithoutExtension(parser.Filename)) + ".xml";

            var builder = new XmlTypesBuilder(parser);

            XmlWriter writer = XmlWriter.Create(xmlfile, new XmlWriterSettings
                                                             {
                                                                 OmitXmlDeclaration = true,
                                                                 Indent = true,
                                                                 IndentChars = "\t",
                                                                 NamespaceHandling = NamespaceHandling.OmitDuplicates,
                                                             });
            builder.WriteToXml(writer);
            writer.Close();

            Console.WriteLine("Wrote {0}", xmlfile);
        }
		public XmlTypesBuilder(Parser parser)
			: base(parser)
		{
		}
 protected XmlPatternBuilder(Parser parser)
 {
     Parser = parser;
 }
 public XmlMessageBuilder(Parser parser)
     : base(parser)
 {
 }
Esempio n. 7
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            var serializer = new XmlSerializer(typeof(Configuration));
            Configuration.SetDefault();

            string configPath = "./config.xml";
            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i].ToLower())
                {
                    case "-config":
                        if (args.Length < i + 2)
                            Shutdown("Value of -config is not defined like : -config {configPath}");

                        configPath = args[i + 1];
                        break;
                    case "-createconfig":
                        var writer = XmlWriter.Create(configPath, new XmlWriterSettings()
                        {
                            Indent = true
                        });
                        serializer.Serialize(writer, Configuration);
                        writer.Close();
                        Shutdown("Config created. Please restart");
                        break;
                }
            }

            if (!File.Exists(configPath))
            {
                var writer = XmlWriter.Create(configPath, new XmlWriterSettings()
                                                              {
                                                                  Indent = true
                                                              });
                serializer.Serialize(writer, Configuration);
                writer.Close();
                Shutdown("Config created. Please restart");
            }
            else
            {
                var reader = XmlReader.Create(configPath, new XmlReaderSettings());
                Configuration = serializer.Deserialize(reader) as Configuration;
                reader.Close();
            }

            var profiles =
            new ParsingProfile[]
                {
                    Configuration.XmlMessagesProfile,
                    Configuration.XmlTypesProfile,
                    Configuration.MessagesProfile,
                    Configuration.TypesProfile,
                    Configuration.DatacenterProfile,
                    Configuration.EnumsProfile,
                };

            foreach (ParsingProfile parsingProfile in profiles)
            {
                if (parsingProfile == null)
                    continue;

                Console.WriteLine("Executing profile \'{0}\' ... ", parsingProfile.Name);

                if (parsingProfile.OutPutNamespace != null)
                    parsingProfile.OutPutNamespace = parsingProfile.OutPutNamespace.Insert(0, Configuration.BaseNamespace);

                if (!Directory.Exists(Configuration.Output))
                    Directory.CreateDirectory(Configuration.Output);

                
                if (Directory.Exists(Path.Combine(Configuration.Output, parsingProfile.OutPutPath)))
                {
                    DeleteDirectory(Path.Combine(Configuration.Output, parsingProfile.OutPutPath));
                }

                Directory.CreateDirectory(Path.Combine(Configuration.Output, parsingProfile.OutPutPath));

                IEnumerable<string> files = Directory.EnumerateFiles(
                    Path.Combine(Configuration.SourcePath, parsingProfile.SourcePath), "*.as",
                    SearchOption.AllDirectories);

                foreach (string file in files)
                {
                    string relativePath = parsingProfile.GetRelativePath(file);

                    if (!Directory.Exists(Path.Combine(Configuration.Output, parsingProfile.OutPutPath, relativePath)))
                        Directory.CreateDirectory(Path.Combine(Configuration.Output, parsingProfile.OutPutPath, relativePath));

                    var parser = new Parser(file, parsingProfile.BeforeParsingReplacementRules,
                                            parsingProfile.IgnoredLines)
                        {IgnoreMethods = parsingProfile.IgnoreMethods};

                    try
                    {
                        if (parsingProfile.EnableParsing)
                            parser.ParseFile();
                    }
                    catch (InvalidCodeFileException)
                    {
                        Console.WriteLine("File {0} not parsed correctly", Path.GetFileName(file));
                        continue;
                    }

                    parsingProfile.ExecuteProfile(parser);
                }

                Console.WriteLine("Done !");
            }
        }
Esempio n. 8
0
 public abstract void ExecuteProfile(Parser parser);