public TaskTopicTestView GetTest(out bool wasTestLoaded) { wasTestLoaded = true; if (isForShowingResults) { if (testResult == null) { GetResults(out bool wereResultsLoaded); wasTestLoaded = wereResultsLoaded; } else { test = testResult.Test; } } else { try { test = testProvider.Load(); } catch { wasTestLoaded = false; } } if (!wasTestLoaded) { return(null); } var tasksAndTopics = new Dictionary <Task, Topic>(); foreach (var topic in test.Topics) { foreach (var pair in GetTasksFromTopic(topic)) { tasksAndTopics.Add(pair.Key, pair.Value); } } var testView = new TaskTopicTestView() { Test = test, TasksAndTopics = tasksAndTopics }; if (testView.TasksAndTopics.Count == 0) { wasTestLoaded = false; } return(testView); }
public PassingWindow(string testPath, string resultPath, bool isShowingResults, string studentName) { InitializeComponent(); IsLoadedProperly = true; this.isShowingResults = isShowingResults; core = new DefaultPassingCore(new JsonDataProvider <Test>(testPath), new JsonDataProvider <TestResult>(resultPath), isShowingResults); if (isShowingResults) { results = core.GetResults(out bool wereResultsLoaded); IsLoadedProperly = wereResultsLoaded; if (!wereResultsLoaded) { MessageBox.Show("Result file was corrupted. Returning to hub."); Close(); } } testView = core.GetTest(out bool wasTestLoaded); if (!wasTestLoaded && IsLoadedProperly) { IsLoadedProperly = wasTestLoaded; MessageBox.Show("Test file was corrupted. Returning to hub."); Close(); } else if (wasTestLoaded) { if (testView.Test.HasPassword && isShowingResults) { var passwordWindow = new TextInputWindow("Enter password"); passwordWindow.ShowDialog(); if (!passwordWindow.EnteredText.Equals(testView.Test.Password)) { IsLoadedProperly = false; MessageBox.Show("Password is wrong. Returning to hub."); Close(); } } tasks = new List <Task>(testView.TasksAndTopics.Keys); currentTaskIndex = 0; if (!isShowingResults) { this.studentName = studentName; results = new List <TaskResult>(); foreach (var task in testView.TasksAndTopics.Keys) { results.Add(new TaskResult(task, null)); } } tasksTreeItems = new Dictionary <Task, TreeViewItem>(); SetQuestionButton.Click += SetQuestionButtonClick; PrevButton.Click += PrevButtonClick; NextButton.Click += NextButtonClick; FinishButton.Click += FinishButtonClick; TestTree.SelectedItemChanged += TestTreeSelectedItemChanged; SetQuestionButton.IsEnabled = false; SetTestToTree(); SetNewPage(); if (!isShowingResults) { SetTime(); } } }