예제 #1
0
 private async Task KvpbaseWrite(string key, string contentType, long contentLength, Stream stream)
 {
     try
     {
         await _Kvpbase.WriteObject(_KvpbaseSettings.Container, key, contentType, contentLength, stream);
     }
     catch (Exception)
     {
         throw new IOException("Unable to write object.");
     }
 }
예제 #2
0
        /// <summary>
        /// Instantiate the stream.
        /// </summary>
        /// <param name="apiKey">API key.</param>
        /// <param name="endpointUrl">Kvpbase node endpoint, i.e. http://hostname:port.</param>
        /// <param name="userGuid">The user GUID.</param>
        /// <param name="container">The container in which the object is stored.</param>
        /// <param name="objectKey">The object key.</param>
        public KvpbaseStream(string apiKey, string endpointUrl, string userGuid, string container, string objectKey)
        {
            if (String.IsNullOrEmpty(apiKey))
            {
                throw new ArgumentNullException(nameof(apiKey));
            }
            if (String.IsNullOrEmpty(endpointUrl))
            {
                throw new ArgumentNullException(nameof(endpointUrl));
            }
            if (String.IsNullOrEmpty(userGuid))
            {
                throw new ArgumentNullException(nameof(userGuid));
            }
            if (String.IsNullOrEmpty(container))
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (String.IsNullOrEmpty(objectKey))
            {
                throw new ArgumentNullException(nameof(objectKey));
            }

            _Kvpbase     = new KvpbaseClient(userGuid, apiKey, endpointUrl);
            _ApiKey      = apiKey;
            _EndpointUrl = endpointUrl;
            _UserGuid    = userGuid;
            _Container   = container;
            _ObjectKey   = objectKey;

            if (!_Kvpbase.ObjectExists(_Container, _ObjectKey))
            {
                if (!_Kvpbase.WriteObject(_Container, _ObjectKey, "application/octet-stream", null))
                {
                    throw new IOException("Unable to create object.");
                }
            }

            if (!GetObjectMetadata())
            {
                throw new IOException("Unable to read object metadata.");
            }
            else
            {
                _Position = 0;
            }
        }