public void FileFactoryAndTrackerTest()
        {
            Config.IsInUnitTesting = true;
            using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService));
                wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService));
                CalcParameters  calcParameters = CalcParametersFactory.MakeGoodDefaults();
                var             clt            = new CalcLoadType("calcloadtype", "kwh", "kW", 0.001, true, Guid.NewGuid().ToStrGuid());
                BitArray        isSick         = new BitArray(calcParameters.InternalTimesteps);
                BitArray        isOnVacation   = new BitArray(calcParameters.InternalTimesteps);
                var             personDto      = CalcPersonDto.MakeExamplePerson();
                Random          r  = new Random();
                Mock <ILogFile> lf = new Mock <ILogFile>();
                using (CalcRepo calcRepo = new CalcRepo(rnd: r, lf: lf.Object, calcParameters: calcParameters))
                {
                    CalcLocation cloc = new CalcLocation("blub", Guid.NewGuid().ToStrGuid());
                    var          cp   = new CalcPerson(personDto,
                                                       cloc, isSick, isOnVacation, calcRepo);

                    /*"personname", 1, 1, null, 1, PermittedGender.Female, lf: null,
                     * householdKey: "hh1", startingLocation: null, traitTag: "traittag",
                     * householdName: "hhname0",calcParameters:calcParameters,isSick:isSick, guid:Guid.NewGuid().ToStrGuid());
                     */
                    var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "testhh", wd.InputDataLogger);
                    fft.RegisterHousehold(new HouseholdKey("hh1"), "test key", HouseholdKeyType.Household, "desc", null, null);
                    fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general key", HouseholdKeyType.General, "desc", null, null);
                    fft.MakeFile <StreamWriter>("file1", "desc", true, ResultFileID.Actions,
                                                new HouseholdKey("hh1"), TargetDirectory.Charts, TimeSpan.FromMinutes(1),
                                                CalcOption.HouseholdContents,
                                                clt.ConvertToLoadTypeInformation(),
                                                cp.MakePersonInformation());
                    //fft.ResultFileList.WriteResultEntries(wd.WorkingDirectory);
                    ResultFileEntryLogger rfel = new ResultFileEntryLogger(wd.SqlResultLoggingService);
                    var rfes = rfel.Load();
                    rfes.Count.Should().BeGreaterThan(0);
                    //ResultFileList.ReadResultEntries(wd.WorkingDirectory);
                    fft.GetResultFileEntry(ResultFileID.Actions, clt.Name, new HouseholdKey("hh1"), cp.MakePersonInformation(), null);
                    fft.Dispose();
                }
                wd.CleanUp();
            }
        }
        public void CheckForCriticalThreshold([NotNull] CalcPerson person, [NotNull] TimeStep time, [NotNull] FileFactoryAndTracker fft,
                                              [NotNull] HouseholdKey householdKey)
        {
            if (time.ExternalStep < 0 &&
                !time.ShowSettling)
            {
                return;
            }

            var builder = new StringBuilder();

            foreach (var calcDesire in Desires)
            {
                if (calcDesire.Value.CriticalThreshold > 0)
                {
                    if (calcDesire.Value.Value < calcDesire.Value.CriticalThreshold)
                    {
                        builder.Append("1");
                    }
                    else
                    {
                        builder.Append("0");
                    }
                    builder.Append(_calcRepo.CalcParameters.CSVCharacter);
                }
            }
            if (builder.Length > 0)
            {
                var sb = new StringBuilder();
                _dsc.GenerateDateStampForTimestep(time, sb);

                if (_sw == null)
                {
                    var personNumber = _persons.Count;
                    _persons.Add(new Tuple <string, HouseholdKey>(person.Name, householdKey), personNumber);
                    _sw = fft.MakeFile <StreamWriter>(
                        "CriticalThresholdViolations." + householdKey + "." + person + ".csv",
                        "Lists the critical threshold violations for " + person, true,
                        ResultFileID.CriticalThresholdViolations, householdKey,
                        TargetDirectory.Debugging, _calcRepo.CalcParameters.InternalStepsize, CalcOption.CriticalViolations, null, person.MakePersonInformation());
                    var header = _dsc.GenerateDateStampHeader();
                    foreach (var calcDesire in Desires)
                    {
                        if (calcDesire.Value.CriticalThreshold > 0)
                        {
#pragma warning disable CC0039 // Don't concatenate strings in loops
                            header += calcDesire.Value.Name;
                            header += _calcRepo.CalcParameters.CSVCharacter;
#pragma warning restore CC0039 // Don't concatenate strings in loops
                        }
                    }
                    if (_sw == null)
                    {
                        throw new LPGException("SW was null");
                    }
                    _sw.WriteLine(header);
                }
                sb.Append(builder);
                _sw.WriteLine(sb);
            }
        }