コード例 #1
0
        /// <summary>
        /// Writes the serialized java request to the named pipe. Waits from the request to be read on java side.
        /// Then reads the response from java(json) an deserializes it to JavaRespnse
        /// </summary>
        /// <param name="request"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task <JavaResponse> RequestAsync(JavaRequest request, CancellationToken ct)
        {
            using (CancellationTokenRegistration ctr = ct.Register(() => OnCancellationRequested()))
            {
                using (var streamWriter = new StreamWriter(_serverPipe, _utf8Encoding, _defaultBufferSize,
                                                           leaveOpen: true)
                {
                    AutoFlush = true
                })
                {
                    Trace.TraceInformation("Sending information to Java.");
                    await streamWriter.WriteLineAsync(request.Serialize());
                }

                ct.ThrowIfCancellationRequested();
                bool isWindows = true;
#if NETCOREAPP
                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    isWindows = false;
                }
#endif
                if (isWindows)
                {
                    _serverPipe.WaitForPipeDrain();
                }

                using (var streamReader = new StreamReader(_serverPipe, _utf8Encoding, false, _defaultBufferSize,
                                                           leaveOpen: true))
                {
                    return(JavaResponse.Deserialize(await streamReader.ReadLineAsync()));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Writes the serialized java request to the named pipe. Waits from the request to be read on java side.
        /// Then reads the response from java(json) an deserializes it to JavaRespnse
        /// </summary>
        /// <param name="request"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task <JavaResponse> RequestAsync(JavaRequest request, CancellationToken ct)
        {
            using (CancellationTokenRegistration ctr = ct.Register(() => OnCancellationRequested()))
            {
                using (var streamWriter = new StreamWriter(_serverPipe, _utf8Encoding, _defaultBufferSize,
                                                           leaveOpen: true)
                {
                    AutoFlush = true
                })
                {
                    Trace.TraceInformation("Sending information to Java.");
                    await streamWriter.WriteLineAsync(request.Serialize());
                }

                ct.ThrowIfCancellationRequested();
                _serverPipe.WaitForPipeDrain();

                using (var streamReader = new StreamReader(_serverPipe, _utf8Encoding, false, _defaultBufferSize,
                                                           leaveOpen: true))
                {
                    return(JavaResponse.Deserialize(await streamReader.ReadLineAsync()));
                }
            }
        }