Inheritance: System.Windows.Window
Exemplo n.º 1
0
        public FeedbackCore(bool verboseOutput, ServerCore serverCore, MainWindow thisParent = null)
        {
            isVerbose = verboseOutput;
            server = serverCore;

            if (thisParent != null)
            {
                isGUI = true;
                parent = thisParent;
            }
        }
Exemplo n.º 2
0
        public VoiceRecogCore(ServerCore vrpnServer, bool verboseOutput, MainWindow thisParent = null)
        {
            server = vrpnServer;
            verbose = verboseOutput;
            if (server == null)
            {
                throw new Exception("The VRPN server does not exist!");
            }

            parent = thisParent;
            if (parent != null)
            {
                isGUI = true;
            }
        }
Exemplo n.º 3
0
        internal static void WriteToLog(string text, MainWindow parent = null)
        {
            string stringTemp = "\r\n" + DateTime.Now.ToString() + ": " + text;

            if (parent != null) //GUI mode
            {
                if (parent.Dispatcher.Thread.ManagedThreadId == Thread.CurrentThread.ManagedThreadId)
                {
                    parent.LogTextBox.AppendText(stringTemp);

                    //Autoscroll mechanism
                    if (parent.LogScrollViewer.VerticalOffset >= (((TextBox)parent.LogScrollViewer.Content).ActualHeight - parent.LogScrollViewer.ActualHeight))
                    {
                        parent.LogScrollViewer.ScrollToEnd();
                    }
                }
                else
                {
                    parent.Dispatcher.BeginInvoke((Action)(() =>
                    {
                        parent.LogTextBox.AppendText(stringTemp);

                        //Autoscroll mechanism
                        if (parent.LogScrollViewer.VerticalOffset >= (((TextBox)parent.LogScrollViewer.Content).ActualHeight - parent.LogScrollViewer.ActualHeight))
                        {
                            parent.LogScrollViewer.ScrollToEnd();
                        }
                    }), null
                    );
                }
            }
            else //Console mode
            {
                Console.Write(stringTemp);
            }
        }
Exemplo n.º 4
0
 internal static void ShowErrorMessage(string title, string text, MainWindow parent = null)
 {
     if (parent != null)
     {
         if (parent.Dispatcher.Thread.ManagedThreadId == Thread.CurrentThread.ManagedThreadId)
         {
             MessageBox.Show(parent, text, title, MessageBoxButton.OK, MessageBoxImage.Error);
         }
         else
         {
             parent.Dispatcher.BeginInvoke((Action)(() =>
             {
                 MessageBox.Show(parent, text, title, MessageBoxButton.OK, MessageBoxImage.Error);
             }), null
             );
         }
     }
     else
     {
         WriteToLog(title + ": " + text);
     }
 }
Exemplo n.º 5
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            //Argument booleans
            bool parentCommandLine = false;
            bool newCommandLine = false;
            bool help = false;
            bool connected = false;
            bool verbose = false;
            bool autoStart = false;
            string startupFile = "";

            string[] args = e.Args;

            //Parse command line arguments
            for (int i = 0; i < args.Length; i++)
            {
                if((args[i].ToLower() == "-c" || args[i].ToLower() == "/c") && !newCommandLine)
                {
                    parentCommandLine = true;
                }
                else if (args[i].ToLower() == "-nc" || args[i].ToLower() == "/nc")
                {
                    parentCommandLine = false;
                    newCommandLine = true;
                }
                else if (args[i].ToLower() == "-v" || args[i].ToLower() == "/v")
                {
                    verbose = true;
                }
                else if (args[i].ToLower() == "-s" || args[i].ToLower() == "/s")
                {
                    autoStart = true;
                }
                else if(args[i].ToLower() == "-h" || args[i].ToLower() == "/h" || args[i].ToLower() == "-?" || args[i].ToLower() == "/?")
                {
                    help = true;
                    connected = NativeInterop.AttachConsole(-1);
                    if (connected)
                    {
                        Console.WriteLine();
                        Console.WriteLine();
                        Console.WriteLine("Usage: KinectWithVRServer [filename] [/c] [/nc] [/s] [/v]");
                        Console.WriteLine();
                        Console.WriteLine("Options:");
                        Console.WriteLine("\t/c\tLaunches the program in the pre-existing command line.");
                        Console.WriteLine("\t/nc\tLaunches the program in a new command line window.");
                        Console.WriteLine("\t/?\tShows this help message.");
                        Console.WriteLine("\t/h\tShows this help message.");
                        Console.WriteLine("\t/s\tStarts the server immediately upon program launch.\r\n\t\tThis is implied when launched in console mode.");
                        Console.WriteLine("\t/v\tVerbose output mode.");
                        NativeInterop.FreeConsole();
                    }
                }
                else if (i == 0)
                {
                    startupFile = args[i];
                }
            }

            if (!help)
            {
                //For Testing
                AvaliableDLLs dlls = new AvaliableDLLs();
                dlls.HasKinectV1 = VerifyDLLs.Kinect1Avaliable();
                dlls.HasKinectV2 = VerifyDLLs.Kinect2Avaliable();
                dlls.HasNetworkedKinect = VerifyDLLs.NetworkedKinectAvaliable();

                if (newCommandLine || parentCommandLine)
                {
                    if (newCommandLine)
                    {
                        connected = NativeInterop.AllocConsole();

                    }
                    else if (parentCommandLine)
                    {
                        connected = NativeInterop.AttachConsole(-1);

                        IntPtr consoleHandle = NativeInterop.GetStdHandle(-10);
                        uint consoleMode = 0;
                        NativeInterop.GetConsoleMode(consoleHandle, out consoleMode);
                        NativeInterop.SetConsoleMode(consoleHandle, (uint)(consoleMode & (~0x0002)));
                    }

                    if (connected)
                    {
                        ConsoleUI.RunServerInConsole(verbose, autoStart, startupFile, dlls);
                    }
                }
                else
                {
                    //Note: You can't put the Try/Catch here to handle if there are no Kinects because the GUI will try to launch on a different thread, and thus it can't pass the error down
                    MainWindow gui = new MainWindow(verbose, autoStart, dlls, startupFile);
                    gui.ShowDialog();
                }
            }

            this.Shutdown();
        }