//public Task<SwiftObject> DownloadObject(Container container, SwiftObject targetObject, CancellationToken cancellationToken) //{ // GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Get); // request.QueryParams.Add("container", container.Name); // request.QueryParams.Add("object", targetObject.Name); // request.Endpoint = targetObject.Endpoint; //} /// <summary> /// Deletes the object/file from SWIFT /// </summary> /// <param name="container">The container.</param> /// <param name="targetObject">The target object.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>New collection of object for this container after deletion</returns> public Task <SwiftObjectsCollection> DeleteObject(Container container, SwiftObject targetObject, CancellationToken cancellationToken) { GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Delete); if (targetObject.Endpoint != null) { request.Endpoint = targetObject.Endpoint; } else { request.Endpoint = new Uri(container.Endpoint.ToString() + "/" + Uri.EscapeDataString(FileUtils.NormalizeFileName(targetObject.Name))); } RestClient <GenericDataProvider, NullableParser> client = new RestClient <GenericDataProvider, NullableParser>(); var tsk = client.Execute(request, cancellationToken); return(tsk.ContinueWith <SwiftObjectsCollection>(tskOk => { if (tsk.Status == TaskStatus.Faulted) { throw tsk.Exception; } return GetObjects(container, cancellationToken).Result; })); //, cancellationToken, TaskContinuationOptions.NotOnFaulted, TaskScheduler.Current); }
//public Task<SwiftObject> DownloadObject(Container container, SwiftObject targetObject, CancellationToken cancellationToken) //{ // GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Get); // request.QueryParams.Add("container", container.Name); // request.QueryParams.Add("object", targetObject.Name); // request.Endpoint = targetObject.Endpoint; //} /// <summary> /// Deletes the object/file from SWIFT /// </summary> /// <param name="container">The container.</param> /// <param name="targetObject">The target object.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>New collection of object for this container after deletion</returns> public Task<SwiftObjectsCollection> DeleteObject(Container container, SwiftObject targetObject, CancellationToken cancellationToken) { GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Delete); if (targetObject.Endpoint != null) { request.Endpoint = targetObject.Endpoint; } else { request.Endpoint = new Uri(container.Endpoint.ToString() + "/" + Uri.EscapeDataString(FileUtils.NormalizeFileName(targetObject.Name))); } RestClient<GenericDataProvider, NullableParser> client = new RestClient<GenericDataProvider, NullableParser>(); var tsk = client.Execute(request, cancellationToken); return tsk.ContinueWith<SwiftObjectsCollection>(tskOk => { if (tsk.Status == TaskStatus.Faulted) { throw tsk.Exception; } return GetObjects(container, cancellationToken).Result; }); //, cancellationToken, TaskContinuationOptions.NotOnFaulted, TaskScheduler.Current); }
public void Delete_unknown_object_from_container_should_throw() { swiftConnectionData = KeystoneData.GetKeystoneToken(); tokenSource = new CancellationTokenSource(); swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant); ContainerCollection containerCollection = null; Assert.DoesNotThrow(() => { var tsk = swiftclient.GetContainers(tokenSource.Token); containerCollection = tsk.Result; }); Assert.NotNull(containerCollection); Container container = containerCollection.First(); SwiftObject badObject = new SwiftObject() { Name = "##I_am_super_bad##"}; Assert.Throws(typeof(AggregateException), () => { var tsk = swiftclient.DeleteObject(container, badObject, tokenSource.Token); var coll = tsk.Result; Assert.NotNull(coll); }); }