diff --git a/ErgometerLibrary/FileHandler.cs b/ErgometerLibrary/FileHandler.cs index c84c8ab..53b4e51 100644 --- a/ErgometerLibrary/FileHandler.cs +++ b/ErgometerLibrary/FileHandler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,9 +9,57 @@ namespace ErgometerLibrary { public class FileHandler { + public static string DataFolder { get; } = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "Ergometer"); + + public static void CheckDataFolder() + { + if(! Directory.Exists(DataFolder)) + { + Directory.CreateDirectory(DataFolder); + } + } + public static int GenerateSession() { - return 0; + string[] existingSessions = Directory.GetDirectories(DataFolder); + + Random rand = new Random(); + int sessionID = rand.Next(int.MinValue, int.MaxValue); + + + while (existingSessions.Contains(sessionID.ToString())) + { + sessionID = rand.Next(int.MinValue, int.MaxValue); + } + + return sessionID; + } + + public static void CreateSession(string naam, int session) + { + Directory.CreateDirectory(GetSessionFolder(session)); + File.Create(Path.Combine(GetSessionFolder(session), "session.prop")); + File.Create(Path.Combine(GetSessionFolder(session), "metingen.ergo")); + File.Create(Path.Combine(GetSessionFolder(session), "chat.log")); + + File.WriteAllText() + } + + private static string GetSessionFolder(int session) + { + return Path.Combine(DataFolder, session.ToString()); + } + private static string GetSessionFile(int session) + { + return Path.Combine(DataFolder, session.ToString(), "session.prop"); + } + private static string GetSessionMetingen(int session) + { + return Path.Combine(DataFolder, session.ToString(), "metingen.ergo"); + } + private static string GetSessionChat(int session) + { + return Path.Combine(DataFolder, session.ToString(), "chat.log"); } } } diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index 7df5d57..1334c8f 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -62,7 +62,7 @@ namespace ErgometerLibrary IsDoctor = doctor; } - public NetCommand Parse(string command) + public static NetCommand Parse(string command) { string[] com = command.Split('»'); @@ -92,13 +92,13 @@ namespace ErgometerLibrary } } - private NetCommand ParseSession(int session) + private static NetCommand ParseSession(int session) { NetCommand temp = new NetCommand(CommandType.SESSION, session); return temp; } - private NetCommand ParseLogoutRequest(int session, string[] args) + private static NetCommand ParseLogoutRequest(int session, string[] args) { if (args.Length != 1) throw new MissingFieldException("Error in NetCommand: Logout Request is missing arguments"); @@ -110,7 +110,7 @@ namespace ErgometerLibrary return temp; } - private NetCommand ParseChatMessage(int session, string[] args) + private static NetCommand ParseChatMessage(int session, string[] args) { if (args.Length != 1) throw new MissingFieldException("Error in NetCommand: Chat Message is missing arguments"); @@ -121,7 +121,7 @@ namespace ErgometerLibrary return temp; } - private NetCommand ParseData(int session, string[] args) + private static NetCommand ParseData(int session, string[] args) { if (args.Length != 9) throw new MissingFieldException("Error in NetCommand: Data is missing arguments"); @@ -132,7 +132,7 @@ namespace ErgometerLibrary return temp; } - private NetCommand ParseLoginRequest(int session, string[] args) + private static NetCommand ParseLoginRequest(int session, string[] args) { bool doctor = bool.Parse(args[1]); if (doctor && args.Length != 5)