private static void UpdateMigrationGridListItem(MigrationTask migrationTask) { // If (MoRef == null) something went wrong. Try update this item by name and exit the function. var item = new GridRow(); if (migrationTask.MoRef == null) { item = MigrationGridList.FirstOrDefault(x => x.Name == migrationTask.EntityName); } else { item = MigrationGridList.FirstOrDefault(x => x.MoRef == migrationTask.MoRef); } if (migrationTask.State != null) { item.State = migrationTask.State; } item.StateReason = migrationTask.StateReason; item.Progress = migrationTask.Progress; item.Start = migrationTask.Start; item.Finish = migrationTask.Finish; MigrationLogger.Trace("{@value0}", item); }
public MainWindow() { InitializeComponent(); var config = new NLog.Config.LoggingConfiguration(); // Targets where to log to: File and Console string logFilePath = "migration-" + DateTime.Now.ToFileTime().ToString() + ".log"; var logfile = new NLog.Targets.FileTarget("logfile") { FileName = logFilePath, Layout = "${longdate} | ${level:uppercase=true:padding=-5:fixedLength=true} | ${logger:padding=-35:fixedLength=true} | ${message}" }; var logconsole = new NLog.Targets.ConsoleTarget("logconsole") { Layout = "${longdate} | ${level:uppercase=true:padding=-5:fixedLength=true} | ${logger:padding=-35:fixedLength=true} | ${message}" }; // Rules for mapping loggers to targets config.AddRule(LogLevel.Trace, LogLevel.Fatal, logconsole); config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); // Apply config NLog.LogManager.Configuration = config; MigrationGridList = (GridList)this.Resources["MigrationGridList"]; _Timer = new DispatcherTimer(DispatcherPriority.Background) { Interval = TimeSpan.FromSeconds(3) }; _Timer.Tick += (s, e) => { var nextMigration = MigrationGridList.FirstOrDefault(x => x.State == "waiting"); if ((nextMigration != null) && (MigrationGridList.Where(x => x.State == "running").Count() < vapiConnection.MAX_MIGRATIONS)) { nextMigration.State = "running"; SortGridCollection(); RunMigration(nextMigration); } else if ((MigrationGridList.Where(x => x.State == "running").Count() == 0) && (nextMigration == null)) { _Timer.Stop(); btnSelectFile.IsEnabled = true; btnStartMigration.Content = "Migration Complete"; vapiConnection.Disconnect(); } }; }