예제 #1
0
        private void executeButton_Click(object sender, EventArgs e)
        {
            if (Global.GlobalFormMain.contentPanel.Controls.Count > 0)
            {
                checkSave();
            }
            if (this.ValidateChildren(ValidationConstraints.Enabled))
            {
                if (executingTypeLabel.Text.Equals(LocRM.GetString("stroopTest", currentCulture)))
                {
                    ExpositionController.BeginStroopTest(executingNameLabel.Text, participantComboBox.Text, markTextBox.Text[0], this);
                }

                else if (executingTypeLabel.Text.Equals(LocRM.GetString("reactionTest", currentCulture)))
                {
                    ExpositionController.BeginReactionTest(executingNameLabel.Text, participantComboBox.Text, markTextBox.Text[0], this);
                }
                else if (executingTypeLabel.Text.Equals(LocRM.GetString("experiment", currentCulture)))
                {
                    ExpositionController.BeginExperimentTest(executingNameLabel.Text, participantComboBox.Text, markTextBox.Text[0], this);
                }
                else if (executingTypeLabel.Text.Equals(LocRM.GetString("matchingTest", currentCulture)))
                {
                    ExpositionController.BeginMatchingTest(executingNameLabel.Text, participantComboBox.Text, markTextBox.Text[0], this);
                }
                else
                {
                    /* do nothing*/
                }
            }
        }
예제 #2
0
        private void executeButton_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren(ValidationConstraints.Enabled))
            {
                if (executingTypeLabel.Text.Equals("StroopTest"))
                {
                    ExpositionController.BeginStroopTest(executingNameLabel.Text, participantTextBox.Text, markTextBox.Text[0], this);
                }

                else if (executingTypeLabel.Text.Equals("ReactionTest"))
                {
                    ExpositionController.BeginReactionTest(executingNameLabel.Text, participantTextBox.Text, markTextBox.Text[0], this);
                }
                else if (executingTypeLabel.Text.Equals("Experimento"))
                {
                    ExpositionController.BeginExperimentTest(executingNameLabel.Text, participantTextBox.Text, markTextBox.Text[0], this);
                }
                else
                {
                    /* do nothing*/
                }
            }
            else
            {
                MessageBox.Show("Algum campo não foi preenchido de forma correta.");
            }
        }
예제 #3
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();
            }
        }
        private async Task startTesting()
        {
            if (executingTest.ProgramInUse.IsOrderRandom && !executingTest.ProgramInUse.TrainingProgram)
            {
                executingTest.ProgramInUse.Shuffle();
            }
            else if (executingTest.ProgramInUse.IsOrderRandom && executingTest.ProgramInUse.TrainingProgram)
            {
                executingTest.ProgramInUse.ShuffleWithTrainingProgram();
            }
            int index = 0;

            foreach (Program program in executingTest.ProgramInUse.ProgramList)
            {
                index++;
                await Task.Delay(executingTest.ProgramInUse.IntervalTime);

                executingTest.ExpositionTime = DateTime.Now;

                if (program.GetType() == typeof(StroopProgram))
                {
                    ExpositionController.BeginStroopTest(program.ProgramName, executingTest.ParticipantName, executingTest.Mark, this);
                }
                else if (program.GetType() == typeof(ReactionProgram))
                {
                    ExpositionController.BeginReactionTest(program.ProgramName, executingTest.ParticipantName, executingTest.Mark, this);
                }
                executingTest.writeLineOutput(index, program);
            }
            Program.writeOutputFile(outputFile, string.Join("\n", executingTest.Output.ToArray()));
            Close();
        }
예제 #5
0
        private int waitIntervalTime(bool isWaitTimeRandom, int waitTime)
        {
            int intervalTimeRandom = 200; // minimal rnd interval time

            intervalCancelled = false;

            // if random interval active, it will be a value between 200 and the defined interval time
            if (isWaitTimeRandom && waitTime > 400)
            {
                Random random = new Random();
                intervalTimeRandom = random.Next(400, waitTime);
            }
            else
            {
                intervalTimeRandom = waitTime;
            }

            Stopwatch intervalStopWatch = new Stopwatch();

            intervalStopWatch.Start();
            long interval = intervalTimeRandom;

            if (Program.hasFixPoint(executingTest.ProgramInUse.FixPoint))
            {
                interval = intervalTimeRandom - fixPointTime;
            }
            while (intervalStopWatch.ElapsedMilliseconds < interval)
            {
                if (expositionBW.CancellationPending)
                {
                    intervalCancelled = true;
                    break;
                }
                /* just wait for interval time to be finished */
            }
            ExpositionController.makingFixPoint(executingTest.ProgramInUse.FixPoint, executingTest.ProgramInUse.FixPointColor,
                                                this);
            if (Program.hasFixPoint(executingTest.ProgramInUse.FixPoint))
            {
                while (intervalStopWatch.ElapsedMilliseconds < intervalTimeRandom)
                {
                    if (expositionBW.CancellationPending)
                    {
                        intervalCancelled = true;
                        break;
                    }
                    /* just wait for interval time to be finished */
                }
            }
            intervalShouldBe = intervalTimeRandom;
            intervalStopWatch.Stop();
            int elapsedTime = (int)intervalStopWatch.ElapsedMilliseconds;

            return(elapsedTime);
        }
