Browse Source

implemeting new server and library

Bart Reedijk 10 years ago
parent
commit
c4a2bdebad
31 changed files with 736 additions and 254 deletions
  1. 2 1
      Proftaak Remote Healthcare/FietsClientV2/CurrentData.cs
  2. 1 1
      Proftaak Remote Healthcare/FietsClientV2/DataHandler.cs
  3. 3 0
      Proftaak Remote Healthcare/FietsClientV2/DoctorModel.cs
  4. 6 8
      Proftaak Remote Healthcare/FietsClientV2/FietsClient.csproj
  5. 2 0
      Proftaak Remote Healthcare/FietsClientV2/Forms/NewPatientForm.cs
  6. 2 1
      Proftaak Remote Healthcare/FietsClientV2/Forms/PatientForm.cs
  7. 0 59
      Proftaak Remote Healthcare/FietsClientV2/JSONObjecten/User.cs
  8. 7 6
      Proftaak Remote Healthcare/FietsClientV2/TCPConnection.cs
  9. 0 6
      Proftaak Remote Healthcare/FietsClientV2/lib/App.config
  10. 0 22
      Proftaak Remote Healthcare/FietsClientV2/lib/JsonConverter.cs
  11. 14 4
      Proftaak Remote Healthcare/FietsLibrary/Communication.cs
  12. 67 0
      Proftaak Remote Healthcare/FietsLibrary/FietsLibrary.csproj
  13. 1 1
      Proftaak Remote Healthcare/FietsLibrary/JSONObjecten/Measurement.cs
  14. 15 4
      Proftaak Remote Healthcare/FietsLibrary/JSONObjecten/Session.cs
  15. 1 1
      Proftaak Remote Healthcare/FietsLibrary/JSONObjecten/User.cs
  16. 20 5
      Proftaak Remote Healthcare/FietsLibrary/JsonConverter.cs
  17. 36 0
      Proftaak Remote Healthcare/FietsLibrary/Properties/AssemblyInfo.cs
  18. 40 0
      Proftaak Remote Healthcare/FietsLibrary/SSLCrypto.cs
  19. 416 0
      Proftaak Remote Healthcare/FietsLibrary/SelfSignedCertificate.cs
  20. 0 0
      Proftaak Remote Healthcare/FietsLibrary/packages.config
  21. 12 0
      Proftaak Remote Healthcare/Proftaak Remote Healthcare.sln
  22. 0 2
      Proftaak Remote Healthcare/Server/AppGlobal.cs
  23. 1 0
      Proftaak Remote Healthcare/Server/Client.cs
  24. 3 1
      Proftaak Remote Healthcare/Server/Server.csproj
  25. 0 0
      Proftaak Remote Healthcare/Server/packages.config
  26. 76 25
      Proftaak Remote Healthcare/ServerV2/AppGlobal.cs
  27. 0 44
      Proftaak Remote Healthcare/ServerV2/JSONObjecten/Measurement.cs
  28. 0 56
      Proftaak Remote Healthcare/ServerV2/JSONObjecten/Session.cs
  29. 2 0
      Proftaak Remote Healthcare/ServerV2/Program.cs
  30. 5 7
      Proftaak Remote Healthcare/ServerV2/ServerV2.csproj
  31. 4 0
      Proftaak Remote Healthcare/ServerV2/packages.config

+ 2 - 1
Proftaak Remote Healthcare/FietsClientV2/CurrentData.cs

@@ -1,4 +1,5 @@
-using FietsClient.JSONObjecten;
+using FietsLibrary.JSONObjecten;
+using FietsLibrary;
 using System;
 using System.Collections.Generic;
 using System.Linq;

+ 1 - 1
Proftaak Remote Healthcare/FietsClientV2/DataHandler.cs

@@ -8,7 +8,7 @@ using System.Threading;
 using System.Windows.Forms;
 using Newtonsoft.Json;
 using System.IO;
