Esempio n. 1
0
        public static async Task <MessageData <byte[]> > PutBytes(this IMessageDataRepository repository, byte[] bytes, TimeSpan timeToLive,
                                                                  CancellationToken cancellationToken = default(CancellationToken))
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            using (var ms = new MemoryStream(bytes, false))
            {
                Uri address = await repository.Put(ms, timeToLive, cancellationToken).ConfigureAwait(false);

                return(new ConstantMessageData <byte[]>(address, bytes));
            }
        }
Esempio n. 2
0
        public static async Task <MessageData <string> > PutString(this IMessageDataRepository repository, string value, TimeSpan timeToLive,
                                                                   CancellationToken cancellationToken = default(CancellationToken))
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }
            if (value == null)
            {
                return(new EmptyMessageData <string>());
            }

            byte[] bytes = Encoding.UTF8.GetBytes(value);
            using (var ms = new MemoryStream(bytes, false))
            {
                Uri address = await repository.Put(ms, timeToLive, cancellationToken).ConfigureAwait(false);

                return(new ConstantMessageData <string>(address, value));
            }
        }
Esempio n. 3
0
        public static async Task <MessageData <string> > PutString(this IMessageDataRepository repository, string value,
                                                                   CancellationToken cancellationToken = default)
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }
            if (value == null)
            {
                return(EmptyMessageData <string> .Instance);
            }

            if (value.Length < MessageDataDefaults.Threshold && !MessageDataDefaults.AlwaysWriteToRepository)
            {
                return(new StringInlineMessageData(value));
            }

            byte[] bytes = Encoding.UTF8.GetBytes(value);

            using var ms = new MemoryStream(bytes, false);

            var address = await repository.Put(ms, default, cancellationToken).ConfigureAwait(false);
        public async Task <Uri> Put(Stream stream, TimeSpan?timeToLive = null, CancellationToken cancellationToken = new CancellationToken())
        {
            string keyId = null;

            using (Stream cryptoStream = _streamProvider.GetEncryptStream(stream, keyId, CryptoStreamMode.Read))
            {
                var address = await _repository.Put(cryptoStream, timeToLive, cancellationToken);

                var addressBuilder = new UriBuilder(address);

                NameValueCollection parameters = new NameValueCollection();
                if (!string.IsNullOrWhiteSpace(addressBuilder.Query))
                {
                    var query = addressBuilder.Query;

                    if (query.Contains("?"))
                    {
                        query = query.Substring(query.IndexOf('?') + 1);
                    }

                    foreach (string parameter in query.Split('&'))
                    {
                        if (string.IsNullOrWhiteSpace(parameter))
                        {
                            continue;
                        }

                        string[] pair = parameter.Split('=');

                        parameters.Add(pair[0], pair.Length == 2 ? pair[1] : "");
                    }
                }

                parameters["keyId"]  = "";
                addressBuilder.Query = parameters.ToString();

                return(addressBuilder.Uri);
            }
        }