Esempio n. 1
0
        public void Sync_Device_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Design = SyncFlags.Insert,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);
            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var newDevice = new Device()
            {
                CruiseID = cruiseID,
                DeviceID = Rand.Guid().ToString(),
            };

            fromDb.Insert(newDevice);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.GetRowCount("Device", "WHERE DeviceID = @p1 AND CruiseID = @p2", newDevice.DeviceID, newDevice.CruiseID)
            .Should().Be(1);
        }
Esempio n. 2
0
        public void SyncStratumTemplates_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "SyncStratumTemplates_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "SyncStratumTemplates_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Processing = SyncFlags.Insert,
            };

            var init     = new DatabaseInitializer();
            var cruiseID = init.CruiseID;
            var saleID   = init.SaleID;

            using var fromDb = init.CreateDatabaseFile(fromPath);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var st = new StratumTemplate
            {
                CruiseID            = cruiseID,
                StratumTemplateName = "something",
            };

            fromDb.Insert(st);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.From <StratumTemplate>().Count().Should().Be(1);
        }
Esempio n. 3
0
        public void Sync_UnitStratum_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Design = SyncFlags.Insert,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);
            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var newCUST = new CuttingUnit_Stratum()
            {
                CruiseID        = cruiseID,
                CuttingUnitCode = Units[1],
                StratumCode     = NonPlotStrata[0].StratumCode,
            };

            fromDb.Insert(newCUST);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.GetRowCount("CuttingUnit_Stratum", "WHERE CuttingUnitCode = @p1 AND StratumCode = @p2", newCUST.CuttingUnitCode, newCUST.StratumCode)
            .Should().Be(1);
        }
Esempio n. 4
0
        public void Sync_SampleGroup_Delete()
        {
            var init     = new DatabaseInitializer();
            var fromPath = base.GetTempFilePath(".crz3", "Sync_SampleGroup_Delete_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sync_SampleGroup_Delete_toFile");

            using var fromDb = init.CreateDatabaseFile(fromPath);
            var cruiseID = init.CruiseID;
            var saleID   = init.SaleID;

            var newStratum = new Stratum
            {
                CruiseID    = cruiseID,
                StratumID   = Guid.NewGuid().ToString(),
                StratumCode = "newStratumCode1",
            };

            fromDb.Insert(newStratum);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            fromDb.Delete(newStratum);

            var syncer      = new DeleteSysncer();
            var syncOptions = new CruiseSyncOptions();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.GetRowCount("Stratum", "WHERE StratumID = @p1", newStratum.StratumID)
            .Should().Be(0);
        }
Esempio n. 5
0
        public void Sync_Sale_Update()
        {
            var fromPath = base.GetTempFilePath(".crz3", "Sale_Update_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sale_Update_toFile");

            var syncOptions = new CruiseSyncOptions();

            var cruiseID = CruiseID;
            var saleID   = SaleID;

            using var fromDb = CreateDatabaseFile(fromPath);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var sale = fromDb.From <Sale>()
                       .Where("SaleID = @p1")
                       .Query(saleID)
                       .FirstOrDefault();

            sale.Remarks = Rand.String();
            fromDb.Update(sale);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            var saleAgain = toDb.From <Sale>().Where("SaleID = @p1").Query(saleID).FirstOrDefault();

            saleAgain.Should().BeEquivalentTo(sale, x => x.Excluding(y => y.Modified_TS));
        }
Esempio n. 6
0
        public void Sync_BiomassEquation_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "Sync_BiomassEquations_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sync_BiomassEquations_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Processing = SyncFlags.InsertUpdate,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var newBiomassEquation = new BiomassEquation
            {
                CruiseID  = cruiseID,
                Component = "sfdf",
                Species   = "sp1",
                Product   = "01",
                LiveDead  = "L",
            };

            fromDb.Insert(newBiomassEquation);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.From <BiomassEquation>().Count().Should().Be(1);
        }
