internal SnapshotBuilder(Snapshot snapshot, SnapshotCollection collection)
 {
     _snapshot   = snapshot;
     _collection = collection;
 }
示例#2
0
        public static void Report(Output output, List <NamedTimeRange> ranges, Snapshot before, Snapshot after, SnapshotDifferences snapshotDifferences)
        {
            bool HasDate(RowDifference rowDifference, FieldDifference fieldDifference)
            {
                var isDate = fieldDifference.After?.GetType() == typeof(DateTime) ||
                             fieldDifference.Before?.GetType() == typeof(DateTime);

                if (isDate)
                {
                    return(true);
                }

                var beforeOriginal    = rowDifference.Before?.GetField(fieldDifference.Name);
                var afterOriginal     = rowDifference.After?.GetField(fieldDifference.Name);
                var isSubstitutedDate = beforeOriginal?.GetType() == typeof(DateTime) ||
                                        afterOriginal?.GetType() == typeof(DateTime);

                return(isSubstitutedDate);
            }

            output.WrapLine("====> Date diagnostics begin");
            output.FormatTable(ranges.Select(r => new { Snapshot = r.Name, r.Start, r.End }), title: "Snapshot date ranges");
            var tablesThatHaveDateDifferences = snapshotDifferences
                                                .TableDifferences
                                                .Select(t => new
            {
                t.TableDefinition,     //For a table
                Diffs = t.RowDifferences.Select(r => new
                {
                    RowDifference = r,                                  //Each set of differences for an individual row
                    DateDiffs     = r.Differences.Differences
                                    .Where(d => HasDate(r, d)).ToList() //and whichever of the differences includes a date
                })
                        .Where(d => d.DateDiffs.Any())                  //but only if there is at least one date difference
                        .ToList()
            })
                                                .Where(t => t.Diffs.Any()) //but only tables where there are dates in the row differences
                                                .ToList();                 //so now we have a list of tables that have row differences (with dates), and their actual rows that contain the date differences

            var cols    = tablesThatHaveDateDifferences.SelectMany(t => t.Diffs.SelectMany(d => d.DateDiffs.Select(dd => dd.Name))).Distinct();
            var keyCols = tablesThatHaveDateDifferences.SelectMany(t => t.Diffs.SelectMany(d => d.RowDifference.Key.GetFieldNames())).Distinct();

            var rep = tablesThatHaveDateDifferences
                      .AsReport(r => r.Title("Dates From Difference Set")
                                .AddColumn(t => t.TableDefinition.TableName)
                                .AddChild(t => t.Diffs, crep =>
            {
                crep.RemoveBufferLimit();
                foreach (var keyCol in keyCols)
                {
                    crep.AddColumn(crep.Lambda(cr => GetKeyValue(keyCol, cr.RowDifference)),
                                   cc => cc.Heading(keyCol));
                }

                foreach (var col in cols)
                {
                    crep.AddColumn(crep.Lambda(cr => GetDateValue(col, cr.DateDiffs, cr.RowDifference, true)),
                                   cc => cc.Heading($"{col} Before"));
                    crep.AddColumn(crep.Lambda(cr => GetDateValue(col, cr.DateDiffs, cr.RowDifference, false)),
                                   cc => cc.Heading($"{col} After"));
                }
            }));

            output.WriteLine();
            output.FormatTable(rep);
            output.WrapLine("====> Date diagnostics end");
        }
示例#3
0
        internal static SnapshotDifferences ExtractDifferences(SnapshotCollection collection, Snapshot before, Snapshot after, ChangeReportOptions changeReportOptions = ChangeReportOptions.Default)
        {
            var tableDiffs = SnapshotDifferenceCalculator.GetDifferences(collection, before, after);

            tableDiffs = SnapshotDifferenceSorter.SortDifferences(collection, tableDiffs);
            tableDiffs = DifferenceRegulator.CleanDifferences(collection, tableDiffs, before, (changeReportOptions & ChangeReportOptions.NoSubs) == 0);
            return(new SnapshotDifferences(tableDiffs));
        }
示例#4
0
        public static List <SnapshotTableDifferences> RequireColumns(SnapshotCollection collection, List <SnapshotTableDifferences> diffs, TableDefinition table, IEnumerable <string> requiredColumns, Snapshot before)
        {
            var result     = new List <SnapshotTableDifferences>();
            var columnList = requiredColumns.ToList();

            foreach (var differences in diffs)
            {
                if (differences.TableDefinition.TableName == table.TableName)
                {
                    var rowDiffs = differences.RowDifferences.Select(r => RequireColumns(r, columnList)).ToList();
                    var newDiffs = new SnapshotTableDifferences(rowDiffs, differences.TableDefinition);
                    result.Add(newDiffs);
                }
                else
                {
                    result.Add(differences);
                }
            }

            return(result);
        }