コード例 #1
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client.Role != UserRoles.Teacher)
            {
                error = CommandError.NoPermissions;
                return(null);
            }

            var id = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);

            var result = DBConnection.PrepareExecProcedureCommand("CheckTestCreatorId", id).ExecuteReader();

            if (result.Read())
            {
                if (result.GetInt32(0) != client.UserId)
                {
                    error = CommandError.NoPermissions;
                    return(null);
                }
            }
            else
            {
                error = CommandError.TestNotFound;
                return(null);
            }
            result.Close();

            DBConnection.PrepareExecProcedureCommand("PassToggle", id).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #2
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var    testName     = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);
            var    result       = DBConnection.PrepareExecProcedureCommand("CheckTestCreator", testName).ExecuteReader();
            string testFilename = null;
            int    testSubject;

            if (result.Read())
            {
                if (result.GetInt32(2) != client.UserId)
                {
                    error = CommandError.NoPermissions;
                    return(null);
                }
                testFilename = result.GetInt32(0) + ".test";
                testSubject  = result.GetInt32(1);
            }
            else
            {
                error = CommandError.TestNotFound;
                return(null);
            }
            result.Close();

            var test = FileProcessor.LoadTestFile(testFilename);

            error = CommandError.None;
            return(SequrityUtils.Encrypt(new NetSerializedTestInfo(test, testName, testSubject).ToJson(), client.SecretDFKey));
        }
コード例 #3
0
        private void onSubjectsRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                subjects = JsonConvert.DeserializeObject <Dictionary <int, string> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));
                comboBoxSubject.Items.Clear();
                if (subjects.Count == 0)
                {
                    comboBoxSubject.SelectedIndex = -1;
                }
                else
                {
                    foreach (var keyValue in subjects)
                    {
                        comboBoxSubject.Items.Add(keyValue.Value);
                    }
                    comboBoxSubject.SelectedIndex = 0;
                }
            }
        }
コード例 #4
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var config = ConfigContainer.GetConfig();

            if (client.Role == UserRoles.Teacher && !config.AllowSubjectsAdding)
            {
                error = CommandError.SubjectAddNotAllowed;
                return(null);
            }

            if (client.Role != UserRoles.Teacher && client.Role != UserRoles.Admin)
            {
                error = CommandError.NoPermissions;
                return(null);
            }

            var subjectName = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);

            var result = DBConnection.PrepareExecProcedureCommand("CheckSubject", subjectName).ExecuteReader();

            if (result.Read())
            {
                error = CommandError.SubjectExists;
                return(null);
            }
            result.Close();

            DBConnection.PrepareExecProcedureCommand("AddSubject", subjectName).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #5
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var testName = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);
            var result   = DBConnection.PrepareExecProcedureCommand("CheckTestAvailability", testName).ExecuteReader();
            int?testId   = null;
            int testSubject;

            if (result.Read())
            {
                if (!result.GetBoolean(2))
                {
                    error = CommandError.TestNotAvailable;
                    return(null);
                }
                testId      = result.GetInt32(0);
                testSubject = result.GetInt32(1);
            }
            else
            {
                error = CommandError.TestNotFound;
                return(null);
            }
            result.Close();

            var test = FileProcessor.LoadTestFile(testId + ".test");

            client.CurrentPassTestId = testId;

            error = CommandError.None;
            return(SequrityUtils.Encrypt(new NetSerializedTestInfo(test, testName, testSubject).ToJson(), client.SecretDFKey));
        }
