private void onLoadRecive(string data)
        {
            loadedTest = null;
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                _error = response.Error;
            }
            else
            {
                FileProcessor.ClearTmpDir(tmpDir);

                var testInfo = NetSerializedTestInfo.FromJson(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));
                using (FileStream file = new FileStream(tmpDir + @"\testtmp.test", FileMode.OpenOrCreate))
                {
                    file.Write(testInfo.Test, 0, testInfo.Test.Length);
                }

                FileProcessor.DecompressFile(tmpDir + @"\testtmp.test", "");
                var  formatter = new BinaryFormatter();
                Test test;
                using (FileStream file = new FileStream(tmpDir + @"\main.dat", FileMode.Open))
                {
                    test = (Test)formatter.Deserialize(file);
                    test.InitSerializedTest();
                }

                var i = 0;
                while (File.Exists(tmpDir + @"\" + i.ToString() + ".dat"))
                {
                    using (FileStream file = new FileStream(tmpDir + @"\" + i.ToString() + ".dat", FileMode.Open))
                    {
                        test.Questions.Add(new Question(file));
                    }
                    i++;
                }

                FileProcessor.ClearTmpDir(tmpDir);
                loadedTest = test;
            }
        }
Пример #2
0
        public ITest LoadForEdit(string fileName, string password = null)
        {
            _fileName = fileName;

            FileProcessor.ClearTmpDir(tmpDir);

            if (password == null)
            {
                FileProcessor.DecompressFile(fileName, "");
            }
            else
            {
                FileProcessor.EncryptDecryptFile(fileName, password, false, tmpDir + @"\testtmp.test");
                FileProcessor.DecompressFile(tmpDir + @"\testtmp.test", "");
            }

            var  formatter = new BinaryFormatter();
            Test test;

            using (FileStream file = new FileStream(tmpDir + @"\main.dat", FileMode.Open))
            {
                test = (Test)formatter.Deserialize(file);
                test.InitSerializedTest();
            }

            var i = 0;

            while (File.Exists(tmpDir + @"\" + i.ToString() + ".dat"))
            {
                using (FileStream file = new FileStream(tmpDir + @"\" + i.ToString() + ".dat", FileMode.Open))
                {
                    test.Questions.Add(new Question(file));
                }
                i++;
            }

            FileProcessor.ClearTmpDir(tmpDir);

            return(test);
        }