예제 #6
0
        private void expositionBW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (!cancelExposition)
            {
                // cleaning screen
                if (ActiveForm != null)
                {
                    this.CreateGraphics().Clear(ActiveForm.BackColor);
                }
                // if expositions type uses any kind of control to show stimulus such as a word label or image picture box
                if (currentControl != null)
                {
                    // if current control is enabled it means that just showed a stimulus
                    if (currentControl.Enabled)
                    {
                        // signaling to interval background worker that exposing must end and control must be removed from screen
                        exposing = false;
                        intervalBW.ReportProgress(50, currentControl);
                    }
                }
                ExpositionController.makingFixPoint(executingTest.ProgramInUse.FixPoint, executingTest.ProgramInUse.FixPointColor, this);
            }
            else
            {
                /*do nothing*/
            }

            if ((e.Cancelled == true) && !intervalCancelled)
            {
                /* user clicked after stimulus is shown*/
                executingTest.writeLineOutput(intervalElapsedTime, intervalShouldBe, hitStopWatch.ElapsedMilliseconds,
                                              currentExposition + 1, expositionAccumulative, currentLists, currentStimuli, currentPositionOutput, currentBeep, currentColor);
            }

            else if ((e.Cancelled == true) && intervalCancelled)
            {
                /* user clicked before stimulus is shown*/
                executingTest.writeLineOutput(intervalElapsedTime, intervalShouldBe, intervalElapsedTime - intervalShouldBe,
                                              currentExposition + 1, expositionAccumulative, currentLists, currentStimuli, currentPositionOutput, currentBeep, currentColor);
            }
            else
            {
                /* user missed stimulus */
                executingTest.CurrentResponse = "NA";
                executingTest.writeLineOutput(intervalElapsedTime, intervalShouldBe, 0, currentExposition + 1, expositionAccumulative, currentLists, currentStimuli,
                                              currentPositionOutput, currentBeep, currentColor);
                hitStopWatch.Stop();
            }
            expositionBW.Dispose();
        }
예제 #7
0
        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();
        }
예제 #8
0
        private void drawStimulu()
        {
            int  count = 0;
            Size size;

            showModel = true;
            stimuluControls.Clear();
            foreach (string element in matchingGroups.ElementAt(groupCounter).getStimulusNames())
            {
                if (stimuluType == 1 || stimuluType == 2)
                {
                    newStimulu           = ExpositionController.InitializeButton(element);
                    newStimulu.Font      = new Font("Arial", this.executingTest.ProgramInUse.StimuluSize, FontStyle.Bold);
                    newStimulu.ForeColor = ColorTranslator.FromHtml(matchingGroups.ElementAt(groupCounter).getColors().ElementAt(count));

                    size = modelControl.PreferredSize;
                }
                else
                {
                    newStimulu     = ExpositionController.InitializeImageBox(executingTest.ProgramInUse.StimuluSize, Image.FromFile(element), false, this);
                    newStimulu.Tag = element;
                    size           = modelControl.Size;
                }

                if (this.executingTest.ProgramInUse.RandomStimulusPosition)
                {
                    newStimulu.Location = stimuluPosition.getRandomPosition(size);
                }
                else
                {
                    newStimulu.Location = stimuluPosition.getPositon(size);
                }
                if (matchingGroups.ElementAt(groupCounter).getModelName().Equals(element))
                {
                    modelAsStimuluControl = newStimulu;
                }
                currentStimulus        = matchingGroups.ElementAt(groupCounter);
                newStimulu.MouseClick += new System.Windows.Forms.MouseEventHandler(this.MatchingExposition_MouseClick);
                stimuluControls.Add(newStimulu);
                count++;
            }
            groupCounter++;
            if (groupCounter > this.executingTest.ProgramInUse.AttemptsNumber)
            {
                groupCounter = 0;
            }
            expositionBW.ReportProgress(currentExposition / (executingTest.ProgramInUse.AttemptsNumber * 2) * 100, stimuluControls);
        }
