private static void InitiateSesion(Chat User, string token, Session.SessionType Type) { switch (Type) { case Session.SessionType.Pass: var ThisPoll = new Analyze(token, 1488).GetPoll(); Queue <Question> Questions = new Queue <Question>(); foreach (var question in ThisPoll.Questions) { Questions.Enqueue(question); } var ses = new Session(User, Questions, Session.SessionType.Pass, ThisPoll); SendQuestion(ses.Questions, ses.Chat); Sessions.Add(ses); break; case Session.SessionType.Create: Sessions.Add(new Session(User, null, Session.SessionType.Create, null)); break; } }
/// <summary> /// Create the instance of a seesion according to the session type. /// </summary> /// <param name="fileName">represents the sessionfile name.</param> /// <returns>instance of a session.</returns> public Session CreateSession(string fileName) { Session session = null; try { // Open the file and determine the SessionType Session.SessionType sessionType = DetermineSessionType(fileName); switch (sessionType) { case Session.SessionType.ST_MEDIA: session = new MediaSession(fileName); break; case Session.SessionType.ST_SCRIPT: session = new ScriptSession(fileName); break; case Session.SessionType.ST_EMULATOR: session = new EmulatorSession(fileName); break; case Session.SessionType.ST_UNKNOWN: break; } if (session != null) { sessionObjects.Add(session); } } catch (Exception ex) { session = null; Exception excp; throw excp = new Exception(ex.Message); } return(session); }
private void validateSession(Session session, string name, string subjectNumber, string ip, Session.SessionType sessionType) { Assert.IsNotNull(session.id); Assert.AreEqual(session.name, name); Assert.AreEqual(session.subjectNumber, subjectNumber); Assert.AreEqual(session.sessionType, sessionType); Assert.AreEqual(session.ip, ip); }
/// <summary> /// Save the session under a new file name. /// /// A new session object will be created from this new saved file (and returned by this method) /// and added to the project. The original session wil not be saved. /// </summary> /// <param name="theCurrentSession"></param> /// <returns>The new created session object, null if save as a new session has been cancelled or failed.</returns> public Session SaveSessionAs(Session theCurrentSession) { Session theNewSession = null; SaveFileDialog theSaveFileDialog = new SaveFileDialog(); theSaveFileDialog.AddExtension = true; theSaveFileDialog.DefaultExt = ".ses"; theSaveFileDialog.OverwritePrompt = false; theSaveFileDialog.Filter = "All session files (*.ses)|*.ses"; DialogResult theDialogResult = theSaveFileDialog.ShowDialog(); // User has specified a file name and has pressed the OK button. if (theDialogResult == DialogResult.OK) { if (File.Exists(theSaveFileDialog.FileName)) { MessageBox.Show(string.Format("File name \"{0}\" already exists.\nOperation cancelled", theSaveFileDialog.FileName)); } else { // Save the current session to a new file. string theCurrentSessionFullFileName = theCurrentSession.SessionFileName; theCurrentSession.SessionFileName = theSaveFileDialog.FileName; theCurrentSession.Save(); Session.SessionType sessionType = theCurrentSession.sessionType; // Create a new session object from this new saved file and replace the current session. switch (sessionType) { case Session.SessionType.ST_MEDIA: theNewSession = new MediaSession(theSaveFileDialog.FileName); LoadSession(); break; case Session.SessionType.ST_SCRIPT: theNewSession = new ScriptSession(theSaveFileDialog.FileName); LoadSession(); break; case Session.SessionType.ST_EMULATOR: theNewSession = new EmulatorSession(theSaveFileDialog.FileName); LoadSession(); break; case Session.SessionType.ST_UNKNOWN: break; } // Create a new session object from this new saved file and replace the current session. if (theNewSession != null) { int theCurrentIndex = GetLoadedSessionsIndex(theCurrentSession); parentProject.Sessions[theCurrentIndex] = theNewSession; parentProject.HasProjectChanged = true; } } } return(theNewSession); }