From 1c7550faabcbe2080ca60567907fe3db17178d69 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Wed, 3 May 2017 14:13:50 +0200
Subject: [PATCH] creating new project

---
 VECTO.sln                                     | 22 +++---
 .../VectoHashing/Properties/AssemblyInfo.cs   | 36 +++++++++
 VectoCommon/VectoHashing/VectoHashing.csproj  | 54 ++++++++++++++
 VectoCommon/VectoHashing/XmlHashProvider.cs   | 73 +++++++++++++++++++
 VectoCore/VectoXML.spp                        |  8 ++
 5 files changed, 182 insertions(+), 11 deletions(-)
 create mode 100644 VectoCommon/VectoHashing/Properties/AssemblyInfo.cs
 create mode 100644 VectoCommon/VectoHashing/VectoHashing.csproj
 create mode 100644 VectoCommon/VectoHashing/XmlHashProvider.cs

diff --git a/VECTO.sln b/VECTO.sln
index 5ae950a30c..e454383d41 100644
--- a/VECTO.sln
+++ b/VECTO.sln
@@ -50,14 +50,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoAPI Test", "..\VECTO_A
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoEngineeringAPI", "..\VECTO_API\VectoEngineeringAPI\VectoEngineeringAPI.csproj", "{41314A40-AB3E-4F43-B1A4-58443F4014F2}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoEngineeringAPITest", "..\VECTO_API\VectoEngineeringAPITest\VectoEngineeringAPITest.csproj", "{35FBDFEF-07E6-4E2C-8C18-4753266A6EDE}"
-EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excel2XML", "..\VECTO_API\Excel2XML\Excel2XML.csproj", "{749F150A-F974-46DC-A1E2-F4153C54FC0D}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoDB", "..\VECTO_API\VectoDB\VectoDB.csproj", "{2C58BA97-2954-4D19-920F-A24B78FC80A4}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoCore BugReportTests", "..\VECTO-Bugreports\BugReportTests\VectoCore BugReportTests.csproj", "{7C364099-9B85-473A-8A42-BBEBE4798FF5}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoHashing", "VectoCommon\VectoHashing\VectoHashing.csproj", "{B673E12F-D323-4C4C-8805-9915B2C72D3D}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -204,14 +204,6 @@ Global
 		{41314A40-AB3E-4F43-B1A4-58443F4014F2}.Release|Any CPU.Build.0 = Release|Any CPU
 		{41314A40-AB3E-4F43-B1A4-58443F4014F2}.Release|x64.ActiveCfg = Release|Any CPU
 		{41314A40-AB3E-4F43-B1A4-58443F4014F2}.Release|x86.ActiveCfg = Release|Any CPU
