Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed table code after Andy broke it
  • Loading branch information
richorama committed Nov 11, 2013
1 parent 4916229 commit e15b136
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion netmfazurestorage/Http/AzureStorageHttpHelper.cs
Expand Up @@ -76,7 +76,7 @@ public static BasicHttpResponse SendWebRequest(string url, string authHeader, st
/// <param name="contentLength"></param>
/// <param name="httpVerb"></param>
/// <returns></returns>
private static HttpWebRequest PrepareRequest(string url, string authHeader, string dateHeader, string versionHeader, byte[] fileBytes = null, int contentLength = 0, string httpVerb = "GET", bool expect100Continue = false, Hashtable additionalHeaders = null)
private static HttpWebRequest PrepareRequest(string url, string authHeader, string dateHeader, string versionHeader, byte[] fileBytes , int contentLength, string httpVerb, bool expect100Continue = false, Hashtable additionalHeaders = null)
{
var uri = new Uri(url);
var request = (HttpWebRequest)WebRequest.Create(uri);
Expand Down
7 changes: 1 addition & 6 deletions netmfazurestorage/Queue/QueueClient.cs
Expand Up @@ -6,17 +6,12 @@
using Microsoft.SPOT;
using NetMf.CommonExtensions;
using netmfazurestorage.Http;
using System.Collections;

namespace netmfazurestorage.Queue
{
public class QueueClient
{
#region private members

private string _httpVerb = "PUT";

#endregion

#region constants

internal const string HttpVerbPut = "PUT";
Expand Down
36 changes: 18 additions & 18 deletions netmfazurestorage/Table/TableClient.cs
Expand Up @@ -17,20 +17,16 @@ public class TableClient
public static string AccountKey;
public static bool AttachFiddler;

#region constants


internal const string VersionHeader = "2011-08-18";
internal const string ContentType = "application/atom+xml";
private string DateHeader { get; set; }

#endregion

#region Properties
private Hashtable additionalHeaders;

internal DateTime InstanceDate { get; set; }

#endregion


protected byte[] GetBodyBytesAndLength(string body, out int contentLength)
{
var content = Encoding.UTF8.GetBytes(body);
Expand All @@ -44,6 +40,10 @@ public TableClient(string accountName, string accountKey)
AccountName = accountName;
AccountKey = accountKey;
DateHeader = DateTime.UtcNow.ToString("R");
additionalHeaders = new Hashtable();
additionalHeaders.Add("DataServiceVersion", "1.0;NetFx");
additionalHeaders.Add("MaxDataServiceVersion", "1.0;NetFx");
additionalHeaders.Add("Content-Type", ContentType);
}

public void CreateTable(string tableName)
Expand All @@ -62,8 +62,8 @@ public void CreateTable(string tableName)

int contentLength = 0;
byte[] payload = GetBodyBytesAndLength(xml, out contentLength);
string header = CreateAuthorizationHeader(payload, ContentType, "/" + AccountName + "/Tables()");
AzureStorageHttpHelper.SendWebRequest("http://" + AccountName + ".table.core.windows.net/Tables()", header, DateHeader, VersionHeader, payload, contentLength);
string header = CreateAuthorizationHeader(payload, "/" + AccountName + "/Tables()");
AzureStorageHttpHelper.SendWebRequest("http://" + AccountName + ".table.core.windows.net/Tables()", header, DateHeader, VersionHeader, payload, contentLength, "POST", false, this.additionalHeaders);
}

[Obsolete("Please use the InsertTableEntity method; this AddTableEntityForTemperature method will be removed in a future release.", false)]
Expand All @@ -87,8 +87,8 @@ public void AddTableEntityForTemperature(string tablename, string partitionKey,

int contentLength = 0;
byte[] payload = GetBodyBytesAndLength(xml, out contentLength);
string header = CreateAuthorizationHeader(payload, ContentType, StringUtility.Format("/{0}/{1}", AccountName, tablename));
AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("http://{0}.table.core.windows.net/{1}", AccountName, tablename), header, DateHeader, VersionHeader, payload, contentLength);
string header = CreateAuthorizationHeader(payload, StringUtility.Format("/{0}/{1}", AccountName, tablename));
AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("http://{0}.table.core.windows.net/{1}", AccountName, tablename), header, DateHeader, VersionHeader, payload, contentLength, "GET", false, this.additionalHeaders);
}

public void InsertTableEntity(string tablename, string partitionKey, string rowKey, DateTime timeStamp, System.Collections.ArrayList tableEntityProperties)
Expand All @@ -110,8 +110,8 @@ public void InsertTableEntity(string tablename, string partitionKey, string rowK

int contentLength = 0;
byte[] payload = GetBodyBytesAndLength(xml, out contentLength);
string header = CreateAuthorizationHeader(payload, ContentType, StringUtility.Format("/{0}/{1}", AccountName, tablename));
AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("http://{0}.table.core.windows.net/{1}", AccountName, tablename), header, DateHeader, VersionHeader, payload, contentLength);
string header = CreateAuthorizationHeader(payload, StringUtility.Format("/{0}/{1}", AccountName, tablename));
AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("http://{0}.table.core.windows.net/{1}", AccountName, tablename), header, DateHeader, VersionHeader, payload, contentLength, "POST", false, this.additionalHeaders);
}

