private static void RunTest([NotNull] Action <GeneralConfig> setOption, [NotNull] string name)
        {
            CleanTestBase.RunAutomatically(false);
            using (var wd1 = new WorkingDir(Utili.GetCurrentMethodAndClass() + name))
            {
                Logger.Threshold = Severity.Error;
                var path = wd1.WorkingDirectory;

                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }
                Directory.CreateDirectory(path);
                using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
                {
                    var sim = new Simulator(db.ConnectionString);
                    Config.IsInUnitTesting       = true;
                    Config.ExtraUnitTestChecking = false;
                    sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles);
                    sim.MyGeneralConfig.WriteExcelColumn = "False";
                    //if (setOption == null) { throw new LPGException("Action was null."); }
                    setOption(sim.MyGeneralConfig);

                    Logger.Info("Temperature:" + sim.MyGeneralConfig.SelectedTemperatureProfile);
                    Logger.Info("Geographic:" + sim.MyGeneralConfig.GeographicLocation);
                    sim.Should().NotBeNull();
                    var cmf = new CalcManagerFactory();
                    CalculationProfiler   calculationProfiler = new CalculationProfiler();
                    CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0],
                                                                           sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.Random,
                                                                           false, null, LoadTypePriority.All, null, null, null,
                                                                           sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2018, 1, 1), new DateTime(2018, 1, 2), new TimeSpan(0, 1, 0),
                                                                           ";", 5, new TimeSpan(0, 10, 0), false, false, false, 3, 3,
                                                                           calculationProfiler, wd1.WorkingDirectory, false);
                    var cm = cmf.GetCalcManager(sim, csps, false);
Exemplo n.º 2
0
        public void GetCalcManagerHouseTest()
        {
            using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
                {
                    var sim = new Simulator(db.ConnectionString);
                    sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.OnlyOverallSum);

                    //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig);
                    sim.Should().NotBeNull();

                    var cmf = new CalcManagerFactory();
                    CalculationProfiler   calculationProfiler = new CalculationProfiler();
                    CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0],
                                                                           sim.TemperatureProfiles[0], sim.Houses[sim.Houses.MyItems.Count - 1], EnergyIntensityType.Random, false,
                                                                           null, LoadTypePriority.RecommendedForHouses, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(),
                                                                           new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3,
                                                                           calculationProfiler, wd.WorkingDirectory, false);

                    var cm = cmf.GetCalcManager(sim, csps, false);

                    cm.Run(ReportCancelFunc);
                    db.Cleanup();
                }
                wd.CleanUp();
            }
        }
Exemplo n.º 3
0
        public void GetCalcManagerModularHousehold03Test()
        {
            using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
                {
                    Config.IsInUnitTesting = true;
                    var sim = new Simulator(db.ConnectionString);
                    sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.ReasonableWithChartsAndPDF);
                    DeviceCategory light = null;
                    foreach (var deviceCategory in sim.DeviceCategories.MyItems)
                    {
                        deviceCategory.RefreshSubDevices();
                        if (deviceCategory.Name.Contains("Light"))
                        {
                            light = deviceCategory;
                        }
                    }
                    if (light != null)
                    {
                        Logger.Info(light.SubDevices.Count.ToString(CultureInfo.CurrentCulture));
                    }
                    sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles);
                    sim.MyGeneralConfig.Enable(CalcOption.TotalsPerLoadtype);
                    sim.MyGeneralConfig.Enable(CalcOption.TotalsPerDevice);
                    sim.MyGeneralConfig.Enable(CalcOption.MakePDF);
                    sim.MyGeneralConfig.Enable(CalcOption.HouseholdContents);
                    sim.Should().NotBeNull();
                    var cmf = new CalcManagerFactory();
                    ModularHousehold chs3 = null;
                    foreach (var modularHousehold in sim.ModularHouseholds.MyItems)
                    {
                        if (modularHousehold.Name.StartsWith("CHS01", StringComparison.Ordinal))
                        {
                            chs3 = modularHousehold;
                        }
                    }
                    if (chs3 == null)
                    {
                        throw new LPGException("Could not find the household CHS01");
                    }
                    Logger.Info(chs3.ToString());
                    CalculationProfiler   calculationProfiler = new CalculationProfiler();
                    CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0],
                                                                           sim.TemperatureProfiles[0], chs3, EnergyIntensityType.Random, false,
                                                                           null, LoadTypePriority.Mandatory, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(),
                                                                           new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3,
                                                                           calculationProfiler, wd.WorkingDirectory, false);

                    var cm = cmf.GetCalcManager(sim, csps, false);

                    cm.Run(ReportCancelFunc);
                    cm.Dispose();
                    db.Cleanup();
                }
                wd.CleanUp();
            }
        }
