-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the DatFileDeletor as a post processing step
- Loading branch information
1 parent
087a014
commit 3c98e1c
Showing
5 changed files
with
120 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,64 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
using Automation; | ||
using Automation.ResultFiles; | ||
using CalcPostProcessor.Steps; | ||
using Common; | ||
using Common.SQLResultLogging; | ||
using Common.SQLResultLogging.InputLoggers; | ||
|
||
namespace CalcPostProcessor.GeneralSteps | ||
{ | ||
/// <summary> | ||
/// A postprocessing step that deletes all .dat files created during the calculation | ||
/// </summary> | ||
[SuppressMessage("ReSharper", "RedundantNameQualifier")] | ||
public class DatFileDeletor: GeneralStepBase | ||
public class DatFileDeletor : GeneralStepBase | ||
{ | ||
[JetBrains.Annotations.NotNull] | ||
private readonly IFileFactoryAndTracker _fft; | ||
private readonly SqlResultLoggingService _srls; | ||
|
||
public DatFileDeletor([JetBrains.Annotations.NotNull] CalcDataRepository repository, [JetBrains.Annotations.NotNull] ICalculationProfiler calculationProfiler, | ||
[JetBrains.Annotations.NotNull] IFileFactoryAndTracker fft) | ||
[JetBrains.Annotations.NotNull] SqlResultLoggingService srls) | ||
: base(repository, AutomationUtili.GetOptionList(CalcOption.HouseholdContents), calculationProfiler, "Delete .dat files", 0) | ||
{ | ||
_fft = fft; | ||
_srls = srls; | ||
} | ||
|
||
/// <summary> | ||
/// Performs the postprocessing step by calling the method to delete .dat files | ||
/// </summary> | ||
/// <param name="parameters"></param> | ||
protected override void PerformActualStep(IStepParameters parameters) | ||
{ | ||
// insert deleting function here | ||
DeleteDatFiles(); | ||
} | ||
|
||
/// <summary> | ||
/// Deletes all .dat files if the CalcOption DeleteDatFiles is set | ||
/// </summary> | ||
private void DeleteDatFiles() | ||
{ | ||
if (Repository.CalcParameters.IsSet(CalcOption.DeleteDatFiles)) | ||
{ | ||
// load a list of all created files from the database | ||
ResultFileEntryLogger rfel = new ResultFileEntryLogger(_srls); | ||
var resultFileEntries = rfel.Load(); | ||
// filter all result files ending with .dat | ||
var datFileEntries = resultFileEntries.Where(f => f.FileName.ToUpperInvariant().EndsWith(".DAT", StringComparison.Ordinal)); | ||
foreach (var datFile in datFileEntries) | ||
{ | ||
File.Delete(datFile.FullFileName); | ||
// remove file entry from the result file list in the database | ||
rfel.DeleteEntry(datFile); | ||
} | ||
} | ||
} | ||
|
||
[JetBrains.Annotations.NotNull] | ||
public override List<CalcOption> NeededOptions => new List<CalcOption>() {CalcOption.DeleteDatFiles}; | ||
public override List<CalcOption> NeededOptions => new List<CalcOption>() { CalcOption.DeleteDatFiles }; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters