Beispiel #1
0
        public async Task FinishEncodeJobAsync(string jobName, int contentId, string newFilename, CancellationToken cancellationToken)
        {
            var job = await _client.Jobs.GetAsync(_settings.ResourceGroup, _settings.AccountName, _settings.MediaServicesTransform, jobName);

            if (job == null)
            {
                throw new InvalidOperationException($"No job with id {jobName} was found");
            }
            var encoded     = _storage.GetContentContainer(contentId).GetContentBlob(newFilename);
            var firstOutput = job.Outputs.FirstOrDefault() as JobOutputAsset;

            if (job.State == JobState.Error)
            {
                // TODO Look at old code, was it better messages?
                var error = firstOutput == null ? string.Empty : string.Concat(firstOutput.Error.Details.Select(ed => ed.Message));
                throw new Exception(error);
            }
            if (firstOutput == null)
            {
                throw new Exception("Asset not found");
            }
            var assetName = firstOutput.AssetName;
            var asset     = await _client.Assets.GetAsync(_settings.ResourceGroup, _settings.AccountName, assetName);

            var assetContainer = _storage.GetContainer(asset.Container);
            await encoded.CopyBlobAsync(assetContainer.GetBlob(encoded.GetName()));

            await _client.Assets.DeleteAsync(_settings.ResourceGroup, _settings.AccountName, assetName);

            await _client.Jobs.DeleteAsync(_settings.ResourceGroup, _settings.AccountName, _settings.MediaServicesTransform, jobName);
        }