From ca17537d3103c887fa5e8136c4aba4a00e31dbbf Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Thu, 27 Jun 2019 17:37:40 +0200
Subject: [PATCH] hashing tool: adding expected document type in viewmodels

---
 HashingTool/ViewModel/HashComponentDataViewModel.cs      | 3 ++-
 .../ViewModel/UserControl/CustomerReportXMLFile.cs       | 3 ++-
 HashingTool/ViewModel/UserControl/HashedXMLFile.cs       | 7 +++++--
 .../ViewModel/UserControl/ManufacturerReportXMLFile.cs   | 3 ++-
 HashingTool/ViewModel/UserControl/ReportXMLFile.cs       | 9 +++++----
 HashingTool/ViewModel/UserControl/VectoJobFile.cs        | 3 ++-
 HashingTool/ViewModel/UserControl/VectoXMLFile.cs        | 6 +++---
 .../ViewModel/VerifyComponentInputDataViewModel.cs       | 3 ++-
 8 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/HashingTool/ViewModel/HashComponentDataViewModel.cs b/HashingTool/ViewModel/HashComponentDataViewModel.cs
index f8e1aab09a..e65a6bb0f2 100644
--- a/HashingTool/ViewModel/HashComponentDataViewModel.cs
+++ b/HashingTool/ViewModel/HashComponentDataViewModel.cs
@@ -43,6 +43,7 @@ using HashingTool.Helper;
 using HashingTool.Util;
 using HashingTool.ViewModel.UserControl;
 using TUGraz.VectoHashing;
