Пример #1
0
        public static CatalogDelta Create
        (
            [NotNull] CatalogState first,
            [NotNull] CatalogState second
        )
        {
            Sure.NotNull(first, "first");
            Sure.NotNull(second, "second");

            RecordState[] firstRecords = first.Records
                                         .ThrowIfNull("first.Records");
            RecordState[] secondRecords = second.Records
                                          .ThrowIfNull("second.Records");

            int[] firstDeleted = first.LogicallyDeleted
                                 .ThrowIfNull("first.LogicallyDeleted");
            int[] secondDeleted = second.LogicallyDeleted
                                  .ThrowIfNull("second.LogicallyDeleted");

            // TODO compare first.Database with second.Database?

            CatalogDelta result = new CatalogDelta
            {
                FirstDate  = first.Date,
                SecondDate = second.Date,
                Database   = first.Database,
                NewRecords = secondRecords.Except
                             (
                    firstRecords,
                    new RecordStateComparer.ByMfn()
                             )
                             .Select(state => state.Mfn)
                             .Where(mfn => mfn != 0)
                             .ToArray()
            };


            result.AlteredRecords = secondRecords.Except
                                    (
                firstRecords,
                new RecordStateComparer.ByVersion()
                                    )
                                    .Select(state => state.Mfn)
                                    .Where(mfn => mfn != 0)
                                    .Except(result.NewRecords.ThrowIfNull("result.NewRecords"))
                                    .Except(secondDeleted)
                                    .ToArray();

            result.DeletedRecords
                = secondDeleted.Except(firstDeleted)
                  .Where(mfn => mfn != 0)
                  .ToArray();

            return(result);
        }
Пример #2
0
        public virtual CatalogState GetCatalogState
        (
            [NotNull] string database
        )
        {
            Sure.NotNullNorEmpty(database, nameof(database));

            CatalogState result = new CatalogState
            {
                Database = database,
                Date     = PlatformAbstraction.Value.Today(),
                Records  = new RecordState[0]
            };

            return(result);
        }