From b2821d0ef0e3a00d1862a6ca048cf8efb5c038b8 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Thu, 14 Sep 2017 17:12:08 +0200 Subject: [PATCH] refacotring modelviews to use base class from report validation, more expressive icons for validating input --- HashingTool/App.xaml | 8 +- HashingTool/HashingTool.csproj | 14 +- HashingTool/Helper/CollectionConverter.cs | 4 +- HashingTool/Helper/HashingHelper.cs | 10 ++ HashingTool/Resources/Icon_XML_OK.xaml | 21 --- HashingTool/Resources/Icon_XML_green.xaml | 21 +++ HashingTool/Resources/Icon_XML_green1.xaml | 21 +++ HashingTool/Resources/Icon_XML_green2.xaml | 21 +++ HashingTool/Resources/Icon_XML_outline.xaml | 21 +++ .../{Icon_XML_NOK.xaml => Icon_XML_red.xaml} | 2 +- HashingTool/Resources/Icon_XML_unknown.xaml | 21 --- HashingTool/ViewModel/ComponentEntry.cs | 1 + .../ViewModel/HashComponentDataViewModel.cs | 83 ++++----- HashingTool/ViewModel/HashedXMLFile.cs | 131 +++++++++----- HashingTool/ViewModel/UserControl/XMLFile.cs | 122 ++++++++++--- .../VerifyComponentInputDataViewModel.cs | 81 ++------- .../ViewModel/VerifyJobInputDataViewModel.cs | 7 +- .../ViewModel/VerifyResultDataViewModel.cs | 9 +- HashingTool/Views/HashComponentData.xaml | 24 ++- HashingTool/Views/HashComponentData.xaml.cs | 2 +- .../UserControl/VectoXMLFileSelector.xaml | 35 ++-- .../Views/VerifyComponentInputData.xaml | 163 +++++++++--------- HashingTool/Views/VerifyJobInputData.xaml | 26 ++- HashingTool/Views/VerifyResults.xaml | 58 +++++-- VectoCommon/VectoHashing/VectoHash.cs | 8 +- 25 files changed, 557 insertions(+), 357 deletions(-) delete mode 100644 HashingTool/Resources/Icon_XML_OK.xaml create mode 100644 HashingTool/Resources/Icon_XML_green.xaml create mode 100644 HashingTool/Resources/Icon_XML_green1.xaml create mode 100644 HashingTool/Resources/Icon_XML_green2.xaml create mode 100644 HashingTool/Resources/Icon_XML_outline.xaml rename HashingTool/Resources/{Icon_XML_NOK.xaml => Icon_XML_red.xaml} (97%) delete mode 100644 HashingTool/Resources/Icon_XML_unknown.xaml diff --git a/HashingTool/App.xaml b/HashingTool/App.xaml index 53da578cb0..ac8aa2b281 100644 --- a/HashingTool/App.xaml +++ b/HashingTool/App.xaml @@ -4,9 +4,11 @@ <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> - <ResourceDictionary Source="Resources/Icon_XML_unknown.xaml" /> - <ResourceDictionary Source="Resources/Icon_XML_OK.xaml" /> - <ResourceDictionary Source="Resources/Icon_XML_NOK.xaml" /> + <ResourceDictionary Source="Resources/Icon_XML_outline.xaml" /> + <ResourceDictionary Source="Resources/Icon_XML_red.xaml" /> + <ResourceDictionary Source="Resources/Icon_XML_green1.xaml" /> + <ResourceDictionary Source="Resources/Icon_XML_green2.xaml" /> + <ResourceDictionary Source="Resources/Icon_XML_green.xaml" /> <ResourceDictionary Source="Resources/Icon_OK.xaml" /> <ResourceDictionary Source="Resources/Icon_NOK.xaml" /> <ResourceDictionary Source="Resources/UserInterfaceResources.xaml" /> diff --git a/HashingTool/HashingTool.csproj b/HashingTool/HashingTool.csproj index 98d705e197..751fae6c4e 100644 --- a/HashingTool/HashingTool.csproj +++ b/HashingTool/HashingTool.csproj @@ -129,15 +129,23 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="Resources\Icon_XML_NOK.xaml"> + <Page Include="Resources\Icon_XML_green2.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> + <Page Include="Resources\Icon_XML_green1.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> + <Page Include="Resources\Icon_XML_red.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="Resources\Icon_XML_OK.xaml"> + <Page Include="Resources\Icon_XML_green.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="Resources\Icon_XML_unknown.xaml"> + <Page Include="Resources\Icon_XML_outline.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> diff --git a/HashingTool/Helper/CollectionConverter.cs b/HashingTool/Helper/CollectionConverter.cs index 78f1fd749c..af1e63f9d2 100644 --- a/HashingTool/Helper/CollectionConverter.cs +++ b/HashingTool/Helper/CollectionConverter.cs @@ -12,7 +12,7 @@ namespace HashingTool.Helper { var val = value as ICollection; if (val == null) { - throw new ArgumentException("can only convert collections!"); + return null; } if (targetType == typeof(object) || targetType == typeof(string)) { var tmp = new string[val.Count]; @@ -20,7 +20,7 @@ namespace HashingTool.Helper foreach (var entry in val) { tmp[i++] = entry.ToString(); } - return string.Join(", ", tmp); + return string.Join("; ", tmp); } throw new ArgumentException("Unhandled target type"); } diff --git a/HashingTool/Helper/HashingHelper.cs b/HashingTool/Helper/HashingHelper.cs index 5206674c70..cac69844fc 100644 --- a/HashingTool/Helper/HashingHelper.cs +++ b/HashingTool/Helper/HashingHelper.cs @@ -90,6 +90,11 @@ namespace HashingTool.Helper try { var h = VectoHash.Load(xml); xmlViewModel.DigestValueComputed = h.ComputeHash(); + xmlViewModel.DigestMethod = h.GetDigestMethod(); + var c14N = h.GetCanonicalizationMethods().ToArray(); + foreach (var c in c14N) { + xmlViewModel.CanonicalizationMethods.Add(c); + } } catch (Exception e) { xmlViewModel.XMLFile.XMLValidationErrors.Add(e.Message); xmlViewModel.DigestValueComputed = ""; @@ -104,6 +109,11 @@ namespace HashingTool.Helper } try { var h = VectoHash.Load(xml); + report.DigestMethod = h.GetDigestMethod(); + var c14N = h.GetCanonicalizationMethods().ToArray(); + foreach (var c in c14N) { + report.CanonicalizationMethods.Add(c); + } try { report.DigestValueRead = h.ReadHash(); } catch { diff --git a/HashingTool/Resources/Icon_XML_OK.xaml b/HashingTool/Resources/Icon_XML_OK.xaml deleted file mode 100644 index 6b66741637..0000000000 --- a/HashingTool/Resources/Icon_XML_OK.xaml +++ /dev/null @@ -1,21 +0,0 @@ -<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> -<DataTemplate x:Key="Icon_XML_OK"> - <Canvas> - <Canvas.RenderTransform> - <TranslateTransform X="-59.285156" Y="-215.2361" /> - </Canvas.RenderTransform> - <Canvas Name="flowRoot4136" Opacity="1"> - <Path Name="path4145" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" - StrokeEndLineCap="Flat" - Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" /> - <Path Name="path4147" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" - StrokeEndLineCap="Flat" - Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" /> - <Path Name="path4149" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" - StrokeEndLineCap="Flat" - Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" /> - </Canvas> - </Canvas> -</DataTemplate> -</ResourceDictionary> \ No newline at end of file diff --git a/HashingTool/Resources/Icon_XML_green.xaml b/HashingTool/Resources/Icon_XML_green.xaml new file mode 100644 index 0000000000..cdbeb12963 --- /dev/null +++ b/HashingTool/Resources/Icon_XML_green.xaml @@ -0,0 +1,21 @@ +<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + <DataTemplate x:Key="Icon_XML_green"> + <Canvas> + <Canvas.RenderTransform> + <TranslateTransform X="-59.285156" Y="-215.2361" /> + </Canvas.RenderTransform> + <Canvas Name="flowRoot4136" Opacity="1"> + <Path Name="path4145" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" /> + <Path Name="path4147" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" /> + <Path Name="path4149" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" /> + </Canvas> + </Canvas> + </DataTemplate> +</ResourceDictionary> \ No newline at end of file diff --git a/HashingTool/Resources/Icon_XML_green1.xaml b/HashingTool/Resources/Icon_XML_green1.xaml new file mode 100644 index 0000000000..f3e264241d --- /dev/null +++ b/HashingTool/Resources/Icon_XML_green1.xaml @@ -0,0 +1,21 @@ +<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + <DataTemplate x:Key="Icon_XML_green1"> + <Canvas> + <Canvas.RenderTransform> + <TranslateTransform X="-59.285156" Y="-215.2361" /> + </Canvas.RenderTransform> + <Canvas Name="flowRoot4136" Opacity="1"> + <Path Name="path4145" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" /> + <Path Name="path4147" Fill="#FFFF0000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" /> + <Path Name="path4149" Fill="#FFFF0000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" /> + </Canvas> + </Canvas> + </DataTemplate> +</ResourceDictionary> \ No newline at end of file diff --git a/HashingTool/Resources/Icon_XML_green2.xaml b/HashingTool/Resources/Icon_XML_green2.xaml new file mode 100644 index 0000000000..280ec67790 --- /dev/null +++ b/HashingTool/Resources/Icon_XML_green2.xaml @@ -0,0 +1,21 @@ +<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + <DataTemplate x:Key="Icon_XML_green2"> + <Canvas> + <Canvas.RenderTransform> + <TranslateTransform X="-59.285156" Y="-215.2361" /> + </Canvas.RenderTransform> + <Canvas Name="flowRoot4136" Opacity="1"> + <Path Name="path4145" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" /> + <Path Name="path4147" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" /> + <Path Name="path4149" Fill="#FFFF0000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" /> + </Canvas> + </Canvas> + </DataTemplate> +</ResourceDictionary> \ No newline at end of file diff --git a/HashingTool/Resources/Icon_XML_outline.xaml b/HashingTool/Resources/Icon_XML_outline.xaml new file mode 100644 index 0000000000..0b9a1766d7 --- /dev/null +++ b/HashingTool/Resources/Icon_XML_outline.xaml @@ -0,0 +1,21 @@ +<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + <DataTemplate x:Key="ICON_XML_outline"> + <Canvas Name="layer1"> + <Canvas.RenderTransform> + <TranslateTransform X="-59.285156" Y="-215.2361" /> + </Canvas.RenderTransform> + <Canvas Name="flowRoot4136" Opacity="1"> + <Path Name="path4145" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" /> + <Path Name="path4147" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" /> + <Path Name="path4149" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" + StrokeEndLineCap="Flat" + Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" /> + </Canvas> + </Canvas> + </DataTemplate> +</ResourceDictionary> \ No newline at end of file diff --git a/HashingTool/Resources/Icon_XML_NOK.xaml b/HashingTool/Resources/Icon_XML_red.xaml similarity index 97% rename from HashingTool/Resources/Icon_XML_NOK.xaml rename to HashingTool/Resources/Icon_XML_red.xaml index 103ee9b4a9..3b8501bb07 100644 --- a/HashingTool/Resources/Icon_XML_NOK.xaml +++ b/HashingTool/Resources/Icon_XML_red.xaml @@ -1,6 +1,6 @@ <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - <DataTemplate x:Key="Icon_XML_NOK"> + <DataTemplate x:Key="Icon_XML_red"> <Canvas> <Canvas.RenderTransform> <TranslateTransform X="-59.285156" Y="-215.2361" /> diff --git a/HashingTool/Resources/Icon_XML_unknown.xaml b/HashingTool/Resources/Icon_XML_unknown.xaml deleted file mode 100644 index b19d923d72..0000000000 --- a/HashingTool/Resources/Icon_XML_unknown.xaml +++ /dev/null @@ -1,21 +0,0 @@ -<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - <DataTemplate x:Key="ICON_XML_unknown"> - <Canvas Name="layer1"> - <Canvas.RenderTransform> - <TranslateTransform X="-59.285156" Y="-215.2361" /> - </Canvas.RenderTransform> - <Canvas Name="flowRoot4136" Opacity="1"> - <Path Name="path4145" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" - StrokeEndLineCap="Flat" - Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" /> - <Path Name="path4147" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" - StrokeEndLineCap="Flat" - Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" /> - <Path Name="path4149" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" - StrokeEndLineCap="Flat" - Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" /> - </Canvas> - </Canvas> - </DataTemplate> -</ResourceDictionary> \ No newline at end of file diff --git a/HashingTool/ViewModel/ComponentEntry.cs b/HashingTool/ViewModel/ComponentEntry.cs index 8c1e45e9b6..2a28208886 100644 --- a/HashingTool/ViewModel/ComponentEntry.cs +++ b/HashingTool/ViewModel/ComponentEntry.cs @@ -6,6 +6,7 @@ namespace HashingTool.ViewModel public string DigestValueRead { get; set; } public string DigestValueComputed { get; set; } public string[] CanonicalizationMethod { get; set; } + public string DigestMethod { get; set; } public bool Valid { get; set; } } } diff --git a/HashingTool/ViewModel/HashComponentDataViewModel.cs b/HashingTool/ViewModel/HashComponentDataViewModel.cs index 6828f7dfd5..e5287341b8 100644 --- a/HashingTool/ViewModel/HashComponentDataViewModel.cs +++ b/HashingTool/ViewModel/HashComponentDataViewModel.cs @@ -2,6 +2,7 @@ using System.Collections.ObjectModel; using System.ComponentModel; using System.IO; +using System.Linq; using System.Text; using System.Windows; using System.Windows.Input; @@ -12,56 +13,36 @@ using HashingTool.Helper; using HashingTool.Util; using HashingTool.ViewModel.UserControl; using TUGraz.VectoHashing; +using TUGraz.VectoHashing.Impl; namespace HashingTool.ViewModel { - public class HashComponentDataViewModel : ObservableObject, IMainView + public class HashComponentDataViewModel : VectoXMLFile, IMainView { private string _digestValue; private XDocument _result; private readonly RelayCommand _saveCommand; - private bool _busy; - private readonly XMLFile _sourceFile; + private bool? _componentDataValid; + private bool _busy; + public HashComponentDataViewModel() + : base("Hash Component Data", false, HashingHelper.IsComponentFile) { - XMLValidationErrors = new ObservableCollection<string>(); - _sourceFile = new XMLFile(IoService, false, HashingHelper.IsComponentFile); - _sourceFile.PropertyChanged += SourceChanged; + _xmlFile.PropertyChanged += SourceChanged; _saveCommand = new RelayCommand(SaveDocument, () => !_busy && ComponentDataValid != null && ComponentDataValid.Value && _result != null); - _busy = false; - - // TODO! - CanonicalizaitionMethods = new ObservableCollection<string>() { - "urn:vecto:xml:2017:canonicalization", - "http://www.w3.org/2001/10/xml-exc-c14n#" - }; } - public string Name - { - get { return "Hash Component Data"; } - } - public ICommand ShowHomeViewCommand { get { return ApplicationViewModel.HomeView; } } - public XMLFile ComponentFile - { - get { return _sourceFile; } - } - - - public ObservableCollection<string> XMLValidationErrors { get; set; } - - public string DigestValue { get { return _digestValue; } @@ -81,9 +62,8 @@ namespace HashingTool.ViewModel private void SourceChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == "Document") { - DoComputeHash(); - } + if (e.PropertyName == "Document" || e.PropertyName == "IsValid") + DoComputeHash(); } private void SaveDocument() @@ -115,22 +95,27 @@ namespace HashingTool.ViewModel } } - public ObservableCollection<string> CanonicalizaitionMethods { get; private set; } - private async void DoComputeHash() { - if (_sourceFile.Document == null) { + if (_busy) { + return; + } + if (_xmlFile.Document == null || _xmlFile.IsValid != XmlFileStatus.ValidXML) { ComponentDataValid = false; DigestValue = ""; + DigestMethod = ""; + CanonicalizationMethods.Clear(); return; } + try { _busy = true; ComponentDataValid = false; DigestValue = ""; - XMLValidationErrors.Clear(); + _xmlFile.XMLValidationErrors.Clear(); + CanonicalizationMethods.Clear(); - var h = VectoHash.Load(_sourceFile.Document); + var h = VectoHash.Load(_xmlFile.Document); _result = h.AddHash(); @@ -145,7 +130,7 @@ namespace HashingTool.ViewModel ComponentDataValid = true; var validator = new XMLValidator(r => { ComponentDataValid = r; }, (s, e) => { - Application.Current.Dispatcher.Invoke(() => XMLValidationErrors.Add( + Application.Current.Dispatcher.Invoke(() => _xmlFile.XMLValidationErrors.Add( string.Format("Validation {0} Line {2}: {1}", s == XmlSeverityType.Warning ? "WARNING" : "ERROR", e.ValidationEventArgs == null ? e.Exception.Message + @@ -156,15 +141,35 @@ namespace HashingTool.ViewModel await validator.ValidateXML(XmlReader.Create(ms)); } if (ComponentDataValid != null && ComponentDataValid.Value) { - DigestValue = h.ComputeHash(); + //var c14N = XMLHashProvider.DefaultCanonicalizationMethod.ToArray(); + //var digestMethod = XMLHashProvider.DefaultDigestMethod; + //DigestValue = h.ComputeHash(c14N, digestMethod); + using (MemoryStream ms = new MemoryStream()) { + using (XmlWriter xw = XmlWriter.Create(ms, new XmlWriterSettings { Indent = true })) { + _result.WriteTo(xw); + xw.Flush(); + } + ms.Flush(); + ms.Seek(0, SeekOrigin.Begin); + var h2 = VectoHash.Load(ms); + var c14N = h2.GetCanonicalizationMethods().ToArray(); + var digestMethod = h2.GetDigestMethod(); + DigestValue = h.ReadHash(); + foreach (var c in c14N) { + CanonicalizationMethods.Add(c); + } + RaisePropertyChanged("CanonicalizationMethods"); + DigestMethod = digestMethod; + } } - _saveCommand.RaiseCanExecuteChanged(); } catch (Exception e) { ComponentDataValid = false; DigestValue = ""; - XMLValidationErrors.Add(e.Message); + _xmlFile.XMLValidationErrors.Add(e.Message); + CanonicalizationMethods.Clear(); } finally { _busy = false; + _saveCommand.RaiseCanExecuteChanged(); } } } diff --git a/HashingTool/ViewModel/HashedXMLFile.cs b/HashingTool/ViewModel/HashedXMLFile.cs index a691a9a660..eb0db4f57a 100644 --- a/HashingTool/ViewModel/HashedXMLFile.cs +++ b/HashingTool/ViewModel/HashedXMLFile.cs @@ -13,35 +13,31 @@ namespace HashingTool.ViewModel { protected readonly XMLFile _xmlFile; - protected string _manufacturerDigestComputed; + protected string _digestValueComputed; protected bool? _valid; protected string _name; protected string _tooltip; - protected readonly Func<XmlDocument, Collection<string>, bool?> _contentCheck; protected string _componentType; protected readonly Action<XmlDocument, VectoXMLFile> _validateHashes; + private string _digestMethod; - public VectoXMLFile(string name, Func<XmlDocument, Collection<string>, bool?> contentCheck, + public VectoXMLFile(string name, bool validate, Func<XmlDocument, Collection<string>, bool?> contentCheck, Action<XmlDocument, VectoXMLFile> hashValidation = null) { _validateHashes = hashValidation; - _xmlFile = new XMLFile(IoService, true, contentCheck); + _xmlFile = new XMLFile(IoService, validate, contentCheck); _xmlFile.PropertyChanged += FileChanged; Name = name; + CanonicalizationMethods = new ObservableCollection<string>(); - // TODO - CanonicalizationMethods = new[] { - "urn:vecto:xml:2017:canonicalization", - "http://www.w3.org/2001/10/xml-exc-c14n#" - }; Valid = null; ValidTooltip = HashingHelper.ToolTipNone; } protected virtual void FileChanged(object sender, PropertyChangedEventArgs e) { - if (_xmlFile.IsValid != null && XMLFile.IsValid.HasValue && _xmlFile.IsValid.Value) { + if (_xmlFile.IsValid == XmlFileStatus.ValidXML) { if (_xmlFile.HasContentValidation) { Valid = _xmlFile.ContentValid; if (Valid != null && Valid.Value) { @@ -80,17 +76,29 @@ namespace HashingTool.ViewModel } } - public string[] CanonicalizationMethods { get; private set; } + public ObservableCollection<string> CanonicalizationMethods { get; private set; } + + public string DigestMethod + { + get { return _digestMethod; } + set { + if (_digestMethod == value) { + return; + } + _digestMethod = value; + RaisePropertyChanged("DigestMethod"); + } + } public string DigestValueComputed { - get { return _manufacturerDigestComputed; } + get { return _digestValueComputed; } internal set { - if (_manufacturerDigestComputed == value) { + if (_digestValueComputed == value) { return; } - _manufacturerDigestComputed = value; + _digestValueComputed = value; RaisePropertyChanged("DigestValueComputed"); } } @@ -135,19 +143,19 @@ namespace HashingTool.ViewModel public class HashedXMLFile : VectoXMLFile { - protected string _manufacturerDigestRead; + protected string _digestValueRead; - public HashedXMLFile(IOService ioService, string name, Func<XmlDocument, Collection<string>, bool?> contentCheck, - Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, contentCheck, hashValidation) {} + public HashedXMLFile(string name, Func<XmlDocument, Collection<string>, bool?> contentCheck, + Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, true, contentCheck, hashValidation) {} public string DigestValueRead { - get { return _manufacturerDigestRead; } + get { return _digestValueRead; } internal set { - if (_manufacturerDigestRead == value) { + if (_digestValueRead == value) { return; } - _manufacturerDigestRead = value; + _digestValueRead = value; RaisePropertyChanged("DigestValueRead"); } } @@ -155,11 +163,13 @@ namespace HashingTool.ViewModel public class ReportXMLFile : HashedXMLFile { - private string _jobDigestRead; + private string _jobDigestValueRead; + private string _jobDigestMethod; + private string[] _jobCanonicalizationMethod; - public ReportXMLFile(IOService ioService, string name, Func<XmlDocument, Collection<string>, bool?> contentCheck, + public ReportXMLFile(string name, Func<XmlDocument, Collection<string>, bool?> contentCheck, Action<XmlDocument, VectoXMLFile> hashValidation = null) - : base(ioService, name, contentCheck, hashValidation) + : base(name, contentCheck, hashValidation) { _xmlFile.PropertyChanged += ReadJobDigest; } @@ -167,28 +177,69 @@ namespace HashingTool.ViewModel private void ReadJobDigest(object sender, PropertyChangedEventArgs e) { var jobDigest = ""; + var jobDigestMethod = ""; + var jobc14NMethod = new string[] { }; + if (e.PropertyName != "Document") { return; } if (_xmlFile.Document != null && _xmlFile.Document.DocumentElement != null) { - var node = + var digestValueNode = _xmlFile.Document.SelectSingleNode("//*[local-name()='InputDataSignature']//*[local-name()='DigestValue']"); - if (node != null) { - jobDigest = node.InnerText; + if (digestValueNode != null) { + jobDigest = digestValueNode.InnerText; + } + var digestMethodNode = + _xmlFile.Document.SelectSingleNode( + "//*[local-name()='InputDataSignature']//*[local-name()='DigestMethod']/@Algorithm"); + if (digestMethodNode != null) { + jobDigestMethod = digestMethodNode.InnerText; + } + + var c14NtMethodNodes = + _xmlFile.Document.SelectNodes("//*[local-name()='InputDataSignature']//*[local-name()='Transform']/@Algorithm"); + if (c14NtMethodNodes != null) { + jobc14NMethod = (from XmlNode node in c14NtMethodNodes select node.InnerText).ToArray(); + } + } + JobCanonicalizationMethod = jobc14NMethod; + JobDigestMethod = jobDigestMethod; + JobDigestValue = jobDigest; + } + + public string JobDigestMethod + { + get { return _jobDigestMethod; } + set { + if (_jobDigestMethod == value) { + return; + } + _jobDigestMethod = value; + RaisePropertyChanged("JobDigestMethod"); + } + } + + public string[] JobCanonicalizationMethod + { + get { return _jobCanonicalizationMethod; } + set { + if (_jobCanonicalizationMethod == value) { + return; } + _jobCanonicalizationMethod = value; + RaisePropertyChanged("JobCanonicalizationMethod"); } - JobDigest = jobDigest; } - public string JobDigest + public string JobDigestValue { - get { return _jobDigestRead; } + get { return _jobDigestValueRead; } internal set { - if (_jobDigestRead == value) { + if (_jobDigestValueRead == value) { return; } - _jobDigestRead = value; - RaisePropertyChanged("JobDigest"); + _jobDigestValueRead = value; + RaisePropertyChanged("JobDigestValue"); } } } @@ -200,7 +251,7 @@ namespace HashingTool.ViewModel public VectoJobFile(string name, Func<XmlDocument, Collection<string>, bool?> contentCheck, - Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, contentCheck, hashValidation) + Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, true, contentCheck, hashValidation) { _xmlFile.PropertyChanged += JobFilechanged; Components = new ObservableCollection<ComponentEntry>(); @@ -240,9 +291,12 @@ namespace HashingTool.ViewModel private void DoValidateHash() { - if (_xmlFile.Document == null || _xmlFile.ContentValid == null || !_xmlFile.ContentValid.Value) { + if (_xmlFile.Document == null || _xmlFile.IsValid != XmlFileStatus.ValidXML || _xmlFile.ContentValid == null || + !_xmlFile.ContentValid.Value) { Components.Clear(); DigestValueComputed = ""; + DigestMethod = ""; + CanonicalizationMethods.Clear(); JobDataValid = false; return; } @@ -263,15 +317,14 @@ namespace HashingTool.ViewModel ? component.Entry.XMLElementName() : string.Format("{0} ({1})", component.Entry.XMLElementName(), i + 1); entry.Valid = h.ValidateHash(component.Entry, i); - entry.CanonicalizationMethod = new[] { - "urn:vecto:xml:2017:canonicalization", - "http://www.w3.org/2001/10/xml-exc-c14n#" - }; + entry.CanonicalizationMethod = h.GetCanonicalizationMethods(component.Entry, i).ToArray(); + entry.DigestMethod = h.GetDigestMethod(component.Entry, i); entry.DigestValueRead = h.ReadHash(component.Entry, i); entry.DigestValueComputed = h.ComputeHash(component.Entry, i); if (!entry.Valid) { _xmlFile.XMLValidationErrors.Add( - string.Format("Digest Value mismatch for component \"{0}\". Read digest value: \"{1}\", computed digest value \"{2}\"", + string.Format( + "Digest Value mismatch for component \"{0}\". Read digest value: \"{1}\", computed digest value \"{2}\"", entry.Component, entry.DigestValueRead, entry.DigestValueComputed)); } Components.Add(entry); diff --git a/HashingTool/ViewModel/UserControl/XMLFile.cs b/HashingTool/ViewModel/UserControl/XMLFile.cs index 17bdf030c5..57096aba1e 100644 --- a/HashingTool/ViewModel/UserControl/XMLFile.cs +++ b/HashingTool/ViewModel/UserControl/XMLFile.cs @@ -1,5 +1,6 @@ using System; using System.Collections.ObjectModel; +using System.ComponentModel; using System.IO; using System.Threading.Tasks; using System.Windows; @@ -11,10 +12,19 @@ using HashingTool.Util; namespace HashingTool.ViewModel.UserControl { + public enum XmlFileStatus + { + Unknown, // no file selected, outline + Invalid, // reading failed, no xml, etc. red + InvalidXML, // does not validate against known schemas + IncorrectContent, // content validation failed + ValidXML // green + } + public class XMLFile : ObservableObject { private string _source; - private bool? _isValid; + private XmlFileStatus _isValid; private bool _busy; @@ -22,12 +32,14 @@ namespace HashingTool.ViewModel.UserControl private XmlDocument _document; private readonly Func<XmlDocument, Collection<string>, bool?> _postVerification; private bool? _contentValid; + private RelayCommand _browseFileCommand; public XMLFile(IOService ioservice, bool validate = false, Func<XmlDocument, Collection<string>, bool?> contentCheck = null) { IoService = ioservice; _validate = validate; + _browseFileCommand = new RelayCommand(BrowseXMLFile, () => !_busy); XMLValidationErrors = new ObservableCollection<string>(); HasContentValidation = contentCheck != null; _postVerification = contentCheck ?? ((x, c) => null); @@ -66,7 +78,7 @@ namespace HashingTool.ViewModel.UserControl get { return _validate; } } - public bool? IsValid + public XmlFileStatus IsValid { get { return _isValid; } private set { @@ -75,14 +87,44 @@ namespace HashingTool.ViewModel.UserControl } _isValid = value; RaisePropertyChanged("IsValid"); + SetToolTip(value); } } + private void SetToolTip(XmlFileStatus value) + { + var toolTip = ""; + switch (value) { + case XmlFileStatus.Unknown: + toolTip = "Select XML File file"; + break; + case XmlFileStatus.Invalid: + toolTip = "Invalid file"; + break; + case XmlFileStatus.InvalidXML: + toolTip = "XML Schema validation failed"; + break; + case XmlFileStatus.IncorrectContent: + toolTip = "Incorrect XML content"; + break; + case XmlFileStatus.ValidXML: + toolTip = "OK"; + break; + } + if (ToolTip == toolTip) { + return; + } + ToolTip = toolTip; + RaisePropertyChanged("ToolTip"); + } + + public string ToolTip { get; internal set; } + public ObservableCollection<string> XMLValidationErrors { get; set; } public ICommand BrowseFileCommand { - get { return new RelayCommand(BrowseXMLFile, () => !_busy); } + get { return _browseFileCommand; } } public ICommand SetXMLFileCommnd @@ -96,7 +138,7 @@ namespace HashingTool.ViewModel.UserControl Document = null; XMLValidationErrors.Clear(); ContentValid = null; - IsValid = null; + IsValid = XmlFileStatus.Unknown; return; } using (var stream = File.OpenRead(fileName)) { @@ -122,24 +164,47 @@ namespace HashingTool.ViewModel.UserControl private async Task LoadXMLFile(Stream stream) { _busy = true; - IsValid = null; + IsValid = XmlFileStatus.Unknown; ContentValid = null; XMLValidationErrors.Clear(); - - - if (_validate) { + var fileValid = XmlFileStatus.ValidXML; + bool? contentValid = null; + try { var ms = new MemoryStream(); - await stream.CopyToAsync(ms); - ms.Seek(0, SeekOrigin.Begin); - stream.Seek(0, SeekOrigin.Begin); - Validate(XmlReader.Create(ms)); + if (_validate) { + // copy stream beforehand if validation is needed later on + await stream.CopyToAsync(ms); + ms.Seek(0, SeekOrigin.Begin); + stream.Seek(0, SeekOrigin.Begin); + } + + var document = new XmlDocument(); + var reader = XmlReader.Create(stream); + document.Load(reader); + Document = document; + var xmlValid = true; + if (_validate) { + xmlValid = await Validate(XmlReader.Create(ms)); + if (!xmlValid) { + fileValid = XmlFileStatus.InvalidXML; + } + } + if (HasContentValidation) { + contentValid = _postVerification(document, XMLValidationErrors); + if (xmlValid && (contentValid == null || !contentValid.Value)) { + fileValid = XmlFileStatus.IncorrectContent; + } + } + } catch (Exception e) { + XMLValidationErrors.Add(e.Message); + fileValid = XmlFileStatus.Invalid; + } finally { + + IsValid = fileValid; + ContentValid = contentValid; + _busy = false; + _browseFileCommand.RaiseCanExecuteChanged(); } - var document = new XmlDocument(); - var reader = XmlReader.Create(stream); - document.Load(reader); - Document = document; - ContentValid = _postVerification(document, XMLValidationErrors); - _busy = false; } public bool HasContentValidation { get; private set; } @@ -156,26 +221,27 @@ namespace HashingTool.ViewModel.UserControl } } - private async void Validate(XmlReader xml) + private async Task<bool> Validate(XmlReader xml) { var valid = true; try { var validator = new XMLValidator(r => { valid = r; }, (s, e) => { - Application.Current.Dispatcher.Invoke(() => XMLValidationErrors.Add( - string.Format("Validation {0} Line {2}: {1}", s == XmlSeverityType.Warning ? "WARNING" : "ERROR", - e.ValidationEventArgs == null - ? e.Exception.Message + - (e.Exception.InnerException != null ? Environment.NewLine + e.Exception.InnerException.Message : "") - : e.ValidationEventArgs.Message, - e.ValidationEventArgs == null ? 0 : e.ValidationEventArgs.Exception.LineNumber))); + Application.Current.Dispatcher.Invoke( + () => + XMLValidationErrors.Add(string.Format("Validation {0} Line {2}: {1}", + s == XmlSeverityType.Warning ? "WARNING" : "ERROR", + e.ValidationEventArgs == null + ? e.Exception.Message + + (e.Exception.InnerException != null ? Environment.NewLine + e.Exception.InnerException.Message : "") + : e.ValidationEventArgs.Message, + e.ValidationEventArgs == null ? 0 : e.ValidationEventArgs.Exception.LineNumber))); }); await validator.ValidateXML(xml); } catch (Exception e) { XMLValidationErrors.Add(e.Message); - } finally { - IsValid = valid; } + return valid; } } } diff --git a/HashingTool/ViewModel/VerifyComponentInputDataViewModel.cs b/HashingTool/ViewModel/VerifyComponentInputDataViewModel.cs index 8a3758f12b..8ee365ba66 100644 --- a/HashingTool/ViewModel/VerifyComponentInputDataViewModel.cs +++ b/HashingTool/ViewModel/VerifyComponentInputDataViewModel.cs @@ -1,40 +1,22 @@ using System; -using System.Collections.ObjectModel; using System.ComponentModel; using System.IO; using System.Linq; using System.Windows; using System.Windows.Input; using HashingTool.Helper; -using HashingTool.ViewModel.UserControl; using TUGraz.VectoHashing; namespace HashingTool.ViewModel { - public class VerifyComponentInputDataViewModel : ObservableObject, IMainView + public class VerifyComponentInputDataViewModel : HashedXMLFile, IMainView { - private string _digestValueComputed; - private string _digestValueRead; private bool _componentDataValid; - private string _componentType; - private readonly XMLFile _componentFile; - public VerifyComponentInputDataViewModel() + : base("Verify Component Data", HashingHelper.IsComponentFile) { - _componentFile = new XMLFile(IoService, true, HashingHelper.IsComponentFile); - _componentFile.PropertyChanged += ComponentFilechanged; - - // TODO! - CanonicalizaitionMethods = new ObservableCollection<string>() { - "urn:vecto:xml:2017:canonicalization", - "http://www.w3.org/2001/10/xml-exc-c14n#" - }; - } - - public string Name - { - get { return "Verify Component Data"; } + _xmlFile.PropertyChanged += ComponentFilechanged; } public ICommand ShowHomeViewCommand @@ -42,48 +24,6 @@ namespace HashingTool.ViewModel get { return ApplicationViewModel.HomeView; } } - public XMLFile ComponentFile - { - get { return _componentFile; } - } - - public string Component - { - get { return _componentType; } - set { - if (_componentType == value) { - return; - } - _componentType = value; - RaisePropertyChanged("Component"); - } - } - - public ObservableCollection<string> CanonicalizaitionMethods { get; private set; } - - public string DigestValueComputed - { - get { return _digestValueComputed; } - set { - if (_digestValueComputed == value) { - return; - } - _digestValueComputed = value; - RaisePropertyChanged("DigestValueComputed"); - } - } - - public string DigestValueRead - { - get { return _digestValueRead; } - set { - if (_digestValueRead == value) { - return; - } - _digestValueRead = value; - RaisePropertyChanged("DigestValueRead"); - } - } public bool ComponentDataValid { @@ -99,14 +39,14 @@ namespace HashingTool.ViewModel private void ComponentFilechanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == "Document") { + if (e.PropertyName == "Document" || e.PropertyName == "ContentValid") { DoValidateHash(); } } private void DoValidateHash() { - if (_componentFile.ContentValid == null || !_componentFile.ContentValid.Value || _componentFile.Document == null) { + if (_xmlFile.ContentValid == null || !_xmlFile.ContentValid.Value || _xmlFile.Document == null) { ComponentDataValid = false; DigestValueComputed = ""; DigestValueRead = ""; @@ -114,7 +54,7 @@ namespace HashingTool.ViewModel return; } try { - var h = VectoHash.Load(_componentFile.Document); + var h = VectoHash.Load(_xmlFile.Document); if (h.GetContainigComponents().Count != 1) { IoService.Messagebox("Selected file is not a component file!", "Error reading XML File", MessageBoxButton.OK); @@ -125,12 +65,19 @@ namespace HashingTool.ViewModel DigestValueRead = h.ReadHash(); DigestValueComputed = h.ComputeHash(); ComponentDataValid = h.ValidateHash(); + DigestMethod = h.GetDigestMethod(); + CanonicalizationMethods.Clear(); + foreach (var c in h.GetCanonicalizationMethods().ToArray()) { + CanonicalizationMethods.Add(c); + } } catch (Exception e) { ComponentDataValid = false; DigestValueComputed = ""; DigestValueRead = ""; Component = ""; - _componentFile.XMLValidationErrors.Add(e.Message); + CanonicalizationMethods.Clear(); + DigestMethod = ""; + _xmlFile.XMLValidationErrors.Add(e.Message); } } } diff --git a/HashingTool/ViewModel/VerifyJobInputDataViewModel.cs b/HashingTool/ViewModel/VerifyJobInputDataViewModel.cs index d4310d6905..a3b3cb8af7 100644 --- a/HashingTool/ViewModel/VerifyJobInputDataViewModel.cs +++ b/HashingTool/ViewModel/VerifyJobInputDataViewModel.cs @@ -1,11 +1,6 @@ -using System; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Windows.Input; +using System.Windows.Input; using HashingTool.Helper; using HashingTool.ViewModel.UserControl; -using TUGraz.VectoHashing; namespace HashingTool.ViewModel { diff --git a/HashingTool/ViewModel/VerifyResultDataViewModel.cs b/HashingTool/ViewModel/VerifyResultDataViewModel.cs index a07397653a..cea7da0bdd 100644 --- a/HashingTool/ViewModel/VerifyResultDataViewModel.cs +++ b/HashingTool/ViewModel/VerifyResultDataViewModel.cs @@ -18,9 +18,9 @@ namespace HashingTool.ViewModel public VerifyResultDataViewModel() { _jobFile = new VectoJobFile("Job File", HashingHelper.IsJobFile, HashingHelper.HashJobFile); - _manufacturerReport = new ReportXMLFile(IoService, "Manufacturer Report", HashingHelper.IsManufacturerReport, + _manufacturerReport = new ReportXMLFile("Manufacturer Report", HashingHelper.IsManufacturerReport, HashingHelper.ValidateDocumentHash); - _customerReport = new ReportXMLFile(IoService, "Customer Report", HashingHelper.IsCustomerReport, + _customerReport = new ReportXMLFile("Customer Report", HashingHelper.IsCustomerReport, HashingHelper.ValidateDocumentHash); Files = new ObservableCollection<VectoXMLFile> { _jobFile, _manufacturerReport, _customerReport }; @@ -68,7 +68,7 @@ namespace HashingTool.ViewModel { get { return _manufacturerReport.Valid != null && _manufacturerReport.Valid.Value && - _manufacturerReport.JobDigest == _jobFile.DigestValueComputed; + _manufacturerReport.JobDigestValue == _jobFile.DigestValueComputed; } } @@ -76,8 +76,9 @@ namespace HashingTool.ViewModel { get { return _customerReport.Valid != null && _customerReport.Valid.Value && - _customerReport.JobDigest == _jobFile.DigestValueComputed; + _customerReport.JobDigestValue == _jobFile.DigestValueComputed; } } + } } diff --git a/HashingTool/Views/HashComponentData.xaml b/HashingTool/Views/HashComponentData.xaml index a4258a4fb0..c4a51a49d0 100644 --- a/HashingTool/Views/HashComponentData.xaml +++ b/HashingTool/Views/HashComponentData.xaml @@ -32,7 +32,7 @@ VerticalAlignment="Top" /> <local:VectoXMLFileSelector DockPanel.Dock="Top" Margin="10,0" VerticalAlignment="Top" - XMLFile="{Binding ComponentFile}" /> + XMLFile="{Binding XMLFile}" /> <Grid DockPanel.Dock="Top" Margin="10,0,1,0"> @@ -41,6 +41,7 @@ <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> @@ -50,13 +51,13 @@ <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,0,5"> <Label> <Label.Content> - <TextBlock Text="{Binding XMLValidationErrors.Count, StringFormat='{}{0} Warnings/Errors'}" /> + <TextBlock Text="{Binding XMLFile.XMLValidationErrors.Count, StringFormat='{}{0} Warnings/Errors'}" /> </Label.Content> <Label.Style> <Style TargetType="Label"> <Setter Property="Foreground" Value="Red" /> <Style.Triggers> - <DataTrigger Binding="{Binding XMLValidationErrors.Count}" Value="0"> + <DataTrigger Binding="{Binding XMLFile.XMLValidationErrors.Count}" Value="0"> <Setter Property="Foreground" Value="Black" /> </DataTrigger> </Style.Triggers> @@ -68,7 +69,7 @@ <Style TargetType="Button"> <Setter Property="IsEnabled" Value="True" /> <Style.Triggers> - <DataTrigger Binding="{Binding XMLValidationErrors.Count}" Value="0"> + <DataTrigger Binding="{Binding XMLFile.XMLValidationErrors.Count}" Value="0"> <Setter Property="IsEnabled" Value="False" /> </DataTrigger> </Style.Triggers> @@ -80,9 +81,14 @@ <Label Grid.Row="1" Grid.Column="0" Name="lblC14N" Content="Canonicalization:" HorizontalAlignment="Left" Margin="0" /> <TextBox Grid.Row="1" Grid.Column="1" Name="lblC14NList" - Text="{Binding CanonicalizaitionMethods, Converter={StaticResource CollectionConverter}}" + Text="{Binding CanonicalizationMethods, Mode=OneWay, Converter={StaticResource CollectionConverter}}" + Margin="10,2" /> + <Label Grid.Row="2" Grid.Column="0" Name="lblDigestMethod" Content="Digest Method:" HorizontalAlignment="Left" + Margin="0" /> + <TextBox Grid.Row="2" Grid.Column="1" Name="tbDigestMethod" + Text="{Binding DigestMethod}" Margin="10,2" /> - <Button Grid.Row="1" Grid.Column="2" Content="Copy" Margin="10,2,0,2" HorizontalAlignment="Right" Width="75" + <Button Grid.Row="3" Grid.Column="2" Content="Copy" Margin="10,2,0,2" HorizontalAlignment="Right" Width="75" Click="Button_Click_1"> <Button.Style> <Style TargetType="Button"> @@ -95,12 +101,12 @@ </Style> </Button.Style> </Button> - <Label Grid.Row="2" Grid.Column="0" x:Name="lblDigestValue" Content="Digest Value:" HorizontalAlignment="Left" + <Label Grid.Row="3" Grid.Column="0" x:Name="lblDigestValue" Content="Digest Value:" HorizontalAlignment="Left" Margin="0" Style="{StaticResource DigestValueLabelStyle}" /> - <TextBox Grid.Row="2" Grid.Column="1" x:Name="tbDigestValue" Text="{Binding DigestValue}" Margin="10,2" + <TextBox Grid.Row="3" Grid.Column="1" x:Name="tbDigestValue" Text="{Binding DigestValue}" Margin="10,2" VerticalAlignment="Top" RenderTransformOrigin="4.1,-2.1" Style="{StaticResource DigestValueTextboxStyle}" Foreground="{StaticResource Color.SuccessGreen}" /> - <ContentControl Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Center" Margin="0,0,0,0" + <ContentControl Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Top" Width="66" Height="64"> <ContentControl.LayoutTransform> <ScaleTransform ScaleX="1.5" ScaleY="1.5" /> diff --git a/HashingTool/Views/HashComponentData.xaml.cs b/HashingTool/Views/HashComponentData.xaml.cs index 9728536fc0..3f6d471c33 100644 --- a/HashingTool/Views/HashComponentData.xaml.cs +++ b/HashingTool/Views/HashComponentData.xaml.cs @@ -22,7 +22,7 @@ namespace HashingTool.Views private void Button_Click(object sender, RoutedEventArgs e) { var dialog = new XMLValidationErrorsDialog(); - dialog.XMLErrors = (DataContext as HashComponentDataViewModel).XMLValidationErrors; + dialog.XMLErrors = (DataContext as HashComponentDataViewModel).XMLFile.XMLValidationErrors; dialog.ShowDialog(); } diff --git a/HashingTool/Views/UserControl/VectoXMLFileSelector.xaml b/HashingTool/Views/UserControl/VectoXMLFileSelector.xaml index 8b598ee9bf..9de941b9b6 100644 --- a/HashingTool/Views/UserControl/VectoXMLFileSelector.xaml +++ b/HashingTool/Views/UserControl/VectoXMLFileSelector.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:views="clr-namespace:HashingTool.Views" + xmlns:userControl="clr-namespace:HashingTool.ViewModel.UserControl" x:Class="HashingTool.Views.VectoXMLFileSelector" mc:Ignorable="d" d:DesignWidth="456" MinHeight="32" d:DataContext="{d:DesignInstance views:VectoXMLFileSelector}"> @@ -13,7 +14,7 @@ <StackPanel Margin="0,5" HorizontalAlignment="Stretch"> <DockPanel HorizontalAlignment="Stretch" Height="Auto" Margin="0" VerticalAlignment="Top"> - <ContentControl DockPanel.Dock="Right" + <!--<ContentControl DockPanel.Dock="Right" Visibility="{Binding XMLFile.HasContentValidation, Converter={StaticResource BoolToVis}}" Width="40" Height="40" Margin="10,-5,5,0"> <ContentControl.LayoutTransform> @@ -35,27 +36,33 @@ </Style.Triggers> </Style> </ContentControl.Style> - </ContentControl> + </ContentControl>--> - <ContentControl DockPanel.Dock="Right" - Visibility="{Binding XMLFile.ValidateInput, Converter={StaticResource BoolToVis}}" Height="33" - Margin="0,5,0,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="90"> + <ContentControl DockPanel.Dock="Right" Height="33" Margin="0,5,5,0" VerticalAlignment="Top" + HorizontalAlignment="Right" Width="90" ToolTip="{Binding XMLFile.ToolTip}"> <ContentControl.LayoutTransform> <ScaleTransform ScaleX="0.5" ScaleY="0.5" /> </ContentControl.LayoutTransform> <ContentControl.Style> <Style TargetType="ContentControl"> - <Setter Property="ContentTemplate" Value="{StaticResource ICON_XML_unknown}" /> + <Setter Property="ContentTemplate" Value="{StaticResource ICON_XML_outline}" /> <Setter Property="ToolTip" Value="Not validated" /> <Style.Triggers> - <DataTrigger Binding="{Binding XMLFile.IsValid}" Value="True"> - <Setter Property="ContentTemplate" Value="{StaticResource Icon_XML_OK}" /> - <Setter Property="ToolTip" Value="Valid XML" /> + <DataTrigger Binding="{Binding XMLFile.IsValid}" Value="{x:Static userControl:XmlFileStatus.ValidXML}"> + <Setter Property="ContentTemplate" Value="{StaticResource Icon_XML_green}" /> + </DataTrigger> + <DataTrigger Binding="{Binding XMLFile.IsValid}" Value="{x:Static userControl:XmlFileStatus.IncorrectContent}"> + <Setter Property="ContentTemplate" Value="{StaticResource Icon_XML_green2}" /> + </DataTrigger> - <DataTrigger Binding="{Binding XMLFile.IsValid}" Value="False"> - <Setter Property="ContentTemplate" Value="{StaticResource Icon_XML_NOK}" /> - <Setter Property="ToolTip" Value="Invalid XML" /> + <DataTrigger Binding="{Binding XMLFile.IsValid}" Value="{x:Static userControl:XmlFileStatus.InvalidXML}"> + <Setter Property="ContentTemplate" Value="{StaticResource Icon_XML_green1}" /> + + </DataTrigger> + <DataTrigger Binding="{Binding XMLFile.IsValid}" Value="{x:Static userControl:XmlFileStatus.Invalid}"> + <Setter Property="ContentTemplate" Value="{StaticResource Icon_XML_red}" /> + </DataTrigger> </Style.Triggers> </Style> @@ -70,9 +77,9 @@ <TextBox DockPanel.Dock="Left" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="23" Margin="0,0,10,0" TextWrapping="NoWrap" Text="{Binding XMLFile.Source, UpdateSourceTrigger=PropertyChanged}"> <TextBox.InputBindings> - <KeyBinding Command="{Binding XMLFile.SetXMLFileCommnd}" Key="Return"/> + <KeyBinding Command="{Binding XMLFile.SetXMLFileCommnd}" Key="Return" /> </TextBox.InputBindings> - </TextBox> + </TextBox> </DockPanel> diff --git a/HashingTool/Views/VerifyComponentInputData.xaml b/HashingTool/Views/VerifyComponentInputData.xaml index 21c7c173e3..642cef1f27 100644 --- a/HashingTool/Views/VerifyComponentInputData.xaml +++ b/HashingTool/Views/VerifyComponentInputData.xaml @@ -8,10 +8,10 @@ xmlns:helper="clr-namespace:HashingTool.Helper" x:Class="HashingTool.Views.VerifyComponentInputData" mc:Ignorable="d" - d:DesignHeight="380" d:DesignWidth="534"> + d:DesignHeight="415" d:DesignWidth="534"> <UserControl.Resources> <helper:CollectionConverter x:Key="CollectionConverter" /> - + </UserControl.Resources> <UserControl.DataContext> <viewModel:VerifyComponentInputDataViewModel /> @@ -25,89 +25,98 @@ HorizontalAlignment="Right" Width="75" Height="22" VerticalAlignment="Bottom" /> <ScrollViewer VerticalScrollBarVisibility="Auto"> - <DockPanel> - <Label DockPanel.Dock="Top" x:Name="lblFileSelect" Content="Component data:" HorizontalAlignment="Left" - Margin="10,2,0,2" - VerticalAlignment="Top" /> - <views:VectoXMLFileSelector DockPanel.Dock="Top" Margin="10,0,0,0" VerticalAlignment="Top" - XMLFile="{Binding ComponentFile}" Height="80" /> - <Grid Margin="0,0,0,0" DockPanel.Dock="Bottom"> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="Auto"></ColumnDefinition> - <ColumnDefinition Width="*"></ColumnDefinition> - </Grid.ColumnDefinitions> - <Grid.RowDefinitions> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="*" /> - </Grid.RowDefinitions> + <DockPanel> + <Label DockPanel.Dock="Top" x:Name="lblFileSelect" Content="Component data:" HorizontalAlignment="Left" + Margin="10,2,0,2" + VerticalAlignment="Top" /> + <views:VectoXMLFileSelector DockPanel.Dock="Top" Margin="10,0,0,0" VerticalAlignment="Top" + XMLFile="{Binding XMLFile}" Height="80" /> + <Grid Margin="0,0,0,0" DockPanel.Dock="Bottom"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="*" /> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto"/> + <RowDefinition Height="*" /> + </Grid.RowDefinitions> - <Label Grid.Row="0" Grid.Column="0" Content="Component:" /> - <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Component}" Margin="10,2" IsReadOnly="True" /> + <Label Grid.Row="0" Grid.Column="0" Content="Component:" /> + <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Component}" Margin="10,2" IsReadOnly="True" /> - <Label Grid.Row="1" Grid.Column="0" Content="Canonicalization methods:" /> - <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding CanonicalizaitionMethods , Converter={StaticResource CollectionConverter}}" + <Label Grid.Row="1" Grid.Column="0" Content="Canonicalization methods:" /> + <TextBox Grid.Row="1" Grid.Column="1" + Text="{Binding CanonicalizationMethods ,Mode=OneWay, Converter={StaticResource CollectionConverter}}" Margin="10,2" IsReadOnly="True" /> + + <Label Grid.Row="2" Grid.Column="0" Content="Digest method:" /> + <TextBox Grid.Row="2" Grid.Column="1" + Text="{Binding DigestMethod ,Mode=OneWay}" + Margin="10,2" IsReadOnly="True" /> + + <Label Grid.Row="3" Grid.Column="0" Content="Digest Value read:" Style="{StaticResource DigestValueLabelStyle}" /> + <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding DigestValueRead}" Margin="10,2" IsReadOnly="True"> + <TextBox.Style> + <Style TargetType="TextBox" BasedOn="{StaticResource DigestValueTextboxStyle}"> + <Style.Triggers> + <DataTrigger Binding="{Binding ComponentDataValid}" Value="True"> + <Setter Property="Foreground" Value="{StaticResource Color.SuccessGreen}" /> + </DataTrigger> + <DataTrigger Binding="{Binding ComponentDataValid}" Value="False"> + <Setter Property="Foreground" Value="{StaticResource Color.ErrorRed}" /> + </DataTrigger> + </Style.Triggers> + </Style> + </TextBox.Style> + </TextBox> - <Label Grid.Row="2" Grid.Column="0" Content="Digest Value read:" Style="{StaticResource DigestValueLabelStyle}" Template="{DynamicResource LabelControlTemplate1}"/> - <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DigestValueRead}" Margin="10,2" IsReadOnly="True"> - <TextBox.Style> - <Style TargetType="TextBox" BasedOn="{StaticResource DigestValueTextboxStyle}"> - <Style.Triggers> - <DataTrigger Binding="{Binding ComponentDataValid}" Value="True"> - <Setter Property="Foreground" Value="{StaticResource Color.SuccessGreen}"/> - </DataTrigger> - <DataTrigger Binding="{Binding ComponentDataValid}" Value="False"> - <Setter Property="Foreground" Value="{StaticResource Color.ErrorRed}"/> - </DataTrigger> - </Style.Triggers> - </Style> - </TextBox.Style> - </TextBox> - - <Label Grid.Row="3" Grid.Column="0" Content="Digest Value computed:" Style="{StaticResource DigestValueLabelStyle}"/> - <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding DigestValueComputed}" Margin="10,2" IsReadOnly="True" > - <TextBox.Style> - <Style TargetType="TextBox" BasedOn="{StaticResource DigestValueTextboxStyle}"> - <Style.Triggers> - <DataTrigger Binding="{Binding ComponentDataValid}" Value="True"> - <Setter Property="Foreground" Value="{StaticResource Color.SuccessGreen}"/> - </DataTrigger> - <DataTrigger Binding="{Binding ComponentDataValid}" Value="False"> - <Setter Property="Foreground" Value="{StaticResource Color.ErrorRed}"/> - </DataTrigger> - </Style.Triggers> - </Style> - </TextBox.Style> + <Label Grid.Row="4" Grid.Column="0" Content="Digest Value computed:" + Style="{StaticResource DigestValueLabelStyle}" /> + <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding DigestValueComputed}" Margin="10,2" IsReadOnly="True"> + <TextBox.Style> + <Style TargetType="TextBox" BasedOn="{StaticResource DigestValueTextboxStyle}"> + <Style.Triggers> + <DataTrigger Binding="{Binding ComponentDataValid}" Value="True"> + <Setter Property="Foreground" Value="{StaticResource Color.SuccessGreen}" /> + </DataTrigger> + <DataTrigger Binding="{Binding ComponentDataValid}" Value="False"> + <Setter Property="Foreground" Value="{StaticResource Color.ErrorRed}" /> + </DataTrigger> + </Style.Triggers> + </Style> + </TextBox.Style> </TextBox> - <ContentControl Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="0,20,0,0" VerticalAlignment="Top" Width="66" Height="30"> - <ContentControl.LayoutTransform> - <ScaleTransform ScaleX="1.5" ScaleY="1.5" /> - </ContentControl.LayoutTransform> - <ContentControl.Style> - <Style TargetType="ContentControl"> - <Setter Property="Content" Value="" /> - <Setter Property="ToolTip" Value="" /> - <Style.Triggers> - <DataTrigger Binding="{Binding ComponentDataValid}" Value="True"> - <Setter Property="ContentTemplate" Value="{StaticResource Icon_OK}" /> - <Setter Property="ToolTip" Value="Component data validates against schema" /> - </DataTrigger> - <DataTrigger Binding="{Binding ComponentDataValid}" Value="False"> - <Setter Property="ContentTemplate" Value="{StaticResource Icon_NOK}" /> - <Setter Property="ToolTip" Value="Component data does NOT validat against schema" /> - </DataTrigger> - </Style.Triggers> - </Style> - </ContentControl.Style> - </ContentControl> - </Grid> + <ContentControl Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="0,20,0,0" + VerticalAlignment="Top" Width="66" Height="45"> + <ContentControl.LayoutTransform> + <ScaleTransform ScaleX="1.5" ScaleY="1.5" /> + </ContentControl.LayoutTransform> + <ContentControl.Style> + <Style TargetType="ContentControl"> + <Setter Property="Content" Value="" /> + <Setter Property="ToolTip" Value="" /> + <Style.Triggers> + <DataTrigger Binding="{Binding ComponentDataValid}" Value="True"> + <Setter Property="ContentTemplate" Value="{StaticResource Icon_OK}" /> + <Setter Property="ToolTip" Value="Component data validates against schema" /> + </DataTrigger> + <DataTrigger Binding="{Binding ComponentDataValid}" Value="False"> + <Setter Property="ContentTemplate" Value="{StaticResource Icon_NOK}" /> + <Setter Property="ToolTip" Value="Component data does NOT validat against schema" /> + </DataTrigger> + </Style.Triggers> + </Style> + </ContentControl.Style> + </ContentControl> + </Grid> - </DockPanel> + </DockPanel> </ScrollViewer> </DockPanel> </UserControl> \ No newline at end of file diff --git a/HashingTool/Views/VerifyJobInputData.xaml b/HashingTool/Views/VerifyJobInputData.xaml index 1fffde3318..ff20b83691 100644 --- a/HashingTool/Views/VerifyJobInputData.xaml +++ b/HashingTool/Views/VerifyJobInputData.xaml @@ -8,7 +8,7 @@ xmlns:helper="clr-namespace:HashingTool.Helper" x:Class="HashingTool.Views.VerifyJobInputData" mc:Ignorable="d" - d:DesignHeight="555" d:DesignWidth="534"> + d:DesignHeight="657" d:DesignWidth="534"> <UserControl.Resources> <helper:CollectionConverter x:Key="CollectionConverter" /> </UserControl.Resources> @@ -48,10 +48,15 @@ Text="{Binding CanonicalizationMethods , Converter={StaticResource CollectionConverter}, Mode=OneWay}" Margin="10,2" IsReadOnly="True" /> - <Label Grid.Row="2" Grid.Column="0" Content="Digest Value computed:" Style="{StaticResource DigestValueLabelStyle}" /> - <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DigestValueComputed}" Margin="10,2" + <Label Grid.Row="2" Grid.Column="0" Content="Digest method:" /> + <TextBox Grid.Row="2" Grid.Column="1" + Text="{Binding DigestMethod, Mode=OneWay}" + Margin="10,2" IsReadOnly="True" /> + + <Label Grid.Row="3" Grid.Column="0" Content="Digest Value computed:" Style="{StaticResource DigestValueLabelStyle}" /> + <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding DigestValueComputed}" Margin="10,2" IsReadOnly="True" Style="{StaticResource DigestValueTextboxStyle}" /> - <ContentControl Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="0,10,0,0" + <ContentControl Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" Width="50" Height="50"> <ContentControl.LayoutTransform> <ScaleTransform ScaleX="1.5" ScaleY="1.5" /> @@ -119,6 +124,7 @@ <RowDefinition /> <RowDefinition /> <RowDefinition /> + <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> @@ -129,8 +135,12 @@ <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding CanonicalizationMethod , Converter={StaticResource CollectionConverter}}" Margin="10,2" IsReadOnly="True" /> - <Label Grid.Row="1" Grid.Column="0" Content="Digest Value read:" Style="{StaticResource DigestValueLabelStyle}" /> - <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding DigestValueRead}" + <Label Grid.Row="1" Grid.Column="0" Content="Digest method:" /> + <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding DigestMethod}" + Margin="10,2" IsReadOnly="True" /> + + <Label Grid.Row="2" Grid.Column="0" Content="Digest Value read:" Style="{StaticResource DigestValueLabelStyle}" /> + <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DigestValueRead}" Margin="10,2" IsReadOnly="True"> <TextBox.Style> <Style TargetType="TextBox" BasedOn="{StaticResource DigestValueTextboxStyle}"> @@ -146,8 +156,8 @@ </TextBox.Style> </TextBox> - <Label Grid.Row="2" Grid.Column="0" Content="Digest Value computed:" Style="{StaticResource DigestValueLabelStyle}" /> - <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DigestValueComputed}" + <Label Grid.Row="3" Grid.Column="0" Content="Digest Value computed:" Style="{StaticResource DigestValueLabelStyle}" /> + <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding DigestValueComputed}" Margin="10,2" IsReadOnly="True" > <TextBox.Style> <Style TargetType="TextBox" BasedOn="{StaticResource DigestValueTextboxStyle}"> diff --git a/HashingTool/Views/VerifyResults.xaml b/HashingTool/Views/VerifyResults.xaml index d908026e8d..c21c99e5e5 100644 --- a/HashingTool/Views/VerifyResults.xaml +++ b/HashingTool/Views/VerifyResults.xaml @@ -17,8 +17,26 @@ <DataTemplate x:Key="ExpanderHeader" DataType="viewModel:VectoXMLFile"> <DockPanel HorizontalAlignment="Stretch" VerticalAlignment="top" MinWidth="450"> <TextBlock DockPanel.Dock="Top" Text="{Binding Name}" FontWeight="Bold" /> - - <views:VectoXMLFileSelector DockPanel.Dock="Left" Margin="0,0,35,0" VerticalAlignment="Top" + <ContentControl DockPanel.Dock="Right" Width="35" Height="35" Margin="10,-10,10,0" + ToolTip="{Binding JobValidToolTip}"> + <ContentControl.LayoutTransform> + <ScaleTransform ScaleX=".4" ScaleY=".4" /> + </ContentControl.LayoutTransform> + <ContentControl.Style> + <Style TargetType="ContentControl"> + <Setter Property="Content" Value="" /> + <Style.Triggers> + <DataTrigger Binding="{Binding Valid}" Value="True"> + <Setter Property="ContentTemplate" Value="{StaticResource Icon_OK}" /> + </DataTrigger> + <DataTrigger Binding="{Binding Valid}" Value="False"> + <Setter Property="ContentTemplate" Value="{StaticResource Icon_NOK}" /> + </DataTrigger> + </Style.Triggers> + </Style> + </ContentControl.Style> + </ContentControl> + <views:VectoXMLFileSelector DockPanel.Dock="Left" Margin="0,0,0,0" VerticalAlignment="Top" XMLFile="{Binding XMLFile}" Height="1" /> </DockPanel> @@ -60,6 +78,7 @@ <RowDefinition /> <RowDefinition /> <RowDefinition /> + <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> @@ -101,8 +120,13 @@ Text="{Binding CanonicalizationMethods, Mode=OneWay , Converter={StaticResource CollectionConverter}}" Margin="10,2" IsReadOnly="True" /> - <Label Grid.Row="2" Grid.Column="0" Content="Digest Value computed:" Style="{StaticResource DigestValueLabelStyle}" /> - <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DigestValueComputed}" + <Label Grid.Row="2" Grid.Column="0" Content="Digest method:" /> + <TextBox Grid.Row="2" Grid.Column="1" + Text="{Binding DigestMethod, Mode=OneWay}" + Margin="10,2" IsReadOnly="True" /> + + <Label Grid.Row="3" Grid.Column="0" Content="Digest Value computed:" Style="{StaticResource DigestValueLabelStyle}" /> + <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding DigestValueComputed}" Margin="10,2" IsReadOnly="True" Style="{StaticResource DigestValueTextboxStyle}" /> </Grid> </DataTemplate> @@ -115,6 +139,8 @@ <RowDefinition /> <RowDefinition /> <RowDefinition /> + <RowDefinition/> + <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> @@ -150,18 +176,26 @@ </Button> </StackPanel> - <Label Grid.Row="1" Grid.Column="0" Content="Job Digest Value from file:" + <Label Grid.Row="1" Grid.Column="0" Content="Job CanonicalizationMethod:" /> + <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding JobCanonicalizationMethod, Mode=OneWay, Converter={StaticResource CollectionConverter}}" + Margin="10,2" IsReadOnly="True" /> + + <Label Grid.Row="2" Grid.Column="0" Content="Job Digest Method:" /> + <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding JobDigestMethod, Mode=OneWay}" + Margin="10,2" IsReadOnly="True" /> + + <Label Grid.Row="3" Grid.Column="0" Content="Job Digest Value:" Style="{StaticResource DigestValueLabelStyle}" /> - <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding JobDigest, Mode=OneWay}" + <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding JobDigestValue, Mode=OneWay}" Margin="10,2" IsReadOnly="True" Style="{StaticResource DigestValueTextboxStyle}" /> - <Label Grid.Row="2" Grid.Column="0" Content="Canonicalization methods:" /> - <TextBox Grid.Row="2" Grid.Column="1" + <Label Grid.Row="4" Grid.Column="0" Content="Canonicalization methods:" /> + <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding CanonicalizationMethods, Mode=OneWay , Converter={StaticResource CollectionConverter}}" Margin="10,2" IsReadOnly="True" /> - <Label Grid.Row="3" Grid.Column="0" Content="Digest Value read:" Style="{StaticResource DigestValueLabelStyle}" /> - <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding DigestValueRead}" Margin="10,2" IsReadOnly="True"> + <Label Grid.Row="5" Grid.Column="0" Content="Digest Value read:" Style="{StaticResource DigestValueLabelStyle}" /> + <TextBox Grid.Row="5" Grid.Column="1" Text="{Binding DigestValueRead}" Margin="10,2" IsReadOnly="True"> <TextBox.Style> <Style TargetType="TextBox" BasedOn="{StaticResource DigestValueTextboxStyle}"> <Style.Triggers> @@ -176,8 +210,8 @@ </TextBox.Style> </TextBox> - <Label Grid.Row="4" Grid.Column="0" Content="Digest Value computed:" Style="{StaticResource DigestValueLabelStyle}" /> - <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding DigestValueComputed}" Margin="10,2" IsReadOnly="True"> + <Label Grid.Row="6" Grid.Column="0" Content="Digest Value computed:" Style="{StaticResource DigestValueLabelStyle}" /> + <TextBox Grid.Row="6" Grid.Column="1" Text="{Binding DigestValueComputed}" Margin="10,2" IsReadOnly="True"> <TextBox.Style> <Style TargetType="TextBox" BasedOn="{StaticResource DigestValueTextboxStyle}"> <Style.Triggers> diff --git a/VectoCommon/VectoHashing/VectoHash.cs b/VectoCommon/VectoHashing/VectoHash.cs index ecc279df70..1f1654c230 100644 --- a/VectoCommon/VectoHashing/VectoHash.cs +++ b/VectoCommon/VectoHashing/VectoHash.cs @@ -285,7 +285,9 @@ namespace TUGraz.VectoHashing private string DoGetDigestMethod(VectoComponents? component, int index) { var nodes = GetNodes(component, index); - return ReadDigestMethod(nodes[index].ParentNode); + var digestmethod = ReadDigestMethod(nodes[index].ParentNode); + digestmethod = digestmethod ?? XMLHashProvider.DefaultDigestMethod; + return digestmethod; } public IEnumerable<string> GetCanonicalizationMethods() @@ -301,7 +303,9 @@ namespace TUGraz.VectoHashing private IEnumerable<string> DoGetCanonicalizationMethods(VectoComponents? component, int index) { var nodes = GetNodes(component, index); - return ReadCanonicalizationMethods(nodes[index].ParentNode); + var c14N = ReadCanonicalizationMethods(nodes[index].ParentNode); + c14N = c14N ?? XMLHashProvider.DefaultCanonicalizationMethod; + return c14N; } public string ReadHash() -- GitLab