Skip to content

Commit

Permalink
Merge branch 'hotfix/v2.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
lhSunde committed Dec 9, 2020
2 parents 16ee470 + 7c1ffcf commit d55d4c1
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 43 deletions.
6 changes: 5 additions & 1 deletion src/Arkivverket.Arkade.CLI/AnalyseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class AnalyseOptions : Options
[Option('f', "format-analysis", HelpText = "Recursively performs PRONOM format analysis on all files in a directory.", Required = true)]
public string FormatCheckTarget { get; set; }

[Option('O', "output-filename", HelpText = "Optional. Overrides default output filename.")]
public string OutputFileName { get; set; }

[Usage(ApplicationAlias = "arkade")]
public static IEnumerable<Example> Examples
{
Expand All @@ -19,7 +22,8 @@ public static IEnumerable<Example> Examples
new AnalyseOptions
{
OutputDirectory = "outputDirectory",
FormatCheckTarget = "/path/to/directory"
FormatCheckTarget = "/path/to/directory",
OutputFileName = "myFormatInfoFile.csv",
});
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/Arkivverket.Arkade.CLI/CommandLineRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ public static void Run(AnalyseOptions options)
string command = GetRunningCommand(options.GetType().Name);

Log.Information($"{{{command.TrimEnd('e')}ing}} format of all content in {options.FormatCheckTarget}");
Arkade.GenerateFileFormatInfoFiles(new DirectoryInfo(options.FormatCheckTarget), options.OutputDirectory);
string outputFileName = options.OutputFileName ?? string.Format(
ArkadeConstants.FileFormatInfoFileName,
Path.GetFileName(options.FormatCheckTarget)
);
Arkade.GenerateFileFormatInfoFiles(
new DirectoryInfo(options.FormatCheckTarget), options.OutputDirectory, outputFileName
);

LogFinishedStatus(command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public class FileFormatInfoGeneratorTests
public void GenerateTest()
{
string workingDirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestData", "Report", "FilesToBeListed");
string testFilePath = Path.Combine(workingDirectoryPath, ArkadeConstants.FileFormatInfoFileName);
string testFilePath = Path.Combine(workingDirectoryPath, string.Format(ArkadeConstants.FileFormatInfoFileName, "FilesToBeListed"));

var testArchive = new Archive(ArchiveType.Noark5, null,
new WorkingDirectory(new DirectoryInfo(workingDirectoryPath)));

if (File.Exists(testFilePath))
File.Delete(testFilePath);

FileFormatInfoGenerator.Generate(testArchive.GetDocumentsDirectory(), workingDirectoryPath);
FileFormatInfoGenerator.Generate(testArchive.GetDocumentsDirectory(), testFilePath, true);

File.Exists(testFilePath).Should().BeTrue();

Expand Down
4 changes: 2 additions & 2 deletions src/Arkivverket.Arkade.Core/Base/Arkade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public void SaveReport(TestSession testSession, FileInfo file)
_arkadeApi.SaveReport(testSession, file);
}

public void GenerateFileFormatInfoFiles(DirectoryInfo filesDirectory, string resultFileDirectoryPath)
public void GenerateFileFormatInfoFiles(DirectoryInfo filesDirectory, string resultFileDirectoryPath, string resultFileName)
{
_arkadeApi.GenerateFileFormatInfoFiles(filesDirectory, resultFileDirectoryPath);
_arkadeApi.GenerateFileFormatInfoFiles(filesDirectory, resultFileDirectoryPath, resultFileName);
}

public ArchiveType? DetectArchiveType(string archiveFileName)
Expand Down
6 changes: 4 additions & 2 deletions src/Arkivverket.Arkade.Core/Base/ArkadeApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ public void SaveReport(TestSession testSession, FileInfo file)
}
}

public void GenerateFileFormatInfoFiles(DirectoryInfo filesDirectory, string resultFileDirectoryPath)
public void GenerateFileFormatInfoFiles(DirectoryInfo filesDirectory, string resultFileDirectoryPath, string resultFileName)
{
FileFormatInfoGenerator.Generate(filesDirectory, resultFileDirectoryPath);
string resultFileFullName = Path.Combine(resultFileDirectoryPath, resultFileName);

FileFormatInfoGenerator.Generate(filesDirectory, resultFileFullName);
}

