コード例 #1
0
 private WriterCommandLineOptions(CommandLineOptions options)
 {
     _options = options;
 }
コード例 #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;
        }
コード例 #3
0
        public static WriterCommandLineOptions Create(string[] args)
        {
            CommandLineOptions options = new CommandLineOptions(false, 0, int.MaxValue,
                new ArgSpec(CULTURE, ArgSpec.Options.Default, "The culture to use (e.g. \"en-us\")"),
                new ArgSpec(OPTIONS, ArgSpec.Options.ValueOptional, "Show options"),
                new ArgSpec(OPENPOST, ArgSpec.Options.Flag, "Open post"),
                new ArgSpec(TESTMODE, ArgSpec.Options.Flag | ArgSpec.Options.Unsettable, "Debug mode"),
                new ArgSpec(VERBOSELOGGING, ArgSpec.Options.Flag | ArgSpec.Options.Unsettable, "Enable verbose logging"),
                new ArgSpec(ALLOWUNSAFECERTIFICATES, ArgSpec.Options.Flag | ArgSpec.Options.Unsettable, "Allow all SSL/TLS certificates"),
                new ArgSpec(PREFERATOM, ArgSpec.Options.Flag, "Prefer Atom to RSD during automatic configuration"),
                new ArgSpec(SUPPRESSBACKGROUNDREQUESTS, ArgSpec.Options.Flag, "Suppress background HTTP requests (for testing purposes)"),
                new ArgSpec(PROXY, ArgSpec.Options.Default, "Override proxy settings"),
                new ArgSpec(PERFLOG, ArgSpec.Options.Default, "File path where performance data should be logged. If the file exists, it will be truncated."),
                new ArgSpec(AUTOMATIONMODE, ArgSpec.Options.Flag | ArgSpec.Options.Unsettable, "Turn on automation mode"),
                new ArgSpec(ATTACHDEBUGGER, ArgSpec.Options.Flag, "Attach debugger on launch"),
                new ArgSpec(FIRSTRUN, ArgSpec.Options.Flag, "Show first run wizard"),
                new ArgSpec(INTAPIHOST, ArgSpec.Options.Default, "Use the specified API server hostname for INT testing"),
                new ArgSpec(LOCSPY, ArgSpec.Options.Flag, "Show localization names instead of values"),
                new ArgSpec(NOPLUGINS, ArgSpec.Options.Flag, "Prevents plugins from loading."),
                new ArgSpec(ADDBLOG, ArgSpec.Options.Default, "Adds a blog.")
                );

            bool success = options.Parse(args, false);
            if (!success)
            {
                MessageBox.Show(options.ErrorMessage, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (BidiHelper.IsRightToLeft ? (MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading) : 0));
                return null;
            }
            else
                return new WriterCommandLineOptions(options);
        }