private async void initializeExposition() { switch (executingTest.ProgramInUse.ExpositionType) { case "Imagem": imagesList = executingTest.ProgramInUse.getImageListFile().ListContent.ToArray(); if (executingTest.ProgramInUse.ExpositionRandom) { imagesList = ExpositionController.ShuffleArray(imagesList, executingTest.ProgramInUse.NumExpositions, 3); } break; } await exposition(); }
private void loadLists() { defineStimuluType(); matchingGroups = new List <MatchingGroup>(); if (this.stimuluType == 0) { this.imageList = this.executingTest.ProgramInUse.getImageListFile().ListContent.ToArray(); if (this.executingTest.ProgramInUse.ExpositionRandom) { imageList = ExpositionController.ShuffleArray(imageList, imageList.Length, Guid.NewGuid().GetHashCode()); } } else if (this.stimuluType == 1 || this.stimuluType == 2) { this.wordList = this.executingTest.ProgramInUse.getWordListFile().ListContent.ToArray(); if (this.executingTest.ProgramInUse.ExpositionRandom) { wordList = ExpositionController.ShuffleArray(wordList, wordList.Length, Guid.NewGuid().GetHashCode()); } if (this.stimuluType == 2) { this.colorList = this.executingTest.ProgramInUse.getColorListFile().ListContent.ToArray(); if (this.executingTest.ProgramInUse.ExpositionRandom) { colorList = ExpositionController.ShuffleArray(colorList, colorList.Length, Guid.NewGuid().GetHashCode()); } } else { this.colorList = new string[1]; colorList[0] = this.executingTest.ProgramInUse.WordColor; } } else { throw new InvalidOperationException(); } createMatchingGroups(); }
// reads lists to string arrays, shuffle them if the exposition is random and call exposition by the type private async Task startTypeExposition() { switch (currentTest.ProgramInUse.ExpositionType) { case "txt": wordList = currentTest.ProgramInUse.getWordListFile().ListContent.ToArray(); colorList = currentTest.ProgramInUse.getColorListFile().ListContent.ToArray(); if (currentTest.ProgramInUse.ExpositionRandom) { wordList = ExpositionController.ShuffleArray(wordList, currentTest.ProgramInUse.NumExpositions, 1); colorList = ExpositionController.ShuffleArray(colorList, currentTest.ProgramInUse.NumExpositions, 5); } await startWordExposition(); break; case "txtimg": imageList = currentTest.ProgramInUse.getImageListFile().ListContent.ToArray(); wordList = currentTest.ProgramInUse.getWordListFile().ListContent.ToArray(); if (currentTest.ProgramInUse.ExpositionRandom) { imageList = ExpositionController.ShuffleArray(imageList, currentTest.ProgramInUse.NumExpositions, 3); wordList = ExpositionController.ShuffleArray(wordList, currentTest.ProgramInUse.NumExpositions, 3); } await startWordImageExposition(); break; case "imgtxt": imageList = currentTest.ProgramInUse.getImageListFile().ListContent.ToArray(); wordList = currentTest.ProgramInUse.getWordListFile().ListContent.ToArray(); if (currentTest.ProgramInUse.ExpositionRandom) { imageList = ExpositionController.ShuffleArray(imageList, currentTest.ProgramInUse.NumExpositions, 3); wordList = ExpositionController.ShuffleArray(wordList, currentTest.ProgramInUse.NumExpositions, 3); } await startImageWordExposition(); break; case "img": imageList = currentTest.ProgramInUse.getImageListFile().ListContent.ToArray(); if (currentTest.ProgramInUse.ExpositionRandom) { imageList = ExpositionController.ShuffleArray(imageList, currentTest.ProgramInUse.NumExpositions, 3); } await startImageExposition(); break; case "txtaud": wordList = currentTest.ProgramInUse.getWordListFile().ListContent.ToArray(); colorList = currentTest.ProgramInUse.getColorListFile().ListContent.ToArray(); audioList = currentTest.ProgramInUse.getAudioListFile().ListContent.ToArray(); if (currentTest.ProgramInUse.ExpositionRandom) { wordList = ExpositionController.ShuffleArray(wordList, currentTest.ProgramInUse.NumExpositions, 1); colorList = ExpositionController.ShuffleArray(colorList, currentTest.ProgramInUse.NumExpositions, 5); audioList = ExpositionController.ShuffleArray(audioList, currentTest.ProgramInUse.NumExpositions, 6); } await startWordAudioExposition(); break; case "imgaud": imageList = currentTest.ProgramInUse.getImageListFile().ListContent.ToArray(); audioList = currentTest.ProgramInUse.getAudioListFile().ListContent.ToArray(); if (currentTest.ProgramInUse.ExpositionRandom) { imageList = ExpositionController.ShuffleArray(imageList, currentTest.ProgramInUse.NumExpositions, 3); audioList = ExpositionController.ShuffleArray(audioList, currentTest.ProgramInUse.NumExpositions, 6); } await startImageExposition(); break; default: throw new Exception(LocRM.GetString("expoType", currentCulture) + currentTest.ProgramInUse.ExpositionType + LocRM.GetString("invalid", currentCulture)); } }
private void loadLists() { switch (executingTest.ProgramInUse.ExpositionType) { case "shapes": if (executingTest.ProgramInUse.StimulusColor == "false") //if stimulusColor is false then there exists a color list { colorsList = executingTest.ProgramInUse.getColorListFile().ListContent.ToArray(); } else //if stimulusColor isn't false then there is no color list { colorsList = new string[] { executingTest.ProgramInUse.StimulusColor }; } colorsList = ExpositionController.ShuffleArray(colorsList, executingTest.ProgramInUse.NumExpositions, 3); break; case "images": imagesList = executingTest.ProgramInUse.getImageListFile().ListContent.ToArray(); if (executingTest.ProgramInUse.ExpositionRandom) { imagesList = ExpositionController.ShuffleArray(imagesList, executingTest.ProgramInUse.NumExpositions, 3); } break; case "words": wordsList = executingTest.ProgramInUse.getWordListFile().ListContent.ToArray(); if (executingTest.ProgramInUse.StimulusColor == "false") //if stimulusColor is false then there exists a color list { colorsList = executingTest.ProgramInUse.getColorListFile().ListContent.ToArray(); } else //if stimulusColor isn't false then there is no color list { colorsList = new string[] { executingTest.ProgramInUse.StimulusColor }; } if (executingTest.ProgramInUse.ExpositionRandom) { wordsList = ExpositionController.ShuffleArray(wordsList, executingTest.ProgramInUse.NumExpositions, 9); colorsList = ExpositionController.ShuffleArray(colorsList, executingTest.ProgramInUse.NumExpositions, 3); } break; case "imageAndWord": wordsList = executingTest.ProgramInUse.getWordListFile().ListContent.ToArray(); imagesList = executingTest.ProgramInUse.getImageListFile().ListContent.ToArray(); if (executingTest.ProgramInUse.StimulusColor == "false") //if stimulusColor is false then there exists a color list { colorsList = executingTest.ProgramInUse.getColorListFile().ListContent.ToArray(); } else //if stimulusColor isn't false then there is no color list { colorsList = new string[] { executingTest.ProgramInUse.StimulusColor }; } if (executingTest.ProgramInUse.ExpositionRandom) { Random rnd = new Random(DateTime.Now.Millisecond); wordsList = ExpositionController.ShuffleArray(wordsList, wordsList.Length, 9); imagesList = ExpositionController.ShuffleArray(imagesList, wordsList.Length, 10); colorsList = ExpositionController.ShuffleArray(colorsList, executingTest.ProgramInUse.NumExpositions, 3); } break; case "wordWithAudio": wordsList = executingTest.ProgramInUse.getWordListFile().ListContent.ToArray(); audioList = executingTest.ProgramInUse.getAudioListFile().ListContent.ToArray(); if (executingTest.ProgramInUse.StimulusColor == "false") //if stimulusColor is false then there exists a color list { colorsList = executingTest.ProgramInUse.getColorListFile().ListContent.ToArray(); } else //if stimulusColor isn't false then there is no color list { colorsList = new string[] { executingTest.ProgramInUse.StimulusColor }; } if (executingTest.ProgramInUse.ExpositionRandom) { wordsList = ExpositionController.ShuffleArray(wordsList, executingTest.ProgramInUse.NumExpositions, 9); colorsList = ExpositionController.ShuffleArray(colorsList, executingTest.ProgramInUse.NumExpositions, 3); audioList = ExpositionController.ShuffleArray(wordsList, executingTest.ProgramInUse.NumExpositions, 9); } break; case "imageWithAudio": imagesList = executingTest.ProgramInUse.getImageListFile().ListContent.ToArray(); audioList = executingTest.ProgramInUse.getAudioListFile().ListContent.ToArray(); if (executingTest.ProgramInUse.ExpositionRandom) { imagesList = ExpositionController.ShuffleArray(imagesList, executingTest.ProgramInUse.NumExpositions, 3); audioList = ExpositionController.ShuffleArray(wordsList, executingTest.ProgramInUse.NumExpositions, 9); } break; } }
private async Task startImageExposition() // inicia exposição de imagem { cts = new CancellationTokenSource(); int j, subtitleCounter = 0; int arrayCounter = 0; string[] labelText = null, imageDirs = null, audioDirs = null, subtitlesArray = null; string actualImagePath = ""; string audioDetail = "false"; try { BackColor = Color.White; wordLabel.ForeColor = Color.Red; if (currentTest.ProgramInUse.ExpandImage) { imgPictureBox.Dock = DockStyle.Fill; } else { imgPictureBox.Dock = DockStyle.None; } imageDirs = currentTest.ProgramInUse.getImageListFile().ListContent.ToArray(); // auxiliar recebe o vetor original if (currentTest.ProgramInUse.ExpositionRandom) // se exposição aleatória, randomiza itens de acordo com o numero de estimulos { imageDirs = ExpositionController.ShuffleArray(imageDirs, currentTest.ProgramInUse.NumExpositions, 3); } subtitlesArray = configureSubtitle(); if (currentTest.ProgramInUse.getAudioListFile() != null) { audioDirs = currentTest.ProgramInUse.getAudioListFile().ListContent.ToArray(); if (currentTest.ProgramInUse.ExpositionRandom) { audioDirs = ExpositionController.ShuffleArray(audioDirs, currentTest.ProgramInUse.NumExpositions, 6); } } if (currentTest.ProgramInUse.getWordListFile() != null) { labelText = currentTest.ProgramInUse.getWordListFile().ListContent.ToArray(); } await showInstructions(currentTest.ProgramInUse, cts.Token); // Apresenta instruções se houver outputContent = new List <string>(); changeBackgroundColor(true); // muda cor de fundo se houver parametro imgPictureBox.BackColor = BackColor; elapsedTime = 0; // zera tempo em milissegundos decorrido j = 0; subtitleCounter = 0; arrayCounter = 0; var audioCounter = 0; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); await Task.Delay(currentTest.ProgramInUse.IntervalTime, cts.Token); // beginAudio if (currentTest.ProgramInUse.AudioCapture) { startRecordingAudio(); } // inicia gravação áudio // endAudio if (currentTest.ProgramInUse.ExpositionType == "imgtxt") { for (int counter = 0; counter < currentTest.ProgramInUse.NumExpositions && runExposition; counter++) // AQUI ver estimulo -> palavra ou imagem como um só e ter intervalo separado { imgPictureBox.Visible = false; wordLabel.Visible = false; subtitleLabel.Visible = false; await intervalOrFixPoint(currentTest.ProgramInUse, cts.Token); if (arrayCounter == imageDirs.Count()) { arrayCounter = 0; } if (currentTest.ProgramInUse.RotateImage != 0) { imgPictureBox.Image = RotateImage(imageDirs[arrayCounter], currentTest.ProgramInUse.RotateImage); } else { imgPictureBox.Image = Image.FromFile(imageDirs[arrayCounter]); } // grava tempo decorrido elapsedTime = stopwatch.ElapsedMilliseconds; SendKeys.SendWait(currentTest.Mark.ToString()); //sending event to neuronspectrum imgPictureBox.Visible = true; if (currentTest.ProgramInUse.SubtitleShow) { subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray); } wordLabel.Visible = false; actualImagePath = Path.GetFileName(imageDirs[arrayCounter].ToString()); arrayCounter++; currentTest.writeLineOutputResult(currentTest.ProgramInUse, actualImagePath, "false", counter + 1, outputContent, elapsedTime, "img", audioDetail); await Task.Delay(currentTest.ProgramInUse.ExpositionTime, cts.Token); imgPictureBox.Visible = false; wordLabel.Visible = false; await Task.Delay(currentTest.ProgramInUse.DelayTime, cts.Token); // se tiver palavras intercala elas com a imagem if (currentTest.ProgramInUse.getWordListFile() != null) { if (j == labelText.Count() - 1) { j = 0; } wordLabel.Text = labelText[j]; elapsedTime = stopwatch.ElapsedMilliseconds; SendKeys.SendWait(currentTest.Mark.ToString()); //sending event to neuronspectrum imgPictureBox.Visible = false; subtitleLabel.Visible = false; wordLabel.ForeColor = ColorTranslator.FromHtml(currentTest.ProgramInUse.WordColor); wordLabel.Visible = true; if (currentTest.ProgramInUse.SubtitleShow) { subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray); } actualImagePath = wordLabel.Text; j++; currentTest.writeLineOutputResult(currentTest.ProgramInUse, actualImagePath, "false", counter + 1, outputContent, elapsedTime, "txt", audioDetail); await Task.Delay(currentTest.ProgramInUse.ExpositionTime, cts.Token); } await Task.Delay(currentTest.ProgramInUse.IntervalTime, cts.Token); } } else { // AQUI ver estimulo -> palavra ou imagem como um só e ter intervalo separado for (int counter = 0; counter < currentTest.ProgramInUse.NumExpositions && runExposition; counter++) { imgPictureBox.Visible = false; wordLabel.Visible = false; subtitleLabel.Visible = false; await intervalOrFixPoint(currentTest.ProgramInUse, cts.Token); if (arrayCounter == imageDirs.Count()) { arrayCounter = 0; } if (currentTest.ProgramInUse.RotateImage != 0) { imgPictureBox.Image = RotateImage(imageDirs[arrayCounter], currentTest.ProgramInUse.RotateImage); } else { imgPictureBox.Image = Image.FromFile(imageDirs[arrayCounter]); } if (currentTest.ProgramInUse.getAudioListFile() != null && currentTest.ProgramInUse.ExpositionType == "imgaud") { if (audioCounter == audioDirs.Length) { audioCounter = 0; } audioDetail = audioDirs[audioCounter]; Player.SoundLocation = audioDetail; audioCounter++; Player.Play(); } elapsedTime = stopwatch.ElapsedMilliseconds; SendKeys.SendWait(currentTest.Mark.ToString()); //sending event to neuronspectrum imgPictureBox.Visible = true; if (currentTest.ProgramInUse.SubtitleShow) { subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray); } currentTest.writeLineOutputResult(currentTest.ProgramInUse, Path.GetFileName(imageDirs[arrayCounter].ToString()), "false", counter + 1, outputContent, elapsedTime, currentTest.ProgramInUse.ExpositionType, Path.GetFileNameWithoutExtension(audioDetail)); arrayCounter++; await Task.Delay(currentTest.ProgramInUse.ExpositionTime, cts.Token); } } imgPictureBox.Visible = false; wordLabel.Visible = false; subtitleLabel.Visible = false; await Task.Delay(currentTest.ProgramInUse.IntervalTime, cts.Token); // beginAudio if (currentTest.ProgramInUse.AudioCapture && currentTest.ProgramInUse.ExpositionType != "txtaud" && currentTest.ProgramInUse.ExpositionType != "imgaud") { stopRecordingAudio(); } // endAudio changeBackgroundColor(false); // retorna à cor de fundo padrão imgPictureBox.Dock = DockStyle.None; wordLabel.Font = new Font(wordLabel.Font.FontFamily, 160); wordLabel.ForeColor = Color.Black; StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray())); this.DialogResult = DialogResult.OK; Close(); } catch (TaskCanceledException) { StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray())); } catch (Exception ex) { throw new Exception(ex.Message); } cts = null; }
private async Task startWordExposition() // starts colored words exposition - classic Stroop { cts = new CancellationTokenSource(); string audioDetail = "false"; int textArrayCounter = 0, colorArrayCounter = 0, audioCounter = 0, subtitleCounter = 0; List <string> outputContent = new List <string>(); try { // reading list files // string array receives lists itens from lists file string[] labelText = currentTest.ProgramInUse.getWordListFile().ListContent.ToArray(); string[] labelColor = currentTest.ProgramInUse.getColorListFile().ListContent.ToArray(); string[] subtitlesArray = configureSubtitle(); string[] audioDirs = null; if (currentTest.ProgramInUse.getAudioListFile() != null) // if there is an audioFile to be played, string array receives audioList itens from list file { audioDirs = currentTest.ProgramInUse.getAudioListFile().ListContent.ToArray(); } if (currentTest.ProgramInUse.ExpositionRandom) // if the presentation is random, shuffles arrays { labelText = ExpositionController.ShuffleArray(labelText, currentTest.ProgramInUse.NumExpositions, 1); labelColor = ExpositionController.ShuffleArray(labelColor, currentTest.ProgramInUse.NumExpositions, 5); if (audioDirs != null) { audioDirs = ExpositionController.ShuffleArray(audioDirs, currentTest.ProgramInUse.NumExpositions, 6); } } if (!Validations.allHexPattern(labelColor)) { throw new Exception("A lista de cores '" + currentTest.ProgramInUse.getColorListFile().ListName + "' contém valores inválidos!\n A lista de" + "cores deve conter apenas valores hexadecimais (ex: #000000)"); } // presenting test instructions: await showInstructions(currentTest.ProgramInUse, cts.Token); textArrayCounter = 0; // counters to zero colorArrayCounter = 0; elapsedTime = 0; // elapsed time to zero subtitleCounter = 0; changeBackgroundColor(true); // changes background color, if there is one defined Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); await Task.Delay(currentTest.ProgramInUse.IntervalTime, cts.Token); // first interval before exposition begins if (currentTest.ProgramInUse.AudioCapture && currentTest.ProgramInUse.ExpositionType != "txtaud") { startRecordingAudio(); } // exposition loop for (int counter = 1; counter <= currentTest.ProgramInUse.NumExpositions && runExposition; counter++) { subtitleLabel.Visible = false; wordLabel.Visible = false; await intervalOrFixPoint(currentTest.ProgramInUse, cts.Token); string textCurrent = labelText[textArrayCounter]; string colorCurrent = labelColor[colorArrayCounter]; if (textArrayCounter == labelText.Count() - 1) { textArrayCounter = 0; } else { textArrayCounter++; } if (colorArrayCounter == labelColor.Count() - 1) { colorArrayCounter = 0; } else { colorArrayCounter++; } wordLabel.Text = textCurrent; wordLabel.ForeColor = ColorTranslator.FromHtml(colorCurrent); if (currentTest.ProgramInUse.getAudioListFile() != null && currentTest.ProgramInUse.ExpositionType == "txtaud") // reproduz audio { if (audioCounter == audioDirs.Length) { audioCounter = 0; } else { /* do nothing */ } audioDetail = audioDirs[audioCounter]; Player.SoundLocation = audioDetail; audioCounter++; Player.Play(); } else { /* do nothing */ } elapsedTime = stopwatch.ElapsedMilliseconds; // grava tempo decorrido SendKeys.SendWait(currentTest.Mark.ToString()); //sending event to neuronspectrum if (currentTest.ProgramInUse.SubtitleShow) { subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray); } wordLabel.Visible = true; currentTest.writeLineOutputResult(currentTest.ProgramInUse, textCurrent, colorCurrent, counter, outputContent, elapsedTime, currentTest.ProgramInUse.ExpositionType, audioDetail ); await Task.Delay(currentTest.ProgramInUse.ExpositionTime, cts.Token); } wordLabel.Visible = false; subtitleLabel.Visible = false; await Task.Delay(currentTest.ProgramInUse.IntervalTime, cts.Token); // beginAudio if (currentTest.ProgramInUse.AudioCapture && currentTest.ProgramInUse.ExpositionType != "txtaud" && currentTest.ProgramInUse.ExpositionType != "imgaud") { stopRecordingAudio(); } // endAudio changeBackgroundColor(false); // retorna à cor de fundo padrão StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray())); this.DialogResult = DialogResult.OK; Close(); // finaliza exposição após execução } catch (TaskCanceledException) { StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray())); } catch (Exception ex) { MessageBox.Show(ex.Message); } cts = null; }