Example #1
0
        public void Write_SimpleScenario_WritesAllValues()
        {
            // Arrange
            var i = new Injector();
            var s = i.GetSimpleScenario();

            Directory.CreateDirectory(scenDirPath);

            var field        = new ScenarioFile();
            var dairy        = new ScenarioFile();
            var scenDefaults = new ScenarioDefaults();
            var grabber      = new WeatherGrabber(@"Assets\Database\Weather");

            var sut = new ScenarioWriter(dairy, field, scenDefaults, grabber);

            // Act
            sut.Write(s, scenDirPath);

            // Assert
            bool filesMatch = checkFilesMatch(
                Path.Combine(scenDirPath, ".NIFA_dairy_scenario").ToString(),
                @"Assets\simpleScenario.NIFA_dairy_scenario");

            Assert.IsTrue(filesMatch);
        }
        public void ReadComplexEditWriteSimple()
        {
            // Arrange
            ScenarioFile     dairy       = new ScenarioFile();
            ScenarioFile     field       = new ScenarioFile();
            ScenarioDefaults d           = new ScenarioDefaults();
            WeatherGrabber   g           = new WeatherGrabber(@"Assets\Database\Weather");
            string           readPath    = @"Assets\complexScenario.NIFA_dairy_scenario";
            string           writePath   = @"Assets\IntegrationTest";
            string           comparePath = @"Assets\simpleScenario.NIFA_dairy_scenario";
            ScenarioReader   r           = new ScenarioReader(dairy, field);
            ScenarioWriter   w           = new ScenarioWriter(dairy, field, d, g);

            Directory.CreateDirectory(writePath);

            // Act
            r.Load(readPath);
            Scenario scenario = r.Parse();

            scenario.Description = "";

            scenario.Cow.BodyMass_kg                    = 635;
            scenario.Cow.DryMatterIntake_kg_d           = 24;
            scenario.Cow.MilkProduction_kg_d            = 34;
            scenario.Cow.CrudeProteinDiet_percent       = 17.6;
            scenario.Cow.StarchDiet_percent             = 12.83;
            scenario.Cow.AcidDetergentFiberDiet_percent = 26.08;

            scenario.Barn.ManureAlleyArea_m2 = 3000;
            scenario.Barn.NumberCows_cnt     = 1000;

            scenario.Lagoon.SurfaceArea_m2 = 142250;
            scenario.Lagoon.VolumeMax_m3   = 519213;

            scenario.Fertigation.Enabled           = false;
            scenario.Field.Id                      = "field";
            scenario.AnaerobicDigester.Enabled     = false;
            scenario.FineSeparator.Enabled         = false;
            scenario.NutrientRecovery.Enabled      = false;
            scenario.ReceiveOffFarmBiomass.Enabled = false;

            w.Write(scenario, writePath);

            // Assert
            Assert.IsTrue(
                checkFilesMatch(
                    comparePath, Path.Combine(writePath, ".NIFA_dairy_scenario")));
        }
        private void SaveExecute(object obj)
        {
            if (zoneEditor != null)
            {
                zoneEditor.Save();
            }
            Dispatcher      dispatcher = Dispatcher.CurrentDispatcher;
            Action <string> report     = msg => StatusText = msg;

            var s = new Task(() =>
            {
                try
                {
                    dispatcher.Invoke(() => IsUIBusy = true);
                    dispatcher.Invoke(report, string.Format("Saving back changes..."));

                    var writer     = new ScenarioWriter();
                    byte[] newFile = writer.Write(ScenarioFile);
                    dispatcher.Invoke(report, string.Format("Recompiling of {0} finished! ", EdataFileViewModel.EdataManager.FilePath));

                    EdataFileViewModel.EdataManager.ReplaceFile(OwnerFile, newFile);
                    dispatcher.Invoke(report, "Replacing new File in edata finished!");

                    EdataFileViewModel.LoadFile(EdataFileViewModel.LoadedFile);

                    EdataContentFile newOwen = EdataFileViewModel.EdataManager.Files.Single(x => x.Path == OwnerFile.Path);

                    OwnerFile = newOwen;
                    dispatcher.Invoke(report, string.Format("Saving of changes finished! {0}", EdataFileViewModel.EdataManager.FilePath));
                }
                catch (Exception ex)
                {
                    Trace.TraceError(string.Format("Error while saving scenario file: {0}", ex));
                    dispatcher.Invoke(report, "Saving interrupted - Did you start Wargame before I was ready?");
                }
                finally
                {
                    dispatcher.Invoke(() => IsUIBusy = false);
                }
            });

            s.Start();
        }