Exemple #1
0
        private void startButton_Click(object sender, RoutedEventArgs e)
        {
            startButton.Name = "Test Running...";
            Thread.Sleep(10);


            // startButton.Visibility = System.Windows.Visibility.Collapsed;  // was .Hidden; for Win PC
            startButton.IsEnabled = false;

            // These are fixed for now
            // TODO  add way to change test parameters
            //
            pTest.SetNumTests(PasatTest.MIN_NUM_PRACTICE_TESTS);

            pTest.SetDelayBetweenPairs(PasatTest.MIN_DELAY_BETWEEN_PAIRS);

            // set the test Form
            pTest.SetFormAFlag(true);

            pTest.SetPracticeTestFlag(true);

            pThread.PASATTestThreadInit(pTest);

            pTest.SetTestDoneFlag(false);

            // Create Timer to simulate the XNA game loop (SoundEffect class is from the XNA Framework)
            if (null == gameTimer)
            {
                gameTimer = new GameTimer();
                gameTimer.UpdateInterval = TimeSpan.FromMilliseconds(33);

                // Call FrameworkDispatcher.Update to update the XNA Framework internals.
                gameTimer.Update += delegate { try { CheckForDone(); } catch { } };
            }

            // Start the GameTimer running.
            gameTimer.Start();

            // Prime the pump or we'll get an exception.
            FrameworkDispatcher.Update();

            pThread.RunTest();  // run the test

/* KEEP this as comment for now...
 * currently using common approach to create/start a thread: see RunTest
 *
 *          // IF the worker thread is idle start it async, need to call bw.CancelAsync() later to stop test early
 *          if (bw.IsBusy != true)
 *          {
 *              bw.RunWorkerAsync();
 *          }
 */
        }
Exemple #2
0
//
// Background worker thread entry point.  This is NOT the UI (primary) thread context.
//
//#if WINDOWS_PHONE
        //public void bw_DoWork(object sender, DoWorkEventArgs e)
//#endif
        private void prvRunTest()
        {
            int error    = 0;
            int retValue = 0;   // 0 for no errors else error code

            //    BackgroundWorker worker = sender as BackgroundWorker;

            //SpeechSynthesizer s = new SpeechSynthesizer();

            //Random myRandomGenerator = new Random();

            int rate = pTest.GetDelayBetweenPairs();

            int numTests = pTest.GetNumTests();

            int[] dataTable  = null;
            int   testLength = 0;

            dataTable = pTest.GetTestTable(out testLength);

            //Int32 randomInt;
            //Int32[,] memory = new Int32[pTest.numTests, testLength[0] ];
            Int32 digit       = 0;
            Int32 newDigit    = 0;
            Int32 expectedSum = 0;

            for (int i = 0; i < numTests; i++)
            {
                //    if ((true == worker.CancellationPending ))
                //    {
                //        e.Cancel = true;
                //        break;
                //    }

                String speakString = "Starting test number " + i + " at " + rate + " milliseconds in 5 seconds";
                // s.Speak(speakString);
                // MessageBox.Show(speakString);    // uncomment for DEBUG
                // Thread.Sleep(5000);

                for (int j = 0; j < testLength; j++)
                {
                    //randomInt = myRandomGenerator.Next(11);
                    //memory[i, j] = randomInt;

                    // Check if this the digit or the sum from the array
                    if ((j % 2) != 0)
                    {
                        // Odd index means this is the sum
                        expectedSum = dataTable[j];
                        newDigit    = expectedSum - digit;
                        if (newDigit <= 0)  // check for table data error(s)
                        {
                            // s.Speak("Error in built in table data, sum minus previous digit is negative");


                            // Thread.Sleep(3000);
                            speakString = "Error in data, sum of " + expectedSum + " minus the previous digit " + digit + " is negative " + newDigit;
                            // s.Speak(speakString);
#if WIN_PC_PLATFORM || WINDOWS_PHONE
                            MessageBox.Show(speakString);
#endif
                            error = 1;
                            Thread.Sleep(3000);
                            break;
                        }
                        digit = newDigit;
                    }
                    else
                    {
                        digit = dataTable[j];
                    }

                    //        s.Speak(i.ToString());
                    // s.Speak(randomInt.ToString());

                    // s.Speak(digit.ToString());
                    PlayDigitSound(digit);              // about 2 Seconds

                    // Check for user cancelling test
                    if (true == pTest.GetTestDoneFlag())
                    {
                        numTests = 0;                           // don't do any more tests
                        break;
                    }

                    Thread.Sleep(rate);                 // 2 or 3 Seconds

                    // Check for user cancelling test
                    if (true == pTest.GetTestDoneFlag())
                    {
                        numTests = 0;                           // don't do any more tests
                        break;
                    }
                }

                if (error != 0)
                {
                    break;
                }

                // calling code now sets the rate
                // rate += pTest.rateIncrement;

                //      if ((worker.CancellationPending == true))
                //      {
                //          e.Cancel = true;
                //          break;
                //      }
            }

            if (error != 0)
            {
                retValue = error;
            }

            //s.Speak("Hello. My name is John Byrne.  I was born a poor white child.");


            // Print out the answers
            //
            // This was important when using RANDOM numbers but not important when using fixed internal table values
            // because the spreadsheets have the same table values
            //
            // COMMENTED OUT
            //

/*
 *          Console.WriteLine("The answers are: ");
 *          for (int i = 0; i < pTest.numTests; i++)
 *          {
 *              Console.WriteLine("Test number: {0}", i);
 *              StringBuilder testNumbersString = new StringBuilder();
 *              testNumbersString.Append("Test Number: " + i.ToString() + "\n");
 *              for (int j = 0; j < pTest.testLength; j++)
 *              {
 *                  //testNumbersString.Append(memory[i,j].ToString() + " ");
 *                  //System.Console.Write(memory[i, j] + " ");
 *              }
 *              MessageBox.Show(testNumbersString.ToString());
 *              Console.WriteLine();
 *
 *              for (int j = 1; j < pTest.testLength; j++)
 *              {
 *                  //Console.Write((memory[i, j - 1] + memory[i, j]) + " ");
 *              }
 *              Console.WriteLine();
 *              Console.WriteLine();
 *          }
 */
            pTest.SetTestDoneFlag(true);        // done

            backThread = null;                  // release reference to background thread
        }
