//Create new session.
 #region
 public Boolean CreateNewSession(string username, Boolean responseStartSession)
 {
     if (!IsDoctor)
     {
         NoPermission("doctor/training/start");
         return(false);
     }
     else
     {
         Session client = Program.GetSessionWithUsername(username);
         if (client == null)
         {
             Send(JsonConvert.SerializeObject(Commands.DoctorTrainingStartError("No client active with given username.")));
             return(false);
         }
         try
         {
             if (Database.AddActiveSession(username))
             {
                 dynamic answer = new
                 {
                     id   = "session/start",
                     data = new
                     {
                         status    = "OK",
                         sessionID = username
                     }
                 };
                 if (responseStartSession)
                 {
                     client.Send(JsonConvert.SerializeObject(answer));
                 }
                 return(true);
             }
             else
             {
                 Send(JsonConvert.SerializeObject(Commands.DoctorTrainingStartError("Username already active. Other session has to be stopped first before starting a new one.")));
                 return(false);
             }
         }
         catch (Exception e)
         {
             Send(JsonConvert.SerializeObject(Commands.DoctorTrainingStartError(e.Message)));
             return(false);
         }
     }
 }
Exemple #2
0
 //Close session
 #region
 public Boolean CloseSession(string sessionId)
 {
     if (!IsDoctor)
     {
         NoPermission("doctor/training/stop");
         return(false);
     }
     else
     {
         Session client = Program.GetSessionWithUsername(sessionId);
         if (client == null)
         {
             Send(JsonConvert.SerializeObject(Commands.DoctorTrianingStopError("No client active with given username.")));
             return(false);
         }
         try
         {
             Database.CloseActiveSession(sessionId);
             dynamic answer = new
             {
                 id   = "session/end",
                 data = new
                 {
                     status = "OK"
                 }
             };
             client.Send(JsonConvert.SerializeObject(answer));
             Program.sessions.Remove(client);
             return(true);
         }
         catch (Exception e)
         {
             Send(JsonConvert.SerializeObject(Commands.DoctorTrianingStopError(e.Message)));
             return(false);
         }
     }
 }
 //StartAstrand from patient
 #region
 public void StartAstrandFromPatient(string patientId)
 {
     try
     {
         Session clientToStart = Program.GetSessionWithUsername(patientId);
         if (clientToStart != null)
         {
             dynamic answer = new
             {
                 id   = "StartAstrand",
                 data = new
                 {
                     sessionId = patientId
                 }
             };
             clientToStart.Send(JsonConvert.SerializeObject(answer));
             dynamic answerToDocter = new
             {
                 id   = "Doctor/StartAstrand",
                 data = new
                 {
                     status = "ok"
                 }
             };
             Send(JsonConvert.SerializeObject(answerToDocter));
             Database.AddActiveSession(patientId);
         }
         else
         {
             Send(JsonConvert.SerializeObject(Commands.StartAstrandError("Patient not found")));
         }
     }
     catch (Exception e)
     {
         Send(JsonConvert.SerializeObject(Commands.StartAstrandError(e.Message)));
     }
 }