コード例 #1
0
        public static async Task<bool> UploadPictureToCloud(PictureViewModel pictureViewModel, byte[] image)
        {

            try
            {
                var blockBlobClient = App.account.CreateCloudBlobClient();
                var contianer = blockBlobClient.GetContainerReference(App.contianerName);
                await contianer.CreateIfNotExistsAsync();
                string blobReference = Guid.NewGuid().ToString();
                CloudBlockBlob picture = contianer.GetBlockBlobReference(blobReference);

                await picture.UploadFromByteArrayAsync(image, 0, image.Length);
                //await picture.UploadFromStreamAsync(image);

                pictureViewModel.PictureUrl = picture.Uri.ToString();

                var tableClient = App.account.CreateCloudTableClient();
                var table = tableClient.GetTableReference(App.tableName);
                await table.CreateIfNotExistsAsync();

                var operation = TableOperation.Insert(pictureViewModel.PictureTableEntity);
                await table.ExecuteAsync(operation);

                return true;
            }
            catch (Exception)
            {
                throw;
            }

        }
コード例 #2
0
 internal void AddImage(PictureViewModel uploadForm)
 {
     allImages.Add(uploadForm);
 }
コード例 #3
0
        public async Task<bool> DeletePictureFormCloud(PictureViewModel pictureViewModel)
        {
            try
            {
                var blob = new CloudBlockBlob(new Uri(pictureViewModel.PictureUrl), App.credentials);
                await blob.DeleteAsync();

                var tableClient = App.account.CreateCloudTableClient();
                var table = tableClient.GetTableReference(App.tableName);

                var operation = TableOperation.Delete(pictureViewModel.PictureTableEntity);
                await table.ExecuteAsync(operation);

                allImages.Remove(pictureViewModel);
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #4
0
 public async Task<MemoryStream> DownloadPictureFromCloud(PictureViewModel pictureViewModel)
 {
     try
     {
         var blob = new CloudBlockBlob(new Uri(pictureViewModel.PictureUrl), App.credentials);
         var ims = new MemoryStream();
         await blob.DownloadToStreamAsync(ims);
         return ims;
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #5
0
 private async void AddToAzureSaveList(int camNum, byte[] image)
 {
     //Remember byte[] to upload more cam pics in the future
     var uploadForm = new PictureViewModel();
     uploadForm.Name = camNum.ToString();
     uploadForm.PictureFile = image;
     _pictureDataSource.AddImage(uploadForm);
 }