Esempio n. 7
0
        public void Sync_CuttingUnit_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "CuttingUnit_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "CuttingUnit_Add_toFile");

            var syncOptions = new CruiseSyncOptions();

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var cuttingUnitID = Guid.NewGuid().ToString();

            fromDb.Insert(new CuttingUnit()
            {
                CruiseID        = cruiseID,
                CuttingUnitID   = cuttingUnitID,
                CuttingUnitCode = "10",
            });
            var newCuttingUnit = fromDb.From <CuttingUnit>().Where("CuttingUnitID = @p1").Query(cuttingUnitID).Single();

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            var cuttingUnitAgain = toDb.From <CuttingUnit>().Where("CuttingUnitID =  @p1")
                                   .Query(cuttingUnitID).FirstOrDefault();

            cuttingUnitAgain.Should().BeEquivalentTo(newCuttingUnit, x => x.Excluding(y => y.Modified_TS));
        }
Esempio n. 8
0
        public void Sync_SampleGroup_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "SampleGroup_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "SampleGroup_Add_toFile");

            var syncOptions = new CruiseSyncOptions();

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var sampleGroupID = Guid.NewGuid().ToString();

            fromDb.Insert(new SampleGroup()
            {
                CruiseID        = cruiseID,
                SampleGroupID   = sampleGroupID,
                SampleGroupCode = "10",
                StratumCode     = Strata[0].StratumCode,
            });
            var newSampleGroup = fromDb.From <SampleGroup>().Where("SampleGroupID = @p1").Query(sampleGroupID).Single();

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            var sampleGroupAgain = toDb.From <SampleGroup>().Where("SampleGroupID =  @p1")
                                   .Query(sampleGroupID).FirstOrDefault();

            sampleGroupAgain.Should().BeEquivalentTo(newSampleGroup);
        }
