private void StartTask() { StartTaskButton.Enabled = false; TaskAnswerRichTextBox.Enabled = true; TaskAnswerRichTextBox.Text = null; CompleteTaskButton.Enabled = true; StudyTask CurrentTask = Program.TaskList[Program.CurrentTaskIndex]; GiveUpButton.Enabled = CurrentTask.ShouldShowFailedQuestion; String ChromePath = Microsoft.Win32.Registry.GetValue(@"HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command", null, null) as string; if (ChromePath != null) { var split = ChromePath.Split('\"'); ChromePath = split.Length >= 2 ? split[1] : null; } ProcessStartInfo ChromeProcess = new ProcessStartInfo(); ChromeProcess.FileName = ChromePath; ChromeProcess.Arguments = "--incognito \"" + CurrentTask.TaskURL.Replace("*", Program.ParticipantIdentifier) + "\""; Browser = Process.Start(ChromeProcess); //open web browser //SetBrowserSize(Browser); //no easy way to set browser size right now, ignoring stopWatch = new Stopwatch(); stopWatch.Start(); }
private void NextTask() { Program.CurrentTaskIndex++; if (Program.CurrentTaskIndex == Program.TaskList.Count) { //this is the end, show dialogue and close MessageBox.Show("Thank you for your participation!"); Application.Exit(); } else { TasksCheckedBox.DataSource = Program.TaskList; TasksCheckedBox.DisplayMember = "DisplayTitle"; for (int i = 0; i < Program.TaskList.Count; i++) { TasksCheckedBox.SetItemChecked(i, Program.TaskList[i].Completed); } TasksCheckedBox.SelectedIndex = Program.CurrentTaskIndex; StudyTask CurrentTask = Program.TaskList[Program.CurrentTaskIndex]; TaskInstructionLabel.Text = CreateFullInstructions(CurrentTask); StartTaskButton.Enabled = true; TaskAnswerRichTextBox.Enabled = false; CompleteTaskButton.Enabled = false; GiveUpButton.Enabled = false; } }
private string CreateFullInstructions(StudyTask Task) { return(Task.Instructions + Environment.NewLine + Environment.NewLine + "Pressing the start task button will open " + Task.TaskURL + " , which you should use to complete the task."); }
public static IRestResponse SendData(StudyTask Task) { var client = new RestClient(Program.RemoteServerLocation); var request = new RestRequest("tasks", Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter("Title", Task.Title); request.AddParameter("System", Task.TaskURL); request.AddParameter("Answer", Task.Answer); request.AddParameter("TimeSpent", Task.TimeSpentOnTask); request.AddParameter("Timestamp", Task.Timestamp); request.AddParameter("BelievesSuccess", Task.ParticipantBelievesSuccess); request.AddParameter("Screenshot", System.Convert.ToBase64String(Task.ScreenshotPNG)); IRestResponse response = client.Execute(request); return(response); }
private void FinishTask(bool GivingUp = false) { stopWatch.Stop(); byte[] TaskScreenshotPNG = GetScreenshotAsPNG(); DialogResult FinishedDialogResult; if (!GivingUp) { FinishedDialogResult = MessageBox.Show("Are you sure you believe you have finished?", "Finished?", MessageBoxButtons.YesNo); } else { FinishedDialogResult = MessageBox.Show("Are you sure you want to give up on this task?", "Finished?", MessageBoxButtons.YesNo); } if (FinishedDialogResult == DialogResult.Yes) { CompleteTaskButton.Enabled = false; GiveUpButton.Enabled = false; StudyTask CurrentTask = Program.TaskList[Program.CurrentTaskIndex]; if (CurrentTask.ShouldShowFailedQuestion && !GivingUp) { DialogResult SucessfulDialogResult = MessageBox.Show("Do you believe you have finished the task successfully?", "Task successful?", MessageBoxButtons.YesNo); if (SucessfulDialogResult == DialogResult.Yes) { CurrentTask.ParticipantBelievesSuccess = true; } else { CurrentTask.ParticipantBelievesSuccess = false; } } else { CurrentTask.ParticipantBelievesSuccess = GivingUp; } CurrentTask.TimeSpentOnTask = stopWatch.ElapsedMilliseconds; CurrentTask.ScreenshotPNG = TaskScreenshotPNG; CurrentTask.Answer = TaskAnswerRichTextBox.Text; CurrentTask.Completed = true; CurrentTask.Timestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; DataPoster.SendData(CurrentTask); Program.SaveEverythingToDisk(); TaskAnswerRichTextBox.Text = null; foreach (Process process in Process.GetProcesses()) { if (process.MainWindowTitle.Contains("GDPVis") || process.MainWindowTitle.Contains("gdp3") || process.ProcessName.Contains("chrome")) { try { process.Kill(); } catch { } } } NextTask(); } else if (FinishedDialogResult == DialogResult.No) { stopWatch.Start(); //start the stopwatch back up again, and continue as we were. } }