コード例 #1
0
        private void openExamBtn_Click(object sender, EventArgs e)
        {
            try
            {
                Random         r          = new Random();
                OpenFileDialog opendialog = new OpenFileDialog();
                opendialog.Filter       = "FCT Exam File (*.FCTEX)|*.FCTEX";
                opendialog.DefaultExt   = "FCTEX";
                opendialog.AddExtension = true;
                requiredDetails         = new RequiredDetails(studentNameTxtBox.Text, studentIDTxtBox.Text, studentPassTxtBox.Text, "TODO");
                if (opendialog.ShowDialog() == DialogResult.OK)
                {
                    var examStringEncrypted = ExamHelper.GetExamFileAsBytes(opendialog.FileName);
                    anExam = ExamHelper.GetExamFromFile(opendialog.FileName, studentPassTxtBox.Text, "", Security.FilterationSecurityLevel.Moderate);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }


            if (anExam == null)
            {
                MessageBox.Show("Invalid Exam");
                return;
            }

            PrepareExamEnvironment();
        }
コード例 #2
0
ファイル: ExamServer.cs プロジェクト: SariSultan/SDES
        private void openExamBtn_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog opendialog = new OpenFileDialog();
                opendialog.Filter       = "FCT Exam File (*.FCTEX)|*.FCTEX";
                opendialog.DefaultExt   = "FCTEX";
                opendialog.AddExtension = true;

                if (opendialog.ShowDialog() == DialogResult.OK)
                {
                    examStringEncrypted = ExamHelper.GetExamFileAsBytes(opendialog.FileName);

                    anExam = ExamHelper.GetExamFromFile(opendialog.FileName, studentPassTxtBox.Text, "", FilterationSecurityLevel.Moderate);
                    foreach (var q in anExam.QuestionsList)
                    {
                        QuizHelper.AddQuestionTortb(ref rtb, q.QuestionNumber, q, true, true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            List <Exm> exams = ExamHelper.GetAllExams();

            gvExamList.DataSource = exams;
            gvExamList.DataBind();
        }
コード例 #4
0
        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;

            while (!saved)
            {
                try
                {
                    if (MessageBox.Show("(Required) Please save your answers file to disk.", "Important Notice", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        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, studentPassTxtBox.Text, adialog.FileName);
                            aLogger.LogMessage($"[Student Saved Exam On Disk] [File Location: ({adialog.FileName})]", LogMsgType.Verbose);

                            MessageBox.Show("Done, closing now.");
                            this.Close();
                        }
                    }
                    else
                    {
                        ExamLog.Add($"[{DateTime.Now}] [Student did not save file to disk. You should save it.]");
                    }
                    saved = true;
                }
                catch (Exception ex)
                {
                    ExamLog.Add($"[{DateTime.Now}] [Student Saved Exam On Disk (Process Failed) (exception: {ex.Message}] ");
                    MessageBox.Show("[ERROR] File Did Not Save Correctly, please retry! \n" + ex.Message);
                }
            }
        }
コード例 #5
0
        public ActionResult Index()
        {
            //This code will bring the datas from wired.com
            ExamXMLModel a  = ExamHelper.AllQuestionsGetter();
            List <Item>  ab = ExamHelper.Last5QuestionsGetter();

            return(View());
        }
コード例 #6
0
ファイル: MbrQuizFrm.cs プロジェクト: SariSultan/SDES
        private void saveXMLBtn_Click(object sender, EventArgs e)
        {
            try
            {
                examDescriptionTxtBox.Text = examDescriptionTxtBox.Text.Trim();
                instructorPassTxtBox.Text  = instructorPassTxtBox.Text.Trim();
                studentPassTxtBox.Text     = studentPassTxtBox.Text.Trim();
                var  errorMSg = "";
                bool error    = false;
                if (FinalQuestions.Count == 0)
                {
                    errorMSg += "* Please select some questions first! \n";
                    error     = true;
                }
                if (studentPassTxtBox.Text.Length < 6 || instructorPassTxtBox.Text.Length < 6)
                {
                    errorMSg += $"* You should select Instructor and Student passwords. (length at least {AESGCM.MinPasswordLength} chars)\n";
                    error     = true;
                }
                if (examDescriptionTxtBox.Text.Trim().Length == 0)
                {
                    errorMSg += "* Please select exam description \n";
                    error     = true;
                }
                int examDuration = 0;
                if (!int.TryParse(examDurationTxtBox.Text, out examDuration))
                {
                    errorMSg += "* Selected valid exam duration as integer value in minutes";
                    error     = true;
                }

                if (error)
                {
                    MessageBox.Show(errorMSg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                SaveFileDialog adialog = new SaveFileDialog();
                adialog.Filter       = "FCT Exam File Template (*.XML)|*.XML";
                adialog.DefaultExt   = "XML";
                adialog.AddExtension = true;
                if (adialog.ShowDialog() == DialogResult.OK)
                {
                    ExamHelper.CreateExamAndSafeXMLToFile(FinalQuestions, examDescriptionTxtBox.Text, examDuration, instructorPassTxtBox.Text, studentPassTxtBox.Text, adialog.FileName);
                    MessageBox.Show("Done, check the file location!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #7
0
 public InstructorValidationData GetV(string instructorPassword)
 {
     try
     {
         return(ExamHelper.GetVFromByteArray(VEncryptedWithKI, instructorPassword));
     }
     catch (Exception ex)
     {
         MessageBox.Show("IN GETV() ln 69");
         return(null);
     }
 }
コード例 #8
0
        public void GetExamCopy()
        {
            //  try
            {
                HighSecurity = highSecChkBox.Checked;
                //Create a client to connecto to phone book service on local server and
                //10048 TCP port.
                client = ScsServiceClientBuilder.CreateClient <INetworkExamService>(
                    new ScsTcpEndPoint(ipTxtBox.Text, int.Parse(portTxtBox.Text)));

                // client.Timeout = 3;
                aLogger.LogMessage($"Trying to connect to the server (timeout {client.Timeout} Seconds)", LogMsgType.Verbose);
                //Connect to the server
                client.Connect();

                aLogger.LogMessage("Connected to server", LogMsgType.Verbose);


                RequiredDetails requiredDetails = new RequiredDetails(studentNameTxtBox.Text, studentIDTxtBox.Text, examKeyTxtBox.Text, (HighSecurity? sharedKeyISTxtBox.Text:"Low Security Settings Selected"));
                //Add some persons
                var copy = client.ServiceProxy.GetExamCopyEncryptedZipped(requiredDetails);
                requiredDetails.DecryptDetails(examKeyTxtBox.Text);
                if (!ExamHelper.ValidateExamCopy(copy, examKeyTxtBox.Text, aLogger, sharedKeyISTxtBox.Text,
                                                 (highSecChkBox.Checked ? Security.FilterationSecurityLevel.High : Security.FilterationSecurityLevel.Moderate), requiredDetails.SequenceNumber))
                {
                    return;
                }

                aLogger.LogMessage("Received Exam Copy", LogMsgType.Verbose);

                aLogger.LogMessage("Checking Exam Copy...", LogMsgType.Verbose);

                var exam = Quizez.ExamHelper.GetExamFromByteArray(copy, examKeyTxtBox.Text, sharedKeyISTxtBox.Text,
                                                                  (highSecChkBox.Checked?Security.FilterationSecurityLevel.High:Security.FilterationSecurityLevel.Moderate));

                aLogger.LogMessage("Exam Checked Correcly ...", LogMsgType.Verbose);

                //Disconnect from server
                //   client.Disconnect();

                //  aLogger.LogMessage("Disconnected from server", LogMsgType.Verbose);

                anExam = exam;
            }
            // catch (Exception ex)
            {
                //  aLogger.LogMessage(ex.Message, LogMsgType.Error);
            }
        }
コード例 #9
0
ファイル: GradingExamHelper.cs プロジェクト: SariSultan/SDES
        public static void GradeExamsAndGenerateReportFromEncrypted(ref RichTextBox rtb, bool addLogs, string studentPass, string instructorPass, SortedList <string, string> encryptedExamFiles, SortedList <string, ExaminationFilterRule> FirewallRules, bool highSecurity)
        {
            rtb.Clear();
            bool includeLogs = addLogs;


            foreach (var item in encryptedExamFiles)
            {
                if (highSecurity)
                {
                    if (FirewallRules.ContainsKey(item.Key))
                    {
                        var examFile = ExamHelper.GetExamFromByteArray(item.Value, studentPass,
                                                                       FirewallRules[item.Key].SharedKeyIS, FilterationSecurityLevel.High);
                        GradeExamQuestion(ref rtb, addLogs, studentPass, instructorPass, examFile);
                    }
                    else
                    {
                        rtb.AppendText($" \n CANNOT GRADE stdID because no shared key available [{item.Key}] \n");
                    }
                }
                else
                {
                    var examFile = ExamHelper.GetExamFromByteArray(item.Value, studentPass, "", FilterationSecurityLevel.Moderate);
                    GradeExamQuestion(ref rtb, addLogs, studentPass, instructorPass, examFile);
                }
            }

            // var list = examsStatusUpdateList;
            //var ExamsEncryptedList = encryptedExamFiles.Select(x => x.Value).ToList();
            //for (int i = 0; i < ExamsEncryptedList.Count; i++)
            //{



            //}


            var tst = rtb.Rtf.Replace("[NEW_PAGE_AUTOMATIC_HERE]", "\\par \\page");

            SaveFileDialog sdlg = new SaveFileDialog();

            sdlg.FileName   = $"StudentExamGradesAnswers";
            sdlg.Filter     = "RTF File (*.rtf)|*.rtf";
            sdlg.DefaultExt = "rtf";
            sdlg.ShowDialog();
            File.WriteAllText(sdlg.FileName, tst);
        }
コード例 #10
0
ファイル: ExamServer.cs プロジェクト: SariSultan/SDES
        private void UpdateDetails(List <ExamStatusUpdate> list)
        {
            if (dgview.InvokeRequired)
            {
                //MessageBox.Show("Called Invoke");
                dgview.BeginInvoke(new Action <List <ExamStatusUpdate> >(UpdateDetails), list);
                return;
            }
            lock (dgview)
            {
                dgview.Rows.Clear();

                for (int i = 0; i < list.Count; i++)
                {
                    var index = dgview.Rows.Add();

                    dgview.Rows[index].Cells["serialCol"].Value = i + 1;
                    var id = list[i].Details.StudentID;;
                    dgview.Rows[index].Cells["idCol"].Value        = id;
                    dgview.Rows[index].Cells["nameCol"].Value      = list[i].Details.StudentName;
                    dgview.Rows[index].Cells["rcvdCol"].Value      = list[i].sent ? "Yes" : "No";
                    dgview.Rows[index].Cells["submittedCol"].Value = list[i].submitted ? "Yes" : "No";
                    if (list[i].submitted)
                    {
                        if (checkBox1.Checked)
                        {
                            if (FirewallRules.ContainsKey(list[i].Details.StudentID))
                            {
                                dgview.Rows[index].Cells["gradeCol"].Value =
                                    ExamHelper.GetExamFromByteArray(aService.submittedFiles[id], studentPassTxtBox.Text,
                                                                    list[i].Details.SharedKeyIS, FilterationSecurityLevel.High).GetExamGrade(instructorPassTxtBox.Text);
                            }
                            else
                            {
                                aLogger.LogMessage($"Wrong Exam Submission for stdID [{list[i].Details.StudentID}]", LogMsgType.Error);
                            }
                        }
                        else
                        {
                            dgview.Rows[index].Cells["gradeCol"].Value =
                                ExamHelper.GetExamFromByteArray(aService.submittedFiles[id], studentPassTxtBox.Text, "", FilterationSecurityLevel.Moderate).GetExamGrade(instructorPassTxtBox.Text);
                        }
                    }
                }
            }
        }
コード例 #11
0
        protected void btnNext_Click(object sender, EventArgs e)
        {
            //validate
            AnswerSheet   answerSheet      = AnswerHelper.GetAnswerSheet(this.UserId, this.ExamId);
            List <string> checkedOptionIds = new List <string>();

            foreach (RepeaterItem item in repOptions.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    var chkOption   = item.FindControl("chkOption") as CheckBox;
                    var litOptionId = item.FindControl("litOptionId") as Literal;

                    if (chkOption.Checked)
                    {
                        checkedOptionIds.Add(litOptionId.Text);
                    }
                }
            }
            if (checkedOptionIds.Count > 0)
            {
                if (answerSheet == null)
                {
                    answerSheet = new AnswerSheet()
                    {
                        Answers = new List <Answer>()
                    };
                }

                if (!answerSheet.Answers.Any(x => x.QuestionId == litId.Text))
                {
                    answerSheet.Answers.Add(new Answer()
                    {
                        QuestionId        = litId.Text,
                        SelectedOptionIds = checkedOptionIds
                    });
                    ExamHelper.SaveAnswerSheet(this.UserId, this.ExamId, answerSheet);
                }
            }
            _SetUIAndBindData();
        }
コード例 #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var ext = new List <string> {
                    "fctans"
                };

                using (var fbd = new FolderBrowserDialog())
                {
                    DialogResult result = fbd.ShowDialog();

                    if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
                    {
                        var myFiles = Directory.GetFiles(fbd.SelectedPath, "*.fctans", SearchOption.AllDirectories).ToList();

                        // var myFiles = Directory.GetFiles(fbd.SelectedPath, "*.*", SearchOption.AllDirectories)
                        //            .Where(s => ext.Contains(Path.GetExtension(s))).ToList();
                        int cnt = 0;
                        foreach (var file in myFiles)
                        {
                            try {
                                ExamsToGrade.Add(ExamHelper.GetExamFromFile(file, studentPassTxtBox.Text, "", Security.FilterationSecurityLevel.Moderate));
                                aLogger.LogMessage($" Added Exam File from [{file}]", LogMsgType.Verbose);
                                cnt++;
                            }
                            catch (Exception ex)
                            {
                                aLogger.LogMessage($"Failed to get file name [{file}], possibly its an invalid exam file (Execption msg: {ex.Message})", LogMsgType.Error);
                            }
                        }

                        aLogger.LogMessage($" TOTAL OF {cnt} exams are loaded correctly, click on Grade files to get the report", LogMsgType.Verbose);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #13
0
        private void openExamBtn_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog opendialog = new OpenFileDialog();
                opendialog.Filter       = "FCT Exam File (*.FCTANS)|*.FCTANS";
                opendialog.DefaultExt   = "FCTANS";
                opendialog.AddExtension = true;

                if (opendialog.ShowDialog() == DialogResult.OK)
                {
                    //  var examStringEncrypted = ExamHelper.GetExamFileAsBytes(opendialog.FileName);
                    ExamsToGrade.Add(ExamHelper.GetExamFromFile(opendialog.FileName, studentPassTxtBox.Text, "", Security.FilterationSecurityLevel.Moderate));
                    aLogger.LogMessage($" Added Exam File from [{opendialog.FileName}]", LogMsgType.Verbose);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #14
0
        private SortedList <int, Exam> GetExams(int numberOfInitiaQuestions, int maxNumOfQuestions, int step = 10)
        {
            SortedList <int, Exam> ret = new SortedList <int, Exam>();

            Parallel.ForEach(BetterEnumerable.SteppedRange(numberOfInitiaQuestions, maxNumOfQuestions, step), (index) =>
            {
                var x = ExamHelper.GetRandomExamforTesting(index);
                lock (ret)
                {
                    ret.Add(index, x);
                }
            });

            //int tempInit = numberOfInitiaQuestions;
            //while (tempInit < maxNumOfQuestions)
            //{
            //    ret.Add(tempInit, ExamHelper.GetRandomExamforTesting(tempInit));
            //    tempInit += step;
            //}
            return(ret);
        }
コード例 #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Exm exam = ExamHelper.GetExam(this.ExamId);

            if (IsAnswerMode)
            {
                AnswerSheet answersheet = AnswerHelper.GetAnswerSheet(this.SubmittedUserId, this.ExamId);
                //feed submitted answers
                exam = ExamHelper.ProcessAnswers(exam, answersheet);
                divExamDetails.Visible = false;
            }

            if (exam != null)
            {
                litIstructions.Text = exam.Instructions != null ? exam.Instructions : "-";
                litTime.Text        = exam.TimeInSeconds.HasValue ? Utils.TimeString(exam.TimeInSeconds.Value) : "-";

                repQuestions.DataSource = exam.Questions;
                repQuestions.DataBind();
            }
        }
コード例 #16
0
        private void _SetUIAndBindData()
        {
            Exm exam = ExamHelper.GetExam(this.ExamId);

            AnswerSheet answersheet = AnswerHelper.GetAnswerSheet(this.UserId, this.ExamId);

            if (!Page.IsPostBack)
            {
                divQuestionContainer.Visible = false;
                divMessage.Visible           = false;
                divWelcome.Visible           = true;

                litIstructions.Text = exam.Instructions != null ? exam.Instructions : "-";
                litTime.Text        = exam.TimeInSeconds.HasValue ? Utils.TimeString(exam.TimeInSeconds.Value) : "-";
                return;
            }
            else if (answersheet != null && answersheet.Answers.Count == exam.Questions.Count)
            {
                divQuestionContainer.Visible = false;
                divMessage.Visible           = true;
                divWelcome.Visible           = false;

                //lblMessage.Text = "Finished!";
            }
            else if (answersheet == null || answersheet.Answers.Count < exam.Questions.Count)
            {
                divQuestionContainer.Visible = true;
                divMessage.Visible           = false;
                divWelcome.Visible           = false;
                Question question = ExamHelper.NextQuestion(exam, answersheet);
                if (question != null)
                {
                    populateQuestionUI(question);
                }
            }
        }
コード例 #17
0
        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)));
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
        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. ");
            }
        }