Selaa lähdekoodia

Merge remote-tracking branch 'origin/Server'

Bart Reedijk 10 vuotta sitten
vanhempi
commit
c7f97efb1b

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

@@ -2,8 +2,10 @@
 using System.Threading;
 using System.Threading.Tasks;
 using System;
+using System.Linq;
 using Server.JSONObjecten;
 
+
 namespace Server
 {
     public class AppGlobal
@@ -23,6 +25,11 @@ namespace Server
             users.Add(new User("no", "no", 0, false, 0));
             users.Add(new User("JK123", "jancoow", 5, true, 100));
             users.Add(new User("TOM", "tommie", 80, false, 77, true));
+
+            users.ElementAt(1).tests.Add(new Session(1, "100"));
+            users.ElementAt(1).tests.Add(new Session(2, "110"));
+            users.ElementAt(0).tests.Add(new Session(3, "230"));
+            users.ElementAt(2).tests.Add(new Session(4, "300"));
         }
 
         public void CheckLogin(string username, string password, out int admin, out int id)
@@ -39,6 +46,11 @@ namespace Server
             }
         }
 
+        public List<User> testU()
+        {
+            return users;
+        } 
+
         public List<Session> GetTests(string patientid)
         {
             foreach (User u in users)
@@ -52,13 +64,13 @@ namespace Server
             return null;
         }
 
-        public void addMeetsessie(string patientid, int mode, string modevalue)
+        public void addSession(string patientid, int mode, string modevalue)
         {
             foreach (User u in users)
             {
                 if (u.id == patientid)
                 {
-                    u.addSession(mode, modevalue);
+                    u.addSession(new Session( mode, modevalue ));
                 }
             }
 

+ 8 - 2
Proftaak Remote Healthcare/Server/Client.cs

@@ -2,6 +2,7 @@
 using System.Text;
 using System.Net.Sockets;
 using System.Threading;
+using Server.FileIO;
 
 namespace Server
 {
@@ -53,14 +54,19 @@ namespace Server
                             break;
                         case "1":   //meetsessies ophalen
 
+                            foreach (User u in _global.testU())
+                            {
+                                JsonConverter.SaveUser(u);
+                            }
+
                             break;
                         case "2":   //Livedata opvragen
 
                             break;
                         case "3":   //Nieuwe meetsessie aanmaken
-                            if (response_parts.Length == 5 && iduser != -1)
+                            if (response_parts.Length == 6 && iduser != -1)
                             {
-                                _global.addMeetsessie(response_parts[1], Int32.Parse(response_parts[2]), response_parts[3]);
+                                _global.addSession(response_parts[1], Int32.Parse(response_parts[2]), response_parts[3]);
                             }
                             break;
                         case "4":   //Check nieuwe meetsessie

+ 20 - 0
Proftaak Remote Healthcare/Server/FileIO/JsonConverter.cs

@@ -0,0 +1,20 @@
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+using Server.JSONObjecten;
+
+namespace Server.FileIO
+{
+    class JsonConverter
+    {
+        public static void SaveUser(User u)
+        {
+            File.WriteAllText(Environment.CurrentDirectory + "\\" + u.id + ".json", u.ToJSON());
+        }
+        
+    }
+}

+ 1 - 0
Proftaak Remote Healthcare/Server/JSONObjecten/Measurement.cs

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
 
 namespace Server.JSONObjecten
 {
+    [Serializable]
     public class Measurement
     {
         public int rpm { get; private set; }

+ 22 - 5
Proftaak Remote Healthcare/Server/JSONObjecten/Session.cs

@@ -5,32 +5,49 @@ using System.Linq;
 using System.Security.Cryptography.X509Certificates;
 using System.Text;
 using System.Threading.Tasks;
+using Newtonsoft.Json;
+
 
 namespace Server.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 deviceID { 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 deviceid, int bikeMode, string modevalue )
+        public Session( int bikeMode, string modevalue )
         {
-            string[] fileEntries = Directory.GetFiles("JSONObjecten/JSON Files/");
-            this.id = int.Parse(fileEntries[fileEntries.Length]);
+            string[] fileEntries = Directory.GetFiles(@"../../JSONObjecten/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.deviceID = deviceid;
             this.bikeMode = bikeMode;
             this.modevalue = modevalue;
             this.date = DateTime.Now;
             this.note = "";
         }
 
+        public string GetJSONString()
+        {
+            return JsonConvert.SerializeObject(this);
+        }
+
     }
 }

+ 22 - 3
Proftaak Remote Healthcare/Server/JSONObjecten/User.cs

@@ -3,12 +3,15 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using Newtonsoft.Json;
 using Server.JSONObjecten;
 
 namespace Server
 {
-    class User
+    [Serializable]
+    public class User
     {
+        
         public string id { get; private set; }
         public string password { get; private set; }
         public List<Session> tests { get; private set; }
@@ -42,9 +45,25 @@ namespace Server
             this.isDoctor = isDoctor;
         }
 
-        public void addSession(int mode, string modevalue)
+        public void addSession(Session session)
         {
-            tests.Add(new Session(0,mode, modevalue));
+            tests.Add(session);
+        }
+
+        public string ToJSON()
+        {
+            return JsonConvert.SerializeObject(this);
+        }
+
+        public string getSessions()
+        {
+            string jsonSessions = "";
+            foreach (Session s in tests)
+            {
+                jsonSessions += s.GetJSONString();
+            }
+            return jsonSessions;
+
         }
 
     }

+ 7 - 0
Proftaak Remote Healthcare/Server/Server.csproj

@@ -33,6 +33,9 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Newtonsoft.Json">
+      <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
@@ -45,6 +48,7 @@
   <ItemGroup>
     <Compile Include="AppGlobal.cs" />
     <Compile Include="Client.cs" />
+    <Compile Include="FileIO\JsonConverter.cs" />
     <Compile Include="JSONObjecten\Measurement.cs" />
     <Compile Include="JSONObjecten\Session.cs" />
     <Compile Include="JSONObjecten\User.cs" />
@@ -57,6 +61,9 @@
   <ItemGroup>
     <Folder Include="JSONObjecten\JSON Files\" />
   </ItemGroup>
+  <ItemGroup>
+    <WCFMetadata Include="Service References\" />
+  </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.