Skip to content

Commit 4f85506

Browse files
committed
moved things out of ctor into 1st validation call
1 parent 765ddda commit 4f85506

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

PDfAValidatorTest/PdfAValidatorTest.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static void ShouldUnpackNewDirectoryInTempdirectory()
1313
var listOfDirectoriesInTempWithoutVeraPdf = Directory.GetDirectories(Path.GetTempPath());
1414
using (var pdfAValidator = new PdfAValidator.PdfAValidator())
1515
{
16+
pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOffice.pdf");
1617
AssertVeraPdfBinCreation(listOfDirectoriesInTempWithoutVeraPdf, pdfAValidator);
1718
}
1819
var listOfDirectoriesInTempAfterVeraPdf = Directory.GetDirectories(Path.GetTempPath());
@@ -72,12 +73,15 @@ public static void ShouldWorkWithCustomJavaAndVeraPdfLocation()
7273
var listOfDirectoriesInTempWithoutVeraPdf = Directory.GetDirectories(Path.GetTempPath());
7374
using (var pdfAValidatorPrepareBins = new PdfAValidator.PdfAValidator())
7475
{
75-
using (var pdfAValidator = new PdfAValidator.PdfAValidator(pdfAValidatorPrepareBins.VeraPdfStartScript, pdfAValidatorPrepareBins.PathJava))
7676
{
77-
AssertVeraPdfBinCreation(listOfDirectoriesInTempWithoutVeraPdf, pdfAValidator);
78-
Assert.True(File.Exists(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf"));
79-
var result = pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
80-
Assert.False(result);
77+
pdfAValidatorPrepareBins.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
78+
using (var pdfAValidator = new PdfAValidator.PdfAValidator(pdfAValidatorPrepareBins.VeraPdfStartScript, pdfAValidatorPrepareBins.PathJava))
79+
{
80+
AssertVeraPdfBinCreation(listOfDirectoriesInTempWithoutVeraPdf, pdfAValidator);
81+
Assert.True(File.Exists(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf"));
82+
var result = pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
83+
Assert.False(result);
84+
}
8185
}
8286
}
8387
var listOfDirectoriesInTempAfterVeraPdf = Directory.GetDirectories(Path.GetTempPath());

PdfAValidator/PdfAValidator.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Xml.Serialization;
99

1010
// TODO Fix the generated casing in report.cs
11-
// TODO Move stuff out of ctor
1211

1312
namespace PdfAValidator
1413
{
@@ -17,6 +16,23 @@ namespace PdfAValidator
1716
/// </summary>
1817
public class PdfAValidator : IDisposable
1918
{
19+
private const string maskedQuote = "\"";
20+
private string _pathVeraPdfDirectory;
21+
/// <summary>
22+
/// Path to java jre used by windows
23+
/// </summary>
24+
/// <value></value>
25+
public string PathJava { private set; get; }
26+
27+
private readonly bool _customVerapdfAndJavaLocations;
28+
29+
private bool isInitilized { get; set; }
30+
31+
/// <summary>
32+
/// Command that is used to invoke VeraPdf
33+
/// </summary>
34+
/// <value>Command with arguments</value>
35+
public string VeraPdfStartScript { private set; get; }
2036
/// <summary>
2137
/// Disposing verapdf bins
2238
/// </summary>
@@ -27,7 +43,6 @@ public void Dispose()
2743
Directory.Delete(_pathVeraPdfDirectory, true);
2844
}
2945
}
30-
3146
/// <summary>
3247
/// Use this constructor to use your own installation of VeraPdf and Java, e.g.: c:\somePath\verapdf.bat
3348
/// </summary>
@@ -38,28 +53,16 @@ public PdfAValidator(string pathToVeraPdfBin, string pathToJava)
3853
VeraPdfStartScript = pathToVeraPdfBin;
3954
PathJava = pathToJava;
4055
_customVerapdfAndJavaLocations = true;
56+
isInitilized = true;
4157
}
4258

4359
/// <summary>
4460
/// Use this constructor to use the embedded veraPdf binaries
4561
/// </summary>
4662
public PdfAValidator()
47-
{ intiPathToVeraPdfBinAndJava(); }
63+
{ }
4864

49-
private const string maskedQuote = "\"";
50-
private string _pathVeraPdfDirectory;
51-
/// <summary>
52-
/// Path to java jre used by windows
53-
/// </summary>
54-
/// <value></value>
55-
public string PathJava { private set; get; }
5665

57-
private readonly bool _customVerapdfAndJavaLocations;
58-
/// <summary>
59-
///
60-
/// </summary>
61-
/// <value></value>
62-
public string VeraPdfStartScript { private set; get; }
6366
/// <summary>
6467
/// Validates a pdf to be compliant with the pdfa standard claimed by its meta data
6568
/// </summary>
@@ -76,6 +79,7 @@ public bool Validate(string pathToPdfFile)
7679
/// <returns></returns>
7780
public report ValidateWithDetailedReport(string pathToPdfFile)
7881
{
82+
intiPathToVeraPdfBinAndJava();
7983
var absolutePathToPdfFile = Path.GetFullPath(pathToPdfFile);
8084

8185
if (!File.Exists(absolutePathToPdfFile))
@@ -131,10 +135,13 @@ private static T DeserializeXml<T>(string sourceXML) where T : class
131135
result = (T)serializer.Deserialize(reader);
132136
return result;
133137
}
134-
135-
136138
private void intiPathToVeraPdfBinAndJava()
137139
{
140+
if (isInitilized)
141+
{
142+
return;
143+
}
144+
138145
_pathVeraPdfDirectory = Path.Combine(Path.GetTempPath(), "VeraPdf" + Guid.NewGuid());
139146
Directory.CreateDirectory(_pathVeraPdfDirectory);
140147

@@ -155,6 +162,7 @@ private void intiPathToVeraPdfBinAndJava()
155162
{
156163
throw new NotImplementedException("Sorry, only supporting linux and windows.");
157164
}
165+
isInitilized = true;
158166
}
159167

160168
private static void SetLinuxFileExecuteable(string filePath)

PdfAValidator/PdfAValidator.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<PackageTags>Pdf PdfA VeraPdf Pdf/A</PackageTags>
88
<Authors>Stefan Seeland</Authors>
99
<Company>Codeuctivity</Company>
10-
<AssemblyVersion>1.0.0.20</AssemblyVersion>
11-
<FileVersion>1.0.0.20</FileVersion>
12-
<Version>1.0.20</Version>
10+
<AssemblyVersion>1.0.0.21</AssemblyVersion>
11+
<FileVersion>1.0.0.21</FileVersion>
12+
<Version>1.0.21</Version>
1313
<PackageIconUrl>https://avatars3.githubusercontent.com/u/8453155?v=2&amp;s=200</PackageIconUrl>
1414
<PackageProjectUrl>https://github.com/Codeuctivity/PdfAValidatorApi</PackageProjectUrl>
1515
<Description>PdfAValidator is based on VeraPdf and is an open source conformance checker for PDF/A files. It is designed to help archives and libraries check that their PDF/A collections conform to the appropriate ISO 19005 archiving standard specification.</Description>

0 commit comments

Comments
 (0)