Created
January 30, 2014 06:52
-
-
Save takekazuomi/8703802 to your computer and use it in GitHub Desktop.
Dump Azure Table in JSON format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
using System.IO; | |
using System.Net; | |
using System.Text; | |
using Microsoft.WindowsAzure.Storage; | |
using Microsoft.WindowsAzure.Storage.Auth.Protocol; | |
using Microsoft.WindowsAzure.Storage.Core; | |
using Microsoft.WindowsAzure.Storage.Core.Auth; | |
namespace TableDumpJson | |
{ | |
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var acct = CloudStorageAccount.DevelopmentStorageAccount; | |
// var account = CloudStorageAccount.Parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://ipv4.fiddler"); | |
var tableClient = account.CreateCloudTableClient(); | |
var table = tableClient.GetTableReference("TestTable"); | |
var context = new OperationContext(); | |
var uri = table.StorageUri.PrimaryUri; | |
var builder = new UriQueryBuilder(); | |
var request = OreOreWebRequestFactory(uri, builder, 90); | |
var canonicalizer = SharedKeyTableCanonicalizer.Instance; | |
var skh = new SharedKeyAuthenticationHandler(canonicalizer, account.Credentials, account.Credentials.AccountName); | |
skh.SignRequest(request, context); | |
var response = request.GetResponse().GetResponseStream(); | |
if (response != null) | |
Console.WriteLine(new StreamReader(response, Encoding.UTF8).ReadToEnd()); | |
} | |
static HttpWebRequest OreOreWebRequestFactory(Uri uri, UriQueryBuilder builder, int? timeout) | |
{ | |
if (builder == null) | |
builder = new UriQueryBuilder(); | |
if (timeout.HasValue && timeout.Value > 0) | |
builder.Add("timeout", timeout.Value.ToString(CultureInfo.InvariantCulture)); | |
var uriRequest = builder.AddToUri(uri); | |
var request = (HttpWebRequest)WebRequest.Create(uriRequest); | |
request.Method = "GET"; | |
request.ContentLength = 0; | |
request.UserAgent = "oreore client 0.1"; | |
request.Headers["x-ms-version"] = "2013-08-15"; | |
request.Headers["Accept-Charset"] = Encoding.UTF8.WebName; | |
request.Headers["MaxDataServiceVersion"] = "3.0;NetFx"; | |
request.Accept = "application/json;odata=nometadata"; | |
request.KeepAlive = true; | |
request.ServicePoint.Expect100Continue = false; | |
return request; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment