Exemple #1
0
        private void OnDataReceived(string data)
        {
            switch (data)
            {
            case MESSAGE_COMPILE_STARTED:
                IsCompiling = true;
                CompileStarted?.Invoke(this, EventArgs.Empty);
                break;

            case MESSAGE_COMPILE_ENDED:
            case MESSAGE_COMPILE_ENDED_WITH_WARNINGS:
                if (!IsStarting)
                {
                    IsCompiling = false;
                    CompileEnded?.Invoke(this, true);
                }
                else
                {
                    nodeProcesses = GetNodeProcessesByExecutablePath(ExecutablesDirectory);
                    IsStarting    = false;
                    Started?.Invoke(this, EventArgs.Empty);
                }
                break;

            case MESSAGE_COMPILE_FAILED:
                IsCompiling = false;
                CompileEnded?.Invoke(this, false);
                break;

            default:
                if (IsRunning && data.StartsWith(MESSAGE_NPM_ERROR))
                {
                    Stop();
                    IsStarting  = false;
                    IsCompiling = false;
                    CompileEnded?.Invoke(this, false);
                }
                else if (IsInstalling)
                {
                    if (data.StartsWith(MESSAGE_NPM_WARNING))
                    {
                        Stop();
                        InstallEnded?.Invoke(this, false);
                    }
                    else if (InstallEndedIdentifier.IsMatch(data))
                    {
                        IsInstalling = false;
                        InstallEnded?.Invoke(this, true);
                    }
                }
                break;
            }

            OutputLine?.Invoke(this, data);
        }
Exemple #2
0
        /// <summary>
        /// Kills the Node.JS server, but keeps the npm console open.
        /// </summary>
        private void KillNodeJs()
        {
            // doesn't work, only closes the CMD, but keeps the NodeJs open
            //npmProcess.Kill();

            // doesn't work
            //npmProcess.Close();

            // doesn't work
            //npmProcess.CloseMainWindow();

            // doesn't work
            // send Ctrl + C command

            /*
             * npmProcess.StandardInput.Write(KeyCodes.CTRL_C);
             * npmProcess.StandardInput.Flush();
             * npmProcess.StandardInput.WriteLine('y');
             * npmProcess.StandardInput.Flush();
             */

            // doesn't work when the process is windowless (which in this case, it is)
            // send Ctrl+C command
            //// <summary>
            //// Sends a specified signal to a console process group that shares the console associated with the calling process.
            //// </summary>
            //// <param name="dwCtrlEvent">The type of signal to be generated. This parameter can be one of the following values:<para>CTRL_C_EVENT 0</para><para>CTRL_BREAK_EVENT 1</para></param>
            //// <param name="dwProcessGroupId">The identifier of the process group to receive the signal.</param>
            //[DllImport("kernel32.dll")]
            //private static extern bool GenerateConsoleCtrlEvent(uint dwCtrlEvent, uint dwProcessGroupId);
            //GenerateConsoleCtrlEvent(1, (uint)npmProcess.Id);
            //npmProcess.StandardInput.WriteLine('y');

            KillAllNodeProcesses();
            IsRunning        = false;
            IsStarting       = false;
            CurrentDirectory = null;
            if (IsCompiling)
            {
                IsCompiling = false;
                CompileEnded?.Invoke(this, false);
            }
            if (IsInstalling)
            {
                IsInstalling = false;
                InstallEnded?.Invoke(this, false);
            }
        }