Exemple #1
0
        // Called by a timer on UI (primary) thread every so often to see if the test completed
        private void CheckForDone()
        {
            try
            {
                FrameworkDispatcher.Update();
            }
            catch
            {
            }

            if (true == pTest.GetTestDoneFlag())
            {
                // stop the timer from calling here now
                gameTimer.Stop();
            }

            if (true == pTest.GetTestDoneFlag())
            {
                // Change UI to show test is finished
                startButton.IsEnabled = true;
                startButton.UpdateLayout();
                thisMainWindow.UpdateLayout();
            }
            return;
        }
Exemple #2
0
 // Called by a timer every so often to see if the test completed
 public bool CheckForDone()
 {
     if (true == pTest.GetTestDoneFlag())
     {
         //thisMainWindow.buttonRunTest.Name = "Run Test";
         thisMainWindow.buttonRunTest.Visible = true;
         //thisMainWindow.ShowAll();
         return(false);              // false return will stop the timer calling here
     }
     return(true);
 }
Exemple #3
0
        // Called by a timer on a thread (NOT from the UI primary thread) every so often to see if the test completed
        private void CheckForDone(object sender, ElapsedEventArgs e)
        {
            if (true == pTest.GetTestDoneFlag())
            {
                // stop the timer from calling here now
                isDoneTimer.Enabled = false;

                // Because this is NOT the UI thread, dispatch to a helper with access to UI controls/windows
                // Place delegate on the Dispatcher of the UI primary thread without waiting.
                thisMainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                      new TimerDoneDelegate(testCompleted));
            }
            return;
        }
Exemple #4
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
        }