Exemple #1
0
        private async void buttonEmpezar_Click(object sender, EventArgs e)
        {
            string testName = textBoxName.Text;

            if (testName == "")
            {
                MessageBox.Show("Inserte un nombre antes de empezar la prueba");
            }
            else
            {
                SessionDao sessionDao = new SessionDao();
                currentSession = new Session(testName);

                try
                {
                    sessionDao.SaveSession(currentSession);
                }
                catch (SqlException ex)
                {
                    if (ex.ErrorCode == 2146232060 || ex.ErrorCode == -2146232060)
                    {
                        MessageBox.Show("Ya existe una prueba con ese nombre. Por favor elija otro");
                        return;
                    }
                    throw ex;
                }

                SessionEventDao sessionEventDao = new SessionEventDao();

                SessionEvent sessionStart = new SessionEvent(currentSession.Id, currentSession.TestName, EventTypes.SESSION_START, DateTime.Now);
                sessionEventDao.SaveSessionEvent(sessionStart);

                requestSAM();

                SessionEvent initialSAM = new SessionEvent(currentSession.Id, currentSession.TestName, EventTypes.INITIAL_SAM, DateTime.Now);
                sessionEventDao.SaveSessionEvent(initialSAM);

                timerLapso.Interval       = 1000;
                buttonTerminar.Enabled    = true;
                comboBoxPantallas.Enabled = false;
                comboBoxWebCam.Enabled    = false;
                buttonEmpezar.Enabled     = false;
                timerLapso.Start();

                TestSet testSet = TestSetDao.GetTestSet(defaultTestSet);

                foreach (PhaseBase phase in testSet.Phases)
                {
                    sessionEventDao.SaveSessionEvent(new SessionEvent(currentSession.Id, currentSession.TestName, string.Concat("INIT_", phase.ValenceArrousalQuadrant, "_", phase.Id.ToString()), DateTime.Now));

                    if (phase.StimuliType == ImagePhase.IAP_TYPE)
                    {
                        var imagePhase = (ImagePhase)phase;
                        imagePlayer             = new ImageDisplay(ConfigurationManager.AppSettings["iaps-path"]);
                        imagePlayer.WindowState = FormWindowState.Maximized;
                        imagePlayer.Show();

                        await Task.Run(async() =>
                        {
                            foreach (IAP image in imagePhase.Iaps)
                            {
                                imagePlayer.ChangeImage(string.Concat(image.IdIaps, ".jpg"));
                                await Task.Delay(2000);
                            }
                        });

                        imagePlayer.Close();
                    }

                    if (phase.StimuliType == VideoPhase.DEVO_TYPE)
                    {
                        var videoPhase = (VideoPhase)phase;

                        foreach (DEVO video in videoPhase.Videos)
                        {
                            videoPlayer             = new VideoDisplay(ConfigurationManager.AppSettings["devo-path"]);
                            videoPlayer.WindowState = FormWindowState.Maximized;
                            videoPlayer.play(string.Concat(video.Id, ".mp4"));
                            videoPlayer.ShowDialog();
                        }
                    }

                    sessionEventDao.SaveSessionEvent(new SessionEvent(currentSession.Id, currentSession.TestName, string.Concat("END_", phase.ValenceArrousalQuadrant, "_", phase.Id.ToString()), DateTime.Now));

                    requestSAM();
                    sessionEventDao.SaveSessionEvent(new SessionEvent(currentSession.Id, currentSession.TestName, string.Concat("SAM_", phase.ValenceArrousalQuadrant), DateTime.Now));
                }
            }
        }