Beispiel #1
0
        static int Main(string[] args)
        {
            if (args.Length == 1 && args[0].ToLowerInvariant() == "/validateall")
            {
                return(ValidateAll() ? 0 : 1);
            }

            CommandLineOptions clo = new CommandLineOptions(
                new ArgSpec("c", ArgSpec.Options.Multiple, "Command XML input file(s)"),
                new ArgSpec("r", ArgSpec.Options.Multiple, "Ribbon XML input file"),
                new ArgSpec("d", ArgSpec.Options.Multiple, "DisplayMessage XML input file(s)"),
                new ArgSpec("s", ArgSpec.Options.Multiple, "Strings CSV input file(s)"),
                new ArgSpec("cenum", ArgSpec.Options.Default, "Path to CommandId.cs enum output file"),
                new ArgSpec("denum", ArgSpec.Options.Default, "Path to MessageId.cs enum output file"),
                new ArgSpec("senum", ArgSpec.Options.Default, "Path to StringId.cs enum output file"),
                new ArgSpec("props", ArgSpec.Options.Required, "Path to Properties.resx output file"),
                new ArgSpec("propsnonloc", ArgSpec.Options.Required, "Path to PropertiesNonLoc.resx output file"),
                new ArgSpec("strings", ArgSpec.Options.Required, "Path to Strings.resx output file")
                );

            if (!clo.Parse(args, true))
            {
                Console.Error.WriteLine(clo.ErrorMessage);
                return(1);
            }

            Hashtable pairsLoc    = new Hashtable();
            Hashtable pairsNonLoc = new Hashtable();

            string[] commandFiles = (string[])ArrayHelper.Narrow(clo.GetValues("c"), typeof(string));
            string[] dialogFiles  = (string[])ArrayHelper.Narrow(clo.GetValues("d"), typeof(string));
            string[] ribbonFiles  = (string[])ArrayHelper.Narrow(clo.GetValues("r"), typeof(string));

            if (commandFiles.Length + dialogFiles.Length == 0)
            {
                Console.Error.WriteLine("No input files were specified.");
                return(1);
            }

            HashSet   ribbonIds;
            Hashtable ribbonValues;

            Console.WriteLine("Parsing commands from " + StringHelper.Join(commandFiles, ";"));
            if (!ParseRibbonXml(ribbonFiles, pairsLoc, pairsNonLoc, typeof(Command), "//ribbon:Command", "Command.{0}.{1}", out ribbonIds, out ribbonValues))
            {
                return(1);
            }
            HashSet commandIds;

            Console.WriteLine("Parsing commands from " + StringHelper.Join(commandFiles, ";"));

            string[] transformedCommandFiles = commandFiles;
            try
            {
                // Transform the files
                XslCompiledTransform xslTransform = new XslCompiledTransform(true);
                string xslFile = Path.GetFullPath("Commands.xsl");

                for (int i = 0; i < commandFiles.Length; i++)//string filename in commandFiles)
                {
                    string inputFile = Path.GetFullPath(commandFiles[i]);
                    if (!File.Exists(inputFile))
                    {
                        throw new ConfigurationErrorsException("File not found: " + inputFile);
                    }

                    xslTransform.Load(xslFile);

                    string transformedFile = inputFile.Replace(".xml", ".transformed.xml");
                    xslTransform.Transform(inputFile, transformedFile);
                    transformedCommandFiles[i] = transformedFile;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Failed to transform file: " + ex);
                return(1);
            }

            if (!ParseCommandXml(transformedCommandFiles, pairsLoc, pairsNonLoc, typeof(Command), "/Commands/Command", "Command.{0}.{1}", out commandIds))
            {
                return(1);
            }
            HashSet dialogIds;

            Console.WriteLine("Parsing messages from " + StringHelper.Join(dialogFiles, ";"));
            if (!ParseCommandXml(dialogFiles, pairsLoc, pairsNonLoc, typeof(DisplayMessage), "/Messages/Message", "DisplayMessage.{0}.{1}", out dialogIds))
            {
                return(1);
            }

            string propsFile = (string)clo.GetValue("props", null);

            Console.WriteLine("Writing localizable resources to " + propsFile);
            WritePairs(pairsLoc, propsFile, true);

            string propsNonLocFile = (string)clo.GetValue("propsnonloc", null);

            Console.WriteLine("Writing non-localizable resources to " + propsNonLocFile);
            WritePairs(pairsNonLoc, propsNonLocFile, false);

            if (clo.IsArgPresent("cenum"))
            {
                string cenum = (string)clo.GetValue("cenum", null);
                Console.WriteLine("Generating CommandId enum file " + cenum);

                // commandId:    command name
                // ribbonValues: command name --> resource id
                commandIds.AddAll(ribbonIds);
                if (!GenerateEnum(commandIds, "CommandId", cenum, null, ribbonValues))
                {
                    return(1);
                }
            }
            if (clo.IsArgPresent("denum"))
            {
                string denum = (string)clo.GetValue("denum", null);
                Console.WriteLine("Generating MessageId enum file " + denum);
                if (!GenerateEnum(dialogIds, "MessageId", denum, null, null))
                {
                    return(1);
                }
            }

            if (clo.IsArgPresent("s"))
            {
                Hashtable pairs = new Hashtable();
                Console.WriteLine("Reading strings");
                foreach (string sPath in clo.GetValues("s"))
                {
                    using (CsvParser csvParser = new CsvParser(new StreamReader(new FileStream(Path.GetFullPath(sPath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.Default), true))
                    {
                        foreach (string[] line in csvParser)
                        {
                            string value = line[1];
                            value = value.Replace(((char)8230) + "", "..."); // undo ellipses
                            string comment = (line.Length > 2) ? line[2] : "";
                            pairs.Add(line[0], new Values(value, comment));
                        }
                    }
                }

                if (clo.IsArgPresent("senum"))
                {
                    string senum = (string)clo.GetValue("senum", null);
                    Console.WriteLine("Writing StringId enum file " + senum);
                    if (!GenerateEnum(new HashSet(pairs), "StringId", senum, pairs, null))
                    {
                        return(1);
                    }
                }
                if (clo.IsArgPresent("strings"))
                {
                    string stringsResx = (string)clo.GetValue("strings", null);
                    Console.WriteLine("Writing " + pairs.Count + " localizable strings to " + stringsResx);
                    WritePairs(pairs, stringsResx, false);
                }
            }

            return(0);
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            if (args.Length == 1 && args[0].ToLowerInvariant() == "/validateall")
            {
                return ValidateAll() ? 0 : 1;
            }

            CommandLineOptions clo = new CommandLineOptions(
                new ArgSpec("c", ArgSpec.Options.Multiple, "Command XML input file(s)"),
                new ArgSpec("r", ArgSpec.Options.Multiple, "Ribbon XML input file"),
                new ArgSpec("d", ArgSpec.Options.Multiple, "DisplayMessage XML input file(s)"),
                new ArgSpec("s", ArgSpec.Options.Multiple, "Strings CSV input file(s)"),
                new ArgSpec("cenum", ArgSpec.Options.Default, "Path to CommandId.cs enum output file"),
                new ArgSpec("denum", ArgSpec.Options.Default, "Path to MessageId.cs enum output file"),
                new ArgSpec("senum", ArgSpec.Options.Default, "Path to StringId.cs enum output file"),
                new ArgSpec("props", ArgSpec.Options.Required, "Path to Properties.resx output file"),
                new ArgSpec("propsnonloc", ArgSpec.Options.Required, "Path to PropertiesNonLoc.resx output file"),
                new ArgSpec("strings", ArgSpec.Options.Required, "Path to Strings.resx output file")
                );

            if (!clo.Parse(args, true))
            {
                Console.Error.WriteLine(clo.ErrorMessage);
                return 1;
            }

            Hashtable pairsLoc = new Hashtable();
            Hashtable pairsNonLoc = new Hashtable();

            string[] commandFiles = (string[])ArrayHelper.Narrow(clo.GetValues("c"), typeof(string));
            string[] dialogFiles = (string[])ArrayHelper.Narrow(clo.GetValues("d"), typeof(string));
            string[] ribbonFiles = (string[])ArrayHelper.Narrow(clo.GetValues("r"), typeof(string));

            if (commandFiles.Length + dialogFiles.Length == 0)
            {
                Console.Error.WriteLine("No input files were specified.");
                return 1;
            }

            HashSet ribbonIds;
            Hashtable ribbonValues;
            Console.WriteLine("Parsing commands from " + StringHelper.Join(commandFiles, ";"));
            if (!ParseRibbonXml(ribbonFiles, pairsLoc, pairsNonLoc, typeof(Command), "//ribbon:Command", "Command.{0}.{1}", out ribbonIds, out ribbonValues))
                return 1;
            HashSet commandIds;
            Console.WriteLine("Parsing commands from " + StringHelper.Join(commandFiles, ";"));

            string[] transformedCommandFiles = commandFiles;
            try
            {
                // Transform the files
                XslCompiledTransform xslTransform = new XslCompiledTransform(true);
                string xslFile = Path.GetFullPath("Commands.xsl");

                for (int i = 0; i < commandFiles.Length; i++)//string filename in commandFiles)
                {
                    string inputFile = Path.GetFullPath(commandFiles[i]);
                    if (!File.Exists(inputFile))
                        throw new ConfigurationErrorsException("File not found: " + inputFile);

                    xslTransform.Load(xslFile);

                    string transformedFile = inputFile.Replace(".xml", ".transformed.xml");
                    xslTransform.Transform(inputFile, transformedFile);
                    transformedCommandFiles[i] = transformedFile;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Failed to transform file: " + ex);
                return 1;
            }

            if (!ParseCommandXml(transformedCommandFiles, pairsLoc, pairsNonLoc, typeof(Command), "/Commands/Command", "Command.{0}.{1}", out commandIds))
                return 1;
            HashSet dialogIds;
            Console.WriteLine("Parsing messages from " + StringHelper.Join(dialogFiles, ";"));
            if (!ParseCommandXml(dialogFiles, pairsLoc, pairsNonLoc, typeof(DisplayMessage), "/Messages/Message", "DisplayMessage.{0}.{1}", out dialogIds))
                return 1;

            string propsFile = (string)clo.GetValue("props", null);
            Console.WriteLine("Writing localizable resources to " + propsFile);
            WritePairs(pairsLoc, propsFile, true);

            string propsNonLocFile = (string)clo.GetValue("propsnonloc", null);
            Console.WriteLine("Writing non-localizable resources to " + propsNonLocFile);
            WritePairs(pairsNonLoc, propsNonLocFile, false);

            if (clo.IsArgPresent("cenum"))
            {
                string cenum = (string)clo.GetValue("cenum", null);
                Console.WriteLine("Generating CommandId enum file " + cenum);

                // commandId:    command name
                // ribbonValues: command name --> resource id
                commandIds.AddAll(ribbonIds);
                if (!GenerateEnum(commandIds, "CommandId", cenum, null, ribbonValues))
                    return 1;
            }
            if (clo.IsArgPresent("denum"))
            {
                string denum = (string)clo.GetValue("denum", null);
                Console.WriteLine("Generating MessageId enum file " + denum);
                if (!GenerateEnum(dialogIds, "MessageId", denum, null, null))
                    return 1;
            }

            if (clo.IsArgPresent("s"))
            {
                Hashtable pairs = new Hashtable();
                Console.WriteLine("Reading strings");
                foreach (string sPath in clo.GetValues("s"))
                {
                    using (CsvParser csvParser = new CsvParser(new StreamReader(new FileStream(Path.GetFullPath(sPath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.Default), true))
                    {
                        foreach (string[] line in csvParser)
                        {
                            string value = line[1];
                            value = value.Replace(((char)8230) + "", "..."); // undo ellipses
                            string comment = (line.Length > 2) ? line[2] : "";
                            pairs.Add(line[0], new Values(value, comment));
                        }
                    }
                }

                if (clo.IsArgPresent("senum"))
                {
                    string senum = (string)clo.GetValue("senum", null);
                    Console.WriteLine("Writing StringId enum file " + senum);
                    if (!GenerateEnum(new HashSet(pairs), "StringId", senum, pairs, null))
                        return 1;
                }
                if (clo.IsArgPresent("strings"))
                {
                    string stringsResx = (string)clo.GetValue("strings", null);
                    Console.WriteLine("Writing " + pairs.Count + " localizable strings to " + stringsResx);
                    WritePairs(pairs, stringsResx, false);
                }
            }

            return 0;
        }
 public LineEnumerator(CsvParser parent)
 {
     this.parent = parent;
 }
 public LineEnumerator(CsvParser parent)
 {
     this.parent = parent;
 }