Esempio n. 1
0
        //public static AzureDataLoader Create(string connectionStr)
        //{
        //    var acct = new CloudStorageAccount(connectionStr, true);
        //    return new AzureDataLoader(acct);
        //}
        public void SavePost(PostSummary post, string postBody)
        {
            var tableClient = _acct.CreateCloudTableClient();

            CloudTable table = tableClient.GetTableReference(POST_TABLE);
            var insertOperation = TableOperation.InsertOrReplace(post);
            table.Execute(insertOperation);

            CloudTable tagTable = tableClient.GetTableReference(TAG_TABLE);
            var tagBatch = new TableBatchOperation();

            foreach(var tagName in post.Tags.Split(','))
            {
                var tag = new TagIndex(tagName, post.Partition, post.ID);
                var tagInsert = TableOperation.InsertOrReplace(tag);
                tagTable.Execute(tagInsert);
            }

            var blobClient = _acct.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(POST_CONTAINER);
            var blockName = string.Format("{0}/{1}.html", post.PartitionKey, post.RowKey);
            var blob = container.GetBlockBlobReference(blockName);
            blob.UploadText(postBody, Encoding.UTF8);
        }