Esempio n. 9
0
        public void Sync_Reports_Add()
        {
            var rand     = new Bogus.Randomizer();
            var fromPath = base.GetTempFilePath(".crz3", "Sync_Reports_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sync_Reports_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Processing = SyncFlags.Insert,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var reportID = Guid.NewGuid().ToString();
            var report   = new Reports
            {
                CruiseID = cruiseID,
                ReportID = reportID,
                Title    = rand.String(),
            };

            fromDb.Insert(report);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.GetRowCount("Reports", "WHERE ReportID = @p1", reportID).Should().Be(1);
        }
Esempio n. 10
0
        public void SyncVolumeEquations_Add()
        {
            var rand     = new Bogus.Randomizer();
            var fromPath = base.GetTempFilePath(".crz3", "SyncVolumeEquations_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "SyncVolumeEquations_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Processing = SyncFlags.Insert,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var volEq = new VolumeEquation
            {
                CruiseID             = cruiseID,
                Species              = "sp1",
                PrimaryProduct       = "01",
                VolumeEquationNumber = "something"
            };

            fromDb.Insert(volEq);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.GetRowCount("VolumeEquation", "WHERE VolumeEquationNumber = @p1", volEq.VolumeEquationNumber).Should().Be(1);
        }
Esempio n. 11
0
        public void Sync_Plot_Stratum_Update()
        {
            var fromPath = base.GetTempFilePath(".crz3", "Sync_Plot_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sync_Plot_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Design    = SyncFlags.Insert,
                FieldData = SyncFlags.InsertUpdate,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            var plot = new Plot()
            {
                CruiseID        = cruiseID,
                PlotID          = Guid.NewGuid().ToString(),
                CuttingUnitCode = Units[0],
                PlotNumber      = 1,
            };

            fromDb.Insert(plot);

            var plotStratum = new Plot_Stratum()
            {
                CruiseID        = cruiseID,
                PlotNumber      = plot.PlotNumber,
                CuttingUnitCode = plot.CuttingUnitCode,
                StratumCode     = PlotStrata[0].StratumCode,
            };

            fromDb.Insert(plotStratum);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            plotStratum.KPI = Rand.Double();
            plotStratum.ThreePRandomValue = Rand.Int();
            toDb.Update(plotStratum);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            var plotStratumAgain = toDb
                                   .From <Plot_Stratum>()
                                   .Where("Plot_Stratum_CN = @p1")
                                   .Query(plotStratum.Plot_Stratum_CN)
                                   .FirstOrDefault();

            plotStratumAgain.Should().BeEquivalentTo(plotStratum, config => config.Excluding(x => x.Modified_TS));
        }
Esempio n. 12
0
        public void Sync_PlotLocation_Update()
        {
            var fromPath = base.GetTempFilePath(".crz3", "Sync_Plot_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sync_Plot_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Design    = SyncFlags.Insert,
                FieldData = SyncFlags.Update,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            var newPlot = new Plot()
            {
                CruiseID        = cruiseID,
                PlotID          = Guid.NewGuid().ToString(),
                CuttingUnitCode = Units[0],
                PlotNumber      = 1,
            };

            fromDb.Insert(newPlot);

            var plotLocation = new PlotLocation()
            {
                PlotID = newPlot.PlotID,
            };

            fromDb.Insert(plotLocation);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            plotLocation.Latitude  = Rand.Double();
            plotLocation.Longitude = Rand.Double();
            fromDb.Update(plotLocation);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            var plotLocationAgain = toDb.From <PlotLocation>()
                                    .Where("PlotID = @p1")
                                    .Query(plotLocation.PlotID)
                                    .FirstOrDefault();

            plotLocationAgain.Should().BeEquivalentTo(plotLocation, config => config.Excluding(x => x.Modified_TS));
        }
Esempio n. 13
0
        public void Sync_Plot_Stratum_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "Sync_Plot_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sync_Plot_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Design    = SyncFlags.Insert,
                FieldData = SyncFlags.Insert,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            var newPlot = new Plot()
            {
                CruiseID        = cruiseID,
                PlotID          = Guid.NewGuid().ToString(),
                CuttingUnitCode = Units[0],
                PlotNumber      = 1,
            };

            fromDb.Insert(newPlot);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var newPlotStratum = new Plot_Stratum()
            {
                CruiseID        = cruiseID,
                PlotNumber      = newPlot.PlotNumber,
                CuttingUnitCode = newPlot.CuttingUnitCode,
                StratumCode     = PlotStrata[0].StratumCode,
            };

            fromDb.Insert(newPlotStratum);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.GetRowCount("Plot", "WHERE PlotID = @p1", newPlot.PlotID)
            .Should().Be(1);
            toDb.ExecuteScalar2 <int>("SELECT COUNT(*) FROM Plot_Stratum WHERE CruiseID = @CruiseID AND PlotNumber = @PlotNumber AND CuttingUnitCode = @CuttingUnitCode", newPlotStratum)
            .Should().Be(1);
        }
Esempio n. 14
0
        public void Sync_Log_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "Sync_Plot_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sync_Plot_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                FieldData = SyncFlags.Insert,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            var tree = new Tree()
            {
                TreeID          = Guid.NewGuid().ToString(),
                CruiseID        = cruiseID,
                CuttingUnitCode = Units[0],
                StratumCode     = Strata[0].StratumCode,
                SampleGroupCode = SampleGroups[0].SampleGroupCode,
                SpeciesCode     = Species[0],
                TreeNumber      = 1,
            };

            fromDb.Insert(tree);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var newLog = new Log()
            {
                LogID     = Guid.NewGuid().ToString(),
                CruiseID  = cruiseID,
                LogNumber = "01",
                TreeID    = tree.TreeID,
            };

            fromDb.Insert(newLog);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.GetRowCount("Log", "WHERE LogID = @p1", newLog.LogID)
            .Should().Be(1);
        }
Esempio n. 15
0
        public void Sync_CuttingUnit_Update()
        {
            var fromPath = base.GetTempFilePath(".crz3", "CuttingUnit_Updated_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "CuttingUnit_Update_toFile");

            var syncOptions = new CruiseSyncOptions();

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            // initialize source database
            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);
            var cuttingUnitID = Guid.NewGuid().ToString();
            var cuttingUnit   = new CuttingUnit()
            {
                CruiseID        = cruiseID,
                CuttingUnitID   = cuttingUnitID,
                CuttingUnitCode = "10",
            };

            fromDb.Insert(cuttingUnit);

            // initialize dest database
            // as exact copy of source database
            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            // modify cutting unit value and save to source database
            cuttingUnit.Area          = Rand.Int();
            cuttingUnit.Description   = Rand.String();
            cuttingUnit.LoggingMethod = "401";
            cuttingUnit.PaymentUnit   = Rand.AlphaNumeric(3);
            cuttingUnit.Rx            = Rand.AlphaNumeric(3);
            cuttingUnit.ModifiedBy    = Rand.AlphaNumeric(4);
            fromDb.Update(cuttingUnit);

            // run sync
            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            var cuttingUnitAgain = toDb.From <CuttingUnit>().Where("CuttingUnitID =  @p1")
                                   .Query(cuttingUnitID).FirstOrDefault();

            cuttingUnitAgain.Should().BeEquivalentTo(cuttingUnit, x => x.Excluding(y => y.Modified_TS));
        }
Esempio n. 16
0
        public void Sync_PlotLocation_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "Sync_Plot_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sync_Plot_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Design    = SyncFlags.Insert,
                FieldData = SyncFlags.Insert,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            var newPlot = new Plot()
            {
                CruiseID        = cruiseID,
                PlotID          = Guid.NewGuid().ToString(),
                CuttingUnitCode = Units[0],
                PlotNumber      = 1,
            };

            fromDb.Insert(newPlot);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var newPlotLocation = new PlotLocation()
            {
                PlotID = newPlot.PlotID,
            };

            fromDb.Insert(newPlotLocation);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.GetRowCount("Plot", "WHERE PlotID = @p1", newPlot.PlotID)
            .Should().Be(1);
            toDb.GetRowCount("PlotLocation", "WHERE PlotID = @p1", newPlot.PlotID)
            .Should().Be(1);
        }
Esempio n. 17
0
        public void Sync_SubPopulation_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "SubPopulation_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "SubPopulation_Add_toFile");

            var syncOptions = new CruiseSyncOptions();

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var sampleGroup      = SampleGroups[0];
            var subPopID         = Guid.NewGuid().ToString();
            var newSubpopulation = new SubPopulation()
            {
                CruiseID        = cruiseID,
                SubPopulationID = subPopID,
                StratumCode     = sampleGroup.StratumCode,
                SampleGroupCode = sampleGroup.SampleGroupCode,
                SpeciesCode     = Species[3],
                LiveDead        = "L",
            };

            fromDb.Insert(newSubpopulation);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            var subPopulationAgain = toDb.From <SubPopulation>()
                                     .Where("SubPopulationID = @p1")
                                     .Query(subPopID).FirstOrDefault();

            subPopulationAgain.Should().BeEquivalentTo(newSubpopulation, x => x
                                                       .Excluding(y => y.Modified_TS)
                                                       .Excluding(y => y.Created_TS)
                                                       .Excluding(y => y.CreatedBy));
        }
        public void Sync_Stratum_Update_StratumCode()
        {
            var fromPath = base.GetTempFilePath(".crz3", "Stratum_Updated_stCode_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Stratum_Update_stCode_toFile");

            var syncOptions = new CruiseSyncOptions();

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            // initialize source database
            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);
            var stratumID = Guid.NewGuid().ToString();
            var stratum   = new Stratum()
            {
                CruiseID    = cruiseID,
                StratumID   = stratumID,
                StratumCode = "10",
                Method      = "100",
            };

            fromDb.Insert(stratum);

            // initialize dest database
            // as exact copy of source database
            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            // modify stratum code and save to source database
            stratum.StratumCode = "11";
            fromDb.Update(stratum);

            // run sync
            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            var stratumAgain = toDb.From <Stratum>().Where("StratumID =  @p1")
                               .Query(stratumID).FirstOrDefault();

            stratumAgain.StratumCode.Should().BeEquivalentTo(stratum.StratumCode);
        }