Exemplo n.º 4
0
        public void TimeOffsetBugTest()
        {
            Config.AdjustTimesForSettlement = false;
            CleanTestBase.RunAutomatically(false);
            var start = DateTime.Now;

            using (var wd1 = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                var path = wd1.WorkingDirectory;
                Config.MakePDFCharts = false;
                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }
                Directory.CreateDirectory(path);
                using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
                {
                    var sim       = new Simulator(db.ConnectionString);
                    var calcstart = DateTime.Now;
                    sim.MyGeneralConfig.StartDateUIString      = "1.1.2015";
                    sim.MyGeneralConfig.EndDateUIString        = "31.1.2015";
                    sim.MyGeneralConfig.InternalTimeResolution = "00:01:00";
                    sim.MyGeneralConfig.RandomSeed             = 5;
                    sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.Reasonable);
                    sim.MyGeneralConfig.ShowSettlingPeriod       = "false";
                    sim.MyGeneralConfig.CSVCharacter             = ";";
                    sim.MyGeneralConfig.SelectedLoadTypePriority = LoadTypePriority.RecommendedForHouseholds;
                    SimIntegrityChecker.Run(sim);

                    sim.Should().NotBeNull();

                    var cmf = new CalcManagerFactory();
                    //CalcDevice.UseRanges = true;
                    var geoloc = sim.GeographicLocations.FindFirstByName("Chemnitz", FindMode.Partial);
                    if (geoloc == null)
                    {
                        throw new LPGException("Geoloc was null");
                    }
                    var chh =
                        sim.ModularHouseholds.It.First(x => x.Name.StartsWith("CHR09", StringComparison.Ordinal));
                    CalculationProfiler calculationProfiler = new CalculationProfiler();

                    CalcStartParameterSet csps = new CalcStartParameterSet(geoloc,
                                                                           sim.TemperatureProfiles[0], chh, EnergyIntensityType.Random,
                                                                           false, null,
                                                                           sim.MyGeneralConfig.SelectedLoadTypePriority, null, null, null,
                                                                           sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 1), new DateTime(2015, 1, 31),
                                                                           new TimeSpan(0, 1, 0), ";", 5, new TimeSpan(0, 1, 0),
                                                                           false, false, false, 3, 3,
                                                                           calculationProfiler, wd1.WorkingDirectory, false);
                    var cm = cmf.GetCalcManager(sim, csps, false);