Exemple #3
0
        // Run Test button
        private void buttonRunTest_Click(object sender, RoutedEventArgs e)
        {
            // Hide the Run Test button
            buttonRunTest.Visibility = System.Windows.Visibility.Hidden;

            // set the test Form
            pTest.SetFormAFlag(true == radioButtonFormA.IsChecked);

            // get values from other controls
            // Delay 3 or 2 Seconds
            int delayBetweenPairs = PasatTest.MIN_DELAY_BETWEEN_PAIRS;

            if (true == radioButton3seconds.IsChecked)
            {
                delayBetweenPairs = PasatTest.MAX_DELAY_BETWEEN_PAIRS;
            }

            pTest.SetDelayBetweenPairs(delayBetweenPairs);

            // If Practice, get number of tests from the Practice textbox
            pTest.SetPracticeTestFlag(true == radioButtonPractice.IsChecked);
            int numTests = 1;

            if (true == radioButtonPractice.IsChecked)
            {
                try
                {
                    //Console.WriteLine("Text in textbox1: " + PASATTestThread.mainWindow.textBox1.Text);
                    numTests = Int32.Parse(textBoxNumOfPracticeTests.Text);
                }
                catch
                {
                    numTests = PasatTest.MIN_NUM_PRACTICE_TESTS;
                }

                // TODO: use a spin control or parsing during user changes in Edit box to have these limits
                if (numTests < PasatTest.MIN_NUM_PRACTICE_TESTS)
                {
                    numTests = PasatTest.MIN_NUM_PRACTICE_TESTS;

                    // Change UI to show number of tests actually used
                    textBoxNumOfPracticeTests.Text = numTests.ToString();
                }

                if (PasatTest.MAX_NUM_PRACTICE_TESTS < numTests)
                {
                    numTests = PasatTest.MAX_NUM_PRACTICE_TESTS;

                    // Change UI to show number of tests actually used
                    textBoxNumOfPracticeTests.Text = numTests.ToString();
                }
            }
            else
            {
                numTests = PasatTest.DEFAULT_NUM_TESTS;
            }
            pTest.SetNumTests(numTests);

            pThread.PASATTestThreadInit(pTest);

            // Show estimated test time needed
            int    minutes, seconds;
            string estTime = pTest.GetTestTimeEstimate(out minutes, out seconds);

            textBlockEstTime.Text = estTime;

            //myMessageBox( "Before running test..." );

            // Set up to check for test completion every 1 Second
            pTest.SetTestDoneFlag(false);
            if (null == isDoneTimer)
            {
                isDoneTimer          = new Timer(1000); // Set up the timer for 1 Second
                isDoneTimer.Elapsed += new ElapsedEventHandler(CheckForDone);
            }
            isDoneTimer.Enabled = true; // Enable the timer

            pThread.RunTest();          // run the test

            //MessageBox.Show("After return from call to RunTest ...");
            //button1.Visibility = Visibility.Visible;
            //button1.UpdateLayout();
            //this.UpdateLayout();
        }
