示例#1
0
文件: Program.cs 项目: DmVa/DbUpdater
        static int Main(string[] args)
        {
            ApplicationSettings.Current.Logger = new Log4NetWrapper(LogManager.GetLogger(typeof(Program)));
            ApplicationSettings.Current.AutoClose = true;
            ApplicationSettings.Current.CommandLineParams = CreateCommandLineArguments(args);

            var settings = ConfigurationManager.GetSection("DbUpdater") as DbUpdaterConfigurationSection;
            var logger = ApplicationSettings.Current.Logger;
            var commandLineParams = ApplicationSettings.Current.CommandLineParams;

            if (!string.IsNullOrEmpty(commandLineParams.ConnectionString))
            {
                settings.ConnectionString = commandLineParams.ConnectionString;
            }

            var updater = new UpdateManager(settings, logger, commandLineParams);
            updater.UpdateProgress += (s, e) =>
            {
                Update_ProgressChanged(0, new ProgressChangedEventArgs(0, e));
            };

            try
            {
                updater.Update();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine($"{ex.Message}.{ex.InnerException?.Message ?? ""}");

                return 1;
            }

            return 0;
        }
示例#2
0
        private void RunSingleUpdate(DbUpdaterConfigurationSection settings, LogWrapper.ILogger logger, DbUpdaterMultipleSourceConfigurationSection multipleSettings, int configurationIndex, CommandLineParams commandLineParams)
        {
            var bw = new BackgroundWorker();
            bw.WorkerReportsProgress = true;
            bw.DoWork += (sender, args) =>
            {
                var updater = new UpdateManager(settings, logger, commandLineParams);
                updater.UpdateProgress += (s, e) => bw.ReportProgress(0, e);
                updater.Update();
            };

            bw.ProgressChanged += Update_ProgressChanged;
            bw.RunWorkerCompleted += (s, e) =>
            {
                IsUpdateInProgress = false;
                if (e.Error != null)
                {
                    DisplayText += "Error: " + e.Error.Message +Environment.NewLine;
                    OnFinishUpdateProcess(true);
                    return;
                }
                if (e.Cancelled)
                {
                    DisplayText += "Cancelled" + Environment.NewLine;
                    OnFinishUpdateProcess(true);
                    return;
                }

                RunSingleUpdateFromMultipleInstance(multipleSettings, logger, configurationIndex, commandLineParams);
            };

            IsUpdateInProgress = true;
            bw.RunWorkerAsync();
        }