예제 #9
0
        public FormReactExposition(string prgName, string participantName, char mark)
        {
            this.FormBorderStyle = FormBorderStyle.None;
            this.MaximizeBox     = true;
            this.StartPosition   = FormStartPosition.Manual;
            ExpositionController.formSecondScreen(this);
            InitializeComponent();
            startTime = hour + "_" + minutes + "_" + seconds;
            executingTest.ParticipantName = participantName;
            executingTest.setProgramInUse(path + "/prg/", prgName);
            executingTest.Mark = mark;

            outputFile = outputDataPath + executingTest.ParticipantName + "_" + executingTest.ProgramInUse.ProgramName + ".txt";
            startExposition();
            this.ShowDialog();
        }
예제 #10
0
        private Point[] createTrianglePoints()
        {
            int[] clientMiddle   = { (ClientSize.Width / 2), (ClientSize.Height / 2) };
            int   size           = ExpositionController.CentimeterToPixel(executingTest.ProgramInUse.StimuluSize, this);
            int   heightTriangle = size;
            Point screenPosition = this.ScreenPosition(new Size(heightTriangle, heightTriangle));

            screenPosition.X -= heightTriangle / 3;
            screenPosition.Y += heightTriangle / 2;

            Point point1 = new Point(screenPosition.X + (heightTriangle / 3), (heightTriangle / 2) + screenPosition.Y);
            Point point2 = new Point((8 * heightTriangle / 6) + screenPosition.X, (heightTriangle / 2) + screenPosition.Y);
            Point point3 = new Point(((heightTriangle / 2)) + screenPosition.X + (heightTriangle / 3), ((heightTriangle / 2)) + screenPosition.Y - heightTriangle);

            Point[] trianglePoints = { point1, point2, point3 };
            return(trianglePoints);
        }
        public MatchingExposition(string prgName, string participantName, char mark)
        {
            this.FormBorderStyle = FormBorderStyle.None;
            this.MaximizeBox     = true;
            this.StartPosition   = FormStartPosition.Manual;
            ExpositionController.formSecondScreen(this);

            InitializeComponent();
            startTime = hour + "_" + minutes + "_" + seconds;
            executingTest.ParticipantName = participantName;
            executingTest.setProgramInUse(prgName);
            executingTest.Mark = mark;

            stimuluControls = new List <Control>();
            outputFile      = MatchingProgram.GetResultsPath() + executingTest.ParticipantName + "_" + executingTest.ProgramInUse.ProgramName + ".txt";
            startExposition();
            this.ShowDialog();
        }
예제 #12
0
        private void drawImage()
        {
            imgPictureBox = ExpositionController.InitializeImageBox(executingTest.ProgramInUse.StimuluSize, Image.FromFile(imagesList[imageCounter]),
                                                                    executingTest.ProgramInUse.ExpandImage, this);
            Point screenPosition = ScreenPosition(imgPictureBox.Size);

            imgPictureBox.Location = screenPosition;

            currentStimuli[0] = StrList.outPutItemName(imagesList[imageCounter]);
            currentLists[0]   = executingTest.ProgramInUse.getImageListFile().ListName;

            imageCounter++;
            if (imageCounter == imagesList.Length)
            {
                imageCounter = 0;
            }
            expositionBW.ReportProgress(currentExposition / executingTest.ProgramInUse.NumExpositions * 100, imgPictureBox);
        }
