private static void PublishAnalytics(IJob job, IAsset asset, JobPublish jobPublish) { string processorId1 = Constants.Media.ProcessorId.FaceDetection; string processorId2 = Constants.Media.ProcessorId.FaceRedaction; string processorId3 = Constants.Media.ProcessorId.MotionDetection; string processorId4 = Constants.Media.ProcessorId.VideoAnnotation; string processorId5 = Constants.Media.ProcessorId.CharacterRecognition; string processorId6 = Constants.Media.ProcessorId.ContentModeration; string[] processorIds = new string[] { processorId1, processorId2, processorId3, processorId4, processorId5, processorId6 }; ITask[] jobTasks = GetJobTasks(job, processorIds); if (jobTasks.Length > 0) { BlobClient blobClient = GetBlobClient(jobPublish); using (DatabaseClient databaseClient = new DatabaseClient(true)) { string collectionId = Constants.Database.DocumentCollection.Metadata; foreach (ITask jobTask in jobTasks) { IAsset outputAsset = jobTask.OutputAssets[0]; string fileExtension = Constants.Media.FileExtension.Json; string[] fileNames = GetFileNames(outputAsset, fileExtension); if (fileNames.Length > 0 && asset != null) { string sourceContainerName = outputAsset.Uri.Segments[1]; string sourceFileName = fileNames[0]; CloudBlockBlob sourceBlob = blobClient.GetBlob(sourceContainerName, string.Empty, sourceFileName, false); string jsonData = string.Empty; using (Stream sourceStream = sourceBlob.OpenRead()) { StreamReader streamReader = new StreamReader(sourceStream); jsonData = streamReader.ReadToEnd(); } if (!string.IsNullOrEmpty(jsonData)) { string documentId = databaseClient.CreateDocument(collectionId, jsonData); MediaProcessor mediaProcessor = Processors.GetMediaProcessorType(jobTask.MediaProcessorId); string processorName = Processors.GetMediaProcessorName(mediaProcessor); processorName = processorName.Replace(' ', Constants.NamedItemSeparator); string destinationFileName = string.Concat(documentId, Constants.NamedItemsSeparator, processorName, fileExtension); blobClient.CopyFile(outputAsset, asset, sourceFileName, destinationFileName, false); } } if (jobTask.Configuration.Contains("mode") && jobTask.Configuration.Contains("analyze")) { IAsset inputAsset = jobTask.InputAssets[0]; string primaryFileName = GetPrimaryFile(inputAsset); blobClient.CopyFile(inputAsset, outputAsset, primaryFileName, primaryFileName, true); } } } } }
public MediaProcessor[] Initialize(string authToken) { MediaClient mediaClient = new MediaClient(authToken); IMediaProcessor[] mediaProcessors = mediaClient.GetEntities(MediaEntity.Processor) as IMediaProcessor[]; List <MediaProcessor> mediaProcessorList = new List <MediaProcessor>(); foreach (IMediaProcessor mediaProcessor in mediaProcessors) { MediaProcessor processorType = Processors.GetMediaProcessorType(mediaProcessor.Id); mediaProcessorList.Add(processorType); } MediaProcessor[] mediaProcessorTypes = mediaProcessorList.ToArray(); SetValue <MediaProcessor[]>(Constants.Cache.ItemKey.MediaProcessors, mediaProcessorTypes); return(mediaProcessorTypes); }