-using FietsClient.JSONObjecten;
+using FietsLibrary.JSONObjecten;
 
 namespace FietsClient
 {

+ 3 - 0
Proftaak Remote Healthcare/FietsClientV2/DoctorModel.cs

@@ -6,6 +6,9 @@ using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Windows.Forms.DataVisualization.Charting;
+using Measurement = FietsLibrary.JSONObjecten.Measurement;
+using FietsLibrary.JSONObjecten;
+using FietsLibrary;
 
 namespace FietsClient
 {

+ 6 - 8
Proftaak Remote Healthcare/FietsClientV2/FietsClient.csproj

@@ -97,16 +97,12 @@
     <Compile Include="Forms\NewPatientForm.Designer.cs">
       <DependentUpon>NewPatientForm.cs</DependentUpon>
     </Compile>
-    <Compile Include="JSONObjecten\Session.cs" />
-    <Compile Include="JSONObjecten\Measurement.cs" />
     <Compile Include="Forms\PatientForm.cs">
       <SubType>Form</SubType>
     </Compile>
     <Compile Include="Forms\PatientForm.Designer.cs">
       <DependentUpon>PatientForm.cs</DependentUpon>
     </Compile>
-    <Compile Include="JSONObjecten\User.cs" />
-    <Compile Include="lib\JsonConverter.cs" />
     <Compile Include="DoctorModel.cs" />
     <Compile Include="PatientModel.cs" />
     <Compile Include="Program.cs" />
@@ -140,7 +136,6 @@
       <DependentUpon>Resources.resx</DependentUpon>
       <DesignTime>True</DesignTime>
     </Compile>
-    <None Include="lib\packages.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -151,9 +146,6 @@
       <DesignTimeSharedInput>True</DesignTimeSharedInput>
     </Compile>
   </ItemGroup>
-  <ItemGroup>
-    <None Include="lib\App.config" />
-  </ItemGroup>
   <ItemGroup>
     <None Include="Resources\FeatureIconRebootMachines.png" />
   </ItemGroup>
@@ -169,6 +161,12 @@
       <Install>false</Install>
     </BootstrapperPackage>
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\FietsLibrary\FietsLibrary.csproj">
+      <Project>{bfc5d226-a81e-4990-a46f-f59ab541fa6a}</Project>
+      <Name>FietsLibrary</Name>
+    </ProjectReference>
+  </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.

+ 2 - 0
Proftaak Remote Healthcare/FietsClientV2/Forms/NewPatientForm.cs

@@ -7,6 +7,8 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using FietsLibrary;
+using FietsLibrary.JSONObjecten;
 
 namespace FietsClient.Forms
 {

+ 2 - 1
Proftaak Remote Healthcare/FietsClientV2/Forms/PatientForm.cs

@@ -9,7 +9,8 @@ using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Windows.Forms;
-using FietsClient.JSONObjecten;
+using FietsLibrary.JSONObjecten;
+using FietsLibrary;
 using System.Windows.Forms.DataVisualization.Charting;
 
 namespace FietsClient

+ 0 - 59
Proftaak Remote Healthcare/FietsClientV2/JSONObjecten/User.cs

@@ -1,59 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Newtonsoft.Json;
-using FietsClient.JSONObjecten;
-
-namespace FietsClient
-{
-    [Serializable]
-    public class User
-    {
-        
-        public string id { get; private set; }
-        public string password { get; private set; }
-        public List<Session> tests { get; private set; }
-        public int age { get; private set; }
-        public bool gender { get; private set; }
-        public int weight { get; private set; }
-
-        public bool isDoctor { get; private set; }
-
-        //Create Patient
-        public User(string id, string password, int age, bool gender, int weight)
-        {
-            this.id = id;
-            this.password = password;
-            this.tests = new List<Session>();
-            this.age = age;
-            this.gender = gender;
-            this.weight = weight;
-            this.isDoctor = false;
-        }
-
-        //Create Patient or Doctor
-        public User(string id, string password, int age, bool gender, int weight, bool isDoctor)
-        {
-            this.id = id;
-            this.password = password;
-            this.tests = new List<Session>();
-            this.age = age;
-            this.gender = gender;
-            this.weight = weight;
-            this.isDoctor = isDoctor;
-        }
-
-        public void AddSession(Session session)
-        {
-            tests.Add(session);
-        }
-        
-        public List<Session> GetSessions()
-        {
-            return tests;
-        }
-
-    }
-}

+ 7 - 6
Proftaak Remote Healthcare/FietsClientV2/TCPConnection.cs

@@ -1,4 +1,5 @@
-using FietsClient.JSONObjecten;
+using FietsLibrary.JSONObjecten;
+using FietsLibrary;
 using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
@@ -139,18 +140,20 @@ namespace FietsClient
                         case "0":   //login and display correct window after login
                             if (response_parts.Length == 4)
                             {
-                                SendGet(1);
+                                
 
                                 if (response_parts[1] == "1" && response_parts[2] == "1")
                                 {
                                     currentData = new CurrentData(userID);
                                     currentData.isDoctor = true;
+                                    SendGet(1);
                                 }
                                 else if (response_parts[2] == "0" && response_parts[1] == "1")
                                 {
 
                                     currentData = new CurrentData(userID);
                                     currentData.isDoctor = false;
+                                    SendGet(1);
                                 }
                                 else
                                     new Login("Geen gebruiker gevonden");
@@ -226,7 +229,7 @@ namespace FietsClient
         public void SendNewSession()
         {
             // send command ( cmdID | username )
-            SendString("3|" + userID + lib.JsonConverter.SerializeSession(currentData.GetSessions().Last()) + "|");
+            SendString("3|" + userID + FietsLibrary.JsonConverter.SerializeSession(currentData.GetSessions().Last()) + "|");
         }
 
         public void SendNewPatient(User user)
@@ -238,7 +241,7 @@ namespace FietsClient
         public void SendNewMeasurement()
         {
             // send command ( cmdID | username )
-            SendString("5|" + userID + lib.JsonConverter.SerializeLastMeasurement(currentData.GetSessions().Last().GetLastMeasurement()) + "|");
+            SendString("5|" + userID + FietsLibrary.JsonConverter.SerializeLastMeasurement(currentData.GetSessions().Last().GetLastMeasurement()) + "|");
         }
 
         public void SendChatMessage(string[] data)
@@ -274,8 +277,6 @@ namespace FietsClient
             SendString("12|" + userID + "|" + power + "|");
         }
 
-
-
         public void SendString(string s)
         {
 

+ 0 - 6
Proftaak Remote Healthcare/FietsClientV2/lib/App.config

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<configuration>
-    <startup> 
-        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
-    </startup>
-</configuration>

+ 0 - 22
Proftaak Remote Healthcare/FietsClientV2/lib/JsonConverter.cs

@@ -1,22 +0,0 @@
-using FietsClient.JSONObjecten;
-using Newtonsoft.Json;
-
-namespace FietsClient.lib
-{
-    class JsonConverter
-    {
-        public static string SerializeSession(Session s)
-        {
-            return JsonConvert.SerializeObject(s);
-        }
-        public static string SerializeUser(User user)
-        {
-            return JsonConvert.SerializeObject(user);
-        }
-
-        public static string SerializeLastMeasurement(Measurement measurement)
-        {
-            return JsonConvert.SerializeObject(measurement);
-        }
-    }
-}

+ 14 - 4
Proftaak Remote Healthcare/ServerV2/Libraries/Communication.cs → Proftaak Remote Healthcare/FietsLibrary/Communication.cs

@@ -2,14 +2,24 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Net.Security;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace ServerV2.Libraries
+namespace FietsLibrary
 {
-    class Communication
+   public class Communication
     {
+        public static void Send(string s, SslStream sslStream)
+        {
+            byte[] b = Encoding.ASCII.GetBytes(s);
+            sslStream.Write(b, 0, b.Length);
+            sslStream.Flush();
+        }
+
+        // depricated
+        /*
         //simple writeline and readline
         public static void WriteTextMessage(TcpClient client, string message)
         {
@@ -19,9 +29,8 @@ namespace ServerV2.Libraries
             stream.Flush();
         }
 
-        public static string ReadTextMessage(TcpClient client)
+        public static string ReadTextMessage(NetworkStream stream)
         {
-            StreamReader stream = new StreamReader(client.GetStream(), Encoding.Unicode);
             return stream.ReadLine();
         }
 
@@ -40,5 +49,6 @@ namespace ServerV2.Libraries
             while (client.GetStream().DataAvailable);
             return Encoding.Unicode.GetString(buffer, 0, totalRead);
         }
+        */
     }
 }

+ 67 - 0
Proftaak Remote Healthcare/FietsLibrary/FietsLibrary.csproj

@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.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>{BFC5D226-A81E-4990-A46F-F59AB541FA6A}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>FietsLibrary</RootNamespace>
+    <AssemblyName>FietsLibrary</AssemblyName>
+    <TargetFrameworkVersion>v4.5.2</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="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="JSONObjecten\Measurement.cs" />
+    <Compile Include="JSONObjecten\Session.cs" />
+    <Compile Include="JSONObjecten\User.cs" />
+    <Compile Include="Communication.cs" />
+    <Compile Include="JsonConverter.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SelfSignedCertificate.cs" />
+    <Compile Include="SSLCrypto.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </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>

+ 1 - 1
Proftaak Remote Healthcare/FietsClientV2/JSONObjecten/Measurement.cs → Proftaak Remote Healthcare/FietsLibrary/JSONObjecten/Measurement.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace FietsClient
+namespace FietsLibrary.JSONObjecten
 
 {
     [Serializable]

+ 15 - 4
Proftaak Remote Healthcare/FietsClientV2/JSONObjecten/Session.cs → Proftaak Remote Healthcare/FietsLibrary/JSONObjecten/Session.cs

@@ -1,13 +1,14 @@
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Security.Cryptography.X509Certificates;
 using System.Text;
 using System.Threading.Tasks;
 using Newtonsoft.Json;
-using System.IO;
 
-namespace FietsClient.JSONObjecten
+
+namespace FietsLibrary.JSONObjecten
 {
     [Serializable]
     public class Session
@@ -22,6 +23,16 @@ namespace FietsClient.JSONObjecten
 
         public Session(int bikeMode, string modevalue)
         {
+            if (!(Directory.Exists(@"JSON Files"))) 
+            {
+                Directory.CreateDirectory(@"JSON Files");
+            }
+            string[] fileEntries = Directory.GetFiles(@"JSON Files\");
+
+            if (fileEntries.Length > 0)
+                this.id = int.Parse(fileEntries[fileEntries.Length]);
+            else
+                this.id = 1;
 
             this.session = new List<Measurement>();
             this.isActive = true;
@@ -40,8 +51,8 @@ namespace FietsClient.JSONObjecten
         {
             return session.Last();
         }
-
-        public void PrintAll()
+	
+	public void PrintAll()
         {
             Console.WriteLine("pulse" + "\t" + "rpm" + "\t" + "speed" + "\t" + " dist" + "\t" + "req pow" + "\t" + "energy" + "\t" + "time" + "\t\t" + "act pow");
 

+ 1 - 1
Proftaak Remote Healthcare/ServerV2/JSONObjecten/User.cs → Proftaak Remote Healthcare/FietsLibrary/JSONObjecten/User.cs

@@ -5,7 +5,7 @@ using System.Text;
 using System.Threading.Tasks;
 using Newtonsoft.Json;
 
-namespace ServerV2.JSONObjecten
+namespace FietsLibrary.JSONObjecten
 {
     [Serializable]
     public class User

+ 20 - 5
Proftaak Remote Healthcare/ServerV2/Libraries/JsonConverter.cs → Proftaak Remote Healthcare/FietsLibrary/JsonConverter.cs

@@ -5,13 +5,28 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Newtonsoft.Json;
-using ServerV2.JSONObjecten;
+using FietsLibrary.JSONObjecten;
 
-namespace ServerV2.FileIO
+namespace FietsLibrary
 {
-    class JsonConverter
+    public class JsonConverter
     {
-        public static void SaveUser(User u)
+        public static string SerializeSession(Session s)
+        {
+            return JsonConvert.SerializeObject(s);
+        }
+
+	public static string SerializeUser(User user)
+        {
+            return JsonConvert.SerializeObject(user);
+        }
+
+	public static string SerializeLastMeasurement(Measurement measurement)
+        {
+            return JsonConvert.SerializeObject(measurement);
+        }
+
+	public static void SaveUser(User u)
         {
             File.WriteAllText(@"JSON Files\" + u.id + ".json", GetUser(u));
         }
@@ -33,7 +48,7 @@ namespace ServerV2.FileIO
 
         public static string GetLastMeasurement(Session currentSession)
         {
-            return JsonConvert.SerializeObject(currentSession.GetMeasurement());
+            return JsonConvert.SerializeObject(currentSession.GetLastMeasurement());
         }
 
         public static string GetUsers(List<User> user)

+ 36 - 0
Proftaak Remote Healthcare/FietsLibrary/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("FietsLibrary")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("FietsLibrary")]
+[assembly: AssemblyCopyright("Copyright ©  2015")]
+[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("bfc5d226-a81e-4990-a46f-f59ab541fa6a")]
+
+// 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")]

+ 40 - 0
Proftaak Remote Healthcare/FietsLibrary/SSLCrypto.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FietsLibrary
+{
+    public class SSLCrypto
+    {
+        public static void CreateSelfSignedCert()
+        {
+            if (!File.Exists("testcert.pfx"))
+            {
+                byte[] c = SelfSignedCertificate.CreateSelfSignCertificatePfx(
+            "CN=brdk.nl", //host name
+            DateTime.Parse("2015-01-01"), //not valid before
+            DateTime.Parse("2025-01-01"), //not valid after
+            "jancoow"); //password to encrypt key file
+
+                using (BinaryWriter binWriter = new BinaryWriter(
+                    File.Open(@"testcert.pfx", FileMode.Create)))
+                {
+                    binWriter.Write(c);
+                }
+            }
+        }
+
+        public static X509Certificate LoadCert()
+        {
+            X509Certificate cert = new X509Certificate2(
+                            @"testcert.pfx",
+                            "jancoow");
+            return cert;
+        }
+
+    }
+}

+ 416 - 0
Proftaak Remote Healthcare/FietsLibrary/SelfSignedCertificate.cs

@@ -0,0 +1,416 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Security.Cryptography.X509Certificates;
+using SecureString = System.Security.SecureString;
+using RuntimeHelpers = System.Runtime.CompilerServices.RuntimeHelpers;
+
+namespace FietsLibrary
+{
+    internal class SelfSignedCertificate
+    {
+        public static byte[] CreateSelfSignCertificatePfx(
+            string x500,
+            DateTime startTime,
+            DateTime endTime)
+        {
+            byte[] pfxData = CreateSelfSignCertificatePfx(
+                x500,
+                startTime,
+                endTime,
+                (SecureString)null);
+            return pfxData;
+        }
+
+        public static byte[] CreateSelfSignCertificatePfx(
+            string x500,
+            DateTime startTime,
+            DateTime endTime,
+            string insecurePassword)
+        {
+            byte[] pfxData;
+            SecureString password = null;
+
+            try
+            {
+                if (!string.IsNullOrEmpty(insecurePassword))
+                {
+                    password = new SecureString();
+                    foreach (char ch in insecurePassword)
+                    {
+                        password.AppendChar(ch);
+                    }
+
+                    password.MakeReadOnly();
+                }
+
+                pfxData = CreateSelfSignCertificatePfx(
+                    x500,
+                    startTime,
+                    endTime,
+                    password);
+            }
+            finally
+            {
+                if (password != null)
+                {
+                    password.Dispose();
+                }
+            }
+
+            return pfxData;
+        }
+
+        public static byte[] CreateSelfSignCertificatePfx(
+            string x500,
+            DateTime startTime,
+            DateTime endTime,
+            SecureString password)
+        {
+            byte[] pfxData;
+
+            if (x500 == null)
+            {
+                x500 = "";
+            }
+
+            SystemTime startSystemTime = ToSystemTime(startTime);
+            SystemTime endSystemTime = ToSystemTime(endTime);
+            string containerName = Guid.NewGuid().ToString();
+
+            GCHandle dataHandle = new GCHandle();
+            IntPtr providerContext = IntPtr.Zero;
+            IntPtr cryptKey = IntPtr.Zero;
+            IntPtr certContext = IntPtr.Zero;
+            IntPtr certStore = IntPtr.Zero;
+            IntPtr storeCertContext = IntPtr.Zero;
+            IntPtr passwordPtr = IntPtr.Zero;
+            RuntimeHelpers.PrepareConstrainedRegions();
+            try
+            {
+                Check(NativeMethods.CryptAcquireContextW(
+                    out providerContext,
+                    containerName,
+                    null,
+                    1, // PROV_RSA_FULL
+                    8)); // CRYPT_NEWKEYSET
+
+                Check(NativeMethods.CryptGenKey(
+                    providerContext,
+                    1, // AT_KEYEXCHANGE
+                    1, // CRYPT_EXPORTABLE
+                    out cryptKey));
+
+                IntPtr errorStringPtr;
+                int nameDataLength = 0;
+                byte[] nameData;
+
+                // errorStringPtr gets a pointer into the middle of the x500 string,
+                // so x500 needs to be pinned until after we've copied the value
+                // of errorStringPtr.
+                dataHandle = GCHandle.Alloc(x500, GCHandleType.Pinned);
+
+                if (!NativeMethods.CertStrToNameW(
+                    0x00010001, // X509_ASN_ENCODING | PKCS_7_ASN_ENCODING
+                    dataHandle.AddrOfPinnedObject(),
+                    3, // CERT_X500_NAME_STR = 3
+                    IntPtr.Zero,
+                    null,
+                    ref nameDataLength,
+                    out errorStringPtr))
+                {
+                    string error = Marshal.PtrToStringUni(errorStringPtr);
+                    throw new ArgumentException(error);
+                }
+
+                nameData = new byte[nameDataLength];
+
+                if (!NativeMethods.CertStrToNameW(
+                    0x00010001, // X509_ASN_ENCODING | PKCS_7_ASN_ENCODING
+                    dataHandle.AddrOfPinnedObject(),
+                    3, // CERT_X500_NAME_STR = 3
+                    IntPtr.Zero,
+                    nameData,
+                    ref nameDataLength,
+                    out errorStringPtr))
+                {
+                    string error = Marshal.PtrToStringUni(errorStringPtr);
+                    throw new ArgumentException(error);
+                }
+
+                dataHandle.Free();
+
+                dataHandle = GCHandle.Alloc(nameData, GCHandleType.Pinned);
+                CryptoApiBlob nameBlob = new CryptoApiBlob(
+                    nameData.Length,
+                    dataHandle.AddrOfPinnedObject());
+
+                CryptKeyProviderInformation kpi = new CryptKeyProviderInformation();
+                kpi.ContainerName = containerName;
+                kpi.ProviderType = 1; // PROV_RSA_FULL
+                kpi.KeySpec = 1; // AT_KEYEXCHANGE
+
+                certContext = NativeMethods.CertCreateSelfSignCertificate(
+                    providerContext,
+                    ref nameBlob,
+                    0,
+                    ref kpi,
+                    IntPtr.Zero, // default = SHA1RSA
+                    ref startSystemTime,
+                    ref endSystemTime,
+                    IntPtr.Zero);
+                Check(certContext != IntPtr.Zero);
+                dataHandle.Free();
+
+                certStore = NativeMethods.CertOpenStore(
+                    "Memory", // sz_CERT_STORE_PROV_MEMORY
+                    0,
+                    IntPtr.Zero,
+                    0x2000, // CERT_STORE_CREATE_NEW_FLAG
+                    IntPtr.Zero);
+                Check(certStore != IntPtr.Zero);
+
+                Check(NativeMethods.CertAddCertificateContextToStore(
+                    certStore,
+                    certContext,
+                    1, // CERT_STORE_ADD_NEW
+                    out storeCertContext));
+
+                NativeMethods.CertSetCertificateContextProperty(
+                    storeCertContext,
+                    2, // CERT_KEY_PROV_INFO_PROP_ID
+                    0,
+                    ref kpi);
+
+                if (password != null)
+                {
+                    passwordPtr = Marshal.SecureStringToCoTaskMemUnicode(password);
+                }
+
+                CryptoApiBlob pfxBlob = new CryptoApiBlob();
+                Check(NativeMethods.PFXExportCertStoreEx(
+                    certStore,
+                    ref pfxBlob,
+                    passwordPtr,
+                    IntPtr.Zero,
+                    7)); // EXPORT_PRIVATE_KEYS | REPORT_NO_PRIVATE_KEY | REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
+
+                pfxData = new byte[pfxBlob.DataLength];
+                dataHandle = GCHandle.Alloc(pfxData, GCHandleType.Pinned);
+                pfxBlob.Data = dataHandle.AddrOfPinnedObject();
+                Check(NativeMethods.PFXExportCertStoreEx(
+                    certStore,
+                    ref pfxBlob,
+                    passwordPtr,
+                    IntPtr.Zero,
+                    7)); // EXPORT_PRIVATE_KEYS | REPORT_NO_PRIVATE_KEY | REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
+                dataHandle.Free();
+            }
+            finally
+            {
+                if (passwordPtr != IntPtr.Zero)
+                {
+                    Marshal.ZeroFreeCoTaskMemUnicode(passwordPtr);
+                }
+
+                if (dataHandle.IsAllocated)
+                {
+                    dataHandle.Free();
+                }
+
+                if (certContext != IntPtr.Zero)
+                {
+                    NativeMethods.CertFreeCertificateContext(certContext);
+                }
+
+                if (storeCertContext != IntPtr.Zero)
+                {
+                    NativeMethods.CertFreeCertificateContext(storeCertContext);
+                }
+
+                if (certStore != IntPtr.Zero)
+                {
+                    NativeMethods.CertCloseStore(certStore, 0);
+                }
+
+                if (cryptKey != IntPtr.Zero)
+                {
+                    NativeMethods.CryptDestroyKey(cryptKey);
+                }
+
+                if (providerContext != IntPtr.Zero)
+                {
+                    NativeMethods.CryptReleaseContext(providerContext, 0);
+                    NativeMethods.CryptAcquireContextW(
+                        out providerContext,
+                        containerName,
+                        null,
+                        1, // PROV_RSA_FULL
+                        0x10); // CRYPT_DELETEKEYSET
+                }
+            }
+
+            return pfxData;
+        }
+
+        private static SystemTime ToSystemTime(DateTime dateTime)
+        {
+            long fileTime = dateTime.ToFileTime();
+            SystemTime systemTime;
+            Check(NativeMethods.FileTimeToSystemTime(ref fileTime, out systemTime));
+            return systemTime;
+        }
+
+        private static void Check(bool nativeCallSucceeded)
+        {
+            if (!nativeCallSucceeded)
+            {
+                int error = Marshal.GetHRForLastWin32Error();
+                Marshal.ThrowExceptionForHR(error);
+            }
+        }
+
+        [StructLayout(LayoutKind.Sequential)]
+        private struct SystemTime
+        {
+            public short Year;
+            public short Month;
+            public short DayOfWeek;
+            public short Day;
+            public short Hour;
+            public short Minute;
+            public short Second;
+            public short Milliseconds;
+        }
+
+        [StructLayout(LayoutKind.Sequential)]
+        private struct CryptoApiBlob
+        {
+            public int DataLength;
+            public IntPtr Data;
+
+            public CryptoApiBlob(int dataLength, IntPtr data)
+            {
+                this.DataLength = dataLength;
+                this.Data = data;
+            }
+        }
+
+        [StructLayout(LayoutKind.Sequential)]
+        private struct CryptKeyProviderInformation
+        {
+            [MarshalAs(UnmanagedType.LPWStr)]
+            public string ContainerName;
+            [MarshalAs(UnmanagedType.LPWStr)]
+            public string ProviderName;
+            public int ProviderType;
+            public int Flags;
+            public int ProviderParameterCount;
+            public IntPtr ProviderParameters; // PCRYPT_KEY_PROV_PARAM
+            public int KeySpec;
+        }
+
+        private static class NativeMethods
+        {
+            [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool FileTimeToSystemTime(
+                [In] ref long fileTime,
+                out SystemTime systemTime);
+
+            [DllImport("AdvApi32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool CryptAcquireContextW(
+                out IntPtr providerContext,
+                [MarshalAs(UnmanagedType.LPWStr)] string container,
+                [MarshalAs(UnmanagedType.LPWStr)] string provider,
+                int providerType,
+                int flags);
+
+            [DllImport("AdvApi32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool CryptReleaseContext(
+                IntPtr providerContext,
+                int flags);
+
+            [DllImport("AdvApi32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool CryptGenKey(
+                IntPtr providerContext,
+                int algorithmId,
+                int flags,
+                out IntPtr cryptKeyHandle);
+
+            [DllImport("AdvApi32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool CryptDestroyKey(
+                IntPtr cryptKeyHandle);
+
+            [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool CertStrToNameW(
+                int certificateEncodingType,
+                IntPtr x500,
+                int strType,
+                IntPtr reserved,
+                [MarshalAs(UnmanagedType.LPArray)] [Out] byte[] encoded,
+                ref int encodedLength,
+                out IntPtr errorString);
+
+            [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+            public static extern IntPtr CertCreateSelfSignCertificate(
+                IntPtr providerHandle,
+                [In] ref CryptoApiBlob subjectIssuerBlob,
+                int flags,
+                [In] ref CryptKeyProviderInformation keyProviderInformation,
+                IntPtr signatureAlgorithm,
+                [In] ref SystemTime startTime,
+                [In] ref SystemTime endTime,
+                IntPtr extensions);
+
+            [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool CertFreeCertificateContext(
+                IntPtr certificateContext);
+
+            [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+            public static extern IntPtr CertOpenStore(
+                [MarshalAs(UnmanagedType.LPStr)] string storeProvider,
+                int messageAndCertificateEncodingType,
+                IntPtr cryptProvHandle,
+                int flags,
+                IntPtr parameters);
+
+            [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool CertCloseStore(
+                IntPtr certificateStoreHandle,
+                int flags);
+
+            [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool CertAddCertificateContextToStore(
+                IntPtr certificateStoreHandle,
+                IntPtr certificateContext,
+                int addDisposition,
+                out IntPtr storeContextPtr);
+
+            [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool CertSetCertificateContextProperty(
+                IntPtr certificateContext,
+                int propertyId,
+                int flags,
+                [In] ref CryptKeyProviderInformation data);
+
+            [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+            [return: MarshalAs(UnmanagedType.Bool)]
+            public static extern bool PFXExportCertStoreEx(
+                IntPtr certificateStoreHandle,
+                ref CryptoApiBlob pfxBlob,
+                IntPtr password,
+                IntPtr reserved,
+                int flags);
+        }
+    }
+
+}

+ 0 - 0
Proftaak Remote Healthcare/FietsClientV2/lib/packages.config → Proftaak Remote Healthcare/FietsLibrary/packages.config


+ 12 - 0
Proftaak Remote Healthcare/Proftaak Remote Healthcare.sln

@@ -8,8 +8,16 @@ EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{06C35F7A-BA2D-4F7D-8F8E-39636027707B}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FietsClient", "FietsClientV2\FietsClient.csproj", "{96E4194B-1E09-42EA-AF10-09FC7B4444F8}"
+	ProjectSection(ProjectDependencies) = postProject
+		{BFC5D226-A81E-4990-A46F-F59AB541FA6A} = {BFC5D226-A81E-4990-A46F-F59AB541FA6A}
+	EndProjectSection
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerV2", "ServerV2\ServerV2.csproj", "{1C8D6858-FC95-4869-8E4A-6FE1BE36EAD6}"
+	ProjectSection(ProjectDependencies) = postProject
+		{BFC5D226-A81E-4990-A46F-F59AB541FA6A} = {BFC5D226-A81E-4990-A46F-F59AB541FA6A}
+	EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FietsLibrary", "FietsLibrary\FietsLibrary.csproj", "{BFC5D226-A81E-4990-A46F-F59AB541FA6A}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -35,6 +43,10 @@ Global
 		{1C8D6858-FC95-4869-8E4A-6FE1BE36EAD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{1C8D6858-FC95-4869-8E4A-6FE1BE36EAD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{1C8D6858-FC95-4869-8E4A-6FE1BE36EAD6}.Release|Any CPU.Build.0 = Release|Any CPU
+		{BFC5D226-A81E-4990-A46F-F59AB541FA6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{BFC5D226-A81E-4990-A46F-F59AB541FA6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{BFC5D226-A81E-4990-A46F-F59AB541FA6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{BFC5D226-A81E-4990-A46F-F59AB541FA6A}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 0 - 2
Proftaak Remote Healthcare/Server/AppGlobal.cs

@@ -13,8 +13,6 @@ namespace Server
         private static AppGlobal _instance;
 
         private List<User> users;
-        private List<User> activePatient;
-        private List<User> activeDoctor;
 
         public static AppGlobal Instance
         {

+ 1 - 0
Proftaak Remote Healthcare/Server/Client.cs

@@ -27,6 +27,7 @@ namespace Server
         public Client(TcpClient socket)
         {
             client = socket;
+            
 
             sslStream = new SslStream(client.GetStream());
             try

+ 3 - 1
Proftaak Remote Healthcare/Server/Server.csproj

@@ -33,8 +33,9 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Newtonsoft.Json">
+    <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+      <Private>True</Private>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
@@ -59,6 +60,7 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="lib\App.config" />
+    <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="JSONObjecten\JSON Files\" />

+ 0 - 0
Proftaak Remote Healthcare/ServerV2/JSONObjecten/packages.config → Proftaak Remote Healthcare/Server/packages.config


+ 76 - 25
Proftaak Remote Healthcare/ServerV2/AppGlobal.cs

@@ -1,7 +1,6 @@
 using Newtonsoft.Json;
-using ServerV2.FileIO;
-using ServerV2.JSONObjecten;
-using ServerV2.Libraries;
+using FietsLibrary.JSONObjecten;
+using FietsLibrary;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -10,23 +9,27 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
+using System.Net.Security;
+using System.IO;
+using System.Security.Authentication;
 
 namespace ServerV2
 {
     class AppGlobal
     {
-        private TcpListener listener;
-        private List<Client> clients = new List<Client>();
-        private List<User> users = new List<User>();
+        public TcpListener listener { get; private set; }
+        public List<Client> clients { get; private set; } = new List<Client>();
+        public List<User> users { get; private set; } = new List<User>();
 
         public AppGlobal()
         {
             listener = new TcpListener(IPAddress.Any, 1288);
             listener.Start();
+            TestMethode();
             while (true)
             {
-                TestMethode();
-                Console.WriteLine(FileIO.JsonConverter.GetUserSessions(users.ElementAt(1)));
+                
+                Console.WriteLine(FietsLibrary.JsonConverter.GetUserSessions(users.ElementAt(1)));
                 Console.WriteLine("waiting for clients...");
                 TcpClient client = listener.AcceptTcpClient();
                 Console.WriteLine("connection received");
@@ -53,13 +56,49 @@ namespace ServerV2
             users.ElementAt(1).tests.Add(session2);
         }
 
+        private SslStream InitialiseConnection(TcpClient client)
+        {
+            SslStream sslStream = new SslStream(client.GetStream());
+            try
+            {
+                sslStream.AuthenticateAsServer(SSLCrypto.LoadCert(), false, SslProtocols.Default, false);
+            }
+            catch (IOException e)
+            {
+                Console.WriteLine("IOExeption occured while a client tried to connect.");
+                Console.WriteLine(e.StackTrace);
+                //Stop();
+            }
+            Console.WriteLine("New client connected");
+            return sslStream;
+        }
+
+        
+
         private void receive(object obj)
         {
             TcpClient client = obj as TcpClient;
             User currentUser;
+
+            SslStream sslStream = InitialiseConnection(client);
+
             while (!(client.Client.Poll(0, SelectMode.SelectRead) && client.Client.Available == 0))
             {
-                string[] response = Encoding.ASCII.GetString(new byte[(int)client.ReceiveBufferSize]).Split('|');
+
+                byte[] bytesFrom = new byte[(int)client.ReceiveBufferSize];
+                try
+                {
+                    sslStream.Read(bytesFrom, 0, (int)client.ReceiveBufferSize);
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("Exception occured while trying to get data from client. Disconnecting...");
+                    Console.WriteLine(e.StackTrace);
+                    //Stop();
+                }
+
+                string[] response = Encoding.ASCII.GetString(bytesFrom).Split('|');
+
                 switch (response[0])
                 {
                     case "0":
@@ -78,32 +117,38 @@ namespace ServerV2
 
                             if (id > -1)
                             {
-                                if (users.First(item => item.id == response[1]).isDoctor)
+                                var user = users.FirstOrDefault(item => item.id == response[1]);
+                                if (user == null)
+                                {
+                                    Console.WriteLine("received incorrect username or password");
+                                    Communication.Send("0|0|0|", sslStream); // Does not exist
+                                }
+                                else if (user.isDoctor)
                                 {
                                     Console.WriteLine($"received login from docter username: {response[1]} ");
-                                    Communication.SendMessage(client, "0|1|1|");   // Doctor
+                                    Communication.Send("0|1|1|", sslStream);   // Doctor
                                 }
-                                else
+                                else if (!user.isDoctor)
                                 {
                                     Console.WriteLine($"received login from patient username: {response[1]} ");
-                                    Communication.SendMessage(client, "0|1|0|");   //Patient
+                                    Communication.Send("0|1|0|", sslStream);   //Patient
                                 }
-                                clients.Add(new Client(client, response[1]));
+                                clients.Add(new Client(client, sslStream, response[1]));
                             }
                             else
                             {
-                                Console.WriteLine("received incorrect username or password");
-                                Communication.SendMessage(client, "0|0|0|"); // Does not exist
+                                Console.WriteLine("IOException");
+                                Communication.Send("0|0|0|", sslStream); // Does not exist
                             }
                         }
                         break;
                     case "1":   //meetsessies ophalen
                         currentUser = users.First(item => item.id == response[1]);
-                        Communication.SendMessage(client, "1|" + FileIO.JsonConverter.GetUserSessions(currentUser));
+                        Communication.Send("1|" + FietsLibrary.JsonConverter.GetUserSessions(currentUser), sslStream);
                         break;
                     case "2":   //Livedata opvragen
                         currentUser = users.First(item => item.id == response[1]);
-                        FileIO.JsonConverter.GetLastMeasurement(currentUser.tests.Last());
+                        FietsLibrary.JsonConverter.GetLastMeasurement(currentUser.tests.Last());
                         break;
                     case "3":   //Nieuwe meetsessie aanmaken
                         if (response.Length == 6)
@@ -132,11 +177,11 @@ namespace ServerV2
 
                             string case6str = "7|" + sender + "|" + receiver + "|" + message;
                             Console.WriteLine(case6str);
-                            Communication.SendMessage(client, case6str);
+                            Communication.Send(case6str, sslStream);
                             for (int i = 0; i < clients.Count; i++)
                             {
                                 if (clients[i].username == receiver)
-                                    Communication.SendMessage(clients[i].tcpClient, "7|" + sender + "|" + receiver + "|" + message);
+                                    Communication.Send("7|" + sender + "|" + receiver + "|" + message, clients[i].sslStream);
                             }
                         }
                         break;
@@ -162,16 +207,18 @@ namespace ServerV2
                                     {
                                         strToSend += (patient + '\t');
                                     }
-                                Communication.SendMessage(client, strToSend.TrimEnd('\t'));
+                                Communication.Send(strToSend.TrimEnd('\t'), sslStream);
                             }
                         }
                         break;
                     case "9": //alles doorsturen voor de dokter
-                        Communication.SendMessage(client, FileIO.JsonConverter.GetUsers(users));
+                        Communication.Send(FietsLibrary.JsonConverter.GetUsers(users), sslStream);
                         break;
                     default:
                         break;
                 }
+
+
             }
         }
 
@@ -179,15 +226,19 @@ namespace ServerV2
 
     class Client
     {
-        public TcpClient tcpClient;
+        public TcpClient client { get; private set; }
+        public SslStream sslStream { get; private set; }
         public string username;
 
-        public Client(TcpClient tcpClient, string username)
+        public Client(TcpClient client, SslStream sslStream, string username)
         {
-            this.tcpClient = tcpClient;
+            this.client = client;
+            this.sslStream = sslStream;
             this.username = username;
         }
 
+        
+
     }
 }
 

+ 0 - 44
Proftaak Remote Healthcare/ServerV2/JSONObjecten/Measurement.cs

@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ServerV2.JSONObjecten
-
-{
-    [Serializable]
-    public class Measurement
-    {
-        public int pulse { get; private set; }
-        public int rpm { get; private set; }
-        public int speed { get; private set; }
-        public int wattage { get; private set; }
-        public int distance { get; private set; }
-        public int requestedPower { get; private set; }
-        public int energy { get; private set; }
-        public int actualPower { get; private set; }
-        public int time { get; private set; }
-        public int bpm { get; private set; }
-
-        public Measurement(int pulse, int rpm, int speed, int wattage, int distance, int requestedPower, int energy, int actualPower, int time, int bpm)
-        {
-            this.pulse = pulse;
-            this.rpm = rpm;
-            this.speed = speed;
-            this.wattage = wattage;
-            this.distance = distance;
-            this.requestedPower = requestedPower;
-            this.energy = energy;
-            this.actualPower = actualPower;
-            this.time = time;
-            this.bpm = bpm;
-        }
-
-
-        public override string ToString()
-        {
-            return "pulse: " + pulse + " - RPM: " + rpm + " speed: " + speed + " - distance: " + distance + " - requested power: " + requestedPower + " - energy: " + energy + " - time: " + time + " - actual power: " + actualPower;
-        }
-    }
-}

+ 0 - 56
Proftaak Remote Healthcare/ServerV2/JSONObjecten/Session.cs

@@ -1,56 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Security.Cryptography.X509Certificates;
-using System.Text;
-using System.Threading.Tasks;
-using Newtonsoft.Json;
-
-
-namespace ServerV2.JSONObjecten
-{
-    [Serializable]
-    public class Session
-    {
-        public int id { get; private set; }
-        public List<Measurement> session { get; private set; }
-        public bool isActive { get; private set; }
-        public int bikeMode { get; private set; }
-        public DateTime date { get; private set; }
-        public string note { get; private set; }
-        public string modevalue { get; private set; }
-
-        public Session(int bikeMode, string modevalue)
-        {
-            if (!(Directory.Exists(@"JSON Files"))) 
-            {
-                Directory.CreateDirectory(@"JSON Files");
-            }
-            string[] fileEntries = Directory.GetFiles(@"JSON Files\");
-
-            if (fileEntries.Length > 0)
-                this.id = int.Parse(fileEntries[fileEntries.Length]);
-            else
-                this.id = 1;
-
-            this.session = new List<Measurement>();
-            this.isActive = true;
-            this.bikeMode = bikeMode;
-            this.modevalue = modevalue;
-            this.date = DateTime.Now;
-            this.note = "";
-        }
-
-        public void AddMeasurement(Measurement m)
-        {
-            session.Add(m);
-        }
-
-        public Measurement GetMeasurement()
-        {
-            return session.Last();
-        }
-
-    }
-}

+ 2 - 0
Proftaak Remote Healthcare/ServerV2/Program.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using FietsLibrary;
 
 namespace ServerV2
 {
@@ -11,6 +12,7 @@ namespace ServerV2
         static void Main(string[] args)
         {
             Console.WriteLine("Server wordt gestart");
+            SSLCrypto.CreateSelfSignedCert();
             new AppGlobal();
         }
     }

+ 5 - 7
Proftaak Remote Healthcare/ServerV2/ServerV2.csproj

@@ -48,20 +48,18 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="AppGlobal.cs" />
-    <Compile Include="JSONObjecten\Measurement.cs" />
-    <Compile Include="JSONObjecten\Session.cs" />
-    <Compile Include="JSONObjecten\User.cs" />
-    <Compile Include="Libraries\Communication.cs" />
-    <Compile Include="Libraries\JsonConverter.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="App.config" />
-    <None Include="JSONObjecten\packages.config" />
+    <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup>
-    <Folder Include="JSONObjecten\JSON Files\" />
+    <ProjectReference Include="..\FietsLibrary\FietsLibrary.csproj">
+      <Project>{bfc5d226-a81e-4990-a46f-f59ab541fa6a}</Project>
+      <Name>FietsLibrary</Name>
+    </ProjectReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 4 - 0
Proftaak Remote Healthcare/ServerV2/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
+</packages>