예제 #13
0
        private void drawModel()
        {
            Size           size;
            List <Control> controls = new List <Control>();

            showModel = false;
            if (stimuluType == 1 || stimuluType == 2)
            {
                modelControl           = ExpositionController.InitializeButton(matchingGroups.ElementAt(groupCounter).getModelName());
                modelControl.Font      = new Font("Arial", this.executingTest.ProgramInUse.StimuluSize, FontStyle.Bold);
                modelControl.ForeColor = ColorTranslator.FromHtml(matchingGroups.ElementAt(groupCounter).getModelColor());

                size = modelControl.PreferredSize;
            }
            else
            {
                modelControl = ExpositionController.InitializeImageBox(executingTest.ProgramInUse.StimuluSize,
                                                                       Image.FromFile(matchingGroups.ElementAt(groupCounter).getModelName()), false, this);
                size = modelControl.Size;
            }

            if (this.executingTest.ProgramInUse.RandomModelPosition)
            {
                modelControl.Location = stimuluPosition.getRandomPosition(size);
            }
            else
            {
                Point position = stimuluPosition.getPositon(size);
                modelControl.Location = position;
            }
            currentStimulus = matchingGroups.ElementAt(groupCounter);

            if (executingTest.ProgramInUse.EndExpositionWithClick)
            {
                modelControl.MouseClick += new System.Windows.Forms.MouseEventHandler(this.MatchingExposition_MouseClick);
            }
            else
            {
                modelControl.MouseClick += new System.Windows.Forms.MouseEventHandler(this.wrongClick_mouseClick);
            }
            controls.Add(modelControl);
            expositionBW.ReportProgress(currentExposition / (executingTest.ProgramInUse.AttemptsNumber * 2) * 100, controls);
        }
예제 #14
0
        private void intervalBW_DoWork(object sender, DoWorkEventArgs e)
        {
            executingTest.InitialDate = DateTime.Now;
            accumulativeStopWatch.Start();

            for (int counter = 0; counter < executingTest.ProgramInUse.NumExpositions && !cancelExposition; counter++)
            {
                ExpositionController.makingFixPoint(executingTest.ProgramInUse.FixPoint, executingTest.ProgramInUse.FixPointColor,
                                                    this);
                currentExposition = counter;
                //preparing execution
                expositionBackground();
                while (expositionBW.IsBusy)
                {
                    /* wait for exposition to be finished */
                }
                Thread.Sleep(1);
            }
        }
예제 #15
0
 private void FormMain_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Control && e.KeyCode == Keys.R) // Ctrl+R - roda teste
     {
         ExpositionController.BeginStroopTest(executingNameLabel.Text, participantComboBox.Text, markTextBox.Text[0], this);
     }
     if (e.Control && e.KeyCode == Keys.D) // Ctrl+D - define programa
     {
         defineTest();
     }
     if (e.Control && e.KeyCode == Keys.N) // Ctrl+N - novo programa
     {
         newProgram();
     }
     if (e.Control && e.KeyCode == Keys.H) // Ctrl+H - intruções / ajuda
     {
         HelpPagesController.showInstructions();
     }
 }
예제 #16
0
        /// <summary>
        /// This is the constructor method for stroop test exposition form.</summary>
        /// <param name="prgName"> Program name is the name of the current StroopProgram that wil be executed.</param>
        /// <param name="mark"> Mark is the char that will be send as signal to the program running background, normally neuronspectrum</param>
        /// <param name="usrName"> Username is the test participant name</param>
        public FormExposition(string prgName, string usrName, char mark)
        {
            this.FormBorderStyle = FormBorderStyle.None;
            this.MaximizeBox     = true;
            this.StartPosition   = FormStartPosition.Manual;
            InitializeComponent();

            // use parameters to create basic information of current program being used
            currentTest = new StroopTest(prgName);
            currentTest.ParticipantName = usrName;
            currentTest.Mark            = mark;
            currentTest.InitialDate     = DateTime.Now;


            ExpositionController.formSecondScreen(this);

            configureCurrentTest();
            startExpo();
            this.ShowDialog();
        }
예제 #17
0
        private void drawCircleShape()
        {
            int   size          = ExpositionController.CentimeterToPixel(executingTest.ProgramInUse.StimuluSize, this);
            float widthEllipse  = size;
            float heightEllipse = size;

            Pen      myPen = new Pen(ColorTranslator.FromHtml(colorsList[colorCounter]));
            Graphics formGraphicsEllipse = CreateGraphics();

            Point screenPosition = this.ScreenPosition(new Size((int)widthEllipse, (int)heightEllipse));
            float xEllipse       = screenPosition.X;
            float yEllipse       = screenPosition.Y;

            formGraphicsEllipse.DrawEllipse(myPen, xEllipse, yEllipse, widthEllipse, heightEllipse);
            formGraphicsEllipse.Dispose();
            colorCounter++;
            if (colorCounter == colorsList.Length)
            {
                colorCounter = 0;
            }
        }
