Beispiel #1
0
        // Returns a ReGameSession object by deserializing file at specified path
        public static ReGameSession Load(string filePath)
        {
            if (File.Exists(filePath))
            {
                BinaryFormatter formatter    = new BinaryFormatter();
                FileStream      saveFile     = File.Open(filePath, FileMode.Open);
                ReGameSession   savedSession = (ReGameSession)formatter.Deserialize(saveFile);
                saveFile.Close();

                return(savedSession);
            }

            return(null);
        }
Beispiel #2
0
        // Returns a pretty-printed string to display info about a session
        public static string FormatSession(ReGameSession session)
        {
            // format info for Therapist, Patient, and Date
            String formattedString =
                "Therapist : " + session.Therapist.Name + System.Environment.NewLine +
                "Patient : " + session.Patient.Name + System.Environment.NewLine +
                "Date : " + session.Date.ToString("MM-dd-yyyy") + System.Environment.NewLine +
                "Results : " + System.Environment.NewLine;

            // Add info for all each game result
            foreach (GameResult result in session.GameResults)
            {
                formattedString += result.ToString() + System.Environment.NewLine;
            }
            return(formattedString);
        }
Beispiel #3
0
        // Serialize a ReGameSession and write it to a .rgs file at specified dst
        public static String Save(ReGameSession session, string destinationPath)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            string timeStamp = string.Format("{0:yyyy-MM-dd_hh-mm-ss}", DateTime.Now);

            string fileName = destinationPath +
                              "/" +
                              session.Therapist.Name + "-" +
                              session.Patient.Name + "-" +
                              timeStamp +
                              REGAME_SAVE_EXTENSION;

            FileStream saveFile = File.Create(fileName);

            formatter.Serialize(saveFile, session);

            saveFile.Close();

            return(fileName);
        }