private async Task LoadExamList() { var(code, res) = await ExamServices.GetExams(3); if (code == ErrorCodes.Success) { _examList = res; return; } if (code == ErrorCodes.NotLoggedIn) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Please login first", }); NavManager.NavigateTo("/User/Login"); } else { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Failed to get exam list", Content = ErrorCodes.MessageMap[code] }); } }
private async Task OnReshareScreen() { await ExamServices.SendEvent(_examId, 1, "The test taker's desktop capture was cancelled", null); _inReshare = true; await Modal.ErrorAsync(new ConfirmOptions() { Title = "Your desktop capture is interrupted", Content = "You could probably clicked the 'Stop sharing' button, click 'OK' to re-initialize your screen capture" }); while (_inReshare) { var streamId = await _webRtcClient.ObtainDesktopStream(); if (streamId is "screen:0:0" or "Screen 1") { if (_localDesktopVideoLoaded) { await _webRtcClient.SetDesktopVideoElement("local-desktop"); } await _webRtcClient.StartStreamingDesktop(); _inReshare = false; }
protected override async Task OnInitializedAsync() { var(res2, answer, _) = await ExamServices.GetAnswer("", ExamId, QuestionNum); Console.WriteLine(res2); if (res2 == ErrorCodes.Success) { _answer = answer; if (answer is ChoiceAnswer choiceAnswer && Question is ChoiceQuestion choiceQuestion) { if (choiceQuestion.MultiChoice) { _choiceChecked = new bool[choiceQuestion.Choices.Count]; foreach (var i in choiceAnswer.Choices) { _choiceChecked[i] = true; } } else { _choiceSingle = choiceAnswer.Choices[0]; } } else if (answer is ShortAnswer shortAnswer && Question is ShortAnswerQuestion shortAnswerQuestion) { _answerString = shortAnswer.Answer; }
/// <summary> /// Confirm to ban a test taker /// </summary> private async Task BanTestTakerConfirm() { var res = await ExamServices.BanExamTaker(_examId, _banTakerName, _banReason); if (res == ErrorCodes.Success) { await Modal.SuccessAsync(new ConfirmOptions() { Content = $"Exam taker {_banTakerName} have been banned" }); // Shows the ban icon on the video panel GetExamTakerVideoCard(_banTakerName).SetBanned(true); } else { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot ban exam taker", Content = ErrorCodes.MessageMap[res] }); } _banTakerName = null; _banModalVisible = false; }
/// <summary> /// Obtain events messages of all takers /// </summary> private async Task GetEvents() { var(ret, warnings) = await ExamServices.GetEvents(_examId, Consts.MessageTypeWarning); // Warning messages if (ret == ErrorCodes.Success) { foreach (var ev in warnings) { GetExamTakerVideoCard(ev.Sender).AddOldMessage(ev); } } var(ret2, takerMessage) = await ExamServices.GetEvents(_examId, Consts.MessageTypeTaker); // Exam taker sent messages if (ret2 == ErrorCodes.Success) { foreach (var ev in takerMessage) { if (!_takerMessages.ContainsKey(ev.Sender)) { _takerMessages[ev.Sender] = new List <EventItem>(); } _takerMessages[ev.Sender].Add(ev); } } // Proctor sent messages var(ret3, proctorMessage) = await ExamServices.GetEvents(_examId, Consts.MessageTypeProctor); if (ret3 == ErrorCodes.Success) { foreach (var ev in proctorMessage) { if (ev.Receipt == null) { // Broadcast messages _broadcastMessages.Add(ev); } else { if (!_takerMessages.ContainsKey(ev.Receipt)) { _takerMessages[ev.Receipt] = new List <EventItem>(); } _takerMessages[ev.Receipt].Add(ev); } } } foreach (var key in _takerMessages.Keys) { // Sort messages _takerMessages[key].Sort((x, y) => DateTime.Compare(x.Time, y.Time)); } _broadcastMessages.Sort((x, y) => DateTime.Compare(x.Time, y.Time)); }
public UploadExamController() { service = new QuestionServices(); serviceExam = new ExamServices(); this.context = context; }
/// <summary> /// Attempts to enter the proctor session /// </summary> /// <returns>true if successes, false if fails</returns> private async Task <bool> Attempt() { var result = await ExamServices.AttemptProctor(_examId); if (result == ErrorCodes.NotLoggedIn) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "You must login first", }); NavManager.NavigateTo("/User/Login"); return(false); } if (result != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Enter proctor failed", Content = ErrorCodes.MessageMap[result] }); NavManager.NavigateTo("/"); return(false); } return(true); }
private async Task HandleUpdateBasicInfo() { var res = await ExamServices.UpdateExamDetails(_updateExamDetailsModel); if (res != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot update exam information", Content = ErrorCodes.MessageMap[res] }); return; } await Message.Success("Exam information updated"); var(res2, details) = await ExamServices.GetExamDetails(_examId); if (res2 == ErrorCodes.Success) { var secs = details.Duration; var hours = secs / 3600; var minutes = (secs - hours * 3600) / 60; var seconds = secs - minutes * 60 - hours * 3600; _updateExamDetailsModel.Name = details.Name; _updateExamDetailsModel.Description = details.Description; _updateExamDetailsModel.StartTime = details.StartTime; _updateExamDetailsModel.Duration = new DateTime(1999, 04, 27, 10, minutes, seconds); _updateExamDetailsModel.OpenBook = details.OpenBook; _updateExamDetailsModel.MaximumTakersNum = details.MaxTakers; } }
/// <summary> /// Obtains the exam details /// </summary> private async Task GetExamDetails() { var(ret, details) = await ExamServices.GetExamDetails(_examId); if (ret == ErrorCodes.Success) { _examDetails = details; } }
private async Task GetProctors() { var(ret, proctors) = await ExamServices.GetProctors(_examId); if (ret == ErrorCodes.Success) { _proctors = proctors.Select(x => x.Id).ToList(); } }
/// <summary> /// Get exam takers /// </summary> private async Task GetExamTakers() { var(err, takers) = await ExamServices.GetTestTakers(_examId); if (err == ErrorCodes.Success) { _examTakerVideoCards = new ExamTakerVideoCard[takers.Count]; _testTakers = takers; } }
private async Task LoadExamList() { var(code, res) = await ExamServices.GetExams(1); if (code == ErrorCodes.Success) { _examList = res; foreach (var e in _examList) { if (e.StartTime < DateTime.Now && e.StartTime.AddSeconds(e.Duration) > DateTime.Now && e.BanReason == null) { _nextExam = e; _haveOngoingExam = true; break; } if (e.StartTime > DateTime.Now && e.BanReason == null) { if (_nextExam == null || (_nextExam.StartTime - DateTime.Now) > (e.StartTime - DateTime.Now)) { _nextExam = e; } } } return; } if (code == ErrorCodes.NotLoggedIn) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Please login first", }); NavManager.NavigateTo("/User/Login"); } else { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Failed to get exam list", Content = ErrorCodes.MessageMap[code] }); } }
private async Task GetQuestions() { var(res, questions) = await ExamServices.GetPaper(_examId); if (res == ErrorCodes.ExamNotBegin) { // If the exam not begin, display the count down _examNotBegin = true; } else if (res == ErrorCodes.Success) { _examNotBegin = false; _questions = questions; } StateHasChanged(); }
/// <summary> /// Sends a new message /// </summary> /// <param name="message"></param> private async Task OnSendMessage(string message) { var ret = await ExamServices.SendEvent(_examId, Consts.MessageTypeProctor, message, _currentChatTaker); if (ret != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Failed to send message", Content = ErrorCodes.MessageMap[ret] }); } else { // After message being sent successfully, add the message to the message list // of the corresponding user if (_currentChatTaker == null) { _broadcastMessages.Add(new EventItem() { Message = message, Receipt = _currentChatTaker, Sender = "Me", Time = DateTime.Now, Type = Consts.MessageTypeProctor }); } else { if (!_takerMessages.ContainsKey(_currentChatTaker)) { _takerMessages[_currentChatTaker] = new List <EventItem>(); } _takerMessages[_currentChatTaker].Add(new EventItem() { Message = message, Receipt = _currentChatTaker, Sender = "Me", Time = DateTime.Now, Type = Consts.MessageTypeProctor }); } } }
protected override async Task OnInitializedAsync() { var(res, answer, time) = await ExamServices.GetAnswer(UserId, ExamId, QuestionNum); if (res == ErrorCodes.Success) { _answer = answer; _time = time; } else if (res == ErrorCodes.QuestionNotAnswered) { _displayText = "The exam taker did not answered this question"; } else { _displayText = "Error fetching answer: " + ErrorCodes.MessageMap[res]; } }
private async Task GetEvents() { var(res, proctorEvents) = await ExamServices.GetEvents(_examId, Consts.MessageTypeProctor); if (res == ErrorCodes.Success) { _messages.AddRange(proctorEvents); } var(res2, takerEvents) = await ExamServices.GetEvents(_examId, Consts.MessageTypeTaker); if (res == ErrorCodes.Success) { _messages.AddRange(takerEvents); } _messages.Sort((a, b) => DateTime.Compare(a.Time, b.Time)); }
protected override async Task OnInitializedAsync() { if (!int.TryParse(ExamId, out _examId)) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot get exam result", Content = "Invalid examId" }); return; } var(r, details) = await ExamServices.GetExamDetails(_examId); if (r != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot get exam result", Content = ErrorCodes.MessageMap[r] }); return; } _examDetails = details; var(res, questions) = await ExamServices.GetPaper(_examId); if (res != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot get exam result", Content = ErrorCodes.MessageMap[res] }); return; } _questions = questions; StateHasChanged(); }
private async Task OnJoinExam() { var(res, details) = await ExamServices.GetExamDetails(_examIdToJoin); if (res != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot obtain exam information", Content = ErrorCodes.MessageMap[res] }); return; } var confirm = await Modal.ConfirmAsync(new ConfirmOptions() { Title = "Confirm to join exam", Content = RenderExamDescription(details) }); if (confirm) { var(re, banReason) = await ExamServices.JoinExam(_examIdToJoin); if (re != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot join the exam", Content = ErrorCodes.MessageMap[re] + (banReason == null ? "" : " Reason: " + banReason) }); return; } await Modal.SuccessAsync(new ConfirmOptions() { Content = "You have successfully joined the exam." }); } _joinExamModalVisible = false; }
private async Task HandleSubmit(EditContext editContext) { var res = await ExamServices.CreateExam(_model); if (res != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Error", Content = ErrorCodes.MessageMap[res] }); } else { await Modal.SuccessAsync(new ConfirmOptions() { Title = "Success", Content = "Click 'OK' to add questions to exam" }); } }
private async Task OnAddProctor() { var res = await ExamServices.AddProctor(_examId, _proctorIdToAdd); if (res != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Failed to add proctor to exam", Content = ErrorCodes.MessageMap[res] }); } else { await Modal.SuccessAsync(new ConfirmOptions() { Title = "Successfully added proctor to exam" }); _proctorIdToAdd = ""; } }
private async Task OnSavePaper() { await HandleUpdateBasicInfo(); foreach (var e in _questionEditors) { await e.SaveQuestion(); } var res = await ExamServices.UpdatePaper(_examId, _questions); if (res != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot save exam paper", Content = ErrorCodes.MessageMap[res] }); return; } await Message.Success("Exam paper saved"); }
protected override async Task OnInitializedAsync() { if (!int.TryParse(ExamId, out _examId)) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Invalid exam ID" }); return; } var(res, details) = await ExamServices.GetExamDetails(_examId); if (res != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Failed to obtain exam information", Content = ErrorCodes.MessageMap[res] }); return; } _model = details; var(res2, takers) = await ExamServices.GetTestTakers(_examId); if (res2 != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Failed to obtain list of exam takers", Content = ErrorCodes.MessageMap[res2] }); return; } _takers = takers; var(res3, proctors) = await ExamServices.GetProctors(_examId); if (res3 != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Failed to obtain list of exam proctors", Content = ErrorCodes.MessageMap[res3] }); return; } _proctors = proctors; var(res4, questions) = await ExamServices.GetPaper(_examId); if (res4 != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Failed to obtain questions", Content = ErrorCodes.MessageMap[res4] }); return; } _questions = questions; }
public ExamController() { services = new ExamServices(); }
public ExamController(ExamServices examServices) { _examServices = examServices; }
protected override async Task OnInitializedAsync() { if (!int.TryParse(ExamId, out _examId)) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot obtain exam information", Content = "Invalid exam ID" }); return; } var(res, details) = await ExamServices.GetExamDetails(_examId); if (res != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot obtain exam information", Content = ErrorCodes.MessageMap[res] }); if (res == ErrorCodes.NotLoggedIn) { NavManager.NavigateTo("/User/Login"); } return; } var secs = details.Duration; var hours = secs / 3600; var minutes = (secs - hours * 3600) / 60; var seconds = secs - minutes * 60 - hours * 3600; _updateExamDetailsModel.Id = _examId; _updateExamDetailsModel.Name = details.Name; _updateExamDetailsModel.Description = details.Description; _updateExamDetailsModel.StartTime = details.StartTime; _updateExamDetailsModel.Duration = new DateTime(1999, 04, 27, hours, minutes, seconds); _updateExamDetailsModel.OpenBook = details.OpenBook; _updateExamDetailsModel.MaximumTakersNum = details.MaxTakers; var(res2, questions) = await ExamServices.GetPaper(_examId); if (res2 != ErrorCodes.Success) { await Modal.ErrorAsync(new ConfirmOptions() { Title = "Cannot obtain exam paper", Content = ErrorCodes.MessageMap[res2] }); return; } _questions = questions; _questionEditors = new QuestionEditor[_questions.Count]; StateHasChanged(); }