예제 #18
0
        // draw on screen filled square stimulus
        private void drawFullSquareShape()
        {
            int   size         = ExpositionController.CentimeterToPixel(executingTest.ProgramInUse.StimuluSize, this);
            float widthSquare  = size;
            float heightSquare = size;

            SolidBrush myBrush            = new SolidBrush(ColorTranslator.FromHtml(colorsList[colorCounter]));
            Graphics   formGraphicsSquare = CreateGraphics();

            Point screenPosition = this.ScreenPosition(new Size((int)widthSquare, (int)heightSquare));
            float xSquare        = screenPosition.X;
            float ySquare        = screenPosition.Y;

            formGraphicsSquare.FillRectangle(myBrush, xSquare, ySquare, widthSquare, heightSquare);
            formGraphicsSquare.Dispose();
            colorCounter++;
            if (colorCounter == colorsList.Length)
            {
                colorCounter = 0;
            }
        }
예제 #19
0
        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();
        }
예제 #20
0
        private void drawWord()
        {
            Point screenPosition = ScreenPosition(wordLabel.PreferredSize);

            // configuring label that have word stimulus dimensions, color and position
            wordLabel = ExpositionController.InitializeWordLabel(executingTest.ProgramInUse.FontSize, wordsList[wordCounter], colorsList[colorCounter], screenPosition);

            currentStimuli[0] = wordsList[wordCounter];
            currentLists[0]   = executingTest.ProgramInUse.getWordListFile().ListName;

            currentColor = colorsList[colorCounter];
            wordCounter++;

            if (wordCounter == wordsList.Length)
            {
                wordCounter = 0;
            }
            colorCounter++;
            if (colorCounter == colorsList.Length)
            {
                colorCounter = 0;
            }
            expositionBW.ReportProgress(currentExposition / executingTest.ProgramInUse.NumExpositions * 100, wordLabel);
        }
예제 #21
0
        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;
        }
예제 #22
0
        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;
        }
예제 #23
0
        // 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));
            }
        }
예제 #24
0
 private void startTestToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ExpositionController.BeginStroopTest(executingNameLabel.Text, participantComboBox.Text, markTextBox.Text[0], this);
 }
예제 #25
0
        private async Task startWordExposition() // starts colored words exposition - classic Stroop
        {
            cts = new CancellationTokenSource();
            string textCurrent = null, colorCurrent = null, 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(programInUse.IntervalTime, cts.Token); });
            var exposition = Task.Run(async delegate { await Task.Delay(programInUse.ExpositionTime, cts.Token); });

            try
            {
                // reading list files:
                labelText      = StrList.readListFile(path + "/lst/" + programInUse.WordsListFile);  // string array receives wordsList itens from list file
                labelColor     = StrList.readListFile(path + "/lst/" + programInUse.ColorsListFile); // string array receives colorsList itens from list file
                subtitlesArray = configureSubtitle();
                if (programInUse.ExpositionRandom)                                                   // if the presentation is random, shuffles arrays
                {
                    labelText  = ExpositionController.shuffleArray(labelText, programInUse.NumExpositions, 1);
                    labelColor = ExpositionController.shuffleArray(labelColor, programInUse.NumExpositions, 5);
                }
                if (programInUse.AudioListFile != "false") // if there is an audioFile to be played, string array receives audioList itens from list file
                {
                    audioDirs = StroopProgram.readDirListFile(path + "/lst/" + programInUse.AudioListFile);
                    if (programInUse.ExpositionRandom)
                    {
                        audioDirs = ExpositionController.shuffleArray(audioDirs, programInUse.NumExpositions, 6);
                    }                                                                                                                                // if the presentation is random, shuffles array
                }
                if (!Validations.allHexPattern(labelColor))
                {
                    throw new Exception("A lista de cores '" + programInUse.ColorsListFile + "' contém valores inválidos!\n A lista de" +
                                        "cores deve conter apenas valores hexadecimais (ex: #000000)");
                }

                // presenting test instructions:
                await showInstructions(programInUse, cts.Token);

                string printCount = "";
                while (true)
                {
                    textArrayCounter  = 0;                     // counters to zero
                    colorArrayCounter = 0;
                    elapsedTime       = 0;                     // elapsed time to zero
                    subtitleCounter   = 0;
                    changeBackgroundColor(programInUse, true); // changes background color, if there is one defined
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    await Task.Delay(programInUse.IntervalTime, cts.Token); // first interval before exposition begins

                    if (programInUse.AudioCapture && programInUse.ExpositionType != "txtaud")
                    {
                        startRecordingAudio();
                    }

                    // exposition loop:
                    for (int counter = 1; counter <= programInUse.NumExpositions; counter++)
                    {
                        subtitleLabel.Visible = false;
                        wordLabel.Visible     = false;
                        await intervalOrFixPoint(programInUse, cts.Token);

                        if (counter < 10)// contador p/ arquivo de audio
                        {
                            printCount = "0" + counter.ToString();
                        }
                        else
                        {
                            printCount = counter.ToString();
                        }

                        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);

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

                        elapsedTime = stopwatch.ElapsedMilliseconds; // grava tempo decorrido
                        SendKeys.SendWait("=");
                        if (programInUse.SubtitleShow)
                        {
                            subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray);
                        }
                        wordLabel.Visible = true;



                        StroopProgram.writeLineOutput(programInUse, textCurrent, colorCurrent, counter, outputContent, elapsedTime, programInUse.ExpositionType, audioDetail);

                        await Task.Delay(programInUse.ExpositionTime, cts.Token);
                    }
                    wordLabel.Visible     = false;
                    subtitleLabel.Visible = false;
                    await Task.Delay(programInUse.IntervalTime, cts.Token);

                    // beginAudio
                    if (programInUse.AudioCapture && programInUse.ExpositionType != "txtaud")
                    {
                        stopRecordingAudio();
                    }                                           // para gravação áudio
                    // endAudio
                    changeBackgroundColor(programInUse, 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(outputFile, string.Join("\n", outputContent.ToArray()));
                Close(); // finaliza exposição após execução
            }
            catch (TaskCanceledException)
            {
                StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray()));
                if (programInUse.AudioCapture)
                {
                    stopRecordingAudio();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            cts = null;
        }
