Ejemplo n.º 1
0
        private async Task <RemoteInvokeResultMessage> RegisterResultCallbackAsync(string id,
                                                                                   CancellationToken cancellationToken)
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug($"准备获取Id为:{id}的响应内容。");
            }

            var task = new ManualResetValueTaskSource <TransportMessage>();

            _resultDictionary.TryAdd(id, task);
            try
            {
                var result = await task.AwaitValue(cancellationToken);

                return(result.GetContent <RemoteInvokeResultMessage>());
            }
            finally
            {
                // 删除回调任务
                ManualResetValueTaskSource <TransportMessage> value;
                _resultDictionary.TryRemove(id, out value);
                value.SetCanceled();
            }
        }
Ejemplo n.º 2
0
        private async Task <RemoteInvokeResultMessage> RegisterResultCallbackAsync(string id, CancellationToken cancellationToken)
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug($"准备获取Id为:{id}的响应内容。");
            }

            var task = new ManualResetValueTaskSource <TransportMessage>();

            _resultDictionary.TryAdd(id, task);
            try
            {
                var result = await task.AwaitValue(cancellationToken);

                return(result.GetContent <RemoteInvokeResultMessage>());
            }
            catch (CPlatformException ex)
            {
                if (_logger.IsEnabled(LogLevel.Error))
                {
                    _logger.LogError(ex.Message, ex);
                }
                return(new RemoteInvokeResultMessage()
                {
                    ExceptionMessage = ex.Message,
                    StatusCode = ex.ExceptionCode,
                });
            }
            catch (Exception ex)
            {
                if (_logger.IsEnabled(LogLevel.Error))
                {
                    _logger.LogError(ex.Message, ex);
                }
                return(new RemoteInvokeResultMessage()
                {
                    ExceptionMessage = ex.Message,
                    StatusCode = StatusCode.UnKnownError,
                });
            }
            finally
            {
                //删除回调任务
                ManualResetValueTaskSource <TransportMessage> value;
                _resultDictionary.TryRemove(id, out value);
                value.SetCanceled();
            }
        }
Ejemplo n.º 3
0
        private async Task <object> RegisterResultCallbackAsync(string id, CancellationToken cancellationToken)
        {
            var task = new ManualResetValueTaskSource <TransportMessage>();

            _resultDictionary.TryAdd(id, task);
            try
            {
                var result = await task.AwaitValue(cancellationToken);

                return(result.GetContent <ReactiveResultMessage>()?.Result);
            }
            finally
            {
                //删除回调任务
                ManualResetValueTaskSource <TransportMessage> value;
                _resultDictionary.TryRemove(id, out value);
                value.SetCanceled();
            }
        }