Ejemplo n.º 1
0
        public void SaveExam(Exam exam, string filePath)
        {
            ExamSerializationService examSerializationService = ExamSerializationService.GetInstance();

            byte[] data = examSerializationService.SerializeEncrypted(exam);
            File.WriteAllText(filePath, string.Empty);
            using (FileStream stream = File.OpenWrite(filePath))
            {
                stream.Write(data, 0, data.Length);
            }
        }
Ejemplo n.º 2
0
        public Exam OpenExam(string filePath, string password)
        {
            Exam result = null;

            if (Path.GetExtension(filePath) != ".smpx")
            {
                throw new ArgumentException("Invalid file extension");
            }
            using (FileStream stream = File.OpenRead(filePath))
            {
                byte[] data = new byte[stream.Length];
                stream.Read(data, 0, data.Length);
                ExamSerializationService examSerializationService = ExamSerializationService.GetInstance();
                result = examSerializationService.DeserializeEncrypted(data, password);
            }
            return(result);
        }