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();
                }
            };
        }
        private void SortGridCollection()
        {
            tbStatus.Text = "Remaining:" + (MigrationGridList.Where(x => x.StateId == (int)GridRow.STATEID.Waiting).Count() + MigrationGridList.Where(x => x.StateId == (int)GridRow.STATEID.Running).Count()).ToString().PadLeft(4) + ",".PadRight(3)
                            + "Success:" + MigrationGridList.Where(x => x.StateId == (int)GridRow.STATEID.Success).Count().ToString().PadLeft(4) + ",".PadRight(3)
                            + "Skipped:" + MigrationGridList.Where(x => x.StateId == (int)GridRow.STATEID.Skipped).Count().ToString().PadLeft(4) + ",".PadRight(3)
                            + "Error:" + MigrationGridList.Where(x => x.StateId == (int)GridRow.STATEID.Error).Count().ToString().PadLeft(4);

            if (_SortGrid)
            {
                ICollectionView migrationGridCollection = CollectionViewSource.GetDefaultView(dgGridList.ItemsSource);
                migrationGridCollection.SortDescriptions.Clear();
                migrationGridCollection.SortDescriptions.Add(new SortDescription("StateId", ListSortDirection.Ascending));

                var border = VisualTreeHelper.GetChild(dgGridList, 0) as Decorator;
                if (border != null)
                {
                    var dgScrollViewer = border.Child as ScrollViewer;
                    dgScrollViewer.ScrollToTop();
                }
            }

            MigrationLogger.Trace("GC.GetTotalMemory = {0}", GC.GetTotalMemory(true));
        }