Exemple #4
0
 protected void OnDeleteEvent(object sender, DeleteEventArgs a)
 {
     pTest.SetTestDoneFlag(true);
     Application.Quit();
     a.RetVal = true;
 }
Exemple #5
0
//
// Background worker thread entry point.  This is NOT the UI (primary) thread context.
//
        private void prvRunTest()
        {
            //SpeechSynthesizer s = new SpeechSynthesizer();

            //Random myRandomGenerator = new Random();

            int startingRate = pTest.GetDelayBetweenPairs();
            int rate         = startingRate;

            int[] dataTable  = null;
            int   testLength = 0;

            dataTable = pTest.GetTestTable(out testLength);

            int numTests = pTest.GetNumTests();

            if (null == sound1)
            {
                prvLoadSounds();
            }

            //Int32 randomInt;
            //Int32[,] memory = new Int32[pTest.numTests, testLength[0] ];
            Int32 digit       = 0;
            Int32 newDigit    = 0;
            Int32 expectedSum = 0;

            int error = 0;

            for (int i = 0; i < numTests; i++)
            {
                String speakString = "Starting test number " + i + " at " + rate + " milliseconds in 5 seconds";
                //s.Speak(speakString);
                // MessageBox.Show(speakString);    // uncomment for DEBUG
                //Thread.Sleep(5000);

                for (int j = 0; j < testLength; j++)
                {
                    //randomInt = myRandomGenerator.Next(11);   // NOTE: This would sometimes generate 0 and 10 which are invalid according to PDF
                    //memory[i, j] = randomInt;

                    // Check if this is the digit or the sum from the array
                    if ((j % 2) != 0)
                    {
                        // This is the sum
                        expectedSum = dataTable[j];
                        newDigit    = expectedSum - digit;
                        if (newDigit <= 0)
                        {
                            // s.Speak("Error in built in table data, sum minus previous digit is negative");
                            //Thread.Sleep(3000);
                            speakString = "Error in data, sum of " + expectedSum + " minus the previous digit " + digit + " is negative " + newDigit;
                            //s.Speak(speakString);
                            error = 1;
                            Thread.Sleep(3000);
                            break;
                        }
                        digit = newDigit;
                    }
                    else
                    {
                        digit = dataTable[j];
                    }

                    //        s.Speak(i.ToString());
                    // s.Speak(randomInt.ToString());

                    //s.Speak(digit.ToString());
                    PlayDigitSound(digit);

                    Thread.Sleep(rate);
                }

                if (error != 0)
                {
                    break;
                }

                // rate no longer changes here
                // rate += pTest.rateIncrement;
            }

            //s.Speak("Hello. My name is John Byrne.  I was born a poor white child.");

// Print out the answers
            //
            // This was important when using RANDOM numbers but not important when using fixed internal table values
            // because the spreadsheets have the same table values
            //
            // COMMENTED OUT
            //

/*
 *          Console.WriteLine("The answers are: ");
 *          for (int i = 0; i < pTest.numTests; i++)
 *          {
 *              Console.WriteLine("Test number: {0}", i);
 *              StringBuilder testNumbersString = new StringBuilder();
 *              testNumbersString.Append("Test Number: " + i.ToString() + "\n");
 *              for (int j = 0; j < pTest.testLength; j++)
 *              {
 *                  //testNumbersString.Append(memory[i,j].ToString() + " ");
 *                  //System.Console.Write(memory[i, j] + " ");
 *              }
 *              MessageBox.Show(testNumbersString.ToString());
 *              Console.WriteLine();
 *
 *              for (int j = 1; j < pTest.testLength; j++)
 *              {
 *                  //Console.Write((memory[i, j - 1] + memory[i, j]) + " ");
 *              }
 *              Console.WriteLine();
 *              Console.WriteLine();
 *          }
 *
 *          // call the windowing system to reset the button
 *          // Can't do this because it's a different thread calling us
 *          // completedFunction();
 */


            pTest.SetTestDoneFlag(true);                // done

            backThread = null;                          // release reference to background thread
        }