コード例 #1
0
        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 byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client.Role != UserRoles.Teacher)
            {
                error = CommandError.NoPermissions;
                return(null);
            }
            var testData = NetSerializedTestInfo.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));

            var result     = DBConnection.PrepareExecProcedureCommand("GetCreatorIdAndLastTestNumber", testData.Name).ExecuteReader();
            var testFileId = 1;

            if (result.Read())
            {
                if (!result.IsDBNull(0))
                {
                    if (result.GetInt32(0) != client.UserId)
                    {
                        error = CommandError.TestNameBusy;
                        return(null);
                    }
                }
                if (!result.IsDBNull(1))
                {
                    testFileId = result.GetInt32(1);
                }
            }
            result.Close();
            FileProcessor.SaveTestFile(testFileId + ".test", testData.Test);
            DBConnection.PrepareExecProcedureCommand("SaveTest", testData.Name, client.UserId.ToString(), testData.Subject.ToString()).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }