コード例 #1
0
        private async Task ListenToChildDomainAsync()
        {
            CrossDomainInvokeResponse childMessage = null;

            //while the child process is aliave and we continue to get messages
            while (!_process.HasExited && (childMessage = await ReadNextResponseAsync()) != null)
            {
                TaskCompletionSource <CrossDomainInvokeResponse> completionSource;

                //find the task completion which signals the completion of the invoke request
                if (_pendingActions.TryGetValue(childMessage.MessageId, out completionSource))
                {
                    //try to mark the task as complete returning the response
                    completionSource.TrySetResult(childMessage);
                }
            }
        }
コード例 #2
0
        private async Task <CrossDomainInvokeResponse> ReadNextResponseAsync()
        {
            byte[] buff = new byte[1024];

            MemoryStream memStream = new MemoryStream();

            do
            {
                int bytesRead = await _pipe.ReadAsync(buff, 0, 1024);

                if (bytesRead == 0)
                {
                    return(null);
                }
                memStream.Write(buff, 0, bytesRead);
            } while (!_pipe.IsMessageComplete);

            return(CrossDomainInvokeResponse.FromByteArray(memStream.ToArray()));
        }
コード例 #3
0
        private async Task HandleInvokeRequest(CrossDomainInvokeRequest request)
        {
            //TODO: assembly loading goo?

            var response = new CrossDomainInvokeResponse()
            {
                MessageId = request.MessageId
            };

            try
            {
                response.Result = await Task.Run <object>(() => request.Method.Invoke(null, request.Arguments));
            }
            catch (TargetInvocationException e)
            {
                response.Exception = e.InnerException;
            }
            catch (Exception e)
            {
                response.Exception = e;
            }

            await SendResponseAsync(response);
        }
コード例 #4
0
        private async Task SendResponseAsync(CrossDomainInvokeResponse message)
        {
            byte[] buff = message.ToByteArray();

            await _pipe.WriteAsync(buff, 0, buff.Length);
        }