+using XmlDocumentType = TUGraz.VectoCore.Utils.XmlDocumentType;
 
 namespace HashingTool.ViewModel
 {
@@ -60,7 +61,7 @@ namespace HashingTool.ViewModel
 		private DateTime? _date;
 
 		public HashComponentDataViewModel()
-			: base("Hash Component Data", false, HashingHelper.IsComponentFile)
+			: base("Hash Component Data", false, HashingHelper.IsComponentFile, XmlDocumentType.DeclarationComponentData)
 		{
 			_xmlFile.PropertyChanged += SourceChanged;
 			_saveCommand = new RelayCommand(SaveDocument,
diff --git a/HashingTool/ViewModel/UserControl/CustomerReportXMLFile.cs b/HashingTool/ViewModel/UserControl/CustomerReportXMLFile.cs
index 659c73f7db..22fc7ba328 100644
--- a/HashingTool/ViewModel/UserControl/CustomerReportXMLFile.cs
+++ b/HashingTool/ViewModel/UserControl/CustomerReportXMLFile.cs
@@ -34,6 +34,7 @@ using System.ComponentModel;
 using System.Linq;
 using System.Xml;
 using TUGraz.VectoHashing;
+using XmlDocumentType = TUGraz.VectoCore.Utils.XmlDocumentType;
 
 namespace HashingTool.ViewModel.UserControl
 {
@@ -48,7 +49,7 @@ namespace HashingTool.ViewModel.UserControl
 		private bool _manufacturerReportDigestValid;
 
 		public CustomerReportXMLFile(string name, Func<XmlDocument, IErrorLogger, bool?> contentCheck,
-			Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, contentCheck, hashValidation)
+			Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, contentCheck, XmlDocumentType.CustomerReport, hashValidation)
 		{
 			
 		}
diff --git a/HashingTool/ViewModel/UserControl/HashedXMLFile.cs b/HashingTool/ViewModel/UserControl/HashedXMLFile.cs
index 1072a9caed..fa172c3614 100644
--- a/HashingTool/ViewModel/UserControl/HashedXMLFile.cs
+++ b/HashingTool/ViewModel/UserControl/HashedXMLFile.cs
@@ -33,6 +33,7 @@ using System;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Xml;
+using XmlDocumentType = TUGraz.VectoCore.Utils.XmlDocumentType;
 
 namespace HashingTool.ViewModel.UserControl
 {
@@ -41,8 +42,10 @@ namespace HashingTool.ViewModel.UserControl
 		protected string _digestValueRead;
 		private DateTime? _date;
 
-		public HashedXMLFile(string name, Func<XmlDocument, IErrorLogger, bool?> contentCheck,
-			Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, true, contentCheck, hashValidation) {}
+		public HashedXMLFile(
+			string name, Func<XmlDocument, IErrorLogger, bool?> contentCheck, XmlDocumentType xmlDocumentType,
+			Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(
+			name, true, contentCheck, xmlDocumentType, hashValidation) { }
 
 		public string DigestValueRead
 		{
diff --git a/HashingTool/ViewModel/UserControl/ManufacturerReportXMLFile.cs b/HashingTool/ViewModel/UserControl/ManufacturerReportXMLFile.cs
index a1fbbb8832..a612e47502 100644
--- a/HashingTool/ViewModel/UserControl/ManufacturerReportXMLFile.cs
+++ b/HashingTool/ViewModel/UserControl/ManufacturerReportXMLFile.cs
@@ -40,6 +40,7 @@ using TUGraz.VectoCommon.Resources;
 using TUGraz.VectoCommon.Utils;
 using TUGraz.VectoCore.InputData.FileIO.XML.Declaration;
 using TUGraz.VectoHashing;
+using XmlDocumentType = TUGraz.VectoCore.Utils.XmlDocumentType;
 
 namespace HashingTool.ViewModel.UserControl
 {
@@ -48,7 +49,7 @@ namespace HashingTool.ViewModel.UserControl
 		private bool _manufacturerReportValid;
 
 		public ManufacturerReportXMLFile(string name, Func<XmlDocument, IErrorLogger, bool?> contentCheck,
-			Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, contentCheck, hashValidation)
+			Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, contentCheck, XmlDocumentType.ManufacturerReport, hashValidation)
 		{
 			_xmlFile.PropertyChanged += UpdateComponents;
 		}
diff --git a/HashingTool/ViewModel/UserControl/ReportXMLFile.cs b/HashingTool/ViewModel/UserControl/ReportXMLFile.cs
index dd4c831c8d..6c4c2496c1 100644
--- a/HashingTool/ViewModel/UserControl/ReportXMLFile.cs
+++ b/HashingTool/ViewModel/UserControl/ReportXMLFile.cs
@@ -37,6 +37,7 @@ using System.Xml;
 using TUGraz.VectoCommon.InputData;
 using TUGraz.VectoCore.InputData.FileIO.XML.Declaration;
 using TUGraz.VectoHashing;
+using XmlDocumentType = TUGraz.VectoCore.Utils.XmlDocumentType;
 
 namespace HashingTool.ViewModel.UserControl
 {
@@ -52,9 +53,8 @@ namespace HashingTool.ViewModel.UserControl
 		protected VectoJobFile _jobData;
 		private string _reportVin;
 
-		public ReportXMLFile(string name, Func<XmlDocument, IErrorLogger, bool?> contentCheck,
-			Action<XmlDocument, VectoXMLFile> hashValidation = null)
-			: base(name, contentCheck, hashValidation)
+		public ReportXMLFile(string name, Func<XmlDocument, IErrorLogger, bool?> contentCheck, XmlDocumentType xmlDocumentType, Action<XmlDocument, VectoXMLFile> hashValidation = null)
+			: base(name, contentCheck, xmlDocumentType, hashValidation)
 		{
 			_xmlFile.PropertyChanged += ReportChanged;
 		}
@@ -123,7 +123,8 @@ namespace HashingTool.ViewModel.UserControl
 
 				JobDigestMatchesReport = vinMatch
 										&& digestMatch;
-			} catch (Exception) {
+			} catch (Exception e) {
+				_xmlFile.LogError(e.Message);
 				JobDigestValueComputed = "";
 				JobDigestMatchesReport = false;
 			}
diff --git a/HashingTool/ViewModel/UserControl/VectoJobFile.cs b/HashingTool/ViewModel/UserControl/VectoJobFile.cs
index 814b309bf3..57fb7a4ae6 100644
--- a/HashingTool/ViewModel/UserControl/VectoJobFile.cs
+++ b/HashingTool/ViewModel/UserControl/VectoJobFile.cs
@@ -38,6 +38,7 @@ using HashingTool.Helper;
 using TUGraz.VectoCommon.Hashing;
 using TUGraz.VectoCommon.Resources;
 using TUGraz.VectoHashing;
+using XmlDocumentType = TUGraz.VectoCore.Utils.XmlDocumentType;
 
 namespace HashingTool.ViewModel.UserControl
 {
@@ -50,7 +51,7 @@ namespace HashingTool.ViewModel.UserControl
 
 
 		public VectoJobFile(string name, Func<XmlDocument, IErrorLogger, bool?> contentCheck,
-			Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, true, contentCheck, hashValidation)
+			Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, true, contentCheck, XmlDocumentType.DeclarationJobData, hashValidation)
 		{
 			_xmlFile.PropertyChanged += JobFilechanged;
 			Components = new ObservableCollection<ComponentEntry>();
diff --git a/HashingTool/ViewModel/UserControl/VectoXMLFile.cs b/HashingTool/ViewModel/UserControl/VectoXMLFile.cs
index 9eabe8527b..564582ca54 100644
--- a/HashingTool/ViewModel/UserControl/VectoXMLFile.cs
+++ b/HashingTool/ViewModel/UserControl/VectoXMLFile.cs
@@ -35,6 +35,7 @@ using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Xml;
 using HashingTool.Helper;
+using XmlDocumentType = TUGraz.VectoCore.Utils.XmlDocumentType;
 
 namespace HashingTool.ViewModel.UserControl
 {
@@ -51,11 +52,10 @@ namespace HashingTool.ViewModel.UserControl
 		private string _digestMethod;
 
 
-		public VectoXMLFile(string name, bool validate, Func<XmlDocument, IErrorLogger, bool?> contentCheck,
-			Action<XmlDocument, VectoXMLFile> hashValidation = null)
+		public VectoXMLFile(string name, bool validate, Func<XmlDocument, IErrorLogger, bool?> contentCheck, XmlDocumentType xmlDocumentType, Action<XmlDocument, VectoXMLFile> hashValidation = null)
 		{
 			_validateHashes = hashValidation;
-			_xmlFile = new XMLFileSelector(IoService, name, validate, contentCheck);
+			_xmlFile = new XMLFileSelector(IoService, name, xmlDocumentType, validate, contentCheck);
 			_xmlFile.PropertyChanged += FileChanged;
 			Name = name;
 			CanonicalizationMethods = new ObservableCollection<string>();
diff --git a/HashingTool/ViewModel/VerifyComponentInputDataViewModel.cs b/HashingTool/ViewModel/VerifyComponentInputDataViewModel.cs
index cd43531d63..16c45b4ec8 100644
--- a/HashingTool/ViewModel/VerifyComponentInputDataViewModel.cs
+++ b/HashingTool/ViewModel/VerifyComponentInputDataViewModel.cs
@@ -39,6 +39,7 @@ using System.Windows.Input;
 using HashingTool.Helper;
 using HashingTool.ViewModel.UserControl;
 using TUGraz.VectoCommon.Hashing;
+using TUGraz.VectoCore.Utils;
 using TUGraz.VectoHashing;
 
 namespace HashingTool.ViewModel
@@ -49,7 +50,7 @@ namespace HashingTool.ViewModel
 		//private bool _componentDataValid;
 
 		public VerifyComponentInputDataViewModel()
-			: base("Verify Component Data", HashingHelper.IsComponentFile, HashingHelper.ValidateDocumentHash)
+			: base("Verify Component Data", HashingHelper.IsComponentFile, XmlDocumentType.DeclarationComponentData, HashingHelper.ValidateDocumentHash)
 		{
 			_xmlFile.PropertyChanged += ComponentFilechanged;
 		}
-- 
GitLab