コード例 #6
0
ファイル: LoginCommand.cs プロジェクト: 0leXis/OleXisTest2.0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var loginData    = LoginData.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            var passwordHash = SequrityUtils.GetHash(loginData.Password);
            var result       = DBConnection.PrepareExecProcedureCommand("CheckLoginInfo", loginData.Login, passwordHash).ExecuteReader();

            if (result.Read())
            {
                client.UserId = result.GetInt32(0);
                client.Role   = (UserRoles)(result.GetInt32(4) - 1);
                var info = new AccountInfo(client.UserId, result.GetString(1), result.GetString(2), client.Role.Value, result.IsDBNull(5) ? null : result.GetString(5));

                client.UpdateExpiredTime();

                result.Close();
                error = CommandError.None;
                return(SequrityUtils.Encrypt(info.ToJson(), client.SecretDFKey));
            }
            else
            {
                result.Close();
                error = CommandError.BadLoginOrPassword;
                return(null);
            }
        }
コード例 #7
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var testId = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);

            var result = DBConnection.PrepareExecProcedureCommand("GetExtendedResultSheet", testId).ExecuteReader();
            List <ExtendedResultSheetItem> extendedResults = new List <ExtendedResultSheetItem>();

            while (result.Read())
            {
                var tmpDateTime = result.GetString(3).Split(':');
                var passingTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(tmpDateTime[0]), Convert.ToInt32(tmpDateTime[1]), Convert.ToInt32(tmpDateTime[2]));
                extendedResults.Add(
                    new ExtendedResultSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetInt32(2),
                        passingTime,
                        result.GetDateTime(4),
                        JsonConvert.DeserializeObject <List <AnswerListItem> >(Encoding.UTF8.GetString((byte[])result.GetValue(5)))
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(extendedResults), client.SecretDFKey));
        }
コード例 #8
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client.Role != UserRoles.Admin)
            {
                error = CommandError.NoPermissions;
                return(null);
            }

            var    editData       = EditUserData.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            string password       = "";
            bool   changePassword = false;

            if (editData.Password != null)
            {
                password       = SequrityUtils.GetHash(editData.Password);
                changePassword = true;
            }

            UserRoles role;
            var       DBReader = DBConnection.PrepareExecProcedureCommand("GetUserRole", editData.id.ToString()).ExecuteReader();

            if (DBReader.Read())
            {
                role = (UserRoles)DBReader.GetInt32(0) - 1;
            }
            else
            {
                error = CommandError.ClientNotFound;
                return(null);
            }
            DBReader.Close();

            int  studentGroup = -1;
            bool changeGroup  = false;

            if (role == UserRoles.Student)
            {
                changeGroup = true;
                DBReader    = DBConnection.PrepareExecProcedureCommand("GetStudentGroup", editData.Group).ExecuteReader();

                if (DBReader.Read())
                {
                    studentGroup = DBReader.GetInt32(0);
                    DBReader.Close();
                }
                else
                {
                    DBReader.Close();
                    error = CommandError.BadStudentGroup;
                    return(null);
                }
            }

            DBConnection.PrepareExecProcedureCommand("EditUser", editData.id.ToString(), editData.Firstname, editData.Lastname, password, studentGroup.ToString(), Convert.ToInt32(changePassword).ToString(), Convert.ToInt32(changeGroup).ToString()).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #9
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client.Role != UserRoles.Student)
            {
                error = CommandError.UserNotStudent;
                return(null);
            }

            if (client.CurrentPassTestId == null)
            {
                error = CommandError.NoCurrentTest;
                return(null);
            }

            var testResult = TestResult.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));

            var command = DBConnection.GetCommand();

            command.CommandText = "call AddTestResult(@param0, @param1, @param2, @param3, @param4)";
            command.Parameters.Add(new MySqlParameter("@param0", client.CurrentPassTestId));
            command.Parameters.Add(new MySqlParameter("@param1", client.UserId));
            command.Parameters.Add(new MySqlParameter("@param2", testResult.Mark));
            command.Parameters.Add(new MySqlParameter("@param3", testResult.PassingTime));
            command.Parameters.Add(new MySqlParameter("@param4", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(testResult.Answers))));
            command.ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #10
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var sheetParams = TestSheetGetParams.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));

            if (client.Role != UserRoles.Teacher && sheetParams.isCreatorTests)
            {
                error = CommandError.NoPermissions;
                return(null);
            }
            bool   useNameFilter    = false;
            bool   useSubjectFilter = false;
            int    subject          = -1;
            string name             = "";

            if (sheetParams.Name != null && sheetParams.Name != "")
            {
                name          = sheetParams.Name;
                useNameFilter = true;
            }
            if (sheetParams.Subject != null && sheetParams.Subject > 0)
            {
                subject          = sheetParams.Subject.Value;
                useSubjectFilter = true;
            }

            MySqlDataReader result;

            if (sheetParams.isCreatorTests)
            {
                result = DBConnection.PrepareExecProcedureCommand("GetTestsCreatorSheet", client.UserId.ToString(), name, subject.ToString(), Convert.ToInt32(useNameFilter).ToString(), Convert.ToInt32(useSubjectFilter).ToString()).ExecuteReader();
            }
            else
            {
                result = DBConnection.PrepareExecProcedureCommand("GetTestsSheet", name, subject.ToString(), Convert.ToInt32(useNameFilter).ToString(), Convert.ToInt32(useSubjectFilter).ToString()).ExecuteReader();
            }

            var testList = new List <TestSheetItem>();

            while (result.Read())
            {
                testList.Add(
                    new TestSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetString(2),
                        result.GetDateTime(3),
                        result.GetInt32(4),
                        result.GetBoolean(5)
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(testList), client.SecretDFKey));
        }
