-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
87 lines (73 loc) · 3.47 KB
/
Copy pathProgram.cs
File metadata and controls
87 lines (73 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.IO;
using GroupDocs.Metadata;
using GroupDocs.Samples.CompareMetadataVersions.Methods;
namespace GroupDocs.Samples.CompareMetadataVersions
{
public static class Program
{
private const string LicensePath = @"YOUR-LICENSE-PATH-HERE";
private static readonly string ProjectRoot = Directory.GetCurrentDirectory();
private static readonly string InputDir = Path.Combine(ProjectRoot, "resources");
private static readonly string OutputDir = Path.Combine(ProjectRoot, "output");
public static int Main()
{
try
{
SetLicense();
Directory.CreateDirectory(OutputDir);
var v1 = Path.Combine(InputDir, "document-v1.docx");
var v2 = Path.Combine(InputDir, "document-v2.docx");
if (!File.Exists(v1) || !File.Exists(v2))
{
Console.WriteLine($"FAIL missing input files at {InputDir}");
return 2;
}
var props1 = ExtractAllMetadata.Run(v1);
Assert(props1.Count > 0, $"ExtractAllMetadata v1 returned {props1.Count} properties");
var props2 = ExtractAllMetadata.Run(v2);
Assert(props2.Count > 0, $"ExtractAllMetadata v2 returned {props2.Count} properties");
var diff = CompareMetadataSets.Run(v1, v2);
Assert(diff.TotalChanges > 0, $"CompareMetadataSets found {diff.TotalChanges} total changes (added={diff.Added.Count}, removed={diff.Removed.Count}, changed={diff.Changed.Count})");
var ownership = DetectOwnershipChanges.Run(v1, v2);
Assert(true, $"DetectOwnershipChanges reported {ownership.Count} identity changes");
var revisions = DetectRevisionHistory.Run(v1, v2);
Assert(true, $"DetectRevisionHistory reported {revisions.Count} time/revision changes");
var jsonPath = Path.Combine(OutputDir, "diff.json");
ExportDiffToJson.Run(diff, jsonPath);
Assert(File.Exists(jsonPath) && new FileInfo(jsonPath).Length > 0, $"ExportDiffToJson wrote {new FileInfo(jsonPath).Length} bytes to diff.json");
var csvPath = Path.Combine(OutputDir, "diff.csv");
ExportDiffToCsv.Run(diff, csvPath);
Assert(File.Exists(csvPath) && new FileInfo(csvPath).Length > 0, $"ExportDiffToCsv wrote {new FileInfo(csvPath).Length} bytes to diff.csv");
Console.WriteLine();
Console.WriteLine("ALL PASS");
return 0;
}
catch (Exception ex)
{
Console.WriteLine($"FAIL {ex.GetType().Name}: {ex.Message}");
Console.WriteLine(ex.StackTrace);
return 1;
}
}
private static void SetLicense()
{
if (!File.Exists(LicensePath))
{
Console.WriteLine($"WARN license file not found at {LicensePath}; running in evaluation mode");
return;
}
var license = new License();
license.SetLicense(LicensePath);
Console.WriteLine("License applied");
}
private static void Assert(bool condition, string message)
{
if (!condition)
{
throw new Exception($"assert failed: {message}");
}
Console.WriteLine($"PASS {message}");
}
}
}