public FilterationRequestResult GenerateExamCopyForSendingToStudent(Exam orgExamCopyEmpty, RequiredDetails details, string srcIP) { details.DecryptDetails(ExamKey); var filterResult = IsValidRequest(details, srcIP); if (filterResult != FilterationResult.Accepted) { throwFirewallException(filterResult, $"IP:{srcIP}"); return(new FilterationRequestResult(filterResult, null)); } var v = GetIV(details); details.SequenceNumber = (long.Parse(details.SequenceNumber) + 1).ToString(); details.VEncryptedWithKI = ExamHelper.GetVAsByteArray(v, InstructorPassword); var examInstance = orgExamCopyEmpty; examInstance.RequiredStudentDetails = details; //we received this from the student // examInstance.RequiredStudentDetails.SetV_CompressedEncryptedWithKI(v, InstructorPassword); //if(examInstance.RequiredStudentDetails.VEncryptedWithKI== null) //{ // MessageBox.Show("Set To Null"); //} //else //{ // MessageBox.Show("examInstance.RequiredStudentDetails.VEncryptedWithKI"); //} return(new FilterationRequestResult(filterResult, ExamHelper.GetExamFileWithoutSave(examInstance, ExamKey, details.SharedKeyIS, SecurityLevel))); }
private void submitExamBtn_Click(object sender, EventArgs e) { string errMsg = ""; bool error = false; string remainingTime = remainingtimeLbl.Text; ExamLog.Add($"[{DateTime.Now}] [Student Tried to Submit SUBMIT EXAM] [Remaing time: {remainingTime}]"); foreach (var q in anExam.QuestionsList) { if (q.StudentAnswer == string.Empty || q.StudentAnswer == null) { error = true; errMsg = errMsg + $" Q{q.QuestionNumber}. "; } } if (error) { MessageBox.Show("Please provide answers for the following questions before you submit the exam" + errMsg); return; } bool saved = false; anExam.RequiredStudentDetails.SequenceNumber = (long.Parse(anExam.RequiredStudentDetails.SequenceNumber) + 1).ToString(); while (!saved) { try { if (MessageBox.Show("(Recommended) Please save file to disk before submitting on network.", "Important Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { SaveFileDialog adialog = new SaveFileDialog(); adialog.Filter = "FCT Exam File (*.FCTANS)|*.FCTANS"; adialog.DefaultExt = "FCTANS"; adialog.FileName = $"{DateTime.Now.Day}-{DateTime.Now.Month}-{DateTime.Now.Year}-Submission-{studentIDTxtBox.Text}"; adialog.AddExtension = true; if (adialog.ShowDialog() == DialogResult.OK) { ExamLog.Add($"[{DateTime.Now}] [Student Saved Exam On Disk] [File Location: ({adialog.FileName})]"); anExam.ExamLog = ExamLog; //anExam.RequiredStudentDetails = requiredDetails; ExamHelper.SaveExamToFile(anExam, examKeyTxtBox.Text, adialog.FileName); aLogger.LogMessage($"[Student Saved Exam On Disk] [File Location: ({adialog.FileName})]", LogMsgType.Verbose); } } else { ExamLog.Add($"[{DateTime.Now}] [Student Did not Select To Save File To Disk]"); } saved = true; } catch (Exception ex) { ExamLog.Add($"[{DateTime.Now}] [Student Saved Exam On Disk (Process Failed) (exception: {ex.Message}] "); MessageBox.Show("File Did Not Save Correctly, please retry!"); } } var reqDetailsEnc = anExam.RequiredStudentDetails; reqDetailsEnc.EncryptDetails(); aLogger.LogMessage("Submitting Exam Through Network ... (Started)", LogMsgType.Verbose); anExam.ExamLog = ExamLog; // anExam.RequiredStudentDetails = requiredDetails; if (client.ServiceProxy.SubmitExamEncryptedZipped(ExamHelper.GetExamFileWithoutSave(anExam, examKeyTxtBox.Text, sharedKeyISTxtBox.Text, (highSecChkBox.Checked ? Security.FilterationSecurityLevel.High : Security.FilterationSecurityLevel.Moderate)), reqDetailsEnc)) { aLogger.LogMessage("Submitting Exam Through Network ... (Done Succesfully.)", LogMsgType.Verbose); MessageBox.Show("Exam Submitted Correctly. Closing..."); client.Disconnect(); aLogger.LogMessage("Disconnected from server", LogMsgType.Verbose); this.Close(); } else { aLogger.LogMessage("Submitting Exam Through Network ... (Process Failed)", LogMsgType.Verbose); MessageBox.Show("ERROR: Submission Failed. "); } }
private void PerformTest(TestType type, int numOfQ, int numOfStd) { TestParameters submitParam = new TestParameters(); TestParameters receiveParam = new TestParameters(); submitParam.MethodCallCount = int.Parse(numberOfTimesTxtBox.Text); submitParam.NumberOfQuestions = numOfQ; submitParam.NumberOfStudent = numOfStd; receiveParam.MethodCallCount = int.Parse(numberOfTimesTxtBox.Text); receiveParam.NumberOfQuestions = numOfQ; receiveParam.NumberOfStudent = numOfStd; var secucirytLevel = highSecChkBox.Checked ? FilterationSecurityLevel.High : FilterationSecurityLevel.Moderate; var endpoint = new ScsTcpEndPoint(ipTxtBox.Text, int.Parse(portTxtBox.Text)); SortedList <string, string> ExamsReceived = new SortedList <string, string>(); var stopwatchReceiving = Stopwatch.StartNew(); Parallel.For(0, numOfStd, index => { using (var client = ScsServiceClientBuilder.CreateClient <INetworkExamServiceTesting>(endpoint)) { var val = index % numOfStd; var keyUsed = $"Keyyyyyyy{val}"; //STEP 1 -- Only get exam copy client.Connect(); var requiredDetails = new RequiredDetails($"StdName{val}", $"Std{val}", "123456", keyUsed, 1); try { var copy = client.ServiceProxy.GetExamCopyEncryptedZipped(requiredDetails, numOfQ, numOfStd); lock (ExamsReceived) { if (!ExamsReceived.Keys.Contains(keyUsed)) { ExamsReceived.Add(keyUsed, copy); } } } catch (Exception ex) { lock (receiveParam) { receiveParam.DroppedMessages += 1; } } } }); List <Task> tasksReq = new List <Task>(); Parallel.For(0, receiveParam.MethodCallCount - numOfStd, index => // for (int index = 0; index < param.MethodCallCount; index++) { var t = Task.Run(() => { using (var client = ScsServiceClientBuilder.CreateClient <INetworkExamServiceTesting>(endpoint)) { var val = index % numOfStd; var keyUsed = $"Keyyyyyyy{val}"; //STEP 1 -- Only get exam copy client.Connect(); var requiredDetails = new RequiredDetails($"StdName{val}", $"Std{val}", "123456", keyUsed, 1); try { var copy = client.ServiceProxy.GetExamCopyEncryptedZipped(requiredDetails, numOfQ, numOfStd); } catch (Exception ex) { lock (receiveParam) { receiveParam.DroppedMessages += 1; } } } }); lock (tasksReq) { tasksReq.Add(t); } } ); Task.WaitAll(tasksReq.ToArray()); stopwatchReceiving.Stop(); receiveParam.TimeRequired = stopwatchReceiving; ReceivingResults.Add(receiveParam); SortedList <string, KeyValuePair <RequiredDetails, string> > ExamsToSubmit = new SortedList <string, KeyValuePair <RequiredDetails, string> >(); if (type == TestType.SubmitExam || type == TestType.Both) // we need to answer and submit aswell { // List<KeyValuePair<RequiredDetails, string>> ExamsToSubmit = new List<KeyValuePair<RequiredDetails, string>>(); Parallel.For(0, numOfStd, index => { var val = index % numOfStd; var keyUsed = $"Keyyyyyyy{val}"; //STEP 2 : Answering the EXAM (assuming all students will have the same answers) var examCopyUnencrypted = ExamHelper.GetExamFromByteArray(ExamsReceived[keyUsed], "123456", keyUsed, secucirytLevel); examCopyUnencrypted.ExamLog = new List <string>(); examCopyUnencrypted.RequiredStudentDetails.SequenceNumber = (long.Parse(examCopyUnencrypted.RequiredStudentDetails.SequenceNumber) + 1).ToString(); var rD = examCopyUnencrypted.RequiredStudentDetails; var examEncrypted = ExamHelper.GetExamFileWithoutSave(examCopyUnencrypted, "123456", keyUsed, secucirytLevel); rD.EncryptDetails(); lock (ExamsToSubmit) { if (!ExamsToSubmit.Keys.Contains(keyUsed)) { ExamsToSubmit.Add(keyUsed, new KeyValuePair <RequiredDetails, string>(rD, examEncrypted)); } } }); ExamsReceived = null; var stopwatchSubmitting = Stopwatch.StartNew(); //step 3 Submit (we want to measure only this List <Task> tasks = new List <Task>(); Parallel.For(0, submitParam.MethodCallCount, index => { var t = Task.Run(() => { var val = index % numOfStd; var keyUsed = $"Keyyyyyyy{val}"; try { using (var clientSubmit = ScsServiceClientBuilder.CreateClient <INetworkExamServiceTesting>(endpoint)) { clientSubmit.Connect(); clientSubmit.ServiceProxy.SubmitExamEncryptedZipped(ExamsToSubmit[keyUsed].Value, ExamsToSubmit[keyUsed].Key, numOfQ, numOfStd); } } catch (Exception ex) { lock (submitParam) { submitParam.DroppedMessages += 1; } } }); lock (tasks) { tasks.Add(t); } }); Task.WaitAll(tasks.ToArray()); stopwatchSubmitting.Stop(); submitParam.TimeRequired = stopwatchSubmitting; SubmissionResults.Add(submitParam); } }