public void CalcParameterLoggerTest() { CalcParameters cp = CalcParameters.GetNew(); cp.SetStartDate(2017, 1, 1); cp.SetEndDate(2018, 1, 1); cp.Enable(CalcOption.ActivationsPerHour); using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); CalcParameterLogger cpl = new CalcParameterLogger(srls); cpl.Run(Constants.GeneralHouseholdKey, cp); GC.Collect(); GC.WaitForPendingFinalizers(); CalcParameters cp2 = cpl.Load(); GC.Collect(); GC.WaitForPendingFinalizers(); string s1 = JsonConvert.SerializeObject(cp, Formatting.Indented); string s2 = JsonConvert.SerializeObject(cp2, Formatting.Indented); s1.Should().Be(s2); cp2.IsSet(CalcOption.ActivationsPerHour).Should().BeTrue(); Assert.NotNull(cp2); wd.CleanUp(); } }
public CalcParameters MakeCalculationParametersFromConfig([NotNull] CalcStartParameterSet csps, bool forceRandom) { CalcParameters cp = CalcParameters.GetNew(); cp.LoadtypesToPostprocess = csps.LoadTypesToProcess; cp.SetDeleteDatFiles(csps.DeleteDatFiles); cp.SetWriteExcelColumn (csps.WriteExcelColumn); cp.SetManyOptionsWithClear(csps.CalcOptions); FileFactoryAndTrackerDummy fftd = new FileFactoryAndTrackerDummy(); var container =PostProcessingManager.RegisterEverything(csps.ResultPath,csps.CalculationProfiler, fftd); using (var scope = container.BeginLifetimeScope()) { var odm = scope.Resolve<OptionDependencyManager>(); odm.EnableRequiredOptions(cp.Options); } cp.SetShowSettlingPeriod(csps.ShowSettlingPeriod); cp.SetRandomSeed(csps.SelectedRandomSeed, forceRandom); cp.SetCsvCharacter(csps.CsvCharacter); cp.SetStartDate(csps.OfficialSimulationStartTime); cp.SetEndDate(csps.OfficialSimulationEndTime.AddDays(1)); cp.SetInternalTimeResolution(csps.InternalTimeResolution); cp.SetExternalTimeResolution(csps.ExternalTimeResolution); cp.SetLoadTypePriority(csps.LoadTypePriority); cp.SetSettlingDays(csps.SettlingDays); cp.SetAffordanceRepetitionCount(csps.AffordanceRepetitionCount); cp.DeviceProfileHeaderMode = csps.DeviceProfileHeaderMode; cp.IgnorePreviousActivitesWhenNeeded = csps.IgnorePreviousActivitiesWhenNeeded; cp.TransportationEnabled = csps.TransportationEnabled; if (cp.TransportationEnabled && csps.CalcTarget.CalcObjectType == CalcObjectType.House) { if (csps.ChargingStationSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } if (csps.TransportationDeviceSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } if (csps.TravelRouteSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } } if (cp.TransportationEnabled && csps.CalcTarget.CalcObjectType == CalcObjectType.ModularHousehold) { if (csps.ChargingStationSet == null) { throw new LPGException("Trying to set transportation options on a household without charging station set. That won't work."); } if (csps.TransportationDeviceSet == null) { throw new LPGException("Trying to set transportation options on a household without transportation device set. That won't work."); } if (csps.TravelRouteSet != null) { throw new LPGException("trying to set transportation options on a house. that won't work."); } } cp.CheckSettings(); //transport mode /*if (csps.TransportationDeviceSet != null || csps.TravelRouteSet != null) { cp.SetTransportMode(true); if (csps.TransportationDeviceSet == null ) { throw new DataIntegrityException("Only a transportation device set was defined, but not a travel route set. This can't work."); } if (csps.TravelRouteSet == null) { throw new DataIntegrityException("Only a travel route set was defined, but not a transportation device set. This can't work."); } }*/ return cp; }