Exemplo n.º 1
0
        public async Task MoveStudyRoomVideoAsync(string assetName, IBinder binder, CancellationToken token)
        {
            var name        = assetName.Replace(AssetType.StudyRoom.ToString(), string.Empty).Trim('-').Split(StudyRoomFunctionBlobScan.Separator);
            var studyRoomId = name[0];
            var sessionId   = name[1];



            //binder.BindAsync<CloudBlob>(new BlobAttribute(""))
            var assetContainer = await binder.BindAsync <CloudBlobContainer>(new BlobAttribute(assetName), token);

            var blobs = await assetContainer.ListBlobsSegmentedAsync(null);

            var blobItem = blobs.Results.SingleOrDefault(w => w.Uri.AbsoluteUri.EndsWith("mp4"));

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


                var destinationBlob = await binder.BindAsync <CloudBlockBlob>(
                    new BlobAttribute(
                        $"{StorageContainer.StudyRoom.Name}/{StorageContainer.StudyRoom.RelativePath}/{studyRoomId}/{studyRoomId}_{sessionId}.mp4"),
                    token);

                destinationBlob.Metadata[StudyRoomFunctionBlobScan.MetaEncodingKey] = "Finish";

                await destinationBlob.StartCopyAsync(url);

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

                    await destinationBlob.ExistsAsync();
                }
            }

            await _videoService.DeleteAssetAsync(assetName, token);
        }