Beispiel #1
0
        /// <summary>
        /// Starts (or restarts) the Node.JS server in the specified directory. If Node.JS is currently already running in the same executables directory, it will be killed. The npm console must already be running prior to calling this method.
        /// </summary>
        /// <param name="directory">The directory in which the Node.JS server will be started.</param>
        private void StartNodeJs(string directory)
        {
            if (IsRunning)
            {
                KillNodeJs();
            }
            else
            {
                KillAllProcesssesOfThisNodeExecutables();
            }

            if (!IsNpmRunning)
            {
                throw new InvalidOperationException("Npm was not started yet.");
            }

            CurrentDirectory = directory.ToLower();

            IsRunning  = true;
            IsStarting = true;

            // the server starts compiling at the start
            IsCompiling = true;
            CompileStarted?.Invoke(this, EventArgs.Empty);

            npmProcess.StandardInput.WriteLine("cd " + CurrentDirectory);
            npmProcess.StandardInput.WriteLine($"{NPM} start {SCRIPTS_PREPEND_NODE_PATH}");
            //npmProcess.StandardInput.WriteLine($"{NPM} start {SCRIPTS_PREPEND_NODE_PATH} 2> errorlog.txt");
        }
Beispiel #2
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);
        }
Beispiel #3
0
 void RunCompilerInternal(CancellationToken cancel)
 {
     lock (compileLock)
     {
         cancel.ThrowIfCancellationRequested();
         try
         {
             CompileStarted?.Invoke(this, new EventArgs());
             var data = Compile(cancel).Generate();
             cancel.ThrowIfCancellationRequested();
             CompileEnded?.Invoke(this, data);
         }
         catch (CompileException e)
         {
             cancel.ThrowIfCancellationRequested();
             CompileError?.Invoke(this, e.Message);
         }
     }
 }