/// <summary>
 /// Show console
 /// </summary>
 public void ShowServerConsole()
 {
     m_console.Show();
 }
示例#2
0
        /// <summary>
        /// Start OSVR server
        /// </summary>
        public void StartServer(bool restart = false)
        {
            string configArgs = string.Empty;

            // is the "Use Custom Config" option checked
            if (m_contextMenu.CustomServerConfigChecked)
            {
                string targetCustomConfig = Properties.Settings.Default.targetCustomConfig;
                // has the user specified a custom config?
                if (!string.IsNullOrEmpty(targetCustomConfig) && File.Exists(targetCustomConfig))
                {
                    configArgs = targetCustomConfig;
                }
                else
                {
                    Common.ShowMessageBox(Common.MSG_MISSING_CUSTOM_CONFIG, MessageBoxButtons.OK, MessageBoxIcon.Error, true);
                    return;
                }
            }
            else
            {
                switch (m_contextMenu.DetectHDKType())
                {
                case ContextMenuWYSIWYG.HDKType.HDK1:
                    if (NativeHelpers.IsExtendedModeEnabled())
                    {
                        if (m_contextMenu.UseIRCameraChecked)
                        {
                            configArgs = Common.CFG_1X_EM_CAM;
                        }
                        else
                        {
                            configArgs = Common.CFG_1X_EM_NOCAM;
                        }
                    }
                    else
                    {
                        if (m_contextMenu.UseIRCameraChecked)
                        {
                            configArgs = Common.CFG_1X_DM_CAM;
                        }
                        else
                        {
                            configArgs = Common.CFG_1X_DM_NOCAM;
                        }
                    }
                    break;

                case ContextMenuWYSIWYG.HDKType.HDK2:
                    if (NativeHelpers.IsExtendedModeEnabled())
                    {
                        if (m_contextMenu.UseIRCameraChecked)
                        {
                            configArgs = Common.CFG_2_EM_CAM;
                        }
                        else
                        {
                            configArgs = Common.CFG_2_EM_NOCAM;
                        }
                    }
                    else
                    {
                        if (m_contextMenu.UseIRCameraChecked)
                        {
                            configArgs = Common.CFG_2_DM_CAM;
                        }
                        else
                        {
                            configArgs = Common.CFG_2_DM_NOCAM;
                        }
                    }
                    break;

                case ContextMenuWYSIWYG.HDKType.UNKNOWN:
                    Common.ShowMessageBox(Common.MSG_UNABLE_TO_DETECT_HDK_TYPE, MessageBoxButtons.OK, MessageBoxIcon.Error, true);
                    return;

                default:
                    // error case already shows error message
                    return;
                }
            }

            string  osvrPath         = OSVRRegistry.GetInstallDirectoryFromRegistry();
            string  completeFilePath = osvrPath + Common.SERVICE_PATH + Common.SERVICE_NAME;
            string  workingDirectory = osvrPath + Common.SERVICE_PATH;
            Process server           = OSVRProcessManager.LaunchExecutable(completeFilePath,
                                                                           workingDirectory,
                                                                           ProcessWindowStyle.Minimized, // Note: this is ignored
                                                                           configArgs,
                                                                           false);

            if (server == null)
            {
                Common.ShowMessageBox(Common.MSG_UNABLE_TO_START_SERVER, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!m_console.Visible)
            {
                m_console.Show();
            }

            m_console.ServerStateChanged(restart ? ServerConsole.ServerStateChange.Restart : ServerConsole.ServerStateChange.Start);

            server.EnableRaisingEvents = true;
            server.OutputDataReceived += Server_OutputDataReceived;
            server.ErrorDataReceived  += Server_ErrorDataReceived;
            server.BeginOutputReadLine();
            server.BeginErrorReadLine();
        }