/// <summary> /// Gets the account details. /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Awaitable task with result as <seealso cref="AccountDetails"/></returns> public Task<AccountDetails> GetAccountDetails(CancellationToken cancellationToken) { GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Head); request.QueryParams.Add("format", "json"); RestClient<GenericDataProvider, AccountDetailsParser> client = new RestClient<GenericDataProvider, AccountDetailsParser>(); var tsk = client.Execute(request, cancellationToken); return tsk.ContinueWith<AccountDetails>(tskOk => { return tskOk.Result.Data as AccountDetails; } , cancellationToken); }
/// <summary> /// Gets the containers. /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns><see cref="ContainerCollection"/> object</returns> public Task<ContainerCollection> GetContainers(CancellationToken cancellationToken) { GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Get); request.QueryParams.Add("format", "json"); RestClient<GenericDataProvider, ContainerCollectionParser> client = new RestClient<GenericDataProvider, ContainerCollectionParser>(); var tsk = client.Execute(request, cancellationToken); return tsk.ContinueWith<ContainerCollection>(tskOk => { ContainerCollection coll = tskOk.Result.Data as ContainerCollection; foreach (Container container in coll) { string endpoint = this.credentials.Endpoint.ToString() + "/" + container.Name; container.Endpoint = new Uri(endpoint); } return coll; ; } , cancellationToken); }
/// <summary> /// Creates the container. /// </summary> /// <param name="containerName">Name of the container.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public Task<ContainerCollection> CreateContainer(string containerName, CancellationToken cancellationToken) { GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Put); string containerUri = request.Endpoint.ToString(); if (containerUri.EndsWith("/")) { containerUri += containerName; } else { containerUri += "/" + containerName; } request.Endpoint = new Uri(containerUri); RestClient<GenericDataProvider, ContainerCollectionParser> client = new RestClient<GenericDataProvider, ContainerCollectionParser>(); var tsk = client.Execute(request, cancellationToken); return tsk.ContinueWith<ContainerCollection>(tskOk => { return GetContainers(cancellationToken).Result; } , cancellationToken); }
//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); }
/// <summary> /// Uploads the object/file to SWFIT server /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="container">The container.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Awaitable task to wait for uploading to finish</returns> public Task UploadObject(string fileName, Container container, CancellationToken cancellationToken) { //request.QueryParams.Add("object", Uri.EscapeDataString(System.IO.Path.GetFileName(fileName))); //request.HeaderParams.Add("object", System.IO.Path.GetFileName(fileName)); //request.HeaderParams.Add("ETag", FileUtils.GenerateMD5Hash(fileName)); //request.HeaderParams.Add("Content-Encoding", "BASE64"); //request.HeaderParams.Add("Content-Length", new System.IO.FileInfo(fileName).Length.ToString()); GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Put); request.Endpoint = new Uri(container.Endpoint + "/" + Uri.EscapeDataString(FileUtils.NormalizeFileName(fileName))); // // Real file name request.HeaderParams.Add("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(fileName)); request.Content = FileUtils.FileContent(fileName); RestClient<GenericDataProvider, NullableParser> client = new RestClient<GenericDataProvider, NullableParser>(); return client.Execute(request, cancellationToken); }
/// <summary> /// Gets the objects for container /// </summary> /// <param name="container">The container.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns><see cref="SwiftObjectsCollection"/> object</returns> public Task<SwiftObjectsCollection> GetObjects(Container container, CancellationToken cancellationToken) { GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Get); request.Endpoint = container.Endpoint; request.QueryParams.Add("format", "json"); RestClient<GenericDataProvider, SwiftObjectsCollectionParser> client = new RestClient<GenericDataProvider, SwiftObjectsCollectionParser>(); var tsk = client.Execute(request, cancellationToken); return tsk.ContinueWith<SwiftObjectsCollection>(tskOk => { SwiftObjectsCollection coll = tskOk.Result.Data; coll.ForEach(obj => obj.Endpoint = new Uri(container.Endpoint.ToString() + "/" + obj.Name)); return coll; }); }
/// <summary> /// Deletes the container. /// </summary> /// <param name="container">The container.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public Task<ContainerCollection> DeleteContainer(Container container, CancellationToken cancellationToken) { GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Delete); request.Endpoint = container.Endpoint; RestClient<GenericDataProvider, ContainerCollectionParser> client = new RestClient<GenericDataProvider, ContainerCollectionParser>(); var tsk = client.Execute(request, cancellationToken); return tsk.ContinueWith<ContainerCollection>(tskOk => { //return tskOk.Result.Data as ContainerCollection; return GetContainers(cancellationToken).Result; } , cancellationToken); }