예제 #26
0
        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;
            }
        }
예제 #27
0
        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 (programInUse.ExpandImage)
                {
                    imgPictureBox.Dock = DockStyle.Fill;
                }
                else
                {
                    imgPictureBox.Dock = DockStyle.None;
                }

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

                subtitlesArray = configureSubtitle();


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

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

                outputContent = new List <string>();

                while (true)
                {
                    changeBackgroundColor(programInUse, 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(programInUse.IntervalTime, cts.Token);

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

                    if (programInUse.ExpositionType == "imgtxt")
                    {
                        for (int counter = 0; counter < programInUse.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;
                            subtitleLabel.Visible = false;
                            await intervalOrFixPoint(programInUse, cts.Token);

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

                            elapsedTime = stopwatch.ElapsedMilliseconds; // grava tempo decorrido
                            SendKeys.SendWait("=");
                            imgPictureBox.Visible = true;
                            if (programInUse.SubtitleShow)
                            {
                                subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray);
                            }
                            wordLabel.Visible = false;
                            actualImagePath   = Path.GetFileName(imageDirs[arrayCounter].ToString());
                            arrayCounter++;


                            StroopProgram.writeLineOutput(programInUse, actualImagePath, "false", counter + 1, outputContent, elapsedTime, "img", audioDetail);

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

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

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

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


                                elapsedTime = stopwatch.ElapsedMilliseconds; // grava tempo decorrido
                                SendKeys.SendWait("=");
                                imgPictureBox.Visible = false;
                                subtitleLabel.Visible = false;
                                wordLabel.ForeColor   = ColorTranslator.FromHtml(programInUse.WordColor);
                                wordLabel.Visible     = true;
                                if (programInUse.SubtitleShow)
                                {
                                    subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray);
                                }
                                actualImagePath = wordLabel.Text;
                                j++;

                                StroopProgram.writeLineOutput(programInUse, actualImagePath, "false", counter + 1, outputContent, elapsedTime, "txt", audioDetail);

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

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


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

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

                            elapsedTime = stopwatch.ElapsedMilliseconds; // grava tempo decorrido
                            SendKeys.SendWait("=");

                            imgPictureBox.Visible = true;

                            if (programInUse.SubtitleShow)
                            {
                                subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray);
                            }

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

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

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


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

                    // beginAudio
                    if (programInUse.AudioCapture)
                    {
                        stopRecordingAudio();
                    }                                           // para gravação áudio
                    // endAudio
                    changeBackgroundColor(programInUse, 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(outputFile, string.Join("\n", outputContent.ToArray()));
                Close();
            }
            catch (TaskCanceledException)
            {
                StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray()));
                if (programInUse.AudioCapture)
                {
                    stopRecordingAudio();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            cts = null;
        }