Beispiel #1
0
        //public bool PutBlockBlob(string containerName, string blobName, string fileNamePath)
        //{
        //    try
        //    {
        //        string deploymentPath =
        //            StringUtilities.Format("{0}/{1}/{2}", _account.UriEndpoints["Blob"], containerName,
        //                                 blobName);
        //        int contentLength;

        //        HttpVerb = "PUT";

        //        byte[] ms = GetPackageFileBytesAndLength(fileNamePath, out contentLength);

        //        string canResource = StringUtilities.Format("/{0}/{1}/{2}", _account.AccountName, containerName, blobName);

        //        string authHeader = CreateAuthorizationHeader(canResource, "\nx-ms-blob-type:BlockBlob", contentLength);

        //        try
        //        {
        //            var blobTypeHeaders = new Hashtable();
        //            blobTypeHeaders.Add("x-ms-blob-type", "BlockBlob");
        //            var response = AzureStorageHttpHelper.SendWebRequest(_client, deploymentPath, authHeader, GetDateHeader(), VersionHeader, ms, contentLength, HttpVerb, true, blobTypeHeaders);
        //            if (response.StatusCode != HttpStatusCode.Created)
        //            {
        //                Debug.Print("Deployment Path was " + deploymentPath);
        //                Debug.Print("Auth Header was " + authHeader);
        //                Debug.Print("Ms was " + ms.Length);
        //                Debug.Print("Length was " + contentLength);
        //            }
        //            else
        //            {
        //                Debug.Print("Success");
        //                Debug.Print("Auth Header was " + authHeader);
        //            }

        //            return response.StatusCode == HttpStatusCode.Created;
        //        }
        //        catch (WebException wex)
        //        {
        //            Debug.Print(wex.ToString());
        //            return false;
        //        }
        //    }
        //    catch (IOException ex)
        //    {
        //        Debug.Print(ex.ToString());
        //        return false;
        //    }
        //    catch (Exception ex)
        //    {
        //        Debug.Print(ex.ToString());
        //        return false;
        //    }
        //}

        public bool PutBlockBlob(string containerName, string blobName, Byte[] ms)
        {
            try
            {
                string deploymentPath =
                    StringUtilities.Format("{0}/{1}/{2}", _account.UriEndpoints["Blob"], containerName,
                                           blobName);
                int contentLength = ms.Length;

                HttpVerb = "PUT";

                string canResource = StringUtilities.Format("/{0}/{1}/{2}", _account.AccountName, containerName, blobName);

                var    timestamp  = GetDateHeader();
                string authHeader = CreateAuthorizationHeader(canResource, timestamp, "\nx-ms-blob-type:BlockBlob", contentLength);

                try
                {
                    var blobTypeHeaders = new Hashtable();
                    blobTypeHeaders.Add("x-ms-blob-type", "BlockBlob");
                    var response = AzureStorageHttpHelper.SendWebRequest(_client, deploymentPath, authHeader, timestamp, VersionHeader, ms, contentLength, HttpVerb, true, blobTypeHeaders);
                    if (response.StatusCode != HttpStatusCode.Created)
                    {
                        Debug.Print("Deployment Path was " + deploymentPath);
                        Debug.Print("Auth Header was " + authHeader);
                        Debug.Print("Ms was " + ms.Length);
                        Debug.Print("Length was " + contentLength);
                    }
                    else
                    {
                        Debug.Print("Success");
                        Debug.Print("Auth Header was " + authHeader);
                    }

                    return(response.StatusCode == HttpStatusCode.Created);
                }
                catch (WebException wex)
                {
                    Debug.Print(wex.ToString());
                    return(false);
                }
            }
            catch (IOException ex)
            {
                Debug.Print(ex.ToString());
                return(false);
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
                return(false);
            }
        }
Beispiel #2
0
        public bool DeleteContainer(string containerName)
        {
            try
            {
                string deploymentPath =
                    StringUtilities.Format("{0}/{1}?{2}", _account.UriEndpoints["Blob"], containerName, ContainerString);

                HttpVerb = "DELETE";

                string canResource = StringUtilities.Format("/{0}/{1}\nrestype:container", _account.AccountName,
                                                            containerName);

                var    timestamp  = GetDateHeader();
                string authHeader = CreateAuthorizationHeader(canResource, timestamp);

                try
                {
                    var response = AzureStorageHttpHelper.SendWebRequest(_client, deploymentPath, authHeader, timestamp, VersionHeader, null, 0, HttpVerb, true);
                    if (response.StatusCode != HttpStatusCode.Accepted)
                    {
                        Debug.Print("Deployment Path was " + deploymentPath);
                        Debug.Print("Auth Header was " + authHeader);
                        Debug.Print("Error Status Code: " + response.StatusCode);
                    }
                    else
                    {
                        Debug.Print("Success");
                        Debug.Print("Auth Header was " + authHeader);
                    }

                    return(response.StatusCode == HttpStatusCode.Accepted);
                }
                catch (WebException wex)
                {
                    Debug.Print(wex.ToString());
                    return(false);
                }
            }
            catch (IOException ex)
            {
                Debug.Print(ex.ToString());
                return(false);
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
                return(false);
            }
        }