Пример #1
0
        /// <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));
        }
Пример #2
0
        /// <summary>
        /// Deletes the container.
        /// </summary>
        /// <param name="containerName">Name of the container.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public Task <ContainerCollection> DeleteContainer(string containerName, CancellationToken cancellationToken)
        {
            var tsk = GetContainers(cancellationToken);
            ContainerCollection containerCollection = tsk.Result;
            Container           deleteContainer     = null;


            foreach (Container container in containerCollection)
            {
                if (container.Name.Equals(containerName))
                {
                    deleteContainer = container;
                }
            }

            if (deleteContainer != null)
            {
                return(DeleteContainer(deleteContainer, cancellationToken));
            }
            else
            {
                throw new ArgumentNullException("containerName", "Container is not found");
            }
        }