예제 #1
0
파일: Program.cs 프로젝트: sillsdev/LfMerge
        public static int Main(string[] args)
        {
            ExceptionLogging.Initialize("17a42e4a67dd2e42d4aa40d8bf2d23ee", Assembly.GetExecutingAssembly().GetName().Name);
            int result  = (int)ErrorCode.NoError;
            var options = Options.ParseCommandLineArgs(args);

            if (options == null)
            {
                return((int)ErrorCode.InvalidOptions);
            }

            // initialize the SLDR
            Sldr.Initialize();

            // Username and Password will usually be "x" because it's dealt with on Language Forge site.
            // However, when debugging LfMerge we want to be able to set it to a real name
            ChorusHelper.Username = options.User;
            ChorusHelper.Password = System.Environment.GetEnvironmentVariable("LANGUAGE_DEPOT_TRUST_TOKEN") ?? options.Password;

            ExceptionLogging.Client.AddInfo(options.ProjectCode, MainClass.ModelVersion);

            MainClass.Logger.Notice("LfMerge {2} (database {0}) starting with args: {1}",
                                    MainClass.ModelVersion, string.Join(" ", args), MainClass.GetVersionInfo("SemVer"));

            if (string.IsNullOrEmpty(options.ProjectCode))
            {
                MainClass.Logger.Error("Command line doesn't contain project code - exiting.");
                return(-1);
            }

            FwProject.AllowDataMigration = options.AllowDataMigration;

            string differentModelVersion = null;

            try
            {
                if (!MainClass.CheckSetup())
                {
                    return((int)ErrorCode.GeneralError);
                }

                MongoConnection.Initialize();

                differentModelVersion = RunAction(options.ProjectCode, options.CurrentAction);
            }
            catch (Exception e)
            {
                MainClass.Logger.Error("Unhandled Exception: \n{0}", e);
                throw;
            }
            finally
            {
                if (Sldr.IsInitialized)
                {
                    Sldr.Cleanup();
                }

                MainClass.Container.Dispose();
                Cleanup();
            }

            if (!string.IsNullOrEmpty(differentModelVersion))
            {
                result = MainClass.StartLfMerge(options.ProjectCode, options.CurrentAction,
                                                differentModelVersion, false);
            }

            MainClass.Logger.Notice("LfMerge-{0} finished", MainClass.ModelVersion);
            return(result);
        }