コード例 #11
0
ファイル: TokenUpdator.cs プロジェクト: 0leXis/OleXisTest2.0
        private void onRecive(string responseData)
        {
            var responseInfo = ResponseInfo.FromJson(responseData);

            if (SequrityUtils.DecryptString(responseInfo.Data, connection.User.SecretKey) == "OK")
            {
                expiredTime = expiredTime.AddMinutes(3);
            }
        }
コード例 #12
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var newPassword  = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);
            var passwordHash = SequrityUtils.GetHash(newPassword);

            DBConnection.PrepareExecProcedureCommand("ChangePassword", client.UserId.ToString(), passwordHash).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #13
0
        private void onTestListRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var itemlist = JsonConvert.DeserializeObject <List <TestSheetItem> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));

                dataGridView.Rows.Clear();
                dataGridView.Columns.Clear();

                dataGridView.Columns.Add("Id", "Id");
                dataGridView.Columns.Add("Name", "Название");
                dataGridView.Columns.Add("Creator", "Создатель");
                dataGridView.Columns.Add("EditDate", "Дата изменения");
                dataGridView.Columns.Add("Subject", "Предмет/Дисциплина");
                dataGridView.Columns.Add("PassAvailable", "Доступен для прохождения");
                dataGridView.Columns.Add("ShowResults", "Просмотреть результат");
                if (comboBoxData.SelectedIndex == 1)
                {
                    dataGridView.Columns.Add("OpenClosePassing", "Разрешить/Запретить прохождение");
                    dataGridView.Columns.Add("Delete", "Удалить");
                }

                foreach (var item in itemlist)
                {
                    var row = new DataGridViewRow();
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.id.ToString()));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Name));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Creator));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.EditDate.ToString()));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(subjectsRoles[item.Subject]));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.PassAvailable ? "Да" : "Нет"));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Просмотреть результаты"));
                    if (comboBoxData.SelectedIndex == 1)
                    {
                        row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Разрешить/Запретить прохождение"));
                        row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Удалить"));
                    }
                    dataGridView.Rows.Add(row);
                }
                if (checkBoxDate.Checked)
                {
                    dataGridView.Sort(dataGridView.Columns[3], ListSortDirection.Ascending);
                }
            }
        }
