コード例 #1
0
        public string[] GetPartition(string Table, string partitionKey, string rowKey)
        {
            List <string> returnlist = new List <string>();

            try
            {
                // execute the query
                using (HttpWebResponse res = RESTExec("GET", string.Format("{0}(PartitionKey='{1}',RowKey='{2}')", Table, partitionKey, rowKey)))
                {
                    // load the xml
                    XmlDocument doc = new XmlDocument();
                    doc.Load(res.GetResponseStream());

                    XmlNodeList nodes = doc.GetElementsByTagName("m:properties");

                    // process each row
                    foreach (XmlNode n in nodes)
                    {
                        // process each column
                        foreach (XmlNode n2 in n.ChildNodes)
                        {
                            returnlist.Add(n2.InnerText);
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                RESTHelper.DisplayWebException(ex);
            }
            return(returnlist.ToArray());
        }
コード例 #2
0
        public void DisplayContainerProperties(string Container)
        {
            try
            {
                // create the request
                using (HttpWebResponse response = RESTExec("HEAD", Container))
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string key;

                        Console.WriteLine("Meta Data for Container: " + Container);

                        for (int i = 0; i < response.Headers.Count; i++)
                        {
                            key = response.Headers.Keys[i];
                            if (key.StartsWith("x-ms-meta-"))
                            {
                                Console.WriteLine(key.Substring(10) + ": " + response.Headers[i]);
                            }
                        }

                        Console.WriteLine();
                    }
                }
            }
            catch (WebException ex)
            {
                RESTHelper.DisplayWebException(ex);
            }
        }
コード例 #3
0
        public XmlNodeList GetTable(string Table)
        {
            List <string> returnlist = new List <string>();
            XmlDocument   doc;

            try
            {
                // execute the query
                using (HttpWebResponse res = RESTExec("GET", Table))
                {
                    // load the xml
                    doc = new XmlDocument();
                    doc.Load(res.GetResponseStream());

                    XmlNodeList nodes = doc.GetElementsByTagName("m:properties");

                    return(nodes);
                }
            }
            catch (WebException ex)
            {
                RESTHelper.DisplayWebException(ex);
            }
            //return returnlist.ToArray();
            return(null);
        }
コード例 #4
0
        public void DisplayBlobProperties(string Container, string Blob)
        {
            try
            {
                // create the request
                using (HttpWebResponse response = RESTExec("HEAD", Container + "/" + Blob))
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string key;

                        Debug.Log("Properties for Blob: " + Blob);

                        for (int i = 0; i < response.Headers.Count; i++)
                        {
                            key = response.Headers.Keys[i];
                            if (key.StartsWith("x-ms-meta-"))
                            {
                                Debug.Log(key.Substring(10) + ": " + response.Headers[i]);
                            }
                        }

                        Debug.Log("");
                    }
                }
            }
            catch (WebException ex)
            {
                RESTHelper.DisplayWebException(ex);
            }
        }
コード例 #5
0
 public void SetBlobMetaData(string Container, string Blob, SortedList <string, string> MetadataList)
 {
     try
     {
         HttpWebResponse response = RESTExec("SetBlobMetaData", Container + "/" + Blob, string.Empty, MetadataList);
         response.Close();
     }
     catch (WebException ex)
     {
         RESTHelper.DisplayWebException(ex);
     }
 }
コード例 #6
0
        public string ListBlobs(string container)
        {
            string returnString = "";

            try
            {
                // create the request
                using (HttpWebResponse response = RESTExec("GET", container + "?comp=list"))
                {
                    // load the xml
                    XmlDocument doc = new XmlDocument();
                    doc.Load(response.GetResponseStream());

                    XmlNodeList nodes = doc.GetElementsByTagName("Blob");

                    if (nodes.Count > 0)
                    {
                        // process each row (blob)
                        foreach (XmlNode n in nodes)
                        {
                            // process each column
                            foreach (XmlNode n2 in n.ChildNodes)
                            {
                                if (n2.Name == "Name")
                                {
                                    returnString += n2.InnerText;
                                    returnString += "@";
                                }
                            }
                        }
                    }
                    else
                    {
                        Debug.Log("No Blobs Defined\n");
                    }
                    return(returnString);
                }
            }
            catch (WebException ex)
            {
                RESTHelper.DisplayWebException(ex);
            }

            return(returnString);
        }
