Ejemplo n.º 1
0
        public static void Main(string[] args)
        {

            TemplateFromDLL templateDriver = new TemplateFromDLL();
            List<string> extractTypes = null;
            bool dumpXmls = false;
            bool listTypes = false;
            string xmlDir = Directory.GetCurrentDirectory();
            OptionSet p = new OptionSet()
                .Add("v", v => templateDriver.verbose++)
                .Add("version", v => printVersion())
                .Add("help|h|?", v => printUsageAndExit())
                .Add("dll=", dllFileName => templateDriver.assembly = Assembly.LoadFile(dllFileName))
                .Add("listtypes", v => listTypes = true)
                .Add("dumpxmls", v => dumpXmls = true)
                .Add("xmldir=", dir => xmlDir = Path.Combine(xmlDir, dir));
            //	.Add ("extract={,}", typeName => templateDriver.extractTypes.Add(typeName));
            extractTypes = p.Parse(args);
            if (templateDriver.assembly == null)
            {
                Console.WriteLine("You must specify the DLL");
                printUsageAndExit();
            }
            if (extractTypes == null || extractTypes.Count == 0)
            {
                extractTypes = templateDriver.getAllTypeNames();
            }
            if (listTypes)
            {
                Console.WriteLine("All Types found in DLL {0}", templateDriver.assembly.FullName);
                foreach (string item in templateDriver.getAllTypeNames())
                {
                    Console.WriteLine(item);
                }
                Environment.Exit(0);
            }
            if (templateDriver.verbose > 0)
                Console.WriteLine("Types to extract:");
            foreach (string t in extractTypes)
            {
                if (templateDriver.verbose > 0)
                    Console.WriteLine("extracting {0}", t);
                IList<TypeRepTemplate> tyReps = templateDriver.mkTemplates(t);
                TextWriter writer = null;
                foreach (TypeRepTemplate tyRep in tyReps)
                {
                    if (tyRep == null)
                    {
                        if (templateDriver.verbose > 1)
                        {
                            // TODO:  We fail for enumeraters, others?
                            Console.WriteLine("Null typerep found, skipping");
                        }
                        continue;
                    }
                    if (dumpXmls)
                    {
                        string xmlFName = Path.Combine(xmlDir, tyRep.TypeName.Replace('.', Path.DirectorySeparatorChar) + ".xml");
                        string xmlFDir = Path.GetDirectoryName(xmlFName);
                        if (!Directory.Exists(xmlFDir))
                        {
                            Directory.CreateDirectory(xmlFDir);
                        }
                        writer = new StreamWriter(xmlFName);
                    }
                    else
                    {
                        writer = Console.Out;
                    }
                    templateDriver.writeXmlStream(tyRep, writer);
                    if (dumpXmls)
                        writer.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            TemplateFromDLL templateDriver = new TemplateFromDLL();
            List <string>   extractTypes   = null;
            bool            dumpXmls       = false;
            bool            listTypes      = false;
            string          xmlDir         = Directory.GetCurrentDirectory();
            OptionSet       p = new OptionSet()
                                .Add("v", v => templateDriver.verbose++)
                                .Add("version", v => printVersion())
                                .Add("help|h|?", v => printUsageAndExit())
                                .Add("dll=", dllFileName => templateDriver.assembly = Assembly.LoadFile(dllFileName))
                                .Add("listtypes", v => listTypes = true)
                                .Add("dumpxmls", v => dumpXmls   = true)
                                .Add("xmldir=", dir => xmlDir    = Path.Combine(xmlDir, dir));

            //	.Add ("extract={,}", typeName => templateDriver.extractTypes.Add(typeName));
            extractTypes = p.Parse(args);
            if (templateDriver.assembly == null)
            {
                Console.WriteLine("You must specify the DLL");
                printUsageAndExit();
            }
            if (extractTypes == null || extractTypes.Count == 0)
            {
                extractTypes = templateDriver.getAllTypeNames();
            }
            if (listTypes)
            {
                Console.WriteLine("All Types found in DLL {0}", templateDriver.assembly.FullName);
                foreach (string item in templateDriver.getAllTypeNames())
                {
                    Console.WriteLine(item);
                }
                Environment.Exit(0);
            }
            if (templateDriver.verbose > 0)
            {
                Console.WriteLine("Types to extract:");
            }
            foreach (string t in extractTypes)
            {
                if (templateDriver.verbose > 0)
                {
                    Console.WriteLine("extracting {0}", t);
                }
                IList <TypeRepTemplate> tyReps = templateDriver.mkTemplates(t);
                TextWriter writer = null;
                foreach (TypeRepTemplate tyRep in tyReps)
                {
                    if (tyRep == null)
                    {
                        if (templateDriver.verbose > 1)
                        {
                            // TODO:  We fail for enumeraters, others?
                            Console.WriteLine("Null typerep found, skipping");
                        }
                        continue;
                    }
                    if (dumpXmls)
                    {
                        string xmlFName = Path.Combine(xmlDir, tyRep.TypeName.Replace('.', Path.DirectorySeparatorChar) + ".xml");
                        string xmlFDir  = Path.GetDirectoryName(xmlFName);
                        if (!Directory.Exists(xmlFDir))
                        {
                            Directory.CreateDirectory(xmlFDir);
                        }
                        writer = new StreamWriter(xmlFName);
                    }
                    else
                    {
                        writer = Console.Out;
                    }
                    templateDriver.writeXmlStream(tyRep, writer);
                    if (dumpXmls)
                    {
                        writer.Close();
                    }
                }
            }
        }