コード例 #14
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var config = ConfigContainer.GetConfig();

            if (client.Role == null && !config.AllowRegistrationRequests)
            {
                error = CommandError.SelfRegistrationNotAllowed;
                return(null);
            }
            if (client.Role == UserRoles.Teacher && !config.AllowStudentsRegistration)
            {
                error = CommandError.StudentRegistrationNotAllowed;
                return(null);
            }

            var registerData = RegisterData.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            var passwordHash = SequrityUtils.GetHash(registerData.Password);

            var DBReader = DBConnection.PrepareExecProcedureCommand("GetStudentGroup", registerData.Group).ExecuteReader();

            if (DBReader.Read())
            {
                var studentGroup = DBReader.GetInt32(0);
                DBReader.Close();

                DBReader = DBConnection.PrepareExecProcedureCommand("CheckUserLogin", registerData.Login).ExecuteReader();
                if (DBReader.Read())
                {
                    if (DBReader.GetInt32(0) > 0)
                    {
                        DBReader.Close();
                        error = CommandError.LoginExists;
                        return(null);
                    }
                }
                DBReader.Close();
                DBConnection.PrepareExecProcedureCommand("RegisterStudent", registerData.Firstname, registerData.Lastname, registerData.Login, passwordHash, studentGroup.ToString()).ExecuteNonQuery();

                error = CommandError.None;
                return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
            }
            else
            {
                DBReader.Close();
                error = CommandError.BadStudentGroup;
                return(null);
            }
        }
コード例 #15
0
        private void onSaveRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                _error = response.Error;
            }
            else
            if (SequrityUtils.DecryptString(response.Data, connection.User.SecretKey) != "OK")
            {
                _error = "UNKNOWN_ERROR";
            }
        }
コード例 #16
0
        private void onUserListRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var userlist = JsonConvert.DeserializeObject <List <UserSheetItem> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));

                dataGridView.Rows.Clear();
                dataGridView.Columns.Clear();

                dataGridView.Columns.Add("Id", "Id");
                dataGridView.Columns.Add("Login", "Логин");
                dataGridView.Columns.Add("Name", "Имя");
                dataGridView.Columns.Add("Surname", "Фамилия");
                dataGridView.Columns.Add("Role", "Тип аккаунта");
                dataGridView.Columns.Add("Group", "Группа");
                if (connection.User.UserRole == UserRoles.Admin)
                {
                    dataGridView.Columns.Add("Edit", "Изменить");
                    dataGridView.Columns.Add("Delete", "Удалить");
                }

                foreach (var item in userlist)
                {
                    var row = new DataGridViewRow();
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.id.ToString()));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Login));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Name));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Surname));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(subjectsRoles[item.Role]));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Group));
                    if (connection.User.UserRole == UserRoles.Admin)
                    {
                        row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Изменить"));
                        if (item.Role != (int)UserRoles.Admin + 1)
                        {
                            row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Удалить"));
                        }
                    }
                    dataGridView.Rows.Add(row);
                }
            }
        }
コード例 #17
0
ファイル: DBTestResults.cs プロジェクト: 0leXis/OleXisTest2.0
        private void onExtendedResultsRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var result = JsonConvert.DeserializeObject <List <AnswerListItem> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));
                using (var resultDialog = new AnswerListDialog(result))
                {
                    resultDialog.ShowDialog();
                }
            }
        }
コード例 #18
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client.Role != UserRoles.Admin)
            {
                error = CommandError.NoPermissions;
                return(null);
            }

            var id = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);

            DBConnection.PrepareExecProcedureCommand("DeleteUser", id).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #19
0
ファイル: NetConnection.cs プロジェクト: 0leXis/OleXisTest2.0
 public void Register(RegisterData registerData, Action <string> onRegister)
 {
     Connect((error) =>
     {
         if (error == null)
         {
             try
             {
                 var netSender = new NetDataSender(
                     new RequestInfo("RegisterStudent", SequrityUtils.Encrypt(registerData.ToJson(), _User.SecretKey), _User.UserToken),
                     (responseData) =>
                 {
                     var responseInfo = ResponseInfo.FromJson(responseData);
                     if (responseInfo.Error != null)
                     {
                         Disconnect();
                         onRegister(responseInfo.Error);
                     }
                     else
                     {
                         if (SequrityUtils.DecryptString(responseInfo.Data, _User.SecretKey) == "OK")
                         {
                             Disconnect();
                             onRegister(null);
                         }
                         else
                         {
                             Disconnect();
                             onRegister(responseInfo.Error);
                         }
                     }
                 },
                     Address);
             }
             catch (Exception e)
             {
                 onRegister("Ошибка авторизации: " + e.Message);
             }
         }
         else
         {
             onRegister(error);
         }
     });
 }