コード例 #7
0
        public void ListContainers()
        {
            try
            {
                // create the request
                using (HttpWebResponse response = RESTExec("GET", "?comp=list"))
                {
                    // load the xml
                    XmlDocument doc = new XmlDocument();
                    doc.Load(response.GetResponseStream());

                    XmlNodeList nodes = doc.GetElementsByTagName("Container");

                    if (nodes.Count > 0)
                    {
                        Console.WriteLine("Containers in Account: " + _Account);

                        // process each row
                        foreach (XmlNode n in nodes)
                        {
                            // process the columns
                            foreach (XmlNode n2 in n.ChildNodes)
                            {
                                if (n2.Name == "Name")
                                {
                                    Console.WriteLine(n2.InnerText);
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No Containers Defined\n");
                    }
                }
            }
            catch (WebException ex)
            {
                RESTHelper.DisplayWebException(ex);
            }

            Console.WriteLine();
        }
コード例 #8
0
        private HttpWebResponse RESTExec(string Method, string Resource, string RequestBody, string IfMatch)
        {
            string uri = @"http://" + _Account + ".table.core.windows.net/" + Resource;

            DateTime now = DateTime.UtcNow;

            // setup the web request
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

            request.Method      = Method;
            request.ContentType = "application/atom+xml";
            request.Headers.Add("x-ms-date", now.ToString("R", System.Globalization.CultureInfo.InvariantCulture));

            // Add the authorization header
            request.Headers.Add("Authorization", RESTHelper.SharedKey(_Account, GenSignature(_Account, Method, Resource, now)));

            // Add the If-Match header if needed
            if (!string.IsNullOrEmpty(IfMatch))
            {
                request.Headers.Add("If-Match", IfMatch);
            }

            // Set the request body and content length
            if (string.IsNullOrEmpty(RequestBody))
            {
                request.ContentLength = 0;
            }
            else
            {
                byte[] ba = new ASCIIEncoding().GetBytes(RequestBody);

                request.ContentLength = ba.Length;
                request.GetRequestStream().Write(ba, 0, ba.Length);
                request.GetRequestStream().Close();
            }

            return((HttpWebResponse)request.GetResponse());
        }
コード例 #9
0
 public void ListTables()
 {
     // process the request
     try
     {
         using (HttpWebResponse res = RESTExec("GET", "Tables"))
         {
             // Display the list of tables
             using (XmlReader reader = XmlReader.Create(res.GetResponseStream()))
             {
                 Debug.Log("Tables in Account: " + _Account);
                 while (reader.ReadToFollowing("d:TableName"))
                 {
                     Debug.Log(reader.ReadElementContentAsString());
                 }
             }
         }
     }
     catch (WebException ex)
     {
         RESTHelper.DisplayWebException(ex);
     }
 }
コード例 #10
0
 public TableHelper(string Account)
 {
     _Account = RESTHelper.GetAccount(Account);
 }
コード例 #11
0
 public TableHelper()
 {
     _Account = RESTHelper.GetAccount(string.Empty);
 }
コード例 #12
0
        private HttpWebResponse RESTExec(string Command, string Resource, string RequestBody, SortedList <string, string> MetadataList)
        {
            DateTime now    = DateTime.UtcNow;
            string   Method = Command;

            Command = Command.ToUpper();

            switch (Command)
            {
            case "GETCONTAINERACL":
                Method    = "HEAD";
                Resource += "?comp=acl";
                break;

            case "SETCONTAINERACL":
                Method    = "PUT";
                Resource += "?comp=acl";
                break;

            case "SETCONTAINERMETADATA":
            case "SETBLOBMETADATA":
                Method    = "PUT";
                Resource += "?comp=metadata";
                break;

            default:
                break;
            }

            string uri = @"http://" + _Account + ".blob.core.windows.net/" + Resource;

            // setup the web request
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

            request.Method        = Method;
            request.ContentLength = 0;
            request.Headers.Add("x-ms-date", now.ToString("R", System.Globalization.CultureInfo.InvariantCulture));


            // Add the authorization header
            if ((Command == "SETCONTAINERMETADATA" || Command == "SETBLOBMETADATA") && MetadataList != null)
            {
                for (int i = 0; i < MetadataList.Count; i++)
                {
                    request.Headers.Add("x-ms-meta-" + MetadataList.Keys[i], MetadataList[MetadataList.Keys[i]]);
                }
            }

            else if (Command == "SETCONTAINERACL")
            {
                request.Headers.Add("x-ms-prop-publicaccess", RequestBody);
                RequestBody = string.Empty;
            }

            request.Headers.Add("Authorization", RESTHelper.SharedKey(_Account, GenSignature(Method, Resource, now, request)));

            if (!string.IsNullOrEmpty(RequestBody))
            {
                // Set the request body and content length
                byte[] ba = new ASCIIEncoding().GetBytes(RequestBody);

                request.ContentLength = ba.Length;
                request.GetRequestStream().Write(ba, 0, ba.Length);
                request.GetRequestStream().Close();
            }


            return((HttpWebResponse)request.GetResponse());
        }
コード例 #13
0
 public BlobHelper(string Account)
 {
     _Account = RESTHelper.GetAccount(Account);
 }
コード例 #14
0
 public BlobHelper()
 {
     _Account = RESTHelper.GetAccount(string.Empty);
 }