/// <summary>
        /// Default Constructor
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            const string gesturesPath = @"..\..\..\Gestures\";
            m_pGestureRecognizer = new Gesture.GestureRecognizer(gesturesPath);
            m_pAudioRecognizer = new AudioRecognizer();

            m_pAudioRecognizer.AudioConfidenceThreshold = 0.8f;

            // Initialize the CityLocations class by calling a method on it
            CityLocations.GetCityLocation("test");

            // Events
            m_pAudioRecognizer.StatusChanged    += OnAudioRecognizerStatusChanged;
            m_pGestureRecognizer.StatusChanged  += OnGestureRecognizerStatusChanged;
            m_pAudioRecognizer.Synced           += OnAudioRecognizerSynced;
            m_pGestureRecognizer.Synced         += OnGestureRecognizerSynced;
            m_pAudioRecognizer.Unsynced         += OnAudioRecognizerUnsynced;
            m_pGestureRecognizer.Unsynced       += OnGestureRecognizerUnsynced;

            // Gesture Callbacks
            string[] mappedGestureNames = new[]
                {
                    "Zoom In",
                    "Zoom Out",
                    "Swipe Left",
                    "Swipe Right",
                    "Swipe Up",
                    "Swipe Down"
                };
            m_pGestureRecognizer.Subscribe(mappedGestureNames[0], GestureZoomInCallback);
            m_pGestureRecognizer.Subscribe(mappedGestureNames[1], GestureZoomOutCallback);
            m_pGestureRecognizer.Subscribe(mappedGestureNames[2], GestureSwipeLeftCallback);
            m_pGestureRecognizer.Subscribe(mappedGestureNames[3], GestureSwipeRightCallback);
            m_pGestureRecognizer.Subscribe(mappedGestureNames[4], GestureSwipeUpCallback);
            m_pGestureRecognizer.Subscribe(mappedGestureNames[5], GestureSwipeDownCallback);

            // Add unmapped gestures so that they will be recognized
            foreach (IavaGesture gesture in GestureFolderReader.Read(gesturesPath))
            {
                if (!Equals("Sync", gesture.Name) && !mappedGestureNames.Contains<string>(gesture.Name))
                {
                    m_pGestureRecognizer.Subscribe(gesture.Name, GestureUnmappedCallback);
                }
            }

            // Audio Callbacks
            m_pAudioRecognizer.Subscribe("Zoom In", ZoomInCallback);
            m_pAudioRecognizer.Subscribe("Zoom Out", ZoomOutCallback);
            m_pAudioRecognizer.Subscribe("Move North", MoveNorthCallback);
            m_pAudioRecognizer.Subscribe("Move South", MoveSouthCallback);
            m_pAudioRecognizer.Subscribe("Move East", MoveEastCallback);
            m_pAudioRecognizer.Subscribe("Move West", MoveWestCallback);
            m_pAudioRecognizer.Subscribe("Exit Application", BlowUp);
            m_pAudioRecognizer.Subscribe("Locate *", LocateCityCallback);
            m_pAudioRecognizer.Subscribe("Get Recognizer Statuses", GetRecognizerStatusesCallback);

            IavaCamera.ImageFrameReady += OnCameraImageFrameReady;
            IavaCamera.SkeletonFrameReady += OnCameraSkeletonFrameReady;

            m_pAudioSyncTimer = new System.Timers.Timer(1000);
            m_pAudioSyncTimer.Elapsed += OnAudioSyncTimerElapsed;

            m_pGestureSyncTimer = new System.Timers.Timer(1000);
            m_pGestureSyncTimer.Elapsed += OnGestureSyncTimerElapsed;

            m_pConsoleTxtBox = new TextBoxStreamWriter(this.txtConsole);
            Console.SetOut(m_pConsoleTxtBox);

            // UI theme stuff...
            lblAudioStatus.Background = lblGestureStatus.Background = unsyncedBrush;
            lblAudioSyncTime.Background = lblGestureSyncTime.Background = backgroundBrush;
            lblAudioTTL.Background = lblGestureTTL.Background = backgroundBrush;
        }
 /// <summary>
 /// Raises when the load button is clicked.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnLoadGesturesClick(object sender, RoutedEventArgs e)
 {
     using (System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog()) {
         if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
             m_pGestureRecognizer = new GestureRecognizer(dialog.SelectedPath);
             m_pGestures = new ObservableCollection<IavaGesture>(GestureFolderReader.Read(dialog.SelectedPath));
             foreach (IavaGesture g in m_pGestures) {
                 m_pGestureRecognizer.Subscribe(g.Name, OnGestureDetected);
             }
             this.lstGestures.ItemsSource = m_pGestures;
             btnStartTest.IsEnabled = true;
         }
     }
 }
        public void GestureRecognizerConstructorTest()
        {
            // Supply an empty file filepath
            try {
                GestureRecognizer recognizer = new GestureRecognizer(string.Empty);
            }

            catch (Exception ex) {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
            }

            // Pass in a null file filepath
            try {
                GestureRecognizer recognizer = new GestureRecognizer(null);
            }

            catch (Exception ex) {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
            }

            // Pass in a file filepath that does not exist
            try {
                GestureRecognizer recognizer = new GestureRecognizer(@"C:\Does\not\exist\");
            }

            catch (Exception ex) {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
            }

            // Pass in an existing filepath
            try {
                GestureRecognizer recognizer = new GestureRecognizer(_directoryPath);
            }
            catch (Exception ex) {
                Assert.Fail(ex.Message);
            }

            try {
                GestureRecognizer_Accessor recognizer = new GestureRecognizer_Accessor(_directoryPath);

                // Make sure GestureCallbacks exist
                Assert.IsNotNull(recognizer.GestureCallbacks);

                // Make sure the GestureCallbacks is a dictionary
                Assert.IsInstanceOfType(recognizer.GestureCallbacks, typeof(Dictionary<string, GestureCallback>));

                // Hold our accessor callbacks (in this case empty)
                Dictionary<string, GestureCallback> expectedCallbacks = new Dictionary<string, GestureCallback>();

                // Make sure we have the same number of callbacks as we are expecting
                Assert.AreEqual(recognizer.GestureCallbacks.Count, expectedCallbacks.Count);

                // Make sure SupportedGestures exist
                Assert.IsNotNull(recognizer.SupportedGestures);

                // Make sure the SupportedGestures is a list
                Assert.IsInstanceOfType(recognizer.SupportedGestures, typeof(List<IavaGesture>));

                // Hold our accessor gestures (in this case empty)
                List<string> expectedGestures = new List<string>();

                // Make sure we have the same number of gestures as we are expecting
                Assert.AreEqual(recognizer.SupportedGestures.Count, expectedGestures.Count);
            }
            catch (Exception ex) {
                Assert.Fail(ex.Message);
            }
        }
        public void OnGestureRecognizedTest()
        {
            try {
                GestureRecognizer recognizer = new GestureRecognizer(_directoryPath);

                bool syncEventFired = false;
                bool waveCallbackInvoked = false;
                bool shakeCallbackInvoked = false;

                // Set the Sync Gesture
                PrivateObject privateObject = new PrivateObject(recognizer);
                privateObject.SetProperty("SyncGesture", new IavaGesture("Sync", new List<IavaSnapshot>()));

                // Register for some Gestures
                recognizer.Synced += (parm1, param2) => { syncEventFired = true; };
                recognizer.Subscribe("Wave", (eventArgs) => { waveCallbackInvoked = true; });
                recognizer.Subscribe("Shake", (eventArgs) => { shakeCallbackInvoked = true; });
                recognizer.Start();

                try {
                    // Recognize the Wave gesture
                    privateObject.Invoke("OnGestureRecognized", null, new GestureEventArgs("Wave"));
                    Thread.Sleep(50);

                    // Make sure the Wave callback fired
                    Assert.IsTrue(waveCallbackInvoked);

                }
                catch (Exception ex) {
                    Assert.Fail(ex.Message);
                }

                try {
                    // Recognize the Shake gesture
                    privateObject.Invoke("OnGestureRecognized", null, new GestureEventArgs("Shake"));
                    Thread.Sleep(50);

                    // Make sure the Shake callback fired
                    Assert.IsTrue(shakeCallbackInvoked);

                }
                catch (Exception ex) {
                    Assert.Fail(ex.Message);
                }

                try {
                    // Recognize the Sync gesture
                    privateObject.Invoke("OnGestureRecognized", null, new GestureEventArgs("Sync"));
                    Thread.Sleep(50);

                    // Make sure the Sync event fired,
                    Assert.IsTrue(syncEventFired);

                }
                catch (Exception ex) {
                    Assert.Fail(ex.Message);
                }

                try {
                    // Reset the Sync, Wave, and Shake callbacks
                    syncEventFired = false;
                    waveCallbackInvoked = false;
                    shakeCallbackInvoked = false;

                    // Recognize the Wave gesture again
                    privateObject.Invoke("OnGestureRecognized", null, new GestureEventArgs("Wave"));
                    Thread.Sleep(50);

                    // Make sure the Wave callback fired
                    Assert.IsTrue(waveCallbackInvoked);

                    // Recognize the Shake gesture again
                    privateObject.Invoke("OnGestureRecognized", null, new GestureEventArgs("Shake"));
                    Thread.Sleep(50);

                    // Make sure the Shake callback fired
                    Assert.IsTrue(shakeCallbackInvoked);
                }
                catch (Exception ex) {
                    Assert.Fail(ex.Message);
                }

                recognizer.Stop();
            }
            catch (Exception ex) {
                Assert.Fail(ex.Message);
            }
        }
        public void GestureSyncUnsyncTest()
        {
            try {
                GestureRecognizer recognizer = new GestureRecognizer(_directoryPath);

                bool syncEventFired = false;
                bool unsyncEventFired = false;

                // Register for the Synced and Unsynced events
                recognizer.Synced += (param1, param2) => syncEventFired = true;
                recognizer.Unsynced += (param1, param2) => unsyncEventFired = true;

                recognizer.Start();

                // Set the Sync Timeout to 5 seconds
                recognizer.SyncTimeoutValue = 5000;

                // Set the Sync Gesture
                PrivateObject privateObject = new PrivateObject(recognizer);
                privateObject.SetProperty("SyncGesture", new IavaGesture("Sync", new List<IavaSnapshot>()));

                // Recognize the 'Sync' Gesture
                privateObject.Invoke("OnGestureRecognized", null, new GestureEventArgs("Sync"));
                Thread.Sleep(50);

                // Make sure the Sync Event fired
                Assert.IsTrue(syncEventFired);

                // Make sure the Unsync Event did not fire
                Assert.IsFalse(unsyncEventFired);

                // Reset the sync event
                syncEventFired = false;

                // Wait for the timeout to occur
                Thread.Sleep(recognizer.SyncTimeoutValue);

                // Make sure the Unsync Event fired
                Assert.IsTrue(unsyncEventFired);

                // Make sure the Sync Event did not fire
                Assert.IsFalse(syncEventFired);

                recognizer.Stop();
            }
            catch (Exception ex) {
                Assert.Fail(ex.Message);
            }
        }
        public void GestureStopTest()
        {
            try {
                GestureRecognizer recognizer = new GestureRecognizer(_directoryPath);

                // Make sure the Recognizer isn't showing a faulty status
                Assert.AreEqual(RecognizerStatus.NotReady, recognizer.Status);

                bool eventFired = false;

                // Register for the Recognizer Stopped Event
                recognizer.Stopped += (param1, param2) => eventFired = true;

                try {
                    // Start the Recognizer
                    recognizer.Start();
                    Thread.Sleep(50);

                    // Make sure we're showing the correct status
                    Assert.AreEqual(RecognizerStatus.Running, recognizer.Status);

                    // Stop the Recognizer
                    recognizer.Stop();
                    Thread.Sleep(50);

                    // Make sure we're showing the correct status
                    Assert.AreEqual(RecognizerStatus.Ready, recognizer.Status);

                    // Make sure the Recognizer Stopped Event was fired
                    Assert.IsTrue(eventFired);
                }
                catch (Exception ex) {
                    Assert.Fail(ex.Message);
                }
            }
            catch (Exception ex) {
                Assert.Fail(ex.Message);
            }
        }