Esempio n. 19
0
        public void Sync_SampleGroup_Update_SampleGroupCode()
        {
            var fromPath = base.GetTempFilePath(".crz3", "SampleGroup_Update_SGCode_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "SampleGroup_Update_SGCode_toFile");

            var syncOptions = new CruiseSyncOptions();

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            // initialize source database
            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);
            var sampleGroupID = Guid.NewGuid().ToString();
            var sampleGroup   = new SampleGroup()
            {
                CruiseID        = cruiseID,
                SampleGroupID   = sampleGroupID,
                SampleGroupCode = "10",
                StratumCode     = Strata[0].StratumCode,
            };

            fromDb.Insert(sampleGroup);

            // initialize dest database
            // as exact copy of source database
            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            // modify sample group code on source database
            sampleGroup.SampleGroupCode = "11";
            fromDb.Update(sampleGroup);

            // run sync
            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            var sampleGroupAgain = toDb.From <SampleGroup>().Where("SampleGroupID =  @p1")
                                   .Query(sampleGroupID).FirstOrDefault();

            sampleGroupAgain.SampleGroupCode.Should().BeEquivalentTo(sampleGroup.SampleGroupCode);
        }
Esempio n. 20
0
        public void Sync_Cruise_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "Cruise_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Cruise_Add_toFile");

            var syncOptions = new CruiseSyncOptions();

            var init       = new DatabaseInitializer();
            var cruiseID   = init.CruiseID;
            var saleID     = init.SaleID;
            var saleNumber = init.SaleNumber;

            using var fromDb = init.CreateDatabaseFile(fromPath);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var newCruise = new Cruise
            {
                CruiseID     = Guid.NewGuid().ToString(),
                CruiseNumber = "123456789",
                SaleID       = saleID,
                SaleNumber   = saleNumber,
            };

            fromDb.Insert(newCruise);
            newCruise = fromDb.From <Cruise>().Where("CruiseID = @p1")
                        .Query(newCruise.CruiseID).FirstOrDefault();

            var syncer = new CruiseSyncer();

            syncer.Sync(newCruise.CruiseID, fromDb, toDb, syncOptions);

            var newCruiseAgain = toDb.From <Cruise>()
                                 .Where("CruiseID = @p1")
                                 .Query(newCruise.CruiseID).FirstOrDefault();

            newCruiseAgain.Should().NotBeNull();
            newCruiseAgain.Should().BeEquivalentTo(newCruise, x => x
                                                   .Excluding(y => y.Modified_TS));
        }
