Exemplo n.º 1
0
        async Task <MessageData <TValue> > Put(PipeContext context, Task <TValue> valueTask)
        {
            var repository = _repository;

            if (repository != null || context.TryGetPayload(out repository))
            {
                TimeSpan?timeToLive = default;
                if (context.TryGetPayload(out SendContext sendContext) && sendContext.TimeToLive.HasValue)
                {
                    timeToLive = sendContext.TimeToLive;
                }

                if (timeToLive.HasValue && MessageDataDefaults.ExtraTimeToLive.HasValue)
                {
                    timeToLive += MessageDataDefaults.ExtraTimeToLive;
                }

                if (!timeToLive.HasValue && MessageDataDefaults.TimeToLive.HasValue)
                {
                    timeToLive = MessageDataDefaults.TimeToLive.Value;
                }

                var value = await valueTask.ConfigureAwait(false);

                if (value is string stringValue)
                {
                    MessageData <string> messageData = timeToLive.HasValue
                        ? await _repository.PutString(stringValue, timeToLive.Value, context.CancellationToken).ConfigureAwait(false)
                        : await _repository.PutString(stringValue, context.CancellationToken).ConfigureAwait(false);

                    return((MessageData <TValue>)messageData);
                }

                if (value is byte[] bytesValue)
                {
                    MessageData <byte[]> messageData = timeToLive.HasValue
                        ? await _repository.PutBytes(bytesValue, timeToLive.Value, context.CancellationToken).ConfigureAwait(false)
                        : await _repository.PutBytes(bytesValue, context.CancellationToken).ConfigureAwait(false);

                    return((MessageData <TValue>)messageData);
                }

                if (value is Stream streamValue)
                {
                    MessageData <Stream> messageData = timeToLive.HasValue
                        ? await _repository.PutStream(streamValue, timeToLive.Value, context.CancellationToken).ConfigureAwait(false)
                        : await _repository.PutStream(streamValue, default, context.CancellationToken).ConfigureAwait(false);
Exemplo n.º 2
0
        async Task <MessageData <TValue> > Put(PipeContext context, Task <TValue> valueTask)
        {
            var repository = _repository;

            if (repository != null || context.TryGetPayload(out repository))
            {
                TimeSpan?timeToLive = default;
                if (context.TryGetPayload(out SendContext sendContext) && sendContext.TimeToLive.HasValue)
                {
                    timeToLive = sendContext.TimeToLive;
                }

                if (timeToLive.HasValue && MessageDataDefaults.ExtraTimeToLive.HasValue)
                {
                    timeToLive += MessageDataDefaults.ExtraTimeToLive;
                }

                if (!timeToLive.HasValue && MessageDataDefaults.TimeToLive.HasValue)
                {
                    timeToLive = MessageDataDefaults.TimeToLive.Value;
                }

                var value = await valueTask.ConfigureAwait(false);

                if (value is string stringValue)
                {
                    MessageData <string> messageData = timeToLive.HasValue
                        ? await _repository.PutString(stringValue, timeToLive.Value, context.CancellationToken).ConfigureAwait(false)
                        : await _repository.PutString(stringValue, context.CancellationToken).ConfigureAwait(false);

                    return((MessageData <TValue>)messageData);
                }

                if (value is byte[] bytesValue)
                {
                    MessageData <byte[]> messageData = timeToLive.HasValue
                        ? await _repository.PutBytes(bytesValue, timeToLive.Value, context.CancellationToken).ConfigureAwait(false)
                        : await _repository.PutBytes(bytesValue, context.CancellationToken).ConfigureAwait(false);

                    return((MessageData <TValue>)messageData);
                }

                throw new MessageDataException("Unsupported message data type: " + TypeMetadataCache <TValue> .ShortName);
            }

            throw new MessageDataException("Message data repository was not available: " + TypeMetadataCache <TValue> .ShortName);
        }
        public static async Task <MessageData <byte[]> > ToMessageData(this IDictionary <string, byte[]> protocolMessages, IMessageDataRepository repository)
        {
            using (var memStream = new MemoryStream())
            {
                var binaryFormatter = new BinaryFormatter();
                binaryFormatter.Serialize(memStream, protocolMessages);

                return(await repository.PutBytes(memStream.ToArray()));
            }
        }
Exemplo n.º 4
0
        public async Task <CreateDocumentCommand> CreateCreateDocumentCommand(Document document, IMessageDataRepository messageDataRepository)
        {
            var messageData = await messageDataRepository.PutBytes(document.Content, TimeSpan.FromMinutes(10));

            var createDocumentCommand = new CreateDocumentCommand(
                document.Id, document.Name, (int)document.DocumentStatus.Id,
                document.DocumentName, document.ContentType,
                document.Created.On, document.Created.UserId,
                document.Updated.On, document.Updated.UserId,
                messageData);

            return(createDocumentCommand);
        }
Exemplo n.º 5
0
        public async Task WhenPublishingABigTestMessage()
        {
            _expectedBlob = new byte[]
            {
                111, 2, 234, 23, 23, 234, 235
            };

            var bigTestMessage = new BigTestMessage
            {
                Blob = await _messageDataRepository.PutBytes(_expectedBlob)
            };

            await _busControl.Publish(bigTestMessage);
        }