コード例 #20
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var resultParams = ServerTestResultGetParams.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));


            bool     useSurnameFilter = false;
            bool     useDateFilter    = false;
            DateTime date             = DateTime.Now;
            string   surname          = "";

            if (resultParams.StudentSurname != null && resultParams.StudentSurname != "")
            {
                surname          = resultParams.StudentSurname;
                useSurnameFilter = true;
            }
            if (resultParams.PassDate != null)
            {
                date          = resultParams.PassDate.Value;
                useDateFilter = true;
            }

            var result = DBConnection.PrepareExecProcedureCommand("GetTestResultSheet", surname, date.ToString("yyyy-MM-dd"), Convert.ToInt32(useSurnameFilter).ToString(), Convert.ToInt32(useDateFilter).ToString()).ExecuteReader();

            var resultList = new List <ResultSheetItem>();

            while (result.Read())
            {
                var tmpDateTime = result.GetString(3).Split(':');
                var passingTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(tmpDateTime[0]), Convert.ToInt32(tmpDateTime[1]), Convert.ToInt32(tmpDateTime[2]));
                resultList.Add(
                    new ResultSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetInt32(2),
                        passingTime,
                        result.GetDateTime(4)
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(resultList), client.SecretDFKey));
        }
コード例 #21
0
        private void onTestsRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var tests = JsonConvert.DeserializeObject <List <string> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));
                listBoxTests.Items.Clear();
                foreach (var testName in tests)
                {
                    listBoxTests.Items.Add(testName);
                }
            }
        }
コード例 #22
0
        private void onRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                if (response.Error != "USER_NOT_STUDENT")
                {
                    MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (SequrityUtils.DecryptString(response.Data, connection.User.SecretKey) != "OK")
                {
                    MessageBox.Show("Неизвестная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #23
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;
            }
        }
コード例 #24
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var    sheetParams      = UserSheetGetParams.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            bool   useSurnameFilter = false;
            bool   useRoleFilter    = false;
            int    role             = -1;
            string surname          = "";

            if (sheetParams.Surname != null && sheetParams.Surname != "")
            {
                surname          = sheetParams.Surname;
                useSurnameFilter = true;
            }
            if (sheetParams.Role != null && sheetParams.Role > 0)
            {
                role          = sheetParams.Role.Value;
                useRoleFilter = true;
            }

            var result   = DBConnection.PrepareExecProcedureCommand("GetUsersSheet", surname, role.ToString(), Convert.ToInt32(useSurnameFilter).ToString(), Convert.ToInt32(useRoleFilter).ToString()).ExecuteReader();
            var userList = new List <UserSheetItem>();

            while (result.Read())
            {
                userList.Add(
                    new UserSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetString(2),
                        result.GetString(3),
                        result.GetInt32(4),
                        result.IsDBNull(5) ? null : result.GetString(5)
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(userList), client.SecretDFKey));
        }
