Пример #1
0
        /// <summary>
        /// 1. serializes an <see cref="IIpcOperation"/> over via <paramref name="stream"/>;
        /// 2. if the operation is synchronous, reads an <see cref="IIpcResult"/> from <paramref name="stream"/>.
        /// </summary>
        internal static async Task <IIpcResult> SendOperationAndExecuteRemotelyAsync(IIpcOperation operation, Stream stream, CancellationToken token)
        {
            await IpcOperation.SerializeAsync(stream, operation, token);

            return(operation.ShouldWaitForServerAck
                ? await IpcResult.DeserializeAsync(stream, token)
                : IpcResult.Success());
        }
Пример #2
0
        /// <summary>
        /// 1. deserializes an <see cref="IIpcOperation"/> from a given <paramref name="stream"/>;
        /// 2. executes the operation (via <paramref name="executor"/>);
        /// 3. serializes and sends back the result via <paramref name="stream"/>.
        ///
        /// If executing the operation (via <paramref name="executor"/>) fails, the <see cref="IIpcResult.ExitCode"/>
        /// of the result is <see cref="IpcResultStatus.ExecutionError"/>
        /// </summary>
        internal static async Task <IIpcResult> ReceiveOperationAndExecuteLocallyAsync(Stream stream, IIpcOperationExecutor executor, CancellationToken token)
        {
            IIpcOperation operation = await IpcOperation.DeserializeAsync(stream, token);

            IIpcResult result = await HandleExceptionsAsync(IpcResultStatus.ExecutionError, () => executor.ExecuteAsync(operation));

            if (operation.ShouldWaitForServerAck)
            {
                await IpcResult.SerializeAsync(stream, result, token);
            }

            return(result);
        }