Esempio n. 21
0
        public void Sync_CuttingUnit_Update_CuttingUnitCode()
        {
            var fromPath = base.GetTempFilePath(".crz3", "CuttingUnit_Updated_code_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "CuttingUnit_Update_code_toFile");

            var syncOptions = new CruiseSyncOptions();

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            // initialize source database
            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);
            var cuttingUnitID = Guid.NewGuid().ToString();
            var cuttingUnit   = new CuttingUnit()
            {
                CruiseID        = cruiseID,
                CuttingUnitID   = cuttingUnitID,
                CuttingUnitCode = "10",
            };

            fromDb.Insert(cuttingUnit);

            // initialize dest database
            // as exact copy of source database
            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            // modify cutting unit value and save to source database
            cuttingUnit.CuttingUnitCode = "11";
            fromDb.Update(cuttingUnit);

            // run sync
            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            var cuttingUnitAgain = toDb.From <CuttingUnit>().Where("CuttingUnitID =  @p1")
                                   .Query(cuttingUnitID).FirstOrDefault();

            cuttingUnitAgain.CuttingUnitCode.Should().BeEquivalentTo(cuttingUnit.CuttingUnitCode);
        }
Esempio n. 22
0
        public void Sync_TallyLedger_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "Sync_Unit_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sync_Unit_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Design        = SyncFlags.Insert,
                FieldData     = SyncFlags.Insert,
                TreeDataFlags = SyncFlags.Insert,
                TreeFlags     = SyncFlags.Insert,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var newTallyLedger = new TallyLedger()
            {
                CruiseID        = cruiseID,
                TallyLedgerID   = Guid.NewGuid().ToString(),
                CuttingUnitCode = Units[0],
                StratumCode     = SampleGroups[0].StratumCode,
                SampleGroupCode = SampleGroups[0].SampleGroupCode,
                TreeCount       = 1,
            };

            fromDb.Insert(newTallyLedger);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.GetRowCount("TallyLedger", "WHERE TallyLedgerID = @p1", newTallyLedger.TallyLedgerID)
            .Should().Be(1);
        }
