Beispiel #1
0
        private async Task intervalOrFixPoint(StroopProgram program, CancellationToken token)
        {
            try
            {
                int intervalTime = 400;                                       // minimal rnd interval time
                if (program.IntervalTimeRandom && program.IntervalTime > 400) // if rnd interval active, it will be a value between 400 and the defined interval time
                {
                    Random random = new Random();
                    intervalTime = random.Next(400, program.IntervalTime);
                }
                else
                {
                    intervalTime = program.IntervalTime;
                }

                if (program.FixPoint == "+" || program.FixPoint == "o")
                {
                    ExpositionController.makingFixPoint(program.FixPoint, program.FixPointColor, this);
                }
                await Task.Delay(intervalTime);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Close();
            }
        }
Beispiel #2
0
 public FormDefineTest(CultureInfo currentCulture)
 {
     this.currentCulture = currentCulture;
     InitializeComponent();
     AutoValidate = AutoValidate.Disable;
     addOptionsComboBox(StroopProgram.GetProgramsPath());
 }
        private void openImgList()
        {
            try
            {
                FormDefine defineFilePath = defineFilePath = new FormDefine("Lista de Imagens: ", path, "lst", "_image", true);
                var        result         = defineFilePath.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string dir = defineFilePath.ReturnValue;
                    imgListNameTextBox.Text = dir.Remove(dir.Length - 6); // removes the _img identification from file while editing (when its saved it is always added again)

                    string[] filePaths = StroopProgram.readDirListFile(path + "/" + dir + ".lst");
                    readImagesIntoDGV(filePaths, imgPathDataGridView);

                    if (firstOpenFlag)
                    {
                        WindowState = FormWindowState.Maximized; firstOpenFlag = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #4
0
        private void exportCVSButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            string[] lines;

            // salva file on .csv format
            saveFileDialog1.Filter           = "Excel CSV (.csv)|*.csv";
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.FileName         = resultComboBox.Text;

            // only saves if there is one selected result to save
            if (resultComboBox.SelectedIndex != -1)
            {
                lines = StroopProgram.readDataFile(path + "/" + resultComboBox.SelectedItem.ToString() + ".txt");
                if (saveFileDialog1.ShowDialog() == DialogResult.OK) // abre caixa para salvar
                {
                    using (TextWriter tw = new StreamWriter(saveFileDialog1.FileName))
                    {
                        tw.WriteLine(LocRM.GetString("stroopResultHeader", currentCulture));
                        for (int i = 0; i < lines.Length; i++)
                        {
                            // writing lines on new file
                            tw.WriteLine(lines[i]);
                        }
                        tw.Close();
                        MessageBox.Show(LocRM.GetString("exportedFile", currentCulture));
                    }
                }
            }
            else
            {
                MessageBox.Show(LocRM.GetString("selectDataFile", currentCulture));
            }
        }
Beispiel #5
0
 private void saveProgramFile(StroopProgram newProgram)
 {
     if (FileManipulation.StroopProgramExists(prgNameTextBox.Text))
     {
         DialogResult dialogResult = MessageBox.Show(LocRM.GetString("programExists", currentCulture), "", MessageBoxButtons.OKCancel);
         if (dialogResult != DialogResult.Cancel)
         {
             if (newProgram.saveProgramFile())
             {
                 MessageBox.Show(LocRM.GetString("programSave", currentCulture));
             }
             this.Parent.Controls.Remove(this);
         }
         else
         {
             MessageBox.Show(LocRM.GetString("programNotSave", currentCulture));
         }
     }
     else
     {
         if (newProgram.saveProgramFile())
         {
             MessageBox.Show(LocRM.GetString("programSave", currentCulture));
         }
         this.Parent.Controls.Remove(this);
     }
 }
        private void exportCVSButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            string[] lines;

            saveFileDialog1.Filter           = "Excel CSV (.csv)|*.csv"; // salva em .csvs
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.FileName         = comboBox1.Text;
            if (comboBox1.SelectedIndex == -1)
            {
                throw new Exception("Selecione um arquivo de dados!");
            }

            lines = StroopProgram.readDataFile(path + "/" + comboBox1.SelectedItem.ToString() + ".txt");
            if (saveFileDialog1.ShowDialog() == DialogResult.OK) // abre caixa para salvar
            {
                using (TextWriter tw = new StreamWriter(saveFileDialog1.FileName))
                {
                    tw.WriteLine(StroopTest.HeaderOutputFileText);
                    for (int i = 0; i < lines.Length; i++)
                    {
                        tw.WriteLine(lines[i]); // escreve linhas no novo arquivo
                    }
                    tw.Close();
                    MessageBox.Show("Arquivo exportado com sucesso!");
                }
            }
        }
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     this.dataGridView1.DataSource = null;
     this.dataGridView1.Rows.Clear();
     string[] line;
     try
     {
         line = StroopProgram.readDataFile(path + "/" + comboBox1.SelectedItem.ToString() + ".txt");
         if (line.Count() > 0)
         {
             for (int i = 0; i < line.Count(); i++)
             {
                 string[] cellArray = line[i].Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                 if (cellArray.Length == dataGridView1.Columns.Count)
                 {
                     dataGridView1.Rows.Add(cellArray);
                     for (int j = 0; j < cellArray.Length; j++)
                     {
                         if (Regex.IsMatch(cellArray[j], hexPattern))
                         {
                             dataGridView1.Rows[i].Cells[j].Style.BackColor = ColorTranslator.FromHtml(cellArray[j]);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex) { MessageBox.Show(ex.Message); }
 }
Beispiel #8
0
 private void stroopButton_Click(object sender, EventArgs e)
 {
     if (stroopButton.Checked)
     {
         comboBox1.SelectedItem = null;
         removeOptionsComboBox();
         addOptionsComboBox(StroopProgram.GetProgramsPath());
     }
 }
Beispiel #9
0
        private void repairProgram(StroopProgram program, string path)
        {
            FormPrgConfig configureProgram;

            try
            {
                configureProgram = new FormPrgConfig(path, "/" + programInUse.ProgramName);
                configureProgram.ShowDialog();
            }
            catch (Exception ex) { throw new Exception("Edição não pode ser feita " + ex.Message); }
        }
Beispiel #10
0
 private void changeBackgroundColor(StroopProgram program, bool flag) // muda cor de fundo
 {
     if (flag && program.BackgroundColor.ToLower() != "false")
     {
         this.BackColor = ColorTranslator.FromHtml(program.BackgroundColor);
     }
     else
     {
         this.BackColor = Color.White;
     }
 }
Beispiel #11
0
 private async Task showInstructions(StroopProgram program, CancellationToken token) // apresenta instruções
 {
     if (program.InstructionText != null)
     {
         instructionLabel.Enabled = true; instructionLabel.Visible = true;
         for (int i = 0; i < program.InstructionText.Count; i++)
         {
             instructionLabel.Text = program.InstructionText[i];
             await Task.Delay(StroopProgram.instructionAwaitTime);
         }
         instructionLabel.Enabled = false; instructionLabel.Visible = false;
     }
 }
Beispiel #12
0
        private void finishExposition()
        {
            wordLabel.Visible     = false;
            subtitleLabel.Visible = false;

            // return background color to default color
            changeBackgroundColor(false);

            StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray()));
            this.DialogResult = DialogResult.OK;

            // closes form finishing exposition
            Close();
        }
Beispiel #13
0
        private void openFilesForEdition(string filePath)
        {
            try
            {
                FormDefine defineFilePath = new FormDefine("Listas de Palavras: ", filePath, "lst", "_words_color", true);
                var        result         = defineFilePath.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string fileName = defineFilePath.ReturnValue;
                    fileName             = fileName.Remove(fileName.Length - 6);
                    listNameTextBox.Text = fileName;

                    string wFile = filePath + "/" + fileName + "_words.lst";
                    string cFile = filePath + "/" + fileName + "_color.lst";

                    if (File.Exists(wFile))
                    {
                        string[] wordsArray = StroopProgram.readListFile(wFile);
                        foreach (string word in wordsArray)
                        {
                            wordsList.Add(word);
                        }
                        wordsListCheckBox.Checked = true;
                    }
                    if (File.Exists(cFile))
                    {
                        string[] colorsArray = StroopProgram.readListFile(cFile);
                        foreach (string color in colorsArray)
                        {
                            colorsList.Add(color);
                        }
                        colorsListCheckBox.Checked = true;
                    }
                    checkTypeOfList();
                    numberItens.Text = wordsDataGridView.RowCount.ToString();
                }
                else
                {
                    wordsListCheckBox.Checked  = true;
                    colorsListCheckBox.Checked = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #14
0
 private void saveProgramFile(StroopProgram newProgram)
 {
     if (File.Exists(path + prgNameTextBox.Text + ".prg"))
     {
         DialogResult dialogResult = MessageBox.Show("O programa já existe, deseja sobrescrevê-lo?", "", MessageBoxButtons.OKCancel);
         if (dialogResult == DialogResult.Cancel)
         {
             throw new Exception("O programa não será salvo!");
         }
     }
     if (newProgram.saveProgramFile(path, instructionBoxText))
     {
         MessageBox.Show("O programa foi salvo com sucesso");
     }
     this.Parent.Controls.Remove(this);
 }
Beispiel #15
0
        private void finishExposition()
        {
            wordLabel.Visible     = false;
            subtitleLabel.Visible = false;

            // Write to the file to indicate finish of task
            FormMain.writer.WriteLine(FormMain.GetTimestamp(DateTime.UtcNow) + ",0,0,0,0");
            // return background color to default color
            changeBackgroundColor(false);

            StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray()));
            this.DialogResult = DialogResult.OK;

            // closes form finishing exposition
            Close();
        }
        private void playCurrentAudio()
        {
            string[] filePath;
            string   program, user, date, hour, new_hour, new_date, archive_name;

            program              = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            user                 = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            date                 = dataGridView1.CurrentRow.Cells[2].Value.ToString().Trim();
            new_date             = date[0].ToString() + date[1].ToString() + "." + date[3].ToString() + date[4].ToString();
            hour                 = dataGridView1.CurrentRow.Cells[3].Value.ToString().Trim();
            new_hour             = hour[0].ToString() + hour[1].ToString() + "h" + hour[3].ToString() + hour[4].ToString() + "." + hour[6].ToString() + hour[7].ToString();
            archive_name         = "audio_" + user + "_" + program + "_" + new_date + "_" + new_hour + ".wav";
            filePath             = Directory.GetFiles(path, archive_name, SearchOption.AllDirectories);
            Player.SoundLocation = filePath[0];
            Player.Play();
        }
Beispiel #17
0
        private void initializeDefaultPrograms() // inicializa programDefault padrão
        {
            StroopProgram programDefault = new StroopProgram();

            programDefault.ProgramName = DEFAULTPGRNAME;
            try
            {
                programDefault.writeDefaultProgramFile(Global.stroopTestFilesPath + Global.programFolderName + programDefault.ProgramName + ".prg"); // ao inicializar formulario escreve arquivo programa padrao
                ReactionProgram.writeDefaultProgramFile();
                StrList.writeDefaultWordsList(Global.testFilesPath + Global.listFolderName);                                                         // escreve lista de palavras padrão
                StrList.writeDefaultColorsList(Global.testFilesPath + Global.listFolderName);                                                        // escreve lista de cores padrão
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Close();
            }
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.dataGridView1.DataSource = null;
            this.dataGridView1.Rows.Clear();
            string[] line;
            string[] filePaths = null;
            try
            {
                dataGridView1.Rows.Clear();
                dataGridView1.Refresh();
                line = StroopProgram.readDataFile(path + "/" + comboBox1.SelectedItem.ToString() + ".txt");
                if (line.Count() > 0)
                {
                    for (int i = 0; i < line.Count(); i++)
                    {
                        string[] cellArray = line[i].Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                        if (cellArray.Length == dataGridView1.Columns.Count)
                        {
                            dataGridView1.Rows.Add(cellArray);
                            for (int j = 0; j < cellArray.Length; j++)
                            {
                                if (Regex.IsMatch(cellArray[j], hexPattern))
                                {
                                    dataGridView1.Rows[i].Cells[j].Style.BackColor = ColorTranslator.FromHtml(cellArray[j]);
                                }
                            }
                        }
                    }
                }
                if (Directory.Exists(path)) // Preenche dgv com arquivos do tipo .wav no diretório dado que possua o padrao da comboBox
                {
                    if (audioPathDataGridView.RowCount > 0)
                    {
                        audioPathDataGridView.Rows.Clear();
                        audioPathDataGridView.Refresh();
                    }

                    filePaths = Directory.GetFiles(path, "audio_" + comboBox1.SelectedItem.ToString() + "*", SearchOption.AllDirectories);
                    DGVManipulation.ReadStringListIntoDGV(filePaths, audioPathDataGridView);
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
Beispiel #19
0
        private void stroopToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            FormDefine   defineProgram;
            DialogResult result;
            string       editProgramName = "error";

            try
            {
                defineProgram = new FormDefine(LocRM.GetString("editProgram", currentCulture),
                                               StroopProgram.GetProgramsPath(), "prg", "program", false, false);
                result = defineProgram.ShowDialog();
                if (result == DialogResult.OK)
                {
                    editProgramName = defineProgram.ReturnValue;
                    FormPrgConfig configureProgram = new FormPrgConfig(editProgramName);
                    this.Controls.Add(configureProgram);
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
Beispiel #20
0
        private void initializeDefaultPrograms() // inicializa programDefault padrão
        {
            StroopProgram programDefault = new StroopProgram();

            programDefault.ProgramName = LocRM.GetString("default", currentCulture);
            try
            {
                // writing default program and lists on to disk
                programDefault.writeDefaultProgramFile(Global.stroopTestFilesPath + Global.programFolderName + programDefault.ProgramName + ".prg");
                ReactionProgram defaultProgram = new ReactionProgram();
                defaultProgram.writeDefaultProgramFile();
                StrList.writeDefaultWordsList(Global.testFilesPath + Global.listFolderName);
                StrList.writeDefaultColorsList(Global.testFilesPath + Global.listFolderName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Close();
            }
        }
        private void addToDestinationList_Click(object sender, EventArgs e)
        {
            // if there is any selected row in origin file, transfer it to import list
            if (originDataGridView.SelectedRows.Count > 0)
            {
                string selectedRowType = originDataGridView.SelectedRows[0].Cells[1].Value.ToString();
                string selectedRowName = originDataGridView.SelectedRows[0].Cells[0].Value.ToString();
                int    i     = originDataGridView.SelectedRows[0].Index;
                int    index = importDataGridView.Rows.Add();
                importDataGridView.Rows[index].Cells[0].Value             = (originDataGridView.SelectedRows[0].Cells[0].Value.ToString());
                importDataGridView.Rows[index].Cells[1].Value             = (originDataGridView.SelectedRows[0].Cells[1].Value.ToString());
                importDataGridView.Rows[index].Cells[2].Value             = (originDataGridView.SelectedRows[0].Cells[2].Value.ToString());
                importDataGridView.Rows[index].DefaultCellStyle.BackColor = originDataGridView.Rows[i].DefaultCellStyle.BackColor;

                originDataGridView.Rows.Remove(originDataGridView.SelectedRows[0]);

                if (selectedRowType == LocRM.GetString("stroopTest", currentCulture))
                {
                    StroopProgram newProgram = new StroopProgram();
                    newProgram.readProgramFile(importDirectory + "/StroopProgram/" + selectedRowName + ".prg");
                    addLists(newProgram);
                }
                else if (selectedRowType == LocRM.GetString("reactionTest", currentCulture))
                {
                    ReactionProgram newReaction = new ReactionProgram(importDirectory + "/ReactionProgram/" + selectedRowName + ".prg");
                    addLists(newReaction);
                }
                else if (selectedRowType == LocRM.GetString("matchingTest", currentCulture))
                {
                    MatchingProgram newProgram = new MatchingProgram(importDirectory + "/MatchingProgram/" + selectedRowName + ".prg");
                    addLists(newProgram);
                }
                else if (selectedRowType == LocRM.GetString("experiment", currentCulture))
                {
                    addPrograms(selectedRowName);
                }
            }
            else
            {
            }
        }
Beispiel #22
0
 private async Task showInstructions(StroopProgram program, CancellationToken token)
 {
     try
     {
         if (program.InstructionText != null)
         {
             instructionLabel.Enabled = true; instructionLabel.Visible = true;
             for (int i = 0; i < program.InstructionText.Count; i++)
             {
                 instructionLabel.Text = program.InstructionText[i];
                 await Task.Delay(Program.instructionAwaitTime, token);
             }
             instructionLabel.Enabled = false; instructionLabel.Visible = false;
         }
     }
     catch (TaskCanceledException)
     {
         this.DialogResult = DialogResult.OK;
         Close();
     }
 }
Beispiel #23
0
        private void openFilesForEdition()
        {
            try
            {
                FormDefine defineFilePath = new FormDefine("Listas de Audio: ", path, "lst", "_audio", true);
                var        result         = defineFilePath.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string dir = defineFilePath.ReturnValue;
                    audioListNameTextBox.Text = dir.Remove(dir.Length - 6); // removes the _audio identification from file while editing (when its saved it is always added again)

                    string[] filePaths = StroopProgram.readDirListFile(path + "/" + dir + ".lst");
                    DGVManipulation.readStringListIntoDGV(filePaths, audioPathDataGridView);
                    numberFiles.Text = audioPathDataGridView.RowCount.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private async void startExpo() // starts Exposition
        {
            if (currentTest.ProgramInUse.Exists(StroopProgram.GetStroopPath()))
            {
                configWordLabel();
                cts = new CancellationTokenSource();

                await showInstructions(currentTest.ProgramInUse, cts.Token);

                changeBackgroundColor(true); // changes background color, if there is one defined
                configureSubtitle();

                await startTypeExposition();

                finishExposition();
            }
            else
            {
                throw new Exception(LocRM.GetString("file", currentCulture) + currentTest.ProgramInUse.ProgramName + ".prg" +
                                    LocRM.GetString("notFoundIn", currentCulture) + Path.GetDirectoryName(StroopProgram.GetStroopPath() + "/prg/"));
            }
        }
Beispiel #25
0
        private void addToDestinationList_Click(object sender, EventArgs e)
        {
            string selectedRowType = originDataGridView.SelectedRows[0].Cells[1].Value.ToString();
            string selectedRowName = originDataGridView.SelectedRows[0].Cells[0].Value.ToString();
            int    index           = exportDataGridView.Rows.Add();

            exportDataGridView.Rows[index].Cells[0].Value = (originDataGridView.SelectedRows[0].Cells[0].Value.ToString());
            exportDataGridView.Rows[index].Cells[1].Value = (originDataGridView.SelectedRows[0].Cells[1].Value.ToString());
            exportDataGridView.Rows[index].Cells[2].Value = (originDataGridView.SelectedRows[0].Cells[2].Value.ToString());


            originDataGridView.Rows.Remove(originDataGridView.SelectedRows[0]);

            if (selectedRowType == LocRM.GetString("stroopTest", currentCulture))
            {
                StroopProgram newProgram = new StroopProgram();
                newProgram.readProgramFile(selectedRowName);
                addLists(newProgram);
            }
            else if (selectedRowType == LocRM.GetString("reactionTest", currentCulture))
            {
                ReactionProgram newReaction = new ReactionProgram(reactionPath + selectedRowName + ".prg");
                addLists(newReaction);
            }
            else if (selectedRowType == LocRM.GetString("matchingTest", currentCulture))
            {
                MatchingProgram newMatching = new MatchingProgram(selectedRowName);
                addLists(newMatching);
            }
            else if (selectedRowType == LocRM.GetString("experiment", currentCulture))
            {
                addPrograms(selectedRowName);
            }
            else
            {
                /* do nothing*/
            }
        }
Beispiel #26
0
        // beginAudio
        private void startRecordingAudio(StroopProgram program)
        {
            int waveInDevices = WaveIn.DeviceCount;

            if (waveInDevices != 0)
            {
                string now = program.InitialDate.Day + "." + program.InitialDate.Month + "_" + hour + "h" + minutes + "." + seconds;

                waveSource            = new WaveIn();
                waveSource.WaveFormat = new WaveFormat(44100, 1);

                waveSource.DataAvailable    += new EventHandler <WaveInEventArgs>(waveSource_DataAvailable);
                waveSource.RecordingStopped += new EventHandler <StoppedEventArgs>(waveSource_RecordingStopped);

                waveFile = new WaveFileWriter(outputDataPath + "/audio_" + program.UserName + "_" + program.ProgramName + "_" + now + ".wav", waveSource.WaveFormat);

                waveSource.StartRecording();
            }
            else
            {
                MessageBox.Show("Dispositivos para gravação de áudio não foram detectados.\nO áudio não será gravado!");
            }
        } // inicia gravação de áudio
Beispiel #27
0
        // endAudio

        private async Task intervalOrFixPoint(StroopProgram program, CancellationToken token)
        {
            try
            {
                int intervalTime = 400;                                       // minimal rnd interval time
                if (program.IntervalTimeRandom && program.IntervalTime > 400) // if rnd interval active, it will be a value between 400 and the defined interval time
                {
                    Random random = new Random();
                    intervalTime = random.Next(400, program.IntervalTime);
                }
                else
                {
                    intervalTime = program.IntervalTime;
                }

                if (program.FixPoint != "+" && program.FixPoint != "o") // if there is no fixPoint determination, executes normal intervalTime
                {
                    await Task.Delay(intervalTime);
                }
                else // if it uses fixPoint
                {
                    SolidBrush myBrush = new SolidBrush(ColorTranslator.FromHtml(program.FixPointColor));

                    switch (program.FixPoint)
                    {
                    case "+":     // cross fixPoint
                        Graphics formGraphicsCross1 = this.CreateGraphics();
                        Graphics formGraphicsCross2 = this.CreateGraphics();
                        float    xCross1            = ClientSize.Width / 2 - 25;
                        float    yCross1            = ClientSize.Height / 2 - 4;
                        float    xCross2            = ClientSize.Width / 2 - 4;
                        float    yCross2            = ClientSize.Height / 2 - 25;
                        float    widthCross         = 2 * 25;
                        float    heightCross        = 2 * 4;
                        formGraphicsCross1.FillRectangle(myBrush, xCross1, yCross1, widthCross, heightCross);
                        formGraphicsCross2.FillRectangle(myBrush, xCross2, yCross2, heightCross, widthCross);
                        await Task.Delay(intervalTime);

                        formGraphicsCross1.Dispose();
                        formGraphicsCross2.Dispose();
                        break;

                    case "o":     // circle fixPoint
                        Graphics formGraphicsEllipse = this.CreateGraphics();
                        float    xEllipse            = ClientSize.Width / 2 - 25;
                        float    yEllipse            = ClientSize.Height / 2 - 25;
                        float    widthEllipse        = 2 * 25;
                        float    heightEllipse       = 2 * 25;
                        formGraphicsEllipse.FillEllipse(myBrush, xEllipse, yEllipse, widthEllipse, heightEllipse);
                        await Task.Delay(intervalTime);

                        formGraphicsEllipse.Dispose();
                        break;
                    }
                    myBrush.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Close();
            }
        }
Beispiel #28
0
        private async Task startWordExposition(StroopProgram program) // starts colored words exposition - classic Stroop
        {
            cts = new CancellationTokenSource();
            string textCurrent = null, colorCurrent = null, outputFileName = null; string audioDetail = "false";

            string[]      labelText = null, labelColor = null, audioDirs = null, subtitlesArray = null;
            int           textArrayCounter = 0, colorArrayCounter = 0, audioCounter = 0, subtitleCounter = 0;
            List <string> outputContent = new List <string>();

            var interval   = Task.Run(async delegate { await Task.Delay(program.IntervalTime, cts.Token); });
            var exposition = Task.Run(async delegate { await Task.Delay(program.ExpositionTime, cts.Token); });

            try
            {
                outputFileName = outputDataPath + program.UserName + "_" + program.ProgramName + ".txt"; // defines outputFileName
                // reading list files:
                labelText  = StroopProgram.readListFile(path + "/lst/" + program.WordsListFile);         // string array receives wordsList itens from list file
                labelColor = StroopProgram.readListFile(path + "/lst/" + program.ColorsListFile);        // string array receives colorsList itens from list file
                if (program.ExpositionRandom)                                                            // if the presentation is random, shuffles arrays
                {
                    labelText  = shuffleArray(labelText, program.NumExpositions, 1);
                    labelColor = shuffleArray(labelColor, program.NumExpositions, 5);
                }
                if (program.AudioListFile != "false") // if there is an audioFile to be played, string array receives audioList itens from list file
                {
                    audioDirs = StroopProgram.readDirListFile(path + "/lst/" + program.AudioListFile);
                    if (program.ExpositionRandom)
                    {
                        audioDirs = shuffleArray(audioDirs, program.NumExpositions, 6);
                    }                            // if the presentation is random, shuffles array
                }
                foreach (string c in labelColor) // tests if colors list contains only hexadecimal color codes
                {
                    if (!Regex.IsMatch(c, "^#(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$"))
                    {
                        throw new Exception("A lista de cores '" + program.ColorsListFile + "' contém valores inválidos!\n" + c + " por exemplo não é um valor válido. A lista de cores deve conter apenas valores hexadecimais (ex: #000000)");
                    }
                }
                // presenting test instructions:
                await showInstructions(program, cts.Token);

                string printCount = "";

                while (true)
                {
                    textArrayCounter  = 0;                             // counters to zero
                    colorArrayCounter = 0;
                    elapsedTime       = 0;                             // elapsed time to zero
                    changeBackgroundColor(program, true);              // changes background color, if there is one defined
                    await Task.Delay(program.IntervalTime, cts.Token); // first interval before exposition begins

                    if (program.AudioCapture && program.ExpositionType != "txtaud")
                    {
                        startRecordingAudio(program);
                    }                                                                                                 // starts audio recording
                    // exposition loop:
                    for (int counter = 1; counter <= program.NumExpositions; counter++)
                    {
                        if (counter < 10)// contador p/ arquivo de audio
                        {
                            printCount = "0" + counter.ToString();
                        }
                        else
                        {
                            printCount = counter.ToString();
                        }

                        subtitleLabel.Visible = false;
                        wordLabel.Visible     = false;
                        await intervalOrFixPoint(program, cts.Token);

                        textCurrent  = labelText[textArrayCounter];
                        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);
                        wordLabel.Left      = (this.ClientSize.Width - wordLabel.Width) / 2; // centraliza label da palavra
                        wordLabel.Top       = (this.ClientSize.Height - wordLabel.Height) / 2;

                        if (program.AudioListFile.ToLower() != "false" && program.ExpositionType == "txtaud") // reproduz audio
                        {
                            if (audioCounter == audioDirs.Length)
                            {
                                audioCounter = 0;
                            }
                            audioDetail          = audioDirs[audioCounter];
                            Player.SoundLocation = audioDetail;
                            audioCounter++;
                            Player.Play();
                        }

                        elapsedTime = elapsedTime + (DateTime.Now.Second * 1000) + DateTime.Now.Millisecond; // grava tempo decorrido
                        SendKeys.SendWait("s");
                        wordLabel.Visible = true;

                        if (program.SubtitleShow)
                        {
                            if (program.SubtitleColor.ToLower() != "false")
                            {
                                subtitleLabel.ForeColor = ColorTranslator.FromHtml(program.SubtitleColor);
                            }
                            else
                            {
                                subtitleLabel.ForeColor = Color.Black;
                            }
                            subtitleLabel.Text = subtitlesArray[subtitleCounter];
                            defineSubPosition(program.SubtitlePlace);
                            subtitleLabel.Visible = true;
                            if (subtitleCounter == (subtitlesArray.Count() - 1))
                            {
                                subtitleCounter = 0;
                            }
                            else
                            {
                                subtitleCounter++;
                            }
                        }

                        StroopProgram.writeLineOutput(program, textCurrent, colorCurrent, counter, outputContent, elapsedTime, program.ExpositionType, audioDetail, hour, minutes, seconds);

                        await Task.Delay(program.ExpositionTime, cts.Token);
                    }

                    wordLabel.Visible = false;
                    await Task.Delay(program.IntervalTime, cts.Token);

                    // beginAudio
                    if (program.AudioCapture && program.ExpositionType != "txtaud")
                    {
                        stopRecordingAudio();
                    }                                      // para gravação áudio
                    // endAudio
                    changeBackgroundColor(program, false); // retorna à cor de fundo padrão

                    break;

                    /*
                     * DialogResult dialogResult = MessageBox.Show("Deseja repetir o teste?", "", MessageBoxButtons.YesNo); // pergunta se deseja repetir o programa
                     * if (dialogResult == DialogResult.Yes) { MessageBox.Show("O teste será repetido!"); } // se deseja repetir o programa mantém o laço while
                     * if (dialogResult == DialogResult.No) { break; } // se não deseja repetir quebra o laço
                     */
                }
                StroopProgram.writeOutputFile(outputFileName, string.Join("\n", outputContent.ToArray()));
                Close(); // finaliza exposição após execução
            }
            catch (TaskCanceledException)
            {
                StroopProgram.writeOutputFile(outputFileName, string.Join("\n", outputContent.ToArray()));
                if (program.AudioCapture)
                {
                    stopRecordingAudio();
                }
                throw new Exception("A Exposição '" + program.ProgramName + "' foi cancelada!");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            cts = null;
        }
Beispiel #29
0
        private void editProgram()
        {
            try
            {
                StroopProgram program = new StroopProgram(editPrgName);

                prgNameTextBox.Text       = program.ProgramName;
                numExpo.Value             = program.NumExpositions;
                expoTime.Value            = program.ExpositionTime;
                rndExpoCheck.Checked      = program.ExpositionRandom;
                intervalTime.Value        = program.IntervalTime;
                rndIntervalCheck.Checked  = program.IntervalTimeRandom;
                audioCaptureCheck.Checked = program.AudioCapture;
                wordSizeNumeric.Value     = Convert.ToInt32(program.FontWordLabel);
                expandImgCheck.Checked    = program.ExpandImage;
                subsRndCheckBox.Checked   = program.RndSubtitlePlace;

                if (program.getWordListFile() != null)
                {
                    openWordListButton.Enabled = true;
                    openWordListButton.Text    = program.getWordListFile().ListName;
                }
                else
                {
                    openWordListButton.Enabled = false;
                }

                if (program.getColorListFile() != null)
                {
                    openColorListButton.Enabled = true;
                    openColorListButton.Text    = program.getColorListFile().ListName;
                }
                else
                {
                    openColorListButton.Enabled = false;
                }

                if (program.getImageListFile() != null)
                {
                    openImgListButton.Enabled = true;
                    openImgListButton.Text    = program.getImageListFile().ListName;
                }
                else
                {
                    openImgListButton.Enabled = false;
                }

                if (program.getAudioListFile() != null)
                {
                    openAudioListButton.Enabled = true;
                    openAudioListButton.Text    = program.getAudioListFile().ListName;
                }
                else
                {
                    openAudioListButton.Enabled = false;
                }

                if (program.BackgroundColor.ToLower() == "false")
                {
                    bgColorPanel.BackColor = Color.White;
                    bgColorButton.Text     = "escolher";
                }
                else
                {
                    if ((Validations.isHexPattern(program.BackgroundColor)))
                    {
                        bgColorButton.Text     = program.BackgroundColor;
                        bgColorPanel.BackColor = ColorTranslator.FromHtml(program.BackgroundColor);
                    }
                }

                if (program.FixPointColor.ToLower() == "false")
                {
                    fixPointColorPanel.BackColor = ColorTranslator.FromHtml("#D01C1F");
                    fixPointColorButton.Text     = "#D01C1F";
                }
                else
                {
                    if ((Validations.isHexPattern(program.FixPointColor)))
                    {
                        fixPointColorButton.Text     = program.FixPointColor;
                        fixPointColorPanel.BackColor = ColorTranslator.FromHtml(program.FixPointColor);
                    }
                    else
                    {
                        throw new Exception(LocRM.GetString("colorMatch", currentCulture));
                    }
                }


                delayTime.Value = program.DelayTime;

                switch (program.RotateImage)
                {
                case 45:
                    rotateImgComboBox.SelectedIndex = 1;
                    break;

                case 90:
                    rotateImgComboBox.SelectedIndex = 2;
                    break;

                case 135:
                    rotateImgComboBox.SelectedIndex = 3;
                    break;

                case 180:
                    rotateImgComboBox.SelectedIndex = 4;
                    break;

                case 225:
                    rotateImgComboBox.SelectedIndex = 5;
                    break;

                case 270:
                    rotateImgComboBox.SelectedIndex = 6;
                    break;

                case 315:
                    rotateImgComboBox.SelectedIndex = 7;
                    break;

                default:
                    rotateImgComboBox.SelectedIndex = 0;
                    break;
                }

                if (program.FixPoint == "+")
                {
                    fixPointCross.Checked  = true;
                    fixPointCircle.Checked = false;
                }
                else
                {
                    if (program.FixPoint == "o")
                    {
                        fixPointCross.Checked  = false;
                        fixPointCircle.Checked = true;
                    }
                    else
                    {
                        fixPointCross.Checked  = false;
                        fixPointCircle.Checked = false;
                    }
                }
                chooseFixPointType();

                // reads instructions if there are any to instruction box text
                if (program.InstructionText != null)
                {
                    instructionsBox.ForeColor = Color.Black;
                    instructionsBox.Text      = program.InstructionText[0];
                    for (int i = 1; i < program.InstructionText.Count; i++)
                    {
                        instructionsBox.AppendText(Environment.NewLine + program.InstructionText[i]);
                    }
                }
                else
                {
                    instructionsBox.Text = instructionBoxText;
                }

                switch (program.ExpositionType)
                {
                case "txt":
                    chooseExpoType.SelectedIndex = 0;
                    openWordListButton.Enabled   = true;
                    openColorListButton.Enabled  = true;
                    openImgListButton.Enabled    = false;
                    openAudioListButton.Enabled  = false;
                    break;

                case "img":
                    chooseExpoType.SelectedIndex = 1;
                    openWordListButton.Enabled   = false;
                    openColorListButton.Enabled  = false;
                    openImgListButton.Enabled    = true;
                    openAudioListButton.Enabled  = false;
                    break;

                case "imgtxt":
                    chooseExpoType.SelectedIndex = 2;
                    openWordListButton.Enabled   = true;
                    openColorListButton.Enabled  = false;
                    openImgListButton.Enabled    = true;
                    openAudioListButton.Enabled  = false;
                    break;

                case "txtaud":
                    chooseExpoType.SelectedIndex = 3;
                    openWordListButton.Enabled   = true;
                    openColorListButton.Enabled  = true;
                    openImgListButton.Enabled    = false;
                    openAudioListButton.Enabled  = true;
                    break;

                case "imgaud":
                    chooseExpoType.SelectedIndex = 4;
                    openWordListButton.Enabled   = false;
                    openColorListButton.Enabled  = false;
                    openImgListButton.Enabled    = true;
                    openAudioListButton.Enabled  = true;
                    break;
                }

                if (program.SubtitleShow)
                {
                    activateSubsCheck.Checked = true;
                    enableSubsItens(true);
                    selectSubDirectionNumber(program.SubtitlePlace);

                    if (program.SubtitlesListFile.ToLower() != "false")
                    {
                        openSubsListButton.Text = program.SubtitlesListFile;
                    }
                    else
                    {
                        openSubsListButton.Text = LocRM.GetString("choose", currentCulture);
                    }

                    if (Validations.isHexPattern(program.SubtitleColor))
                    {
                        subColorButton.Text     = program.SubtitleColor;
                        subColorPanel.BackColor = ColorTranslator.FromHtml(program.SubtitleColor);
                    }
                    else
                    {
                        subColorButton.Text     = LocRM.GetString("choose", currentCulture);
                        subColorPanel.BackColor = Color.White;
                    }
                }
                else
                {
                    activateSubsCheck.Checked = false;
                    enableSubsItens(false);
                }

                wordColorButton.Text     = program.WordColor;
                wordColorPanel.BackColor = ColorTranslator.FromHtml(program.WordColor);
            }
            catch (FileNotFoundException e)
            {
                MessageBox.Show(LocRM.GetString("cantEdìtProgramMissingFiles", currentCulture) + e.Message);
                return;
            }
        }
Beispiel #30
0
        private async Task startImageExposition(StroopProgram program) // inicia exposição de imagem
        {
            cts = new CancellationTokenSource();
            int j, k;
            int arrayCounter = 0;

            string[] labelText       = null, imageDirs = null, audioDirs = null, subtitlesArray = null;
            string   outputFileName  = "";
            string   actualImagePath = "";
            string   audioDetail     = "false";

            try
            {
                BackColor           = Color.White;
                wordLabel.ForeColor = Color.Red;

                outputFileName = outputDataPath + program.UserName + "_" + program.ProgramName + ".txt";

                if (program.ExpandImage)
                {
                    imgPictureBox.Dock = DockStyle.Fill;
                }
                else
                {
                    imgPictureBox.Dock = DockStyle.None;
                }

                imageDirs = StroopProgram.readDirListFile(path + "/lst/" + program.ImagesListFile); // auxiliar recebe o vetor original
                if (program.ExpositionRandom)                                                       // se exposição aleatória, randomiza itens de acordo com o numero de estimulos
                {
                    imageDirs = shuffleArray(imageDirs, program.NumExpositions, 3);
                }

                if (program.SubtitleShow)
                {
                    subtitlesArray = StroopProgram.readListFile(path + "/lst/" + program.SubtitlesListFile);
                    if (program.SubtitleColor.ToLower() != "false")
                    {
                        subtitleLabel.ForeColor = ColorTranslator.FromHtml(program.SubtitleColor);
                    }
                    else
                    {
                        subtitleLabel.ForeColor = Color.Black;
                    }
                    subtitleLabel.Enabled = true;
                    subtitleLabel.Left    = (this.ClientSize.Width - subtitleLabel.Width) / 2; // centraliza label da palavra
                    subtitleLabel.Top     = (imgPictureBox.Bottom + 50);
                }


                if (program.AudioListFile != "false")
                {
                    audioDirs = StroopProgram.readDirListFile(path + "/lst/" + program.AudioListFile);
                    if (program.ExpositionRandom)
                    {
                        audioDirs = shuffleArray(audioDirs, program.NumExpositions, 6);
                    }
                }
                if (program.WordsListFile.ToLower() != "false")
                {
                    labelText = StroopProgram.readListFile(path + "/lst/" + program.WordsListFile);
                }

                await showInstructions(program, cts.Token); // Apresenta instruções se houver

                outputContent = new List <string>();

                while (true)
                {
                    changeBackgroundColor(program, true); // muda cor de fundo se houver parametro
                    imgPictureBox.BackColor = BackColor;

                    elapsedTime  = 0; // zera tempo em milissegundos decorrido
                    j            = 0; k = 0;
                    arrayCounter = 0;
                    var audioCounter = 0;

                    await Task.Delay(program.IntervalTime, cts.Token);

                    string printCount = "";
                    // beginAudio
                    if (program.AudioCapture)
                    {
                        startRecordingAudio(program);
                    }                                                           // inicia gravação áudio
                    // endAudio

                    if (program.ExpositionType == "imgtxt")
                    {
                        for (int counter = 0; counter < program.NumExpositions; counter++) // AQUI ver estimulo -> palavra ou imagem como um só e ter intervalo separado
                        {
                            if (counter < 10)                                              // contador p/ arquivo de audio
                            {
                                printCount = "0" + counter.ToString();
                            }
                            else
                            {
                                printCount = counter.ToString();
                            }


                            imgPictureBox.Visible = false; wordLabel.Visible = false;
                            if (program.SubtitleShow)
                            {
                                subtitleLabel.Visible = false;
                            }
                            await intervalOrFixPoint(program, cts.Token);

                            if (arrayCounter == imageDirs.Count())
                            {
                                arrayCounter = 0;
                            }
                            if (program.RotateImage != 0)
                            {
                                imgPictureBox.Image = RotateImage(imageDirs[arrayCounter], program.RotateImage);
                            }
                            else
                            {
                                imgPictureBox.Image = Image.FromFile(imageDirs[arrayCounter]);
                            }

                            elapsedTime = elapsedTime + (DateTime.Now.Second * 1000) + DateTime.Now.Millisecond; // grava tempo decorrido
                            SendKeys.SendWait("s");
                            imgPictureBox.Visible = true;
                            wordLabel.Visible     = false;
                            actualImagePath       = Path.GetFileName(imageDirs[arrayCounter].ToString());
                            arrayCounter++;

                            if (program.SubtitleShow)
                            {
                                if (program.SubtitleColor.ToLower() != "false")
                                {
                                    subtitleLabel.ForeColor = ColorTranslator.FromHtml(program.SubtitleColor);
                                }
                                else
                                {
                                    subtitleLabel.ForeColor = Color.Black;
                                }
                                subtitleLabel.Text = subtitlesArray[k];
                                defineSubPosition(program.SubtitlePlace);
                                subtitleLabel.Visible = true;
                                if (k == (subtitlesArray.Count() - 1))
                                {
                                    k = 0;
                                }
                                else
                                {
                                    k++;
                                }
                            }

                            StroopProgram.writeLineOutput(program, actualImagePath, "false", counter + 1, outputContent, elapsedTime, "img", audioDetail, hour, minutes, seconds);

                            await Task.Delay(program.ExpositionTime, cts.Token);

                            imgPictureBox.Visible = false;
                            wordLabel.Visible     = false;

                            await Task.Delay(program.DelayTime, cts.Token);

                            if (program.WordsListFile.ToLower() != "false") // se tiver palavras intercala elas com a imagem
                            {
                                if (j == labelText.Count() - 1)
                                {
                                    j = 0;
                                }
                                wordLabel.Text = labelText[j];

                                wordLabel.Left = (this.ClientSize.Width - wordLabel.Width) / 2;
                                wordLabel.Top  = (this.ClientSize.Height - wordLabel.Height) / 2;

                                elapsedTime = elapsedTime + (DateTime.Now.Second * 1000) + DateTime.Now.Millisecond; // grava tempo decorrido
                                SendKeys.SendWait("s");
                                imgPictureBox.Visible = false;
                                wordLabel.ForeColor   = ColorTranslator.FromHtml(program.WordColor);
                                wordLabel.Visible     = true;
                                actualImagePath       = wordLabel.Text;
                                j++;

                                StroopProgram.writeLineOutput(program, actualImagePath, "false", counter + 1, outputContent, elapsedTime, "txt", audioDetail, hour, minutes, seconds);

                                await Task.Delay(program.ExpositionTime, cts.Token);
                            }

                            await Task.Delay(program.IntervalTime, cts.Token);
                        }
                    }
                    else
                    {
                        for (int counter = 0; counter < program.NumExpositions; counter++) // AQUI ver estinulo -> palavra ou imagem como um só e ter intervalo separado
                        {
                            imgPictureBox.Visible = false; wordLabel.Visible = false;
                            if (program.SubtitleShow)
                            {
                                subtitleLabel.Visible = false;
                            }
                            await intervalOrFixPoint(program, cts.Token);


                            if (arrayCounter == imageDirs.Count())
                            {
                                arrayCounter = 0;
                            }
                            if (program.RotateImage != 0)
                            {
                                imgPictureBox.Image = RotateImage(imageDirs[arrayCounter], program.RotateImage);
                            }
                            else
                            {
                                imgPictureBox.Image = Image.FromFile(imageDirs[arrayCounter]);
                            }

                            if (program.AudioListFile.ToLower() != "false" && program.ExpositionType == "imgaud")
                            {
                                if (audioCounter == audioDirs.Length)
                                {
                                    audioCounter = 0;
                                }
                                audioDetail          = audioDirs[audioCounter];
                                Player.SoundLocation = audioDetail;
                                audioCounter++;
                                Player.Play();
                            }

                            elapsedTime = elapsedTime + (DateTime.Now.Second * 1000) + DateTime.Now.Millisecond; // grava tempo decorrido
                            SendKeys.SendWait("s");

                            imgPictureBox.Visible = true;

                            if (program.SubtitleShow)
                            {
                                if (program.SubtitleColor.ToLower() != "false")
                                {
                                    subtitleLabel.ForeColor = ColorTranslator.FromHtml(program.SubtitleColor);
                                }
                                else
                                {
                                    subtitleLabel.ForeColor = Color.Black;
                                }
                                subtitleLabel.Text = subtitlesArray[k];
                                defineSubPosition(program.SubtitlePlace);
                                subtitleLabel.Visible = true;
                                if (k == (subtitlesArray.Count() - 1))
                                {
                                    k = 0;
                                }
                                else
                                {
                                    k++;
                                }
                            }

                            StroopProgram.writeLineOutput(program, Path.GetFileName(imageDirs[arrayCounter].ToString()), "false", counter + 1, outputContent, elapsedTime, program.ExpositionType, Path.GetFileNameWithoutExtension(audioDetail), hour, minutes, seconds);

                            arrayCounter++;
                            await Task.Delay(program.ExpositionTime, cts.Token);
                        }
                    }

                    imgPictureBox.Visible = false; wordLabel.Visible = false;
                    if (program.SubtitleShow)
                    {
                        subtitleLabel.Visible = false;
                    }

                    await Task.Delay(program.IntervalTime, cts.Token);

                    // beginAudio
                    if (program.AudioCapture)
                    {
                        stopRecordingAudio();
                    }                                      // para gravação áudio
                    // endAudio
                    changeBackgroundColor(program, false); // retorna à cor de fundo padrão

                    break;

                    /*
                     * DialogResult dialogResult = MessageBox.Show("Deseja repetir o teste?", "", MessageBoxButtons.YesNo); // pergunta se deseja repetir o programa
                     *
                     * if (dialogResult == DialogResult.Yes) { MessageBox.Show("O teste será repetido!"); } // se deseja repetir o programa mantém o laço while
                     * if (dialogResult == DialogResult.No) { break; } // se não deseja repetir quebra o laço
                     */
                }
                imgPictureBox.Dock  = DockStyle.None;
                wordLabel.Font      = new Font(wordLabel.Font.FontFamily, 160);
                wordLabel.ForeColor = Color.Black;
                StroopProgram.writeOutputFile(outputFileName, string.Join("\n", outputContent.ToArray()));
                Close();
            }
            catch (TaskCanceledException)
            {
                StroopProgram.writeOutputFile(outputFileName, string.Join("\n", outputContent.ToArray()));
                if (program.AudioCapture)
                {
                    stopRecordingAudio();
                }
                throw new Exception("A Exposição '" + program.ProgramName + "' foi cancelada!");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            cts = null;
        }