Exemplo n.º 5
0
        public void DumpHouseholdContentsToTextTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) {
                using (var wd1 = new WorkingDir(Utili.GetCurrentMethodAndClass())) {
                    var sim = new Simulator(db.ConnectionString)
                    {
                        MyGeneralConfig =
                        {
                            StartDateUIString      = "01.01.2015",
                            EndDateUIString        = "02.01.2015",
                            InternalTimeResolution = "00:01:00",
                            ExternalTimeResolution = "00:15:00",
                            RandomSeed             = 5
                        }
                    };
                    sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles);
                    sim.MyGeneralConfig.Enable(CalcOption.TotalsPerDevice);
                    sim.MyGeneralConfig.CSVCharacter = ";";
                    //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig);
                    sim.Should().NotBeNull();
                    SimIntegrityChecker.Run(sim);
                    CalcManagerFactory.DoIntegrityRun = false;

                    var cmf = new CalcManagerFactory();
                    var calculationProfiler = new CalculationProfiler();
                    var csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0],
                                                         EnergyIntensityType.Random, false, null, LoadTypePriority.RecommendedForHouses, null, null, null,
                                                         sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 1), new DateTime(2015, 1, 2), new TimeSpan(0, 1, 0), ";", 5,
                                                         new TimeSpan(0, 15, 0), false, false, false, 3, 3, calculationProfiler, wd1.WorkingDirectory, false);
                    var cm = cmf.GetCalcManager(sim, csps, false);
                    //,, wd1.WorkingDirectory, sim.ModularHouseholds[0], false,
                    //sim.TemperatureProfiles[0], sim.GeographicLocations[0], EnergyIntensityType.Random, version,
                    //LoadTypePriority.RecommendedForHouses, null,null
                    var dls = new DayLightStatus(new BitArray(100));
                    if (cm.CalcObject == null)
                    {
                        throw new LPGException("xxx");
                    }

                    cm.CalcObject.Init(dls, 1);
                    CalcManager.ExitCalcFunction = true;
                    cm.CalcObject.DumpHouseholdContentsToText();
                    cm.Dispose();

                    db.Cleanup();
                    wd1.CleanUp();
                }
            }
        }
Exemplo n.º 6
0
        public void Run()
        {
            using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
                {
                    var sim = new Simulator(db.ConnectionString);
                    var calculationProfiler = new CalculationProfiler();
                    var csps = new CalcStartParameterSet(sim.GeographicLocations[0],
                                                         sim.TemperatureProfiles[0],
                                                         sim.ModularHouseholds[0],
                                                         EnergyIntensityType.EnergySaving,
                                                         false,
                                                         null,
                                                         LoadTypePriority.OptionalLoadtypes,
                                                         null,
                                                         null,
                                                         null,
                                                         new List <CalcOption>(),
                                                         new DateTime(2018, 1, 1),
                                                         new DateTime(2018, 1, 10),
                                                         new TimeSpan(0, 1, 0),
                                                         ";",
                                                         1,
                                                         new TimeSpan(0, 1, 0),
                                                         false,
                                                         false,
                                                         false,
                                                         3,
                                                         3,
                                                         calculationProfiler, wd.WorkingDirectory, false);
                    var cmf = new CalcManagerFactory();
                    var cm  = cmf.GetCalcManager(sim, csps, false);
                    cm.Run(null);

                    var mq = new Mock <ICalculationProfiler>();
                    wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService));
                    //FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory,"objname",cm.Logfile.FileFactoryAndTracker);
                    //fft.RegisterHouseholdKey(Constants.GeneralHouseholdKey,"general");
                    //fft.RegisterHouseholdKey(Constants.GeneralHouseholdKey,"general");
                    var pcm = new PostProcessingManager(mq.Object, cm.CalcRepo.FileFactoryAndTracker);
                    //Debug.Assert(calcResult != null, nameof(calcResult) + " != null");
                    pcm.Run(wd.WorkingDirectory);
                    db.Cleanup();
                }
                wd.CleanUp();
            }
        }
