Permalink
Browse files

added an experimental table insert with type inspection

  • Loading branch information...
1 parent 7e70614 commit d2bc8eaa04146160e3f0b7e63fd84843d26bd737 @richorama committed Nov 7, 2013
@@ -16,7 +16,7 @@ namespace netmfazurestorage
{
public class Program
{
- private const string AccountName = "netmftest";
+ private const string AccountName = "netmftest"; // please upload pictures of cats to this storage account.
private const string AccountKey = "gYU/Nf/ib97kHQrVkxhdD3y0lKz6ZOVaR1FjeDpESecGuqZOEq1TE+5+SXfZ/DBzKsXH3m0NDsLxTbTqQxL9yA==";
private static BlobClient _blobClient;
private static TableClient _tableClient;
@@ -37,6 +37,8 @@ public static void RunTests()
public static void Main()
{
+
+
RunTests();
return;
@@ -110,6 +110,29 @@ public void InsertTableEntity(string tablename, string partitionKey, string rowK
SendWebRequest(StringUtility.Format("http://{0}.table.core.windows.net/{1}", AccountName, tablename), header, payload, contentLength);
}
+ public void InsertTableEntity_Experimental(string tablename, string partitionKey, string rowKey, DateTime timeStamp, Hashtable 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 xml:base=\"http://{0}.table.core.windows.net/\" 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'2008-09-18T23%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>", AccountName, timestamp, partitionKey, rowKey, GetTableXml(tableEntityProperties), tablename);
+
+ int contentLength = 0;
+ byte[] payload = GetBodyBytesAndLength(xml, out contentLength);
+ string header = CreateAuthorizationHeader(payload, ContentType, StringUtility.Format("/{0}/{1}", AccountName, tablename));
+ SendWebRequest(StringUtility.Format("http://{0}.table.core.windows.net/{1}", AccountName, tablename), header, payload, contentLength);
+ }
+
private string GetTableXml(ArrayList tableEntityProperties)
{
string result=string.Empty;
@@ -126,6 +149,28 @@ private string GetTableXml(ArrayList tableEntityProperties)
return result;
}
+ private static string GetTableXml(Hashtable tableEntityProperties)
+ {
+ string result = string.Empty;
+ foreach (var key in tableEntityProperties.Keys)
+ {
+ var value = tableEntityProperties[key];
+ if (value == null) continue;
+ var type = value.GetType().Name;
+ switch (type)
+ {
+ case "DateTime":
+ value = ((DateTime)value).ToString("yyyy-MM-ddTHH:mm:ss.0000000Z");
+ break;
+ case "Boolean":
+ value = (Boolean) value ? "true" : "false"; // bool is title case when you call ToString()
+ break;
+ }
+ result += StringUtility.Format("<d:{0} m:type=\"Edm.{2}\">{1}</d:{0}>", key, value, type);
+ }
+ return result;
+ }
+
#region Request Handling
//DataServiceVersion: Set the value of this header to 1.0;NetFx.
@@ -1,5 +1,6 @@
using System;
using netmfazurestorage.Table;
+using System.Collections;
namespace netmfazurestorage.Tests
{
@@ -17,6 +18,7 @@ public void Run()
this.TestCreate();
this.TestInsert();
this.TestInsertDouble();
+ this.TestInsertExperimental();
}
private void TestCreate()
@@ -70,5 +72,18 @@ public void TestInsertDouble()
}
+ public void TestInsertExperimental()
+ {
+ var values = new Hashtable();
+ values.Add("guidfield", Guid.NewGuid());
+ values.Add("int32field", 32);
+ values.Add("stringfield", "string");
+ //values.Add("datetimefield", DateTime.Now);
+ values.Add("doublefield", (double)123.22);
+ values.Add("int64field", (Int64)64);
+ values.Add("boolfield", true);
+ this.client.InsertTableEntity_Experimental("netmftest", "2", Guid.NewGuid().ToString(), DateTime.Now, values);
+ }
+
}
}
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual C# Express 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "netmfazurestorage", "netmfazurestorage.csproj", "{1662719F-BF15-4E0A-B4FA-86F29D4B078D}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {1662719F-BF15-4E0A-B4FA-86F29D4B078D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1662719F-BF15-4E0A-B4FA-86F29D4B078D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1662719F-BF15-4E0A-B4FA-86F29D4B078D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {1662719F-BF15-4E0A-B4FA-86F29D4B078D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1662719F-BF15-4E0A-B4FA-86F29D4B078D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1662719F-BF15-4E0A-B4FA-86F29D4B078D}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Binary file not shown.

0 comments on commit d2bc8ea

Please sign in to comment.