Exemplo n.º 1
0
        public async Task MoveImageAsync(long id, IBinder binder, CancellationToken token)
        {
            var containerName = await _videoService.GetAssetContainerAsync(id, AssetType.Thumbnail, token);

            if (containerName == null)
            {
                return;
            }
            var container = await binder.BindAsync <CloudBlobContainer>(new BlobAttribute(containerName), token);

            if (await container.ExistsAsync())
            {
                var blobs = await container.ListBlobsSegmentedAsync(MediaServices.PrefixThumbnailBlobName, null);

                var blob = (CloudBlockBlob)blobs.Results.SingleOrDefault();
                if (!(blob is null))
                {
                    var url = blob.GetDownloadLink(TimeSpan.FromHours(1));

                    var destinationBlob = await binder.BindAsync <CloudBlockBlob>(
                        new BlobAttribute(
                            $"{StorageContainer.File.Name}/{StorageContainer.File.RelativePath}/{id}/preview-0.jpg"),
                        token);


                    await destinationBlob.StartCopyAsync(url);

                    while (destinationBlob.CopyState.Status != CopyStatus.Success)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(0.2), token);

                        await destinationBlob.ExistsAsync();
                    }
                }

                await _videoService.DeleteImageAssetAsync(id, token);
            }
        }