Пример #1
0
        public static void Main(string[] args)
        {
            long           startTime = DateTime.Now.Ticks;
            IList <string> remArgs   = new List <string>();
            IList <string> inDirs    = new List <string>();
            string         outDir    = "";

            // Use a try/catch block for parser exceptions
            try
            {
                // if we have at least one command-line argument
                if (args.Length > 0)
                {
                    OptionSet p = new OptionSet()
                                  .Add("v", v => Verbosity++)
                                  .Add("version", v => showVersion())
                                  .Add("help|h|?", v => showUsage())
                                  .Add("inxmldir=", dir => inDirs.Add(Path.Combine(Directory.GetCurrentDirectory(), dir)))
                                  .Add("outxmldir=", dir => outDir = Path.Combine(Directory.GetCurrentDirectory(), dir))
                    ;

                    remArgs = p.Parse(args);

                    // Load .Net templates
                    foreach (string r in inDirs)
                    {
                        doFile(r, ".xml", addOldNetTranslation, null);
                    }

                    UpdateTranslationTemplate tx = new UpdateTranslationTemplate();

                    foreach (KeyValuePair <string, OldT> de in oldAppEnv)
                    {
                        // update translation template
                        NewT txTemplate = tx.upgrade(de.Value);

                        String xmlFName = Path.Combine(outDir,
                                                       ((string)de.Key).Replace('.', Path.DirectorySeparatorChar) + ".xml");
                        String xmlFDir = Path.GetDirectoryName(xmlFName);
                        Console.WriteLine(xmlFName + ": " + de.Value.Java);

                        if (!Directory.Exists(xmlFDir))
                        {
                            Directory.CreateDirectory(xmlFDir);
                        }
                        XmlSerializer s = new XmlSerializer(txTemplate.GetType(), CS2JConstants.TranslationTemplateNamespace);
                        TextWriter    w = new StreamWriter(xmlFName);
                        s.Serialize(w, txTemplate);
                        w.Close();
                    }
                }
                else
                {
                    showUsage();
                }
            }
            catch (System.Exception e)
            {
                Console.Error.WriteLine("exception: " + e);
                Console.Error.WriteLine(e.StackTrace); // so we can get stack trace
            }
            double elapsedTime = ((DateTime.Now.Ticks - startTime) / TimeSpan.TicksPerMillisecond) / 1000.0;

            if (Verbosity >= 1)
            {
                System.Console.Out.WriteLine("Total run time was {0} seconds.", elapsedTime);
            }
        }
Пример #2
0
		public static void Main (string[] args)
		{
            long startTime = DateTime.Now.Ticks;
            IList<string> remArgs = new List<string>();		
			IList<string> inDirs = new List<string>();
			string outDir = "";
			
            // Use a try/catch block for parser exceptions
            try
            {
                // if we have at least one command-line argument
                if (args.Length > 0)
                {
			
                    OptionSet p = new OptionSet ()
                        .Add ("v", v => Verbosity++)
                        .Add ("version", v => showVersion())
                        .Add ("help|h|?", v => showUsage())
                        .Add ("inxmldir=", dir => inDirs.Add(Path.Combine(Directory.GetCurrentDirectory(), dir)))
                        .Add ("outxmldir=", dir => outDir = Path.Combine(Directory.GetCurrentDirectory(), dir))
                        ;

                    remArgs = p.Parse (args);
                            
                    // Load .Net templates
                    foreach (string r in inDirs)
                        doFile(r, ".xml", addOldNetTranslation, null);

					UpdateTranslationTemplate tx = new UpdateTranslationTemplate();
					
					foreach (KeyValuePair<string,OldT> de in oldAppEnv)
                    {   
						// update translation template
						NewT txTemplate = tx.upgrade(de.Value);
						
						String xmlFName = Path.Combine(outDir,
                                                           ((string)de.Key).Replace('.', Path.DirectorySeparatorChar) + ".xml");       
						String xmlFDir = Path.GetDirectoryName(xmlFName);
						Console.WriteLine (xmlFName + ": " + de.Value.Java);
						
						if (!Directory.Exists(xmlFDir))
						{
							Directory.CreateDirectory(xmlFDir);
						}
						XmlSerializer s = new XmlSerializer(txTemplate.GetType(), CS2JConstants.TranslationTemplateNamespace);
						TextWriter w = new StreamWriter(xmlFName);
						s.Serialize(w, txTemplate);
						w.Close();
					}
                }
                else
                {
                    showUsage();
                }
            }
            catch (System.Exception e)
            {
                Console.Error.WriteLine("exception: " + e);
                Console.Error.WriteLine(e.StackTrace); // so we can get stack trace
            }
            double elapsedTime = ((DateTime.Now.Ticks - startTime) / TimeSpan.TicksPerMillisecond) / 1000.0;
            if (Verbosity >= 1)
            {
                System.Console.Out.WriteLine("Total run time was {0} seconds.", elapsedTime);
            }
        }