private void InitializeClients() { switch (_StorageType) { case StorageType.AwsS3: _S3Region = _AwsSettings.GetAwsRegionEndpoint(); _S3Credentials = new Amazon.Runtime.BasicAWSCredentials(_AwsSettings.AccessKey, _AwsSettings.SecretKey); if (String.IsNullOrEmpty(_AwsSettings.Endpoint)) { _S3Config = new AmazonS3Config { RegionEndpoint = _S3Region, UseHttp = !_AwsSettings.Ssl, }; // _S3Client = new AmazonS3Client(_S3Credentials, _S3Region); _S3Client = new AmazonS3Client(_S3Credentials, _S3Config); } else { _S3Config = new AmazonS3Config { RegionEndpoint = _S3Region, ServiceURL = _AwsSettings.Endpoint, ForcePathStyle = true, UseHttp = !_AwsSettings.Ssl }; _S3Client = new AmazonS3Client(_S3Credentials, _S3Config); } break; case StorageType.Azure: _AzureCredentials = new StorageCredentials(_AzureSettings.AccountName, _AzureSettings.AccessKey); _AzureAccount = new CloudStorageAccount(_AzureCredentials, true); _AzureBlobClient = new CloudBlobClient(new Uri(_AzureSettings.Endpoint), _AzureCredentials); _AzureContainer = _AzureBlobClient.GetContainerReference(_AzureSettings.Container); break; case StorageType.Disk: if (!Directory.Exists(_DiskSettings.Directory)) { Directory.CreateDirectory(_DiskSettings.Directory); } break; case StorageType.Kvpbase: _Kvpbase = new KvpbaseClient(_KvpbaseSettings.UserGuid, _KvpbaseSettings.ApiKey, _KvpbaseSettings.Endpoint); break; default: throw new ArgumentException("Unknown storage type: " + _StorageType.ToString()); } }
/// <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; } }