Exemplo n.º 1
0
        private void StartProcess()
        {
            if (TrySetCanceled() || _tcs.Task.IsCompleted)
            {
                return;
            }

            _process.StartInfo.UseShellExecute        = false;
            _process.StartInfo.RedirectStandardOutput = true;
            _process.StartInfo.RedirectStandardError  = true;

            _process.OutputDataReceived += (sender, args) => OnDataReceived(args, _outputData, _outputTcs);
            _process.ErrorDataReceived  += (sender, args) => OnDataReceived(args, _errorData, _errorTcs);
            _process.Exited             += (o, e) => _ = HandleExitAsync();

            _timeoutCts?.CancelAfter(_timeout);

            if (!_process.Start())
            {
                TrySetException(new InvalidOperationException($"Failed to start process '{_process.StartInfo.FileName}'"));
            }

            _process.BeginOutputReadLine();
            _process.BeginErrorReadLine();
            _ctRegistration = _cancellationToken.Register(HandleCancel, false);
        }
Exemplo n.º 2
0
        public async Task RunStructuringAsync(string Output, IEnumerable <string> Directories, string NetCommand, string ProjectName)
        {
            DirectoryInfo OutputDirectory = new DirectoryInfo(Output + @"\" + ProjectName);

            if (!OutputDirectory.Exists)
            {
                Directory.CreateDirectory(OutputDirectory.FullName);
                CreateDirectories(Directories, OutputDirectory);

                await Task.Factory.StartNew(() =>
                {
                    baseProcess.StartInfo.WorkingDirectory       = OutputDirectory.FullName;
                    baseProcess.StartInfo.FileName               = "dotnet";
                    baseProcess.StartInfo.Arguments              = NetCommand;
                    baseProcess.StartInfo.UseShellExecute        = false;
                    baseProcess.StartInfo.RedirectStandardOutput = true;
                    baseProcess.StartInfo.CreateNoWindow         = true;
                    baseProcess.OutputDataReceived              += new DataReceivedEventHandler((sender, e) =>
                    {
                        // Prepend line numbers to each line of the output.
                        WriteLog(e.Data);
                    });

                    baseProcess.EnableRaisingEvents = true;
                    baseProcess.Exited += (sender, e) =>
                    {
                        WriteLog("Done.");
                        baseProcess.Kill();
                    };
                    baseProcess.Start();
                    baseProcess.BeginOutputReadLine();
                    baseProcess.WaitForExit();
                });
            }
            else
            {
                WriteLog("A Project with this Name already exists!");
            }
        }