Exemplo n.º 7
0
        private static void CalculateOneHousehold([NotNull] string path)
        {
            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
            Directory.CreateDirectory(path);
            using var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass());
            var sim = new Simulator(db.ConnectionString);

            Config.IsInUnitTesting = true;
            sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.Reasonable);
            sim.MyGeneralConfig.Enable(CalcOption.DeviceProfilesIndividualHouseholds);
            sim.MyGeneralConfig.ShowSettlingPeriodBool = true;
            //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig);

            sim.Should().NotBeNull();
            var cmf = new CalcManagerFactory();
            CalculationProfiler calculationProfiler = new CalculationProfiler();
            //todo: put in a full house with transportation
            //var house = sim.Houses.CreateNewItem()
            CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0],
                                                                   sim.TemperatureProfiles[0], sim.ModularHouseholds[0],
                                                                   EnergyIntensityType.Random, false,
                                                                   null, LoadTypePriority.Mandatory, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(),
                                                                   new DateTime(2015, 1, 15),
                                                                   new DateTime(2015, 1, 18),
                                                                   new TimeSpan(0, 1, 0), ";",
                                                                   5, new TimeSpan(0, 1, 0),
                                                                   false, false, false, 3,
                                                                   sim.MyGeneralConfig.RepetitionCount,
                                                                   calculationProfiler, path, false);

            var cm = cmf.GetCalcManager(sim, csps, false);

            bool success = cm.Run(ReportCancelFunc);

            if (!success)
            {
                throw new LPGException("Calculation failed");
            }

            db.Cleanup();
        }
        public static void StartHouse(int house)
        {
            CleanTestBase.RunAutomatically(false);
            var start = DateTime.Now;

            using (var wd1 = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                var path = wd1.WorkingDirectory;
                Config.MakePDFCharts = false;
                using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
                {
                    var sim       = new Simulator(db.ConnectionString);
                    var calcstart = DateTime.Now;
                    sim.MyGeneralConfig.StartDateUIString      = "1.1.2015";
                    sim.MyGeneralConfig.EndDateUIString        = "31.1.2015";
                    sim.MyGeneralConfig.InternalTimeResolution = "00:01:00";
                    sim.MyGeneralConfig.RandomSeed             = 5;
                    sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles);
                    sim.MyGeneralConfig.Enable(CalcOption.HouseSumProfilesFromDetailedDats);
                    sim.MyGeneralConfig.CSVCharacter             = ";";
                    sim.MyGeneralConfig.SelectedLoadTypePriority = LoadTypePriority.All;
                    SimIntegrityChecker.Run(sim);
                    //CalcParameters
                    //CalcParametersFactory.SetGlobalTimeParameters(sim.MyGeneralConfig);
                    //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig);
                    sim.Should().NotBeNull();

                    var cmf = new CalcManagerFactory();
                    //CalcDevice.UseRanges = true;
                    var geoloc = sim.GeographicLocations.FindFirstByName("Chemnitz", FindMode.Partial);
                    if (geoloc == null)
                    {
                        throw new LPGException("Geoloc was null");
                    }
                    var house1 =
                        sim.Houses.It[house];
                    CalculationProfiler   calculationProfiler = new CalculationProfiler();
                    CalcStartParameterSet csps = new CalcStartParameterSet(geoloc,
                                                                           sim.TemperatureProfiles[0], house1, EnergyIntensityType.Random, false,
                                                                           null, LoadTypePriority.All, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(),
                                                                           new DateTime(2015, 1, 1), new DateTime(2015, 1, 31), new TimeSpan(0, 1, 0), ";", 5, new TimeSpan(0, 1, 0), false, false, false, 3, 3,
                                                                           calculationProfiler, path, false);
                    var cm = cmf.GetCalcManager(sim, csps, false);
Exemplo n.º 9
0
        public void GetCalcManagerModularHouseholdTest()
        {
            using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
                {
                    var            sim   = new Simulator(db.ConnectionString);
                    DeviceCategory light = null;
                    foreach (var deviceCategory in sim.DeviceCategories.MyItems)
                    {
                        deviceCategory.RefreshSubDevices();
                        if (deviceCategory.Name.Contains("Light"))
                        {
                            light = deviceCategory;
                        }
                    }
                    if (light != null)
                    {
                        Logger.Info("Light devices:" + light.SubDevices.Count);
                    }
                    sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles);
                    sim.MyGeneralConfig.Enable(CalcOption.OverallSum);
                    sim.Should().NotBeNull();

                    var cmf = new CalcManagerFactory();
                    CalculationProfiler   calculationProfiler = new CalculationProfiler();
                    CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0],
                                                                           sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.Random, false,
                                                                           null, LoadTypePriority.Mandatory, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(),
                                                                           new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3,
                                                                           calculationProfiler, wd.WorkingDirectory, false);

                    var cm = cmf.GetCalcManager(sim, csps, false);

                    cm.Run(ReportCancelFunc);
                    db.Cleanup();
                }
                wd.CleanUp();
            }
        }
