コード例 #1
0
        public IHttpActionResult GetMP3(string id)
        {
            // Create a retrieve operation that takes a mp3 entity.
            TableOperation getOperation = TableOperation.Retrieve <MP3Entity>(partitionName, id);

            // Execute the retrieve operation.
            TableResult getOperationResult = table.Execute(getOperation);

            // Construct response including a new DTO as apprporiatte
            if (getOperationResult.Result == null)
            {
                return(NotFound());
            }
            else
            {
                MP3Entity mp3Entity = (MP3Entity)getOperationResult.Result;
                MP3       p         = new MP3()
                {
                    MP3ID   = mp3Entity.RowKey,
                    Artist  = mp3Entity.Artist,
                    MP3Blob = mp3Entity.MP3Blob,
                    Title   = mp3Entity.Title
                };
                return(Ok(p));
            }
        }
コード例 #2
0
        public IHttpActionResult PutMP3(string id, MP3 mp3)
        {
            if (id != mp3.MP3ID)
            {
                return(BadRequest());
            }

            // Create a retrieve operation that takes a mp3 entity.
            TableOperation retrieveOperation = TableOperation.Retrieve <MP3Entity>(partitionName, id);

            // Execute the operation.
            TableResult retrievedResult = table.Execute(retrieveOperation);

            // Assign the result to a MP3Entity object.
            MP3Entity updateEntity = (MP3Entity)retrievedResult.Result;

            updateEntity.Artist  = mp3.Artist;
            updateEntity.MP3Blob = mp3.MP3Blob;
            updateEntity.Title   = mp3.Title;

            // Create the TableOperation that inserts the mp3 entity.
            // Note semantics of InsertOrReplace() which are consistent with PUT
            // See: https://stackoverflow.com/questions/14685907/difference-between-insert-or-merge-entity-and-insert-or-replace-entity
            var updateOperation = TableOperation.InsertOrReplace(updateEntity);

            // Execute the insert operation.
            table.Execute(updateOperation);

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public static void go()
        {
            const String partitionName = "MP3s_Partition_1";

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString());

            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            CloudTable table = tableClient.GetTableReference("MP3s");

            // If table doesn't already exist in storage then create and populate it with some initial values, otherwise do nothing
            if (!table.Exists())
            {
                // Create table if it doesn't exist already
                table.CreateIfNotExists();

                // Create the batch operation.
                TableBatchOperation batchOperation = new TableBatchOperation();

                // Create a mp3 entity and add it to the table.
                MP3Entity mp3Obj1 = new MP3Entity(partitionName, "1");
                mp3Obj1.Artist  = "Bob Marley";
                mp3Obj1.Title   = "Widget";
                mp3Obj1.MP3Blob = "BlobFor11";

                // Create another mp3 entity and add it to the table.
                MP3Entity mp3Obj2 = new MP3Entity(partitionName, "2");
                mp3Obj2.Artist  = "Santana";
                mp3Obj2.Title   = "Material";
                mp3Obj2.MP3Blob = "BlobFor22";

                // Create another mp3 entity and add it to the table.
                MP3Entity mp3Obj3 = new MP3Entity(partitionName, "3");
                mp3Obj3.Artist  = "Thingy";
                mp3Obj3.Title   = "Widget";
                mp3Obj3.MP3Blob = "BlobFor33";

                // Create another mp3 entity and add it to the table.
                MP3Entity mp3Obj4 = new MP3Entity(partitionName, "4");
                mp3Obj4.Artist  = "Skepta";
                mp3Obj4.Title   = "Material";
                mp3Obj4.MP3Blob = "BlobFor4";

                // Add mp3 entities to the batch insert operation.
                batchOperation.Insert(mp3Obj1);
                batchOperation.Insert(mp3Obj2);
                batchOperation.Insert(mp3Obj3);
                batchOperation.Insert(mp3Obj4);

                // Execute the batch operation.
                table.ExecuteBatch(batchOperation);
            }
        }
コード例 #4
0
        public IHttpActionResult PostMP3(MP3 mp3)
        {
            MP3Entity mp3Entity = new MP3Entity()
            {
                RowKey       = getNewMaxRowKeyValue(),
                PartitionKey = partitionName,
                Artist       = mp3.Artist,
                MP3Blob      = mp3.MP3Blob,
                Title        = mp3.Title
            };

            // Create the TableOperation that inserts the mp3 entity.
            var insertOperation = TableOperation.Insert(mp3Entity);

            // Execute the insert operation.
            table.Execute(insertOperation);

            return(CreatedAtRoute("DefaultApi", new { id = mp3Entity.RowKey }, mp3Entity));
        }
コード例 #5
0
        public IHttpActionResult DeleteMP3(string id)
        {
            // Create a retrieve operation that takes a mp3 entity.
            TableOperation retrieveOperation = TableOperation.Retrieve <MP3Entity>(partitionName, id);

            // Execute the retrieve operation.
            TableResult retrievedResult = table.Execute(retrieveOperation);

            if (retrievedResult.Result == null)
            {
                return(NotFound());
            }
            else
            {
                MP3Entity      deleteEntity    = (MP3Entity)retrievedResult.Result;
                TableOperation deleteOperation = TableOperation.Delete(deleteEntity);

                // Execute the operation.
                table.Execute(deleteOperation);

                return(Ok(retrievedResult.Result));
            }
        }