Esempio n. 23
0
        public void SyncTreeDefaultValues_Add()
        {
            var fromPath = base.GetTempFilePath(".crz3", "SyncTreeDefaultValues_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "SyncTreeDefaultValues_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Processing = SyncFlags.Insert,
            };

            var init = new DatabaseInitializer()
            {
                TreeDefaults = null,
            };
            var cruiseID = init.CruiseID;
            var saleID   = init.SaleID;

            using var fromDb = init.CreateDatabaseFile(fromPath);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var tdv = new TreeDefaultValue
            {
                CruiseID       = cruiseID,
                SpeciesCode    = "sp1",
                PrimaryProduct = "01",
            };

            fromDb.Insert(tdv);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.From <TreeDefaultValue>().Count().Should().Be(1);
        }
Esempio n. 24
0
        public void Sync(string cruiseID, DbConnection source, DbConnection destination, CruiseSyncOptions options, IProgress <float> progress = null)
        {
            var   steps       = 16;
            float p           = 0.0f;
            var   transaction = destination.BeginTransaction();

            try
            {
                SyncCuttingUnits(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);
                SyncStrata(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);
                SyncCuttingUnit_Stratum(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);
                SyncSampleGroup(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);
                SyncSubPopulation(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);

                // field setup
                SyncLogFieldSetup(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);
                SyncTreeFieldSetup(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);

                // validation
                SyncTreeAuditRule(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);
                SyncTreeAuditRuleSelector(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);
                SyncTreeAuditResolution(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);

                // field data
                SyncPlots(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);
                SyncPlotLocation(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);
                SyncPlot_Strata(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);

                SyncTallyLedger(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);

                //SyncLog(cruiseID, source, destination, options);
                //progress?.Report(p++ / steps);
                //SyncStem(cruiseID, source, destination, options);
                //progress?.Report(p++ / steps);

                //processing
                SyncVolumeEquations(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);

                SyncReports(cruiseID, source, destination, options);
                progress?.Report(p++ / steps);

                transaction.Commit();
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw;
            }
        }
Esempio n. 25
0
        private void SyncVolumeEquations(string cruiseID, DbConnection source, DbConnection destination, CruiseSyncOptions options)
        {
            var deletedItems = source.From <VolumeEquation_Tombstone>()
                               .Where("CruiseID = @p1")
                               .Query(cruiseID);

            foreach (var i in deletedItems)
            {
                var match = destination.From <VolumeEquation>()
                            .Where("CruiseID = @CruiseID AND Species = @Species AND PrimaryProduct = @PrimaryProduct AND VolumeEquationNumber = @VolumeEquationNumber")
                            .Query2(new { i.CruiseID, i.Species, i.PrimaryProduct, i.VolumeEquationNumber })
                            .FirstOrDefault();

                if (match != null)
                {
                    var x = destination.ExecuteNonQuery2("DELETE FROM VolumeEquation WHERE CruiseID = @CruiseID AND Species = @Species AND PrimaryProduct = @PrimaryProduct AND VolumeEquationNumber = @VolumeEquationNumber", new { i.CruiseID, i.Species, i.PrimaryProduct, i.VolumeEquationNumber });
                }
                else
                {
                    destination.Insert(i, option: Backpack.SqlBuilder.OnConflictOption.Replace);
                }
            }
        }
Esempio n. 26
0
        private void SyncPlotLocation(string cruiseID, DbConnection source, DbConnection destination, CruiseSyncOptions options)
        {
            var deletedItems = source.From <PlotLocation_Tombstone>()
                               .Join("Plot", "USING (PlotID)")
                               .Where("CruiseID = @p1")
                               .Query(cruiseID);

            foreach (var i in deletedItems)
            {
                var match = destination.From <PlotLocation>()
                            .Where("PlotID = @PlotID")
                            .Query2(new { i.PlotID }).FirstOrDefault();

                if (match != null)
                {
                    var x = destination.ExecuteNonQuery2("DELETE FROM PlotLocation WHERE PlotID = @PlotID;",
                                                         new { i.PlotID });
                }
                else
                {
                    destination.Insert(i, option: Backpack.SqlBuilder.OnConflictOption.Replace);
                }
            }
        }
