public static Asset CreateAsset([ActivityTrigger] DurableActivityContext context) { ValueTuple <MediaWorkflowManifest, string> jobInput = context.GetInput <(MediaWorkflowManifest, string)>(); MediaWorkflowManifest workflowManifest = jobInput.Item1; string fileName = jobInput.Item2; MediaClient mediaClient = new MediaClient(workflowManifest); CloudBlockBlob blob = _blobClient.GetBlockBlob(_containerName, null, fileName); return(mediaClient.CreateAsset(workflowManifest.OutputAssetStorage, workflowManifest.AssetName, blob)); }
private Asset[] CreateInputAssets(MediaClient mediaClient, string storageAccount, string assetName, string assetDescription, string assetAlternateId, string[] fileNames) { List <Asset> inputAssets = new List <Asset>(); StorageBlobClient blobClient = new StorageBlobClient(mediaClient.MediaAccount, storageAccount); foreach (string fileName in fileNames) { string sourceContainer = Constant.Storage.BlobContainer.MediaServices; Asset inputAsset = mediaClient.CreateAsset(blobClient, blobClient, storageAccount, assetName, assetDescription, assetAlternateId, sourceContainer, fileName); inputAssets.Add(inputAsset); } return(inputAssets.ToArray()); }
public JsonResult Create(int assetCount, string assetType, bool assetPublish) { try { string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { StorageBlobClient sourceBlobClient = new StorageBlobClient(); StorageBlobClient assetBlobClient = new StorageBlobClient(mediaClient.MediaAccount, mediaClient.PrimaryStorageAccount); for (int i = 1; i <= assetCount; i++) { List <Task> uploadTasks = new List <Task>(); string containerName = Constant.Storage.BlobContainer.MediaServices; string directoryPath = assetType; string assetName = MediaAsset.GetAssetName(sourceBlobClient, containerName, directoryPath, out MediaFile[] sourceFiles); assetName = string.Concat(i.ToString(), Constant.Media.Asset.NameDelimiter, assetName); Asset asset = mediaClient.CreateAsset(mediaClient.PrimaryStorageAccount, assetName); foreach (MediaFile sourceFile in sourceFiles) { CloudBlockBlob sourceBlob = sourceBlobClient.GetBlockBlob(containerName, directoryPath, sourceFile.Name); CloudBlockBlob assetBlob = assetBlobClient.GetBlockBlob(asset.Container, null, sourceFile.Name); Stream sourceStream = sourceBlob.OpenReadAsync().Result; Task uploadTask = assetBlob.UploadFromStreamAsync(sourceStream); uploadTasks.Add(uploadTask); } if (assetPublish) { Task.WaitAll(uploadTasks.ToArray()); string streamingPolicyName = assetType == Constant.Media.Asset.SingleBitrate ? PredefinedStreamingPolicy.DownloadOnly : PredefinedStreamingPolicy.ClearStreamingOnly; mediaClient.CreateLocator(asset.Name, asset.Name, streamingPolicyName, null); } } } return(Json(assetCount)); } catch (ApiErrorException ex) { return(new JsonResult(ex.Response.Content) { StatusCode = (int)ex.Response.StatusCode }); } }
private static MediaIngestManifest CreateAsset(MediaClient mediaClient, MediaIngestManifest ingestManifest, out Asset inputAsset, ILogger logger) { string storageAccount = mediaClient.PrimaryStorageAccount; string assetName = ingestManifest.AssetName; string assetDescription = ingestManifest.AssetDescription; string assetAlternateId = ingestManifest.AssetAlternateId; string sourceContainer = Constant.Storage.BlobContainer.MediaServices; string[] fileNames = ingestManifest.FileNames; StorageBlobClient assetBlobClient = new StorageBlobClient(ingestManifest.MediaAccount, storageAccount); inputAsset = mediaClient.CreateAsset(_blobClient, assetBlobClient, storageAccount, assetName, assetDescription, assetAlternateId, sourceContainer, fileNames); string logData = string.Concat("New Asset: ", JsonConvert.SerializeObject(inputAsset)); WriteLog(ingestManifest.Name, logData, logger, false); ingestManifest.AssetName = inputAsset.Name; if (string.IsNullOrEmpty(ingestManifest.JobInputFileUrl) && ingestManifest.JobInputMode == MediaJobInputMode.AssetFile) { string fileName = fileNames[0]; ingestManifest.JobInputFileUrl = assetBlobClient.GetDownloadUrl(inputAsset.Container, fileName, false); } return(ingestManifest); }