public ArchiveType? DetectArchiveType(string archiveFileName)
Expand Down
6 changes: 5 additions & 1 deletion src/Arkivverket.Arkade.Core/Metadata/MetadataFilesCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ public void Create(Archive archive, ArchiveMetadata metadata, bool generateDocum
if (generateDocumentFileInfo)
{
string resultFileDirectoryPath = archive.WorkingDirectory.AdministrativeMetadata().DirectoryInfo().FullName;
DirectoryInfo documentsDirectory = archive.GetDocumentsDirectory();
string resultFileName = string.Format(ArkadeConstants.FileFormatInfoFileName, documentsDirectory.Name);
string resultFileFullName = Path.Combine(resultFileDirectoryPath, resultFileName);

try
{
FileFormatInfoGenerator.Generate(archive.GetDocumentsDirectory(), resultFileDirectoryPath);
FileFormatInfoGenerator.Generate(documentsDirectory, resultFileFullName, true);
}
catch (SiegfriedFileFormatIdentifierException siegfriedException)
{
Expand Down
37 changes: 21 additions & 16 deletions src/Arkivverket.Arkade.Core/Report/FileFormatInfoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ namespace Arkivverket.Arkade.Core.Report
public static class FileFormatInfoGenerator
{
private static readonly List<FileTypeStatisticsElement> AmountOfFilesPerFileType = new List<FileTypeStatisticsElement>();
private static readonly List<ListElement> ListElements = new List<ListElement>();

public static void Generate(DirectoryInfo filesDirectory, string resultFileDirectoryPath)
public static void Generate(DirectoryInfo filesDirectory, string resultFileFullPath, bool filesAreReferencedFromFilesDirectoryParent = false)
{
var listElements = new List<ListElement>();

IEnumerable<SiegfriedFileInfo> siegfriedFileInfoSet = GetFormatInfoAllFiles(filesDirectory);

ArrangeFileFormatStatistics(siegfriedFileInfoSet, filesDirectory.Parent?.Parent);
DirectoryInfo startDirectory = filesAreReferencedFromFilesDirectoryParent
? filesDirectory.Parent
: filesDirectory;

ArrangeFileFormatStatistics(siegfriedFileInfoSet, startDirectory, listElements);

WriteFileList(resultFileDirectoryPath);
WriteFileList(resultFileFullPath, listElements);

WriteFileTypeStatisticsFile(resultFileDirectoryPath);
WriteFileTypeStatisticsFile(resultFileFullPath);
}

private static IEnumerable<SiegfriedFileInfo> GetFormatInfoAllFiles(DirectoryInfo directory)
Expand All @@ -32,17 +37,17 @@ private static IEnumerable<SiegfriedFileInfo> GetFormatInfoAllFiles(DirectoryInf
}

private static void ArrangeFileFormatStatistics(IEnumerable<SiegfriedFileInfo> siegfriedFileInfoSet,
DirectoryInfo startDirectory)
DirectoryInfo startDirectory, List<ListElement> listElements)
{
foreach (SiegfriedFileInfo siegfriedFileInfo in siegfriedFileInfoSet)
{
string fileName = startDirectory != null
? Path.GetRelativePath(startDirectory.FullName, siegfriedFileInfo.FileName)
string fileName = startDirectory?.Parent != null
? Path.GetRelativePath(startDirectory.Parent.FullName, siegfriedFileInfo.FileName)
: siegfriedFileInfo.FileName;

var documentFileListElement = new ListElement
{
FileName = fileName,
FileName = fileName.Replace('\\','/'),
FileExtension = siegfriedFileInfo.FileExtension,
FileFormatPuId = siegfriedFileInfo.Id,
FileFormatName = siegfriedFileInfo.Format,
Expand All @@ -51,7 +56,7 @@ private static void ArrangeFileFormatStatistics(IEnumerable<SiegfriedFileInfo> s
FileScanError = siegfriedFileInfo.Errors,
};

ListElements.Add(documentFileListElement);
listElements.Add(documentFileListElement);

string key = documentFileListElement.FileFormatPuId + " - " + documentFileListElement.FileFormatName;

Expand All @@ -71,20 +76,20 @@ private static void ArrangeFileFormatStatistics(IEnumerable<SiegfriedFileInfo> s
}
}

private static void WriteFileList(string fileLocation)
private static void WriteFileList(string fullFileName, List<ListElement> listElements)
{
string fullFileName = Path.Combine(fileLocation, ArkadeConstants.FileFormatInfoFileName);

using (var writer = new StreamWriter(fullFileName))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(ListElements);
csv.WriteRecords(listElements);
}
}

private static void WriteFileTypeStatisticsFile(string fileLocation)
private static void WriteFileTypeStatisticsFile(string fileFormatInfoFileName)
{
string fullFileName = Path.Combine(fileLocation, ArkadeConstants.FileFormatInfoStatisticsFileName);
string fullFileName = Path.Combine(Path.GetDirectoryName(fileFormatInfoFileName),
string.Format(ArkadeConstants.FileFormatInfoStatisticsFileName,
Path.GetFileNameWithoutExtension(fileFormatInfoFileName)));

using (var writer = new StreamWriter(fullFileName))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Arkivverket.Arkade.Core/Util/ArkadeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class ArkadeConstants
public const string SiegfriedWindowsExecutable = "siegfried.exe";
public const string Noark5TestListFileName = "noark5-testlist.txt";
public const string MetadataFileName = "arkade-ip-metadata.json";
public const string FileFormatInfoFileName = "fileformatinfo.csv";
public const string FileFormatInfoStatisticsFileName = "fileformatinfo-statistics.csv";
public const string FileFormatInfoFileName = "{0}-fileformatinfo.csv";
public const string FileFormatInfoStatisticsFileName = "{0}-statistics.csv";
public struct FileFormatInfoHeaders
{
public const string FileName = "Filnavn";
Expand Down
18 changes: 18 additions & 0 deletions src/Arkivverket.Arkade.GUI/Resources/ToolsGUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/Arkivverket.Arkade.GUI/Resources/ToolsGUI.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ChooseDirectoryToAnalyse" xml:space="preserve">
<value>Velg katalog hvis innhold skal analyseres</value>
</data>
<data name="CloseDialogButtonText" xml:space="preserve">
<value>Lukk</value>
</data>
Expand Down Expand Up @@ -145,6 +148,9 @@ Resultat lagret i:</value>
<data name="FormatCheckRunButtonText" xml:space="preserve">
<value>Kjør</value>
</data>
<data name="SaveFormatFileExtensionFilter" xml:space="preserve">
<value>CSV (Semikolondelt) (*.csv)|*.csv</value>
</data>
<data name="ToolsDialogTitle" xml:space="preserve">
<value>Verktøy</value>
</data>
Expand Down
49 changes: 34 additions & 15 deletions src/Arkivverket.Arkade.GUI/ViewModels/ToolsDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
Expand Down Expand Up @@ -77,7 +77,7 @@ private void ChooseDirectoryForFormatCheck()
FormatCheckStatus = string.Empty;

DirectoryPicker(Resources.ToolsGUI.FormatCheckActionChooseTargetDirectory,
null,
Resources.ToolsGUI.ChooseDirectoryToAnalyse,
out string directoryForFormatCheck
);

Expand All @@ -90,15 +90,33 @@ out string directoryForFormatCheck

private async void RunFormatCheck()
{
DirectoryPicker(Resources.ToolsGUI.FormatCheckActionChooseOutputDirectory,
Resources.ToolsGUI.FormatCheckOutputDirectoryPickerTitle,
out string directoryToSaveFormatCheckResults
);
string action = Resources.ToolsGUI.FormatCheckActionChooseOutputDirectory;

_log.Information($"User action: Open choose directory for {action} dialog");

if (directoryToSaveFormatCheckResults == null)
var saveFileDialog = new SaveFileDialog
{
Title = Resources.ToolsGUI.FormatCheckOutputDirectoryPickerTitle,
DefaultExt = "csv",
AddExtension = true,
Filter = Resources.ToolsGUI.SaveFormatFileExtensionFilter,
FileName = string.Format(
ArkadeConstants.FileFormatInfoFileName,
Path.GetFileName(DirectoryForFormatCheck)
)
};

if (saveFileDialog.ShowDialog() != DialogResult.OK)
{
_log.Information($"User action: Abort choose directory for {action}");
return;

DirectoryToSaveFormatCheckResult = directoryToSaveFormatCheckResults;
}

string filePath = saveFileDialog.FileName;

_log.Information($"User action: Chose directory for {action}: {filePath}");

DirectoryToSaveFormatCheckResult = Path.GetDirectoryName(filePath);

await Task.Run(
() =>
Expand All @@ -107,14 +125,13 @@ await Task.Run(
CloseButtonIsEnabled = false;
ProgressBarVisibility = Visibility.Visible;

_arkadeApi.GenerateFileFormatInfoFiles(new DirectoryInfo(DirectoryForFormatCheck), DirectoryToSaveFormatCheckResult);
_arkadeApi.GenerateFileFormatInfoFiles(new DirectoryInfo(DirectoryForFormatCheck),
DirectoryToSaveFormatCheckResult, Path.GetFileName(filePath));
});

CloseButtonIsEnabled = true;
ProgressBarVisibility = Visibility.Hidden;

string filePath = $"{Path.Combine(DirectoryToSaveFormatCheckResult, ArkadeConstants.FileFormatInfoFileName)}";

FormatCheckStatus = $"{Resources.ToolsGUI.FormatCheckCompletedMessage}\n" +
$"{filePath}";

Expand All @@ -126,10 +143,12 @@ private void DirectoryPicker(string action, string title, out string directory)
{
_log.Information($"User action: Open choose directory for {action} dialog");

var selectDirectoryDialog = new FolderBrowserDialog();
var selectDirectoryDialog = new FolderBrowserDialog
{
Description = title,
UseDescriptionForTitle = true,
};

if (title != null)
selectDirectoryDialog.Description = title;

if (selectDirectoryDialog.ShowDialog() == DialogResult.OK)
{
Expand Down

0 comments on commit d55d4c1

Please sign in to comment.