public void SetUp()
 {
     container = new Container(Constants.REMOTE_CONTAINER_NAME);
 }
示例#2
0
        private string getContainerCDNUri(Container container)
        {
            try
            {
                var public_container = GetPublicContainerInformation(container.Name);
                return public_container == null ? "" : public_container.CdnUri;
            }
            catch (ContainerNotFoundException)
            {
                return "";
            }
            catch (WebException we)
            {
                Log.Error(this, "Error getting container CDN Uril from getContainerInformation for container '"
                    + container.Name + "' for user "
                    + _usercreds.Username, we);

                var response = (HttpWebResponse)we.Response;
                if (response != null && response.StatusCode == HttpStatusCode.Unauthorized)
                    throw new AuthenticationFailedException(we.Message);
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// This method retrieves the number of storage objects in a container, and the total size, in bytes, of the container
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// Container container = connection.GetContainerInformation("container name");
        /// </code>
        /// </example>
        /// <param name="containerName">The name of the container to query about</param>
        /// <returns>An instance of container, with the number of storage objects contained and total byte allocation</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public Container GetContainerInformation(string containerName)
        {
            if (string.IsNullOrEmpty(containerName))
                throw new ArgumentNullException();

            Log.Info(this, "Getting container information for container '"
                + containerName + "' for user "
                + _usercreds.Username);

            try
            {
                var getContainerInformation = new GetContainerInformation(StorageUrl, containerName);
                var getContainerInformationResponse = _requestfactory.Submit(getContainerInformation, AuthToken, _usercreds.ProxyCredentials);
                var container = new Container(containerName)
                                    {
                                        ByteCount =
                                            long.Parse(
                                            getContainerInformationResponse.Headers[Constants.X_CONTAINER_BYTES_USED]),
                                        ObjectCount =
                                            long.Parse(
                                            getContainerInformationResponse.Headers[
                                                Constants.X_CONTAINER_STORAGE_OBJECT_COUNT])
                                    };
                var url = getContainerCDNUri(container);
                if (!string.IsNullOrEmpty(url))
                    url += "/";
                container.CdnUri = url;
                return container;
            }
            catch (WebException we)
            {
                Log.Error(this, "Error getting container information for container '"
                    + containerName + "' for user "
                    + _usercreds.Username, we);

                var response = (HttpWebResponse)we.Response;
                if (response != null && response.StatusCode == HttpStatusCode.NotFound)
                    throw new ContainerNotFoundException("The requested container does not exist");
                if (response != null && response.StatusCode == HttpStatusCode.Unauthorized)
                    throw new AuthenticationFailedException(we.Message);
                throw;
            }
        }
示例#4
0
 private Container getContainerInformation(string containerName)
 {
     var getContainerInformation = new GetContainerInformation(StorageUrl, containerName);
     var getContainerInformationResponse = _requestfactory.Submit(getContainerInformation, AuthToken, _usercreds.ProxyCredentials);
     var container = new Container(containerName)
     {
         ByteCount =
             long.Parse(
             getContainerInformationResponse.Headers[Constants.X_CONTAINER_BYTES_USED]),
         ObjectCount =
             long.Parse(
             getContainerInformationResponse.Headers[
                 Constants.X_CONTAINER_STORAGE_OBJECT_COUNT])
     };
     var url = GetContainerCdnUri(container);
     if (!string.IsNullOrEmpty(url)) url += "/";
     container.CdnUri = url;
     return container;
 }