Exemplo n.º 10
0
        public void RunLocationStatisticsMakerTest()
        {
            using WorkingDir wd    = new WorkingDir(Utili.GetCurrentMethodAndClass());
            using DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass());
            Simulator sim = new Simulator(db.ConnectionString)
            {
                MyGeneralConfig = { StartDateUIString = "15.1.2015", EndDateUIString = "18.1.2015", InternalTimeResolution = "00:01:00" }
            };

            sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles);
            sim.MyGeneralConfig.Enable(CalcOption.LocationsFile);
            //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig);
            sim.Should().NotBeNull();
            sim.MyGeneralConfig.RandomSeed = 10;
            CalcManagerFactory    cmf = new CalcManagerFactory();
            CalculationProfiler   calculationProfiler = new CalculationProfiler();
            CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0],
                                                                   sim.TemperatureProfiles[0], sim.ModularHouseholds[0],
                                                                   EnergyIntensityType.Random, false, null,
                                                                   LoadTypePriority.All, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(),
                                                                   new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", 10, new TimeSpan(0, 1, 0), false, false, false, 3, 3,
                                                                   calculationProfiler, wd.WorkingDirectory, false);
            CalcManager cm = cmf.GetCalcManager(sim, csps, false);
Exemplo n.º 11
0
        public void GetCalcManagerModularHouseholdTestForDevicePicking()
        {
            using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
                {
                    var            sim   = new Simulator(db.ConnectionString);
                    DeviceCategory light = null;
                    foreach (var deviceCategory in sim.DeviceCategories.MyItems)
                    {
                        deviceCategory.RefreshSubDevices();
                        if (deviceCategory.Name.Contains("Light"))
                        {
                            light = deviceCategory;
                        }
                    }
                    if (light != null)
                    {
                        Logger.Info("Light devices:" + light.SubDevices.Count);
                    }
                    sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.OnlyOverallSum);
                    sim.Should().NotBeNull();
                    var cmf = new CalcManagerFactory();
                    CalculationProfiler   calculationProfiler = new CalculationProfiler();
                    CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0],
                                                                           sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.Random, false,
                                                                           null, LoadTypePriority.Mandatory, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(),
                                                                           new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3,
                                                                           calculationProfiler, wd.WorkingDirectory, false);

                    var cm = cmf.GetCalcManager(sim, csps, false);

                    var chh = (CalcHousehold)cm.CalcObject;
                    var devicenameByCategoryAndLocationID = new Dictionary <string, string>();
                    if (chh == null)
                    {
                        throw new LPGException("xxx");
                    }

                    foreach (var device in chh.CollectDevices())
                    {
                        var key = device.DeviceCategoryGuid + "##" + device.CalcLocation.Name;
                        if (devicenameByCategoryAndLocationID.ContainsKey(key))
                        {
                            var otherDev = devicenameByCategoryAndLocationID[key];

                            Logger.Warning("Suspicious: " + key + " dev 1:" + otherDev + " dev 2:" + device.Name);
                        }
                        else
                        {
                            devicenameByCategoryAndLocationID.Add(key, device.Name);
                        }
                    }
                    Logger.Info("-----");
                    foreach (var autoDev in chh.CollectAutoDevs())
                    {
                        var key = autoDev.DeviceCategoryGuid + "##" + autoDev.CalcLocation.Name;
                        if (devicenameByCategoryAndLocationID.ContainsKey(key))
                        {
                            var devicename = devicenameByCategoryAndLocationID[key];
                            if (devicename != autoDev.Name)
                            {
                                Logger.Warning("For " + key + " it should be " + devicename + " but it is " + autoDev.Name);
                            }
                        }
                    }
                    cm.CalcRepo.Logfile.Dispose();
                    db.Cleanup();
                }
                wd.CleanUp();
            }
        }
        private static bool RunOneCalcEntry([NotNull] CalcStartParameterSet csps, [NotNull] Simulator sim, bool forceRandom)
        {
            CalcManager.StartRunning();
            Logger.Info("Running the simulation for " + csps.CalcTarget.Name + " from " +
                        sim.MyGeneralConfig.StartDateDateTime.ToShortDateString() + " to " +
                        sim.MyGeneralConfig.EndDateDateTime.ToShortDateString());
            CalcManager calcManager = null;

            try {
                var cmf = new CalcManagerFactory();
                calcManager = cmf.GetCalcManager(sim, csps, forceRandom);
                //, forceRandom,
                //temperatureProfile,  geographicLocation, calcEntry.EnergyIntensity,
                //fileVersion, loadTypePriority, deviceSelection, transportationDeviceSet, travelRouteSet);
                _calcManagers.Add(calcManager);

                /*CalcObjectType cot;
                 * if (calcEntry.CalcObject.GetType() == typeof(ModularHousehold)) {
                 *  cot = CalcObjectType.ModularHousehold;
                 * }
                 * else if (calcEntry.CalcObject.GetType() == typeof(House)) {
                 *  cot = CalcObjectType.House;
                 * }
                 * else if (calcEntry.CalcObject.GetType() == typeof(Settlement)) {
                 *  cot = CalcObjectType.Settlement;
                 * }
                 * else {
                 *  throw new LPGException("Forgotten Calc Object Type. Please report!");
                 * }*/
                calcManager.Run(csps.ReportCancelFunc);

                Logger.Info("Finished the simulation...");
                _calcManagers.Remove(calcManager);
            }
            catch (DataIntegrityException die) {
                calcManager?.Dispose();
                if (die.Element != null)
                {
                    if (csps.OpenTabFunc == null)
                    {
                        throw new LPGException("OpenTabFunc was null");
                    }
                    if (csps.Dispatcher != null && !csps.Dispatcher.IsCorrectThread())
                    {
                        csps.Dispatcher.BeginInvoke(csps.OpenTabFunc, die.Element);
                    }
                    else
                    {
                        csps.OpenTabFunc(die.Element);
                    }
                }
                csps.ReportCancelFunc?.Invoke();

                throw;
            }
            finally {
                if (calcManager != null)
                {
                    calcManager.Dispose();
                    // ReSharper disable once RedundantAssignment
#pragma warning disable S1854   // Dead stores should be removed
#pragma warning disable IDE0059 // Value assigned to symbol is never used
                    calcManager = null;
#pragma warning restore IDE0059 // Value assigned to symbol is never used
#pragma warning restore S1854   // Dead stores should be removed
#pragma warning disable S1215   // "GC.Collect" should not be called
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
#pragma warning restore S1215 // "GC.Collect" should not be called
                    //if (Logger.Get().Errors.Count == 0) {
                    //    string finishedFile = Path.Combine(csps.ResultPath, Constants.FinishedFileFlag);
                    //    TimeSpan duration = DateTime.Now - csps.CalculationStartTime;
                    //    using (var sw = new StreamWriter(finishedFile)) {
                    //        sw.WriteLine("Finished at " + DateTime.Now);
                    //        sw.WriteLine("Duration in seconds:");
                    //        sw.WriteLine(duration.TotalSeconds);
                    //    }
                    //}
                }
            }

            return(true);
        }