コード例 #1
0
        public async Task WriteStreamAsync(PipeMessageByteCode code, int command = 0, bool waitForConnect = true)
        {
            DebugTrace("TestService " + ServiceName + ": WriteStreamAsync writing " + code.ToString());

            var toWrite = (code == PipeMessageByteCode.OnCustomCommand) ? new byte[] { (byte)command } : new byte[] { (byte)code };

            // Wait for the client connection before writing to the pipe.
            if (waitForConnect)
            {
                await _waitClientConnect;
            }
            await _serverStream.WriteAsync(toWrite, 0, 1).WaitAsync(TimeSpan.FromSeconds(60)).ConfigureAwait(false);

            DebugTrace("TestService " + ServiceName + ": WriteStreamAsync completed");
        }
コード例 #2
0
        public async Task WriteStreamAsync(PipeMessageByteCode code, int command = 0)
        {
            DebugTrace("TestService " + ServiceName + ": WriteStreamAsync writing " + code.ToString());

            var toWrite = (code == PipeMessageByteCode.OnCustomCommand) ? new byte[] { (byte)command } : new byte[] { (byte)code };

            // Wait for the client connection before writing to the pipe.
            // Exception: if it's a Stop message, it may be because the test has completed and we're cleaning up the test service so there's no client at all.
            // Tests that verify "Stop" itself should ensure the client connection has completed before calling stop, by waiting on some other message from the pipe first.
            if (code != PipeMessageByteCode.Stop)
            {
                await _waitClientConnect;
            }
            await _serverStream.WriteAsync(toWrite, 0, 1).WaitAsync(TimeSpan.FromSeconds(60)).ConfigureAwait(false);

            DebugTrace("TestService " + ServiceName + ": WriteStreamAsync completed");
        }
コード例 #3
0
 public async Task WriteStreamAsync(PipeMessageByteCode code, int command = 0)
 {
     if (_waitClientConnect.IsCompleted)
     {
         Task      writeCompleted;
         const int WriteTimeout = 60000;
         if (code == PipeMessageByteCode.OnCustomCommand)
         {
             writeCompleted = _serverStream.WriteAsync(new byte[] { (byte)command }, 0, 1);
         }
         else
         {
             writeCompleted = _serverStream.WriteAsync(new byte[] { (byte)code }, 0, 1);
         }
         await writeCompleted.TimeoutAfter(WriteTimeout).ConfigureAwait(false);
     }
     else
     {
         // We get here if the service is getting torn down before a client ever connected.
         // some tests do this.
     }
 }
コード例 #4
0
ファイル: TestService.cs プロジェクト: simonynx/corefx
        private async Task WriteStreamAsync(PipeMessageByteCode code, int command = 0)
        {
            const int writeTimeout = 60000;
            Task      writeCompleted;

            if (_waitClientConnect.IsCompleted)
            {
                if (code == PipeMessageByteCode.OnCustomCommand)
                {
                    writeCompleted = _serverStream.WriteAsync(new byte[] { (byte)command }, 0, 1);
                    await writeCompleted.TimeoutAfter(writeTimeout).ConfigureAwait(false);
                }
                else
                {
                    writeCompleted = _serverStream.WriteAsync(new byte[] { (byte)code }, 0, 1);
                    await writeCompleted.TimeoutAfter(writeTimeout).ConfigureAwait(false);
                }
            }
            else
            {
                throw new TimeoutException($"Client didn't connect to the pipe");
            }
        }