示例#1
0
        public void CreateQueue(string queueName)
        {
            //PUT https://myaccount.queue.core.windows.net/myqueue HTTP/1.1
            var    url  = StringUtility.Format("{0}/{1}", _account.UriEndpoints["Queue"], queueName);
            string can  = StringUtility.Format("/{0}/{1}", _account.AccountName, queueName);
            var    auth = CreateAuthorizationHeader(can, "", 0, true, "PUT");

            AzureStorageHttpHelper.SendWebRequest(url, auth, DateHeader, VersionHeader, fileBytes: null, contentLength: 0, httpVerb: "PUT");
        }
        public HttpStatusCode InsertTableEntity(string tablename, string partitionKey, string rowKey, DateTime timeStamp, Hashtable tableEntityProperties)
        {
            var xml           = FormatEntityXml(tablename, partitionKey, rowKey, timeStamp, tableEntityProperties);
            var contentLength = 0;
            var payload       = GetBodyBytesAndLength(xml, out contentLength);
            var header        = CreateAuthorizationHeader(payload, StringUtility.Format("/{0}/{1}", _account.AccountName, tablename));

            return(AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("{0}/{1}", _account.UriEndpoints["Table"], tablename), header, DateHeader, VersionHeader, payload, contentLength, "POST", false, this.additionalHeaders).StatusCode);
        }
示例#3
0
        public void DeleteQueue(string queueName)
        {
            //DELETE https://myaccount.queue.core.windows.net/myqueue HTTP/1.1
            var    url  = StringUtility.Format("{0}/{1}", _account.UriEndpoints["Queue"], queueName);
            string can  = StringUtility.Format("/{0}/{1}", _account.AccountName, queueName);
            var    auth = CreateAuthorizationHeader(can, "", 0, true, "DELETE");

            AzureStorageHttpHelper.SendWebRequest(url, auth, DateHeader, VersionHeader, null, 0, "DELETE");
        }
示例#4
0
        public bool PutBlockBlob(string containerName, string blobName, string fileNamePath)
        {
            try
            {
                string deploymentPath =
                    StringUtility.Format("{0}/{1}/{2}", _account.UriEndpoints["Blob"], containerName,
                                         blobName);
                int contentLength;

                HttpVerb = "PUT";

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

                string canResource = StringUtility.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(deploymentPath, authHeader, DateHeader, 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);
            }

            return(true);
        }
        public Hashtable QueryTable(string tablename, string partitionKey, string rowKey)
        {
            var header   = CreateAuthorizationHeader(null, StringUtility.Format("/{0}/{1}(PartitionKey='{2}',RowKey='{3}')", _account.AccountName, tablename, partitionKey, rowKey));
            var response = AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("{0}/{1}(PartitionKey='{2}',RowKey='{3}')", _account.UriEndpoints["Table"], tablename, partitionKey, rowKey), header, DateHeader, VersionHeader, null, 0, "GET", false, this.additionalHeaders);
            var entities = ParseResponse(response.Body);

            if (entities.Count == 1)
            {
                return(entities[0] as Hashtable);
            }
            return(null);
        }
        public HttpStatusCode DeleteTableEntity(string tablename, string partitionKey, string rowKey)
        {
            var       header  = CreateAuthorizationHeader(null, StringUtility.Format("/{0}/{1}(PartitionKey='{2}',RowKey='{3}')", _account.AccountName, tablename, partitionKey, rowKey));
            Hashtable headers = new Hashtable();

            foreach (var key in this.additionalHeaders.Keys)
            {
                headers.Add(key, this.additionalHeaders[key]);
            }
            headers.Add("If-Match", "*");
            return(AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("{0}/{1}(PartitionKey='{2}',RowKey='{3}')", _account.UriEndpoints["Table"], tablename, partitionKey, rowKey), header, DateHeader, VersionHeader, null, 0, "DELETE", false, headers).StatusCode);
        }
示例#7
0
        public void DeleteMessage(string queueName, string messageId, string popReceipt)
        {
            // DELETE http://myaccount.queue.core.windows.net/myqueue/messages/messageid?popreceipt=string-value
            string can = StringUtility.Format("/{0}/{3}/messages/{2}\npopreceipt:{1}", _account.AccountName, popReceipt,
                                              messageId, queueName);
            string auth = CreateAuthorizationHeader(can, "", 0, true, "DELETE");
            string url  =
                StringUtility.Format("{0}/{3}/messages/{2}?popreceipt={1}",
                                     _account.UriEndpoints["Queue"], popReceipt, messageId, queueName);

            AzureStorageHttpHelper.SendWebRequest(url, auth, DateHeader, VersionHeader, null, 0, "DELETE");
        }
示例#8
0
        public void CreateQueueMessage(string queueName, string message)
        {
            // POST http://myaccount.queue.core.windows.net/netmfdata/messages?visibilitytimeout=<int-seconds>&messagettl=<int-seconds>
            int    length     = 0;
            string messageXml = StringUtility.Format("<QueueMessage><MessageText>{0}</MessageText></QueueMessage>",
                                                     Convert.ToBase64String(Encoding.UTF8.GetBytes(message)));

            byte[] content = GetXmlBytesAndLength(messageXml, out length);
            string can     = StringUtility.Format("/{0}/{1}/messages", _account.AccountName, queueName);
            string auth    = CreateAuthorizationHeader(can, "", length, false, "POST");
            string url     = StringUtility.Format("{0}/{1}/messages", _account.UriEndpoints["Queue"], queueName);

            AzureStorageHttpHelper.SendWebRequest(url, auth, DateHeader, VersionHeader, content, length, "POST");
        }
        public ArrayList QueryTable(string tablename, string query)
        {
            if (query.IsNullOrEmpty())
            {
                query = "";
            }
            else
            {
                query = "$filter=" + query.Replace(" ", "%20");
            }
            var header   = CreateAuthorizationHeader(null, StringUtility.Format("/{0}/{1}()", _account.AccountName, tablename));
            var response = AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("{0}/{1}()?{2}", _account.UriEndpoints["Table"], tablename, query), header, DateHeader, VersionHeader, null, 0, "GET", false, this.additionalHeaders);

            return(ParseResponse(response.Body));
        }
示例#10
0
        public bool DeleteContainer(string containerName)
        {
            try
            {
                string deploymentPath =
                    StringUtility.Format("{0}/{1}?{2}", _account.UriEndpoints["Blob"], containerName, ContainerString);

                HttpVerb = "DELETE";

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

                string authHeader = CreateAuthorizationHeader(canResource);

                try
                {
                    var response = AzureStorageHttpHelper.SendWebRequest(deploymentPath, authHeader, DateHeader, 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);
            }
        }
示例#11
0
        public BasicHttpResponse CreateTable(string tableName)
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" +
                         "<entry xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\"  " +
                         "xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" " +
                         "xmlns=\"http://www.w3.org/2005/Atom\"> " +
                         "<id>http://" + _account.AccountName + ".table.core.windows.net/Tables('"
                         + tableName +
                         "')</id>" +
                         "<title />" +
                         "<updated>" + InstanceDate.ToString("yyyy-MM-ddTHH:mm:ss.0000000Z") + "</updated>" +
                         "<author><name/></author> " +
                         "<content type=\"application/xml\"><m:properties><d:TableName>" + tableName + "</d:TableName></m:properties></content></entry>";

            int contentLength = 0;

            byte[] payload = GetBodyBytesAndLength(xml, out contentLength);
            string header  = CreateAuthorizationHeader(payload, "/" + _account.AccountName + "/Tables()");

            return(AzureStorageHttpHelper.SendWebRequest(_account.UriEndpoints["Table"] + "/Tables()", header, DateHeader, VersionHeader, payload, contentLength, "POST", false, this.additionalHeaders));
        }
示例#12
0
        public BasicHttpResponse InsertTableEntity(string tablename, string partitionKey, string rowKey, DateTime timeStamp, System.Collections.ArrayList tableEntityProperties)
        {
            var timestamp = timeStamp.ToString("yyyy-MM-ddTHH:mm:ss.0000000Z");

            string xml =
                StringUtility.Format("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><entry xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" m:etag=\"W/&quot;datetime'2013-11-11T18%3A46%3A19.4277424Z'&quot;\" xmlns=\"http://www.w3.org/2005/Atom\">" +
                                     "<id>http://{0}.table.core.windows.net/{5}(PartitionKey='{2}',RowKey='{3}')</id>" +
                                     "<title/><updated>{1}</updated><author><name /></author>" +
                                     "<link />" +
                                     //"<category term=\"{0}.Tables\" scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\" />" +
                                     "<content type=\"application/xml\"><m:properties><d:PartitionKey>{2}</d:PartitionKey><d:RowKey>{3}</d:RowKey>" +
                                     "<d:Timestamp m:type=\"Edm.DateTime\">{1}</d:Timestamp>" +
                                     "{4}" +
                                     "</m:properties>" +
                                     "</content>" +
                                     "</entry>", _account.AccountName, timestamp, partitionKey, rowKey, GetTableXml(tableEntityProperties), tablename);

            int contentLength = 0;

            byte[] payload = GetBodyBytesAndLength(xml, out contentLength);
            string header  = CreateAuthorizationHeader(payload, StringUtility.Format("/{0}/{1}", _account.AccountName, tablename));

            return(AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("{0}/{1}", _account.UriEndpoints["Table"], tablename), header, DateHeader, VersionHeader, payload, contentLength, "POST", false, this.additionalHeaders));
        }
示例#13
0
        public QueueMessageWrapper RetrieveQueueMessage(string queueName, bool peekOnly)
        {
            string can = StringUtility.Format("/{0}/{1}/messages", _account.AccountName, queueName);
            string url = StringUtility.Format("{0}/{1}/messages", _account.UriEndpoints["Queue"], queueName);

            if (peekOnly)
            {
                url += "?peekonly=true";
                can += "\npeekonly:true";
            }
            string auth = CreateAuthorizationHeader(can, "", 0, true);

            var response = AzureStorageHttpHelper.SendWebRequest(url, auth, DateHeader, VersionHeader);

            if (response.Body == null)
            {
                return(null);
            }

            string retMessage = GetNodeValue(response.Body, "MessageText");
            string messageId  = GetNodeValue(response.Body, "MessageId");

            string popReceipt = string.Empty;//this will remain empty if we are peeking

            if (!peekOnly)
            {
                popReceipt = GetNodeValue(response.Body, "PopReceipt");
            }

            string decoded = new string(Encoding.UTF8.GetChars(Convert.FromBase64String(retMessage)));

            return(new QueueMessageWrapper()
            {
                Message = decoded, PopReceipt = popReceipt, MessageId = messageId
            });
        }