Example #1
0
        /// <summary>
        /// The enumerator implementation
        /// </summary>
        public override IEnumerator <View> GetEnumerator()
        {
            IViewResult result;
            Random      numgen = new Random();
            int         a, b;
            RandomizedQueue <string> pres     = new RandomizedQueue <string>();
            RandomizedQueue <string> usedPres = new RandomizedQueue <string>();

            pres.AddRange(presentation);
            using (var logWriter = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "krmon_log_" + settings.SubjectName + "_" + DateTime.Now.ToString("MM dd yyyy H mm ss") + ".txt")))
                using (var anslog = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "krmon_anslog_" + settings.SubjectName + "_" + DateTime.Now.ToString("MM dd yyyy H mm ss") + ".txt")))
                    using (var dataWriter = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "krmon_data_" + settings.SubjectName + "_" + DateTime.Now.ToString("MM dd yyyy H mm ss") + ".csv")))
                    {
                        //Alternating Study and Test Phases
                        for (int i = 0; i < settings.NumRounds; i++)
                        {
                            yield return(new ChoiceView(new string[]
                            {
                                "Start Study Phase"
                            }, out result)
                            {
                                Text = "Click When Ready"
                            });

                            while (pres.Count > 0)
                            {
                                var stimulus = pres.RemoveRandom();
                                yield return(new TextView(stimulus, this.settings.PresentationTime, GUIUtils.Constants.DISPLAY_FONT_LARGE));

                                yield return(new RestView(this.settings.RestTime));

                                usedPres.Add(stimulus);
                            }
                            pres.AddRange(usedPres);
                            usedPres.Clear();

                            a = numgen.Next(4, 13);
                            b = numgen.Next(4, 13);

                            yield return(new VocabView(string.Format("{0} x {1} = {2}", a, b, a * b), "Verify", settings.DisplayTime, settings.DelayTime, true, anslog, out result));

                            yield return(new ChoiceView(new string[]
                            {
                                "Start Test Phase"
                            }, out result)
                            {
                                Text = "Click When Ready"
                            });

                            var connected = true; // assume it's connected
                            using (var invoker = new SingleThreadedInvoker())
                                using (var connectionListener = new EEGDataListener(invoker, s => connected = true, null, s => connected = false))
                                {
                                    // listen for a broken connection
                                    this.dataSource.AddListener(connectionListener);
                                    foreach (var view in this.GetViews(invoker, anslog, logWriter, dataWriter, i, pres))
                                    {
                                        if (connected)
                                        {
                                            yield return(view);
                                        }
                                        else
                                        {
                                            GUIUtils.Alert("Lost connection to headset!");
                                            break;
                                        }
                                    }

                                    this.dataSource.RemoveListener(connectionListener);
                                }
                        }
                    }
        }