コード例 #25
0
        private void onRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (SequrityUtils.DecryptString(response.Data, connection.User.SecretKey) == "OK")
                {
                    MessageBox.Show("Регистрация завершена успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Непредвиденная ошибка регистрации", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #26
0
ファイル: NetConnection.cs プロジェクト: 0leXis/OleXisTest2.0
 public void Login(LoginData loginData, Action <string, AccountInfo> onLogin)
 {
     Connect((error) =>
     {
         if (error == null)
         {
             try
             {
                 var netSender = new NetDataSender(
                     new RequestInfo("Login", SequrityUtils.Encrypt(loginData.ToJson(), _User.SecretKey), _User.UserToken),
                     (responseData) =>
                 {
                     var responseInfo = ResponseInfo.FromJson(responseData);
                     if (responseInfo.Error != null)
                     {
                         onLogin(responseInfo.Error, null);
                     }
                     else
                     {
                         var loginInfo = AccountInfo.FromJson(SequrityUtils.DecryptString(responseInfo.Data, _User.SecretKey));
                         updator.Start();
                         User.UserId   = loginInfo.UserId;
                         User.UserRole = loginInfo.Role;
                         onLogin(null, loginInfo);
                     }
                 },
                     Address);
             }
             catch (Exception e)
             {
                 onLogin("Ошибка авторизации: " + e.Message, null);
             }
         }
         else
         {
             onLogin(error, null);
         }
     });
 }
コード例 #27
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var resultId = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);

            var result = DBConnection.PrepareExecProcedureCommand("GetExtendedResult", resultId).ExecuteReader();
            List <AnswerListItem> extendedResult = null;

            if (result.Read())
            {
                extendedResult = JsonConvert.DeserializeObject <List <AnswerListItem> >(Encoding.UTF8.GetString((byte[])result.GetValue(0)));
            }
            else
            {
                error = CommandError.TestResultNotFound;
                return(null);
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(extendedResult), client.SecretDFKey));
        }
コード例 #28
0
ファイル: NetConnection.cs プロジェクト: 0leXis/OleXisTest2.0
 private void Connect(Action <string> onConnected)
 {
     try
     {
         var netSender = new NetDataSender(
             new RequestInfo("OpenConnection", null, null),
             (responseData) =>
         {
             var responseInfo = ResponseInfo.FromJson(responseData);
             var data         = Encoding.UTF8.GetString(responseInfo.Data);
             _User            = new User(data.Substring(0, data.IndexOf(' ')));
             string publicKey;
             _User.SecretKey = SequrityUtils.DiffieHellmanGetSecretKey(data.Substring(data.IndexOf(' ') + 1), out publicKey);
             var netSender2  = new NetDataSender(
                 new RequestInfo("SetDF", Encoding.UTF8.GetBytes(publicKey), _User.UserToken),
                 (string responseData2) =>
             {
                 responseInfo = ResponseInfo.FromJson(responseData2);
                 if (SequrityUtils.DecryptString(responseInfo.Data, _User.SecretKey) == "CONNECTION_STARTED")
                 {
                     _IsConnected = true;
                     onConnected(null);
                 }
                 else
                 {
                     onConnected("Неизвестная ошибка подключения");
                 }
             },
                 Address);
         },
             Address);
     }
     catch (Exception e)
     {
         onConnected("Ошибка подключения: " + e.Message);
     }
 }
コード例 #29
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));
        }
コード例 #30
0
ファイル: DBTestResults.cs プロジェクト: 0leXis/OleXisTest2.0
        private void onResultsRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var resultslist = JsonConvert.DeserializeObject <List <ResultSheetItem> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));

                dataGridView.Rows.Clear();
                dataGridView.Columns.Clear();

                dataGridView.Columns.Add("Id", "Id");
                dataGridView.Columns.Add("NameSurname", "Имя/Фамилия учащегося");
                dataGridView.Columns.Add("Mark", "Оценка");
                dataGridView.Columns.Add("PassDate", "Дата выполнения");
                dataGridView.Columns.Add("PassingTime", "Время выполнения");
                dataGridView.Columns.Add("ExtendedResults", "Расширенные результаты");

                foreach (var item in resultslist)
                {
                    var row = new DataGridViewRow();
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.id.ToString()));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.NameSurname));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Mark.ToString()));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.PassDate.ToString("dd.MM.yyyy")));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.PassingTime.ToString("hh:mm:ss")));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Расширенные результаты"));
                    dataGridView.Rows.Add(row);
                }
            }
        }