Esempio n. 27
0
        private void SyncReports(string cruiseID, DbConnection source, DbConnection destination, CruiseSyncOptions options)
        {
            var deletedItems = source.From <Reports_Tombstone>()
                               .Where("CruiseID = @p1")
                               .Query(cruiseID);

            foreach (var i in deletedItems)
            {
                var match = destination.From <Reports>()
                            .Where("CruiseID = @CruiseID AND ReportID = @ReportID")
                            .Query2(new { i.CruiseID, i.ReportID })
                            .FirstOrDefault();

                if (match != null)
                {
                    var x = destination.ExecuteNonQuery2("DELETE FROM Reports WHERE CruiseID = @CruiseID AND ReportID = @ReportID;",
                                                         new { i.CruiseID, i.ReportID });
                }
                else
                {
                    destination.Insert(i, option: Backpack.SqlBuilder.OnConflictOption.Replace);
                }
            }
        }
Esempio n. 28
0
        private void synclog(string cruiseid, DbConnection source, DbConnection destination, CruiseSyncOptions options)
        {
            var deletedItems = source.From <Log_Tombstone>()
                               .Where("CruiseID = @p1")
                               .Query(cruiseid);

            foreach (var i in deletedItems)
            {
                var match = destination.From <Log>()
                            .Where("LogID = @LogID")
                            .Query2(new { i.LogID })
                            .FirstOrDefault();

                if (match != null)
                {
                    var x = destination.ExecuteNonQuery2("DELETE FROM Log WHERE LogID = @LogID;", new { i.LogID });
                }
                else
                {
                    destination.Insert(i, option: Backpack.SqlBuilder.OnConflictOption.Replace);
                }
            }
        }
Esempio n. 29
0
        private void SyncPlot_Strata(string cruiseID, DbConnection source, DbConnection destination, CruiseSyncOptions options)
        {
            var deletedItems = source.From <Plot_Stratum_Tombstone>()
                               .Where("CruiseID = @p1")
                               .Query(cruiseID);

            foreach (var i in deletedItems)
            {
                var match = destination.From <Plot_Stratum>()
                            .Where("CruiseID = @CruiseID AND PlotNumber = @PlotNumber AND StratumCode = @StratumCode")
                            .Query2(new { i.CruiseID, i.PlotNumber, i.StratumCode }).FirstOrDefault();

                if (match != null)
                {
                    var x = destination.ExecuteNonQuery2("DELETE FROM Plot_Stratum WHERE CruiseID = @CruiseID AND PlotNumber = @PlotNumber AND StratumCode = @StratumCode;",
                                                         new { i.CruiseID, i.PlotNumber, i.StratumCode });
                }
                else
                {
                    destination.Insert(i, option: Backpack.SqlBuilder.OnConflictOption.Replace);
                }
            }
        }
Esempio n. 30
0
        private void SyncTallyLedger(string cruiseID, DbConnection source, DbConnection destination, CruiseSyncOptions options)
        {
            var deletedItems = source.From <TallyLedger_Tombstone>()
                               .Where("CruiseID = @p1")
                               .Query(cruiseID);

            foreach (var i in deletedItems)
            {
                var match = destination.From <TallyLedger>()
                            .Where("TallyLedgerID = @TallyLedgerID")
                            .Query2(i.TallyLedgerID)
                            .FirstOrDefault();

                if (match != null)
                {
                    var x = destination.ExecuteNonQuery2("DELETE FROM TallyLedger WHERE TallyLedgerID = @TallyLedgerID;",
                                                         new { i.TallyLedgerID });
                }
                else
                {
                    destination.Insert(i, option: Backpack.SqlBuilder.OnConflictOption.Replace);
                }
            }
        }