-		{35FBDFEF-07E6-4E2C-8C18-4753266A6EDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{35FBDFEF-07E6-4E2C-8C18-4753266A6EDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{35FBDFEF-07E6-4E2C-8C18-4753266A6EDE}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{35FBDFEF-07E6-4E2C-8C18-4753266A6EDE}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{35FBDFEF-07E6-4E2C-8C18-4753266A6EDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{35FBDFEF-07E6-4E2C-8C18-4753266A6EDE}.Release|Any CPU.Build.0 = Release|Any CPU
-		{35FBDFEF-07E6-4E2C-8C18-4753266A6EDE}.Release|x64.ActiveCfg = Release|Any CPU
-		{35FBDFEF-07E6-4E2C-8C18-4753266A6EDE}.Release|x86.ActiveCfg = Release|Any CPU
 		{749F150A-F974-46DC-A1E2-F4153C54FC0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{749F150A-F974-46DC-A1E2-F4153C54FC0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{749F150A-F974-46DC-A1E2-F4153C54FC0D}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -236,6 +228,14 @@ Global
 		{7C364099-9B85-473A-8A42-BBEBE4798FF5}.Release|Any CPU.Build.0 = Release|Any CPU
 		{7C364099-9B85-473A-8A42-BBEBE4798FF5}.Release|x64.ActiveCfg = Release|Any CPU
 		{7C364099-9B85-473A-8A42-BBEBE4798FF5}.Release|x86.ActiveCfg = Release|Any CPU
+		{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Release|Any CPU.Build.0 = Release|Any CPU
+		{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Release|x64.ActiveCfg = Release|Any CPU
+		{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Release|x86.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -254,9 +254,9 @@ Global
 		{512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64} = {D29E62A2-CF08-469F-B29F-1B25DCB35386}
 		{D959CB7C-F514-4F5E-9C33-684D0012474B} = {D29E62A2-CF08-469F-B29F-1B25DCB35386}
 		{41314A40-AB3E-4F43-B1A4-58443F4014F2} = {D29E62A2-CF08-469F-B29F-1B25DCB35386}
-		{35FBDFEF-07E6-4E2C-8C18-4753266A6EDE} = {D29E62A2-CF08-469F-B29F-1B25DCB35386}
 		{749F150A-F974-46DC-A1E2-F4153C54FC0D} = {351FF7E8-B56B-445E-8E98-A61E07C990DA}
 		{2C58BA97-2954-4D19-920F-A24B78FC80A4} = {D29E62A2-CF08-469F-B29F-1B25DCB35386}
 		{7C364099-9B85-473A-8A42-BBEBE4798FF5} = {CC93EA68-F3FE-4BCB-9292-1101F94A4D09}
+		{B673E12F-D323-4C4C-8805-9915B2C72D3D} = {73A5BF70-6168-456F-95E5-A1402BFA488C}
 	EndGlobalSection
 EndGlobal
diff --git a/VectoCommon/VectoHashing/Properties/AssemblyInfo.cs b/VectoCommon/VectoHashing/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000000..80e43d082c
--- /dev/null
+++ b/VectoCommon/VectoHashing/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("VectoHashing")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("VectoHashing")]
+[assembly: AssemblyCopyright("Copyright ©  2017")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("334248fa-331e-4255-97fe-617e1a497f6f")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/VectoCommon/VectoHashing/VectoHashing.csproj b/VectoCommon/VectoHashing/VectoHashing.csproj
new file mode 100644
index 0000000000..a0f3da0a2d
--- /dev/null
+++ b/VectoCommon/VectoHashing/VectoHashing.csproj
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{B673E12F-D323-4C4C-8805-9915B2C72D3D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>TUGraz.VectoHashing</RootNamespace>
+    <AssemblyName>VectoHashing</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Security" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="XmlHashProvider.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file
diff --git a/VectoCommon/VectoHashing/XmlHashProvider.cs b/VectoCommon/VectoHashing/XmlHashProvider.cs
new file mode 100644
index 0000000000..bc25160ed3
--- /dev/null
+++ b/VectoCommon/VectoHashing/XmlHashProvider.cs
@@ -0,0 +1,73 @@
+using System;
+using System.IO;
+using System.Security.Cryptography;
+using System.Security.Cryptography.Xml;
+using System.Xml;
+
+namespace VectoDB
+{
+	public class XmlHashProvider
+	{
+		protected string File;
+
+		public XmlHashProvider(string file)
+		{
+			File = file;
+		}
+
+		public string ComputeHash(string xpath)
+		{
+			var xml = new XmlDocument() { PreserveWhitespace = true };
+			var manager = new XmlNamespaceManager(xml.NameTable);
+			manager.AddNamespace("ved", "urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.6");
+			manager.AddNamespace("tns", "urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.6");
+
+			using (var fs = new FileStream(File, FileMode.Open)) {
+				using (var sr = new StreamReader(fs)) {
+					xml.Load(new LineCleaningTextReader(sr));
+				}
+			}
+
+			var nodeList = xml.SelectNodes(string.Format("{0}/descendant-or-self::node()|{0}//@*", xpath), manager);
+			if (nodeList == null || nodeList.Count == 0) {
+				throw new Exception(string.Format("Selected node '{0}' not found in input!", xpath));
+			}
+			var transform = new XmlDsigC14NTransform();
+			transform.LoadInput(nodeList);
+
+			var sha256 = new SHA256CryptoServiceProvider();
+
+			var hash = sha256.ComputeHash((Stream)transform.GetOutput(typeof(Stream)));
+			return Convert.ToBase64String(hash);
+		}
+
+		private class LineCleaningTextReader : TextReader
+		{
+			private readonly TextReader _src;
+
+			public LineCleaningTextReader(TextReader src)
+			{
+				_src = src;
+			}
+
+			public override int Read()
+			{
+				int r = _src.Read();
+				switch (r) {
+					case 0xD: // \r
+						switch (_src.Peek()) {
+							case 0xA:
+							case 0x85: // \n or NEL char
+								_src.Read();
+								break;
+						}
+						return 0xA;
+					case 0x85: //NEL
+						return 0xA;
+					default:
+						return r;
+				}
+			}
+		}
+	}
+}
\ No newline at end of file
diff --git a/VectoCore/VectoXML.spp b/VectoCore/VectoXML.spp
index c06a8df0da..edbf55c904 100644
--- a/VectoCore/VectoXML.spp
+++ b/VectoCore/VectoXML.spp
@@ -10,10 +10,18 @@
 		<File FilePath="VectoCoreTest\TestData\XML\XMLReaderEngineering\engineering_job-sample_ref.xml" HomeFolder="Yes"/>
 		<File FilePath="VectoCoreTest\TestData\XML\XMLReaderEngineering\engineering_retarder-sample_ref.xml" HomeFolder="Yes"/>
 		<File FilePath="VectoCoreTest\TestData\XML\XMLReaderEngineering\engineering_vehicle_ref.xml" HomeFolder="Yes"/>
+		<File FilePath="VectoCoreTest\TestData\XML\Hashing\vecto_engine-sample Encoding ISO 8859-15.xml" HomeFolder="Yes"/>
+		<File FilePath="VectoCoreTest\TestData\XML\Hashing\vecto_engine-sample Encoding UTF-16 BE BOM.xml" HomeFolder="Yes"/>
+		<File FilePath="VectoCoreTest\TestData\XML\Hashing\vecto_engine-sample Encoding UTF-16 LE.xml" HomeFolder="Yes"/>
+		<File FilePath="VectoCoreTest\TestData\XML\Hashing\vecto_engine-sample Encoding UTF-8 BOM.xml" HomeFolder="Yes"/>
+		<File FilePath="VectoCoreTest\TestData\XML\Hashing\vecto_engine-sample Encoding UTF-8.xml" HomeFolder="Yes"/>
+		<File FilePath="VectoCoreTest\TestData\XML\Hashing\vecto_engine-sample Encoding windows-1292.xml" HomeFolder="Yes"/>
 		<File FilePath="VectoCoreTest\TestData\XML\XMLReaderDeclaration\vecto_engine-sample.xml" HomeFolder="Yes"/>
+		<File FilePath="VectoCoreTest\TestData\XML\Hashing\vecto_engine-sample_Whitespaces.xml" HomeFolder="Yes"/>
 		<File FilePath="VectoCoreTest\TestData\XML\XMLReaderDeclaration\vecto_gearbox-sample.xml" HomeFolder="Yes"/>
 		<File FilePath="VectoCoreTest\TestData\XML\XMLReaderDeclaration\vecto_vehicle-sample.xml" HomeFolder="Yes"/>
 		<File FilePath="VectoCoreTest\TestData\XML\XMLReaderDeclaration\vecto_vehicle-sample_FULL.xml" HomeFolder="Yes"/>
+		<File FilePath="VectoCoreTest\TestData\XML\Hashing\vecto_vehicle-sample_FULL_Entry_Order.xml" HomeFolder="Yes"/>
 	</Folder>
 	<Folder FolderName="XSL Files" ExtStr="xsl;xslt">
 		<File FilePath="E:\QUAM\Workspace\VECTO_API\API\RenderTable.xslt" HomeFolder="Yes"/>
-- 
GitLab