public void InsertTableEntity_Experimental(string tablename, string partitionKey, string rowKey, DateTime timeStamp, Hashtable tableEntityProperties)
Expand All @@ -133,8 +133,8 @@ public void InsertTableEntity_Experimental(string tablename, string partitionKey

int contentLength = 0;
byte[] payload = GetBodyBytesAndLength(xml, out contentLength);
string header = CreateAuthorizationHeader(payload, ContentType, StringUtility.Format("/{0}/{1}", AccountName, tablename));
AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("http://{0}.table.core.windows.net/{1}", AccountName, tablename), header, DateHeader, VersionHeader, payload, contentLength);
string header = CreateAuthorizationHeader(payload, StringUtility.Format("/{0}/{1}", AccountName, tablename));
AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("http://{0}.table.core.windows.net/{1}", AccountName, tablename), header, DateHeader, VersionHeader, payload, contentLength, "POST", false, this.additionalHeaders);
}

private string GetTableXml(ArrayList tableEntityProperties)
Expand Down Expand Up @@ -177,8 +177,8 @@ private static string GetTableXml(Hashtable tableEntityProperties)

public Hashtable QueryTable(string tablename, string partitionKey, string rowKey)
{
var header = CreateAuthorizationHeader(null, ContentType, StringUtility.Format("/{0}/{1}(PartitionKey='{2}',RowKey='{3}')", AccountName, tablename, partitionKey, rowKey));
var xml = AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("http://{0}.table.core.windows.net/{1}(PartitionKey='{2}',RowKey='{3}')", AccountName, tablename, partitionKey, rowKey), header, DateHeader, VersionHeader, null, 0, "GET");
var header = CreateAuthorizationHeader(null, StringUtility.Format("/{0}/{1}(PartitionKey='{2}',RowKey='{3}')", AccountName, tablename, partitionKey, rowKey));
var xml = AzureStorageHttpHelper.SendWebRequest(StringUtility.Format("http://{0}.table.core.windows.net/{1}(PartitionKey='{2}',RowKey='{3}')", AccountName, tablename, partitionKey, rowKey), header, DateHeader, VersionHeader, null, 0, "GET", false, this.additionalHeaders);
string token = null;
Hashtable results = null;
var nextStart = 0;
Expand Down Expand Up @@ -258,7 +258,7 @@ private string NextToken(string xml, string startToken, string endToken, int sta
Date + "\n" +
CanonicalizedResource;*/
// Signature=Base64(HMAC-SHA256(UTF8(StringToSign)))
protected string CreateAuthorizationHeader(byte[] content, string contentType, string canonicalResource)
protected string CreateAuthorizationHeader(byte[] content, string canonicalResource)
{
//string toSign = String.Format("{0}\n{1}\n{2}\n{3}\n{4}",
// HttpVerb, hash, contentType, InstanceDate, canonicalResource);
Expand Down
Binary file not shown.
Binary file modified netmfazurestorage/obj/Debug/TinyCLR_DebugReferences.cache
Binary file not shown.

0 comments on commit e15b136

Please sign in to comment.