Example #1
0
        private static void UpdateVariables()
        {
            MigrationHistoryHelpers mig = new MigrationHistoryHelpers();
            var dh = mig.GetDatabaseHistories(currSiteId);

            AspnetDbHelpers ah   = new AspnetDbHelpers();
            var             corp = ah.GetAllCorporationInfo().FirstOrDefault(f => f.SiteId == currSiteId);

            Institution      = corp?.Site_Name;
            InitialMigration = (dh.Count == 0) ? "No Migration" : dh.OrderBy(o => o.LastMigrationDate).Select(s => s.LastMigrationDate.ToString()).First();
            LastMigration    = (dh.Count == 0) ? "No Migration" : dh.OrderBy(o => o.LastMigrationDate).Select(s => s.LastMigrationDate.ToString()).Last();
        }
        private void BTrans_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            DispatchLabel("Creating statistics.");

            var rList  = new List <dynamic>();
            var initRC = JsonConvert.DeserializeObject <List <TableRowCount> >(initRowCount);
            NumedicsGlobalHelpers ngh = new NumedicsGlobalHelpers();

            SqlPurge sp = new SqlPurge();

            sp.Purge();

            DispatchLabel("Logging Transaction.");

            MigrationHistoryHelpers mig = new MigrationHistoryHelpers();

            mig.LogMigration();
            TransactionManager.ExecuteTransaction();

            foreach (var table in ngh.GetTableRowCount())
            {
                var preRowCnt = initRC.Where(f => f.TableName == table.TableName).Select(s => s.RowCnt).FirstOrDefault();
                var ms        = MappingStatistics.SqlTableStatistics.FirstOrDefault(w => w.Tablename == table.TableName);
                var diff      = (ms == null) ? 0 : ms.Difference;
                var n         = new
                {
                    TableName            = table.TableName,
                    PreMigrationRows     = preRowCnt,
                    PostMigratioRows     = table.RowCnt,
                    RowsAdded            = table.RowCnt - preRowCnt,
                    MappedRowsCommitted  = (ms == null) ? 0 : ms.PreSaveCount,
                    MappedRowsSaved      = (ms == null) ? 0 : ms.PostSaveCount,
                    MappedRowsDifference = diff,
                    Result = ((table.RowCnt - preRowCnt) == 0) ? "NO CHANGE" : (diff == 0) ? "SUCCESS" : "FAIL"
                };

                rList.Add(n);
            }

            dgMigResults.ItemsSource = rList.OrderBy(o => o.TableName); //MappingStatistics.SqlTableStatistics.OrderBy(o => o.Tablename);

            ((DataGridTextColumn)dgMigResults.Columns[0]).Binding = new Binding("TableName");
            ((DataGridTextColumn)dgMigResults.Columns[1]).Binding = new Binding("PreMigrationRows");
            ((DataGridTextColumn)dgMigResults.Columns[2]).Binding = new Binding("PostMigratioRows");
            ((DataGridTextColumn)dgMigResults.Columns[3]).Binding = new Binding("RowsAdded");
            ((DataGridTextColumn)dgMigResults.Columns[4]).Binding = new Binding("MappedRowsCommitted");
            ((DataGridTextColumn)dgMigResults.Columns[5]).Binding = new Binding("MappedRowsSaved");
            ((DataGridTextColumn)dgMigResults.Columns[6]).Binding = new Binding("MappedRowsDifference");
            ((DataGridTextColumn)dgMigResults.Columns[7]).Binding = new Binding("Result");

            var successCnt = rList.Count(w => w.Result == "SUCCESS");
            var failCnt    = rList.Count(w => w.Result == "FAIL");
            var ncCnt      = rList.Count(w => w.Result == "NO CHANGE");

            stkLoading.Visibility = Visibility.Hidden;

            lblTblsUpCnt.Content  = rList.Count.ToString();
            lblFailUpCnt.Content  = failCnt.ToString();
            lblNoChgUpCnt.Content = ncCnt.ToString();
            lblSuccUpCnt.Content  = successCnt.ToString();

            lblLogLoc.Content = MigrationVariables.LogFileLocation;

            spMigrationResults.Visibility = Visibility.Visible;
            DispatchLabel("Transaction Complete.");
        }