static public void CreateResponseBox()
        {
            Thread thread = new Thread(() =>
            {
                ResponseBox respBox = new ResponseBox();
                respBox.Loaded     += (sender, e) =>
                {
                    GrammarManipulator.ResponseBoxLoaded();
                };
                respBox.Closed += (sender, e) =>
                {
                    GrammarManipulator.ResponseBoxDeloaded();
                    respBox.Dispatcher.InvokeShutdown();                        //so by closing the window the thread is shutdown as well. otherwise we get ghost thread which doesnt allow th application to exit
                };
                respBox.Show();
                System.Windows.Threading.Dispatcher.Run();                      //for calling the dispatcher of the current window/uielement  needed for running
            });

            thread.SetApartmentState(ApartmentState.STA);                       //STA state in needed by wpf
            thread.Start();                                                     //starts the thread
        }
        public static void CreateResponseBox()
        {
            Thread thread = new Thread(() =>
            {
                ResponseBox respBox = new ResponseBox();
                respBox.Loaded += (sender, e) =>
                {
                    GrammarManipulator.ResponseBoxLoaded();
                };
                respBox.Closed += (sender, e) =>
                {
                    GrammarManipulator.ResponseBoxDeloaded();
                    respBox.Dispatcher.InvokeShutdown();                        //so by closing the window the thread is shutdown as well. otherwise we get ghost thread which doesnt allow th application to exit
                };
                respBox.Show();
                System.Windows.Threading.Dispatcher.Run();                      //for calling the dispatcher of the current window/uielement  needed for running
            });

            thread.SetApartmentState(ApartmentState.STA);                       //STA state in needed by wpf
            thread.Start();                                                     //starts the thread
        }
Esempio n. 3
0
        private static void BasicGrammar_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (e.Result != null & e.Result.Confidence >= 0.85)
            {
                DataStore.AddRecentCommand(e.Result.Text);
                DataStore.AddToMessageDump(e.Result.Text);
                if (e.Result.Text.Contains("Open") | e.Result.Text.Contains("Execute") | e.Result.Text.Contains("Run") | e.Result.Text.Contains("Initialize") | e.Result.Text.Contains("Start"))
                {
                    Task.Run(() =>
                    {
                        writeToTextBox(e.Result.Text);
                    });

                    try
                    {
                        ResponseBox.CreateResponseBox();
                    }

                    catch (Exception ex)
                    {
                        DataStore.AddToErrorLog(string.Format("Main exception {0}\nMain exception stack trace {1}\nInner exception {2}\ninner Exception stack trace {3}", ex.Message, ex.StackTrace, ex.InnerException.Message, ex.InnerException.StackTrace));
                    }

                    try
                    {
                        BasicResponse(new Response(CommandType.Open, DateTime.Now.TimeOfDay.Hours, e.Result.Text));
                    }
                    catch (Exception excep)
                    {
                        DataStore.AddToErrorLog(string.Format("Main exception {0}\nMain exception stack trace {1}\nInner exception {2}\ninner Exception stack trace {3}", excep.Message, excep.StackTrace, excep.InnerException.Message, excep.InnerException.StackTrace));
                    }
                }
                else if (e.Result.Text.Contains("Search the web") | e.Result.Text.Contains("Search the internet"))
                {
                    BasicResponse(new Response(CommandType.Search, DateTime.Now.TimeOfDay.Hours, e.Result.Text));
                    ProgramManager.SendOpenCommand("Google Chrome");
                }
                else
                {
                    try
                    {
                        Task.Run(() =>
                        {
                            writeToTextBox(e.Result.Text);
                        });
                        SystemOptions.OpenSystemCommandsDialog();
                    }
                    catch (Exception ex)
                    {
                        DataStore.AddToErrorLog(string.Format("An exception occured. \nException Message : {0}\n Exception StackTrace : {1}", ex.Message, ex.StackTrace));
                    }
                    try
                    {
                        BasicResponse(new Response(CommandType.Basic, DateTime.Now.TimeOfDay.Hours, e.Result.Text));
                    }
                    catch (Exception excep)
                    {
                        DataStore.AddToErrorLog(string.Format("An exception occured. \nException Message : {0}\n Exception StackTrace : {1}", excep.Message, excep.StackTrace));
                    }
                }
            }
        }