コード例 #1
0
        public async Task <string> Post(string table, string partitionKey, TableEntry entry)
        {
            var ms  = new MemoryStream();
            var doc = CreateEntryXML(partitionKey, entry.RowKey, entry.Properties);

            doc.Save(ms, SaveOptions.DisableFormatting);
            ms.Seek(0, SeekOrigin.Begin);
            var content = new StreamContent(ms);

            content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/atom+xml");
            var uri  = string.Format(@"http://{0}.table.core.windows.net/{1}{2}", StorageAccount, table, SAS);
            var resp = await Cli.PostAsync(uri, content);

            return(await resp.Content.ReadAsStringAsync());
        }
コード例 #2
0
        public async Task <string> PostMultipart(string table, string partitionKey, IEnumerable <TableEntry> entries)
        {
            var batchId     = Guid.NewGuid().ToString();
            var changeSetId = Guid.NewGuid().ToString();
            var tableUri    = string.Format(@"http://{0}.table.core.windows.net/{1}", StorageAccount, table);
            var entryPrefix = "\n--changeset_" + changeSetId +
                              "\nContent-Type: application/http" +
                              "\nContent-Transfer-Encoding: binary" +
                              "\n\nPOST " + tableUri + " HTTP/1.1" +
                              "\nContent-Type: application/atom+xml;type=entry;charset=utf-8\n";

            var stream = new MemoryStream();
            var writer = new StreamWriter(stream);

            writer.WriteLine("--batch_" + batchId +
                             "\nContent-Type: multipart/mixed; boundary=changeset_" + changeSetId);
            foreach (var doc in entries.Select(x => CreateEntryXML(partitionKey, x.RowKey, x.Properties)))
            {
                writer.WriteLine(entryPrefix);
                writer.Flush();
                doc.Save(stream, SaveOptions.DisableFormatting);
            }
            writer.WriteLine("\n--changeset_" + changeSetId + "--" +
                             "\n--batch_" + batchId + "--");
            writer.Flush();
            stream.Seek(0, SeekOrigin.Begin);
            var content = new StreamContent(stream);

            content.Headers.Add("x-ms-version", "2009-04-14");
            content.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/mixed; boundary=batch_" + batchId);

            var uri  = string.Format(@"http://{0}.table.core.windows.net/$batch{1}", StorageAccount, SAS);
            var resp = await Cli.PostAsync(uri, content);

            return(await resp.Content.ReadAsStringAsync());
        }