Exemple #1
0
        /// <summary>
        ///     Default constructor.
        /// </summary>
        /// <param name="adapterProcess">
        ///     The emulicious process adapter.
        /// </param>
        /// <param name="processId">
        ///     The emulicious process id.
        /// </param>
        /// <param name="stopProcess">
        ///     The flag to stop the process on exit.
        /// </param>
        public EmuliciousTargetHostProcessWrapper(ITargetHostProcess adapterProcess, int processId,
                                                  bool stopProcess = false)
        {
            srcProcess         = adapterProcess;
            this.processId     = processId;
            stopProcessOnClose = stopProcess;

            srcProcess.ErrorDataReceived += OnErrorReceived;
            srcProcess.Exited            += OnExited;
        }
Exemple #2
0
        public ITargetHostProcess StartProcess(string pythonExePath, string webBrowserUrl)
        {
            if (string.IsNullOrEmpty(pythonExePath))
            {
                MessageBox.Show(Strings.PythonInterpreterPathNullOrEmpty, Strings.ProductTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(null);
            }

            _webBrowserUrl     = webBrowserUrl;
            _targetHostProcess = _targetInterop.ExecuteCommandAsync(pythonExePath, "\"" + _debuggerAdapterDirectory + "\"");

            if (!string.IsNullOrEmpty(webBrowserUrl) && Uri.TryCreate(webBrowserUrl, UriKind.RelativeOrAbsolute, out _))
            {
                _timer = new Timer(OnBrowserLaunchElapsedTimer, null, 5000, Timeout.Infinite);
            }

            return(_targetHostProcess);
        }
Exemple #3
0
        public ITargetHostProcess StartProcess(string pythonExePath, string webBrowserUrl)
        {
            if (string.IsNullOrEmpty(pythonExePath))
            {
                MessageBox.Show(Strings.PythonInterpreterPathNullOrEmpty, Strings.ProductTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(null);
            }

            _webBrowserUrl     = webBrowserUrl;
            _targetHostProcess = _targetInterop.ExecuteCommandAsync(pythonExePath, "\"" + _debuggerAdapterDirectory + "\"");

            if (!string.IsNullOrEmpty(webBrowserUrl) && Uri.TryCreate(webBrowserUrl, UriKind.RelativeOrAbsolute, out _))
            {
                _adapterHostContext.Events.PreviewProtocolEvent += MonitorLaunchBrowserMessage;
            }

            return(_targetHostProcess);
        }
        public ITargetHostProcess StartProcess(string pythonExePath, string webBrowserUrl)
        {
            if (string.IsNullOrEmpty(pythonExePath))
            {
                MessageBox.Show(Strings.PythonInterpreterPathNullOrEmpty, Strings.ProductTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(null);
            }

            _webBrowserUrl     = webBrowserUrl;
            _targetHostProcess = _targetInterop.ExecuteCommandAsync(pythonExePath, "\"" + _debuggerAdapterDirectory + "\"");

            if (!string.IsNullOrEmpty(webBrowserUrl) && Uri.TryCreate(webBrowserUrl, UriKind.RelativeOrAbsolute, out var uri))
            {
                OnPortOpenedHandler.CreateHandler(uri.Port, null, null, () => _targetHostProcess.HasExited, LaunchBrowserDebugger);
            }

            return(_targetHostProcess);
        }
        /// <inheritdoc />
        public ITargetHostProcess LaunchAdapter(IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop)
        {
            ITargetHostProcess resultProcess = null;

            try
            {
                ITargetHostProcess runningProcess = null;

                // Check if an emulicious process is running and reuse it.
                var emuliciousProcess = Process.GetProcesses().Where(process => process.ProcessName.Contains("java") && process.MainWindowTitle == "Emulicious").ToList();

                var processId = -1;
                if (emuliciousProcess.Count > 0)
                {
                    // use the process and capture it in an ITargetHostProcess.
                    runningProcess = new ExistingTargetHostProcess(emuliciousProcess[0]);
                    processId      = emuliciousProcess.First().Id;
                }

                // Check if an instance of Emulicious is already running.
                // If so capture it as the instance to debug.
                // Otherwise launch a new instance.
                // If launching an instance. Wait to connect.
                if (runningProcess == null)
                {
                    // Launch emulicious.

                    var emuliciousExec = EmuliciousDebuggerLaunchProvider.EmuliciousExecutable;

                    /*
                     * File.WriteAllLines(Path.Combine(EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath, "Properties.log"),
                     *  new []
                     *  {
                     *      emuliciousExec,
                     *      EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath,
                     *      EmuliciousDebuggerLaunchProvider.EmuliciousDebugFolder,
                     *      EmuliciousDebuggerLaunchProvider.EmuliciousAttach.ToString(),
                     *      EmuliciousDebuggerLaunchProvider.EmuliciousLaunchDelay.ToString(),
                     *      EmuliciousDebuggerLaunchProvider.EmuliciousPort.ToString(),
                     *      EmuliciousPackage.DebugAdapterPath
                     *  });
                     */
                    var args = new List <string>();

                    if (EmuliciousDebuggerLaunchProvider.EmuliciousRemoteDebugArgument)
                    {
                        args.Add(string.Format("-remotedebug {0}", EmuliciousDebuggerLaunchProvider.EmuliciousPort));
                    }

                    try
                    {
                        var process = Process.Start(emuliciousExec, string.Join(" ", args));
                        if (process != null)
                        {
                            process.WaitForExit();
                        }
                    }
                    catch (Exception err)
                    {
                        File.WriteAllLines(Path.Combine(EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath, "LaunchProcess.log"),
                                           new[]
                        {
                            emuliciousExec,
                            err.ToString()
                        });
                    }

                    Thread.Sleep(EmuliciousDebuggerLaunchProvider.EmuliciousLaunchDelay);

                    // Capture the emulicious process id for destruction if not attaching.
                    emuliciousProcess = Process.GetProcesses().Where(process =>
                                                                     process.ProcessName.Contains("java") && process.MainWindowTitle == "Emulicious").ToList();

                    if (emuliciousProcess.Count > 0)
                    {
                        // Update process id for debugger disconnection.
                        processId = emuliciousProcess.First().Id;
                    }
                    else
                    {
                        // No process was found, this is a failure.
                        processId = -1;
                    }
                }

                resultProcess = new EmuliciousTargetHostProcessWrapper(targetInterop.ExecuteCommandAsync(
                                                                           EmuliciousPackage.DebugAdapterPath,
                                                                           string.Format("{0} \"{1}\" \"{2}\"",
                                                                                         EmuliciousDebuggerLaunchProvider.EmuliciousPort,
                                                                                         EmuliciousDebuggerLaunchProvider.EmuliciousDebugFolder,
                                                                                         EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath)), processId,
                                                                       !EmuliciousDebuggerLaunchProvider.EmuliciousAttach);

#if __ADAPTER_LOG__
                File.AppendAllLines(Path.Combine(EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath, "AdapterLog.log"),
                                    new [] { "Process result: " + resultProcess + " Proc id: " + processId });
#endif
            }
            catch (Exception e)
            {
                // Capture any exceptions and save them for research.
                File.WriteAllText(Path.Combine(EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath, "Exception.log"),
                                  e.ToString());
                throw;
            }

            return(resultProcess);
        }