Example #1
0
        public MessageData <TValue> GetProperty(TransformContext <TInput> context)
        {
            if (context.HasInput)
            {
                MessageData <TValue> value = _property.Get(context.Input);
                if (value?.Address != null)
                {
                    return(MessageDataFactory.Load <TValue>(_repository, value.Address, context.CancellationToken));
                }
            }

            return(new EmptyMessageData <TValue>());
        }
        public Task <MessageData <TValue> > GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            if (!context.HasInput)
            {
                return(TaskUtil.Default <MessageData <TValue> >());
            }

            Task <MessageData <TValue> > inputTask = _inputProvider.GetProperty(context);

            if (inputTask.IsCompleted)
            {
                MessageData <TValue> messageData = inputTask.Result;

                if (messageData?.Address != null)
                {
                    var repository = _repository;
                    if (repository != null || context.TryGetPayload(out repository))
                    {
                        return(Task.FromResult(MessageDataFactory.Load <TValue>(repository, messageData.Address, context.CancellationToken)));
                    }
                }

                return(Task.FromResult <MessageData <TValue> >(new EmptyMessageData <TValue>()));
            }

            async Task <MessageData <TValue> > GetPropertyAsync()
            {
                MessageData <TValue> messageData = await inputTask.ConfigureAwait(false);

                if (messageData?.Address != null)
                {
                    var repository = _repository;
                    if (repository != null || context.TryGetPayload(out repository))
                    {
                        return(MessageDataFactory.Load <TValue>(repository, messageData.Address, context.CancellationToken));
                    }
                }

                return(new EmptyMessageData <TValue>());
            }

            return(GetPropertyAsync());
        }