示例#1
0
        private async Task AttachTestTimeoutAsync(string hostCode)
        {
            var exe = CompileCode(hostCode);

            // start the test process w/ our handle
            var              eventName = Guid.NewGuid().ToString();
            EventWaitHandle  handle    = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
            ProcessStartInfo psi       = new ProcessStartInfo(exe, eventName);

            psi.UseShellExecute       = false;
            psi.RedirectStandardError = psi.RedirectStandardOutput = true;
            psi.CreateNoWindow        = true;
            // Add Python to PATH so that the host can locate the DLL in case it's not in \Windows\System32 (e.g. for EPD)
            psi.EnvironmentVariables["PATH"] = Environment.GetEnvironmentVariable("PATH") + ";" + Path.GetDirectoryName(Version.InterpreterPath);

            Process p       = Process.Start(psi);
            var     outRecv = new OutputReceiver();

            p.OutputDataReceived += outRecv.OutputDataReceived;
            p.ErrorDataReceived  += outRecv.OutputDataReceived;
            p.BeginErrorReadLine();
            p.BeginOutputReadLine();

            try {
                bool isAttached = false;

                // start the attach with the GIL held
                AutoResetEvent attachStarted = new AutoResetEvent(false);
                AutoResetEvent attachDone    = new AutoResetEvent(false);

                // We run the Attach and StartListeningAsync on a separate thread,
                // because StartListeningAsync waits until debuggee has connected
                // back (which it won't do until handle is set).
                var task = Task.Run(async() =>
                {
                    var proc = PythonProcess.Attach(p.Id);
                    try {
                        proc.ProcessLoaded += (sender, args) => {
                            attachDone.Set();
                            isAttached = false;
                        };

                        attachStarted.Set();
                        await proc.StartListeningAsync(10000);
                    } finally {
                        await DetachProcessAsync(proc);
                    }
                });

                Assert.IsTrue(attachStarted.WaitOne(10000), "Failed to start attaching within 10s");
                Assert.IsFalse(isAttached, "should not have attached yet"); // we should be blocked
                handle.Set();                                               // let the code start running

                Assert.IsTrue(attachDone.WaitOne(10000), "Failed to attach within 10s");
            } finally {
                Debug.WriteLine(String.Format("Process output: {0}", outRecv.Output.ToString()));
                DisposeProcess(p);
            }
        }
示例#2
0
 public OutStream(
     string name,
     int bufferSize,
     CompressionCodec codec,
     OutputReceiver receiver)
 {
     this.name        = name;
     this._bufferSize = bufferSize;
     this.codec       = codec;
     this.receiver    = receiver;
     this._suppress   = false;
 }
示例#3
0
        /// <summary>
        /// Adds an output to a transaction
        /// </summary>
        /// <param name="value"></param>
        /// <param name="receiver"></param>
        /// <returns></returns>
        public Transaction AddOutput(int value, string receiver)
        {
            if (value < 0)
            {
                return(this);
            }

            OutputValue.Add(value);
            OutputReceiver.Add(receiver);

            return(this);
        }
示例#4
0
 public OutStream(
     string name,
     int bufferSize,
     CompressionCodec codec,
     OutputReceiver receiver)
 {
     this.name = name;
     this._bufferSize = bufferSize;
     this.codec = codec;
     this.receiver = receiver;
     this._suppress = false;
 }
示例#5
0
        protected internal async ValueTask <(int ExitCode, string OutputText)> RunGitCommandOutAsync(string command, IEnumerable <string>?args, string?stdinText = null, int[]?expectedResults = null)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo(GitConfiguration.GitProgramPath)
            {
                UseShellExecute        = false,
                CreateNoWindow         = true,
                WorkingDirectory       = this.FullPath,
                RedirectStandardInput  = true,
                RedirectStandardError  = true,
                RedirectStandardOutput = true
            };
            IEnumerable <string> allArgs = new string[] { command }.Concat(args ?? Array.Empty <string>());

#if NETFRAMEWORK
            startInfo.Arguments = string.Join(" ", allArgs.Select(x => EscapeGitCommandlineArgument(x)));
            FixConsoleUTF8BOMEncoding();
#else
            foreach (var v in allArgs)
            {
                startInfo.ArgumentList.Add(v);
            }
#endif

            using var p = Process.Start(startInfo);

            if (p == null)
            {
                throw new GitExecCommandException($"Unable to start 'git {command}' operation");
            }

            var rcv = new OutputReceiver(p);

            if (!string.IsNullOrEmpty(stdinText))
            {
                await p.StandardInput.WriteAsync(stdinText).ConfigureAwait(false);
            }

            p.StandardInput.Close();

            await Task.WhenAll(p.WaitForExitAsync(), rcv.DoneTask).ConfigureAwait(false);

            if (expectedResults != null ? !(expectedResults.Length == 0 || expectedResults.Contains(p.ExitCode)) : p.ExitCode != 0)
            {
                throw new GitExecCommandException($"Unexpected error {p.ExitCode} from 'git {command}' operation in '{FullPath}': {rcv.StdErr}");
            }

            return(p.ExitCode, rcv.StdOut);
        }
        // var testCase = require('./test/test-doubled.js'); for(var x in testCase) { console.log(x); }
        public static string EvaluateJavaScript(string code)
        {
            // TODO: Escaping code
            string args = "-e \"" + code + "\"";
            var    psi  = new ProcessStartInfo(NodePath, args);

            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError  = true;
            var proc         = Process.Start(psi);
            var outpReceiver = new OutputReceiver();

            proc.OutputDataReceived += outpReceiver.DataRead;
            proc.BeginErrorReadLine();
            proc.BeginOutputReadLine();

            return(outpReceiver._data.ToString());
        }
示例#7
0
        /// <summary>
        /// Generates the hash of the transaction
        /// </summary>
        /// <returns></returns>
        public IDownloadable GenerateHash()
        {
            Curl curl = new Curl();

            curl.Absorb(TangleNet::TryteString.FromAsciiString(SendTo).ToTrits());
            curl.Absorb(TangleNet::TryteString.FromAsciiString(From).ToTrits());
            curl.Absorb(TangleNet::TryteString.FromAsciiString(Mode + "").ToTrits());
            curl.Absorb(TangleNet::TryteString.FromAsciiString(Data.GetHashCode() + "").ToTrits());
            curl.Absorb(TangleNet::TryteString.FromAsciiString(Time + "").ToTrits());
            curl.Absorb(TangleNet::TryteString.FromAsciiString(OutputValue.GetHashCode() + "").ToTrits());
            curl.Absorb(TangleNet::TryteString.FromAsciiString(OutputReceiver.GetHashCode() + "").ToTrits());
            curl.Absorb(TangleNet::TryteString.FromAsciiString(Data.GetHashCode() + "").ToTrits());

            var hash = new int[60];

            curl.Squeeze(hash);

            Hash = Converter.TritsToTrytes(hash);

            return(this);
        }
示例#8
0
        // var testCase = require('./test/test-doubled.js'); for(var x in testCase) { console.log(x); }
        public static string EvaluateJavaScript(string code) {
            // TODO: Escaping code
            string args = "-e \"" + code + "\"";
            var psi = new ProcessStartInfo(NodePath, args);
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError = true;
            var proc = Process.Start(psi);
            var outpReceiver = new OutputReceiver();
            proc.OutputDataReceived += outpReceiver.DataRead;
            proc.BeginErrorReadLine();
            proc.BeginOutputReadLine();

            return outpReceiver._data.ToString();
        }
示例#9
0
 public MainWindowViewModelTests(Xunit.Abstractions.ITestOutputHelper testOutputHelper)
 {
     _testOutputHelper = testOutputHelper;
     _receiver         = new OutputReceiver(testOutputHelper);
 }