public static MediaPublished PublishInsight(MediaPublish insightPublish) { string accountId = insightPublish.PartitionKey; string indexId = insightPublish.RowKey; IndexerClient indexerClient = new IndexerClient(accountId, insightPublish.MediaAccount.IndexerKey); JObject index = indexerClient.GetIndex(indexId, null, false); MediaPublished mediaPublished = null; string assetId = IndexerClient.GetAssetId(index); if (!string.IsNullOrEmpty(assetId)) { MediaClient mediaClient = new MediaClient(insightPublish.MediaAccount); IAsset asset = mediaClient.GetEntityById(MediaEntity.Asset, assetId) as IAsset; DocumentClient documentClient = new DocumentClient(); index = DocumentClient.SetContext(index, insightPublish.MediaAccount, assetId); string documentId = UpsertDocument(documentClient, index, MediaProcessor.VideoIndexer, asset, null); mediaPublished = new MediaPublished { AssetId = assetId, IndexId = indexId, DocumentId = documentId, UserId = insightPublish.UserId, MobileNumber = insightPublish.MobileNumber, StatusMessage = string.Empty }; } return(mediaPublished); }
private static IAsset GetSourceAsset(MediaClient mediaClient, string sourceUrl) { string locatorId = sourceUrl.Split('/')[3]; locatorId = string.Concat(Constant.Media.Stream.LocatorIdPrefix, locatorId); ILocator locator = mediaClient.GetEntityById(MediaEntity.Locator, locatorId) as ILocator; return(locator.Asset); }
public static string PublishJob(MediaJobNotification jobNotification, bool webHook) { string jobPublication = string.Empty; if (jobNotification != null && jobNotification.EventType == MediaJobNotificationEvent.JobStateChange && (jobNotification.Properties.NewState == JobState.Error || jobNotification.Properties.NewState == JobState.Canceled || jobNotification.Properties.NewState == JobState.Finished)) { if (webHook) { string settingKey = Constants.AppSettingKey.MediaJobNotificationStorageQueueName; string queueName = AppSetting.GetValue(settingKey); MessageClient messageClient = new MessageClient(); messageClient.AddMessage(queueName, jobNotification); } else { EntityClient entityClient = new EntityClient(); string tableName = Constants.Storage.TableName.JobPublish; string partitionKey = jobNotification.Properties.AccountName; string rowKey = jobNotification.Properties.JobId; JobPublish jobPublish = entityClient.GetEntity <JobPublish>(tableName, partitionKey, rowKey); if (jobPublish != null) { tableName = Constants.Storage.TableName.JobPublishProtection; ContentProtection contentProtection = entityClient.GetEntity <ContentProtection>(tableName, partitionKey, rowKey); string accountName = jobPublish.PartitionKey; string accountKey = jobPublish.MediaAccountKey; MediaClient mediaClient = new MediaClient(accountName, accountKey); IJob job = mediaClient.GetEntityById(MediaEntity.Job, rowKey) as IJob; if (job != null) { mediaClient.SetProcessorUnits(job, ReservedUnitType.Basic); if (jobNotification.Properties.NewState == JobState.Finished) { PublishContent(mediaClient, job, jobPublish, contentProtection); } string messageText = GetNotificationMessage(accountName, job); MessageClient.SendText(messageText, jobPublish.MobileNumber); } if (contentProtection != null) { tableName = Constants.Storage.TableName.JobPublishProtection; entityClient.DeleteEntity(tableName, contentProtection); } tableName = Constants.Storage.TableName.JobPublish; entityClient.DeleteEntity(tableName, jobPublish); } } } return(jobPublication); }
public static MediaJobInput[] GetJobInputs(MediaClient mediaClient, string[] assetIds) { List <MediaJobInput> jobInputs = new List <MediaJobInput>(); foreach (string assetId in assetIds) { IAsset asset = mediaClient.GetEntityById(MediaEntity.Asset, assetId) as IAsset; if (asset != null) { MediaJobInput jobInput = GetJobInput(asset); jobInputs.Add(jobInput); } } return(jobInputs.ToArray()); }
public static void PurgePublishContent(TableClient tableClient) { string tableName = Constant.Storage.Table.ContentPublish; MediaPublish[] contentPublishes = tableClient.GetEntities <MediaPublish>(tableName); foreach (MediaPublish contentPublish in contentPublishes) { string jobId = contentPublish.RowKey; MediaClient mediaClient = new MediaClient(contentPublish.MediaAccount); IJob job = mediaClient.GetEntityById(MediaEntity.Job, jobId) as IJob; if (job == null) { tableClient.DeleteEntity(tableName, contentPublish); DeleteContentProtections(tableClient, contentPublish.RowKey); } } }
public static MediaPublished PublishContent(MediaPublish contentPublish) { string accountId = contentPublish.PartitionKey; string jobId = contentPublish.RowKey; MediaClient mediaClient = new MediaClient(contentPublish.MediaAccount); IJob job = mediaClient.GetEntityById(MediaEntity.Job, jobId) as IJob; MediaPublished mediaPublished = null; if (job != null) { mediaClient.SetProcessorUnits(job, null, ReservedUnitType.Basic, false); PublishJob(mediaClient, job, contentPublish); mediaPublished = new MediaPublished() { UserId = contentPublish.UserId, MobileNumber = contentPublish.MobileNumber, StatusMessage = GetNotificationMessage(accountId, job) }; } return(mediaPublished); }
public static void PurgePublishInsight(TableClient tableClient) { DocumentClient documentClient = new DocumentClient(); string collectionId = Constant.Database.Collection.ContentInsight; JObject[] documents = documentClient.GetDocuments(collectionId); foreach (JObject document in documents) { if (document["accountId"] != null) { MediaAccount mediaAccount = new MediaAccount() { Id = document["accountId"].ToString(), DomainName = document["accountDomain"].ToString(), EndpointUrl = document["accountEndpoint"].ToString(), ClientId = document["clientId"].ToString(), ClientKey = document["clientKey"].ToString() }; string assetId = document["assetId"].ToString(); MediaClient mediaClient = new MediaClient(mediaAccount); IAsset asset = mediaClient.GetEntityById(MediaEntity.Asset, assetId) as IAsset; if (asset == null) { string documentId = document["id"].ToString(); documentClient.DeleteDocument(collectionId, documentId); string tableName = Constant.Storage.Table.InsightPublish; MediaPublish insightPublish = tableClient.GetEntity <MediaPublish>(tableName, mediaAccount.Id, documentId); if (insightPublish != null) { tableClient.DeleteEntity(tableName, insightPublish); } } } } }
public static void DeleteEntities(string authToken, bool allEntities, bool liveOnly) { User authUser = new User(authToken); MediaClient mediaClient = new MediaClient(authToken); if (liveOnly) { DeleteLive(authToken, authUser.MediaAccount.Id, mediaClient); } else if (!allEntities) { IAsset[] assets = mediaClient.GetEntities(MediaEntity.Asset) as IAsset[]; foreach (IAsset asset in assets) { if (asset.ParentAssets.Count > 0) { DeleteAsset(authToken, authUser.MediaAccount.Id, mediaClient, asset); } } } else { DeleteLive(authToken, authUser.MediaAccount.Id, mediaClient); IIngestManifest[] manifests = mediaClient.GetEntities(MediaEntity.Manifest) as IIngestManifest[]; foreach (IIngestManifest manifest in manifests) { manifest.Delete(); } IJobTemplate[] jobTemplates = mediaClient.GetEntities(MediaEntity.JobTemplate) as IJobTemplate[]; foreach (IJobTemplate jobTemplate in jobTemplates) { jobTemplate.Delete(); } IJob[] jobs = mediaClient.GetEntities(MediaEntity.Job) as IJob[]; foreach (IJob job in jobs) { DeleteJob(authUser.MediaAccount.Id, job); } INotificationEndPoint[] notificationEndpoints = mediaClient.GetEntities(MediaEntity.NotificationEndpoint) as INotificationEndPoint[]; foreach (INotificationEndPoint notificationEndpoint in notificationEndpoints) { if (notificationEndpoint.EndPointType == NotificationEndPointType.AzureTable) { IMonitoringConfiguration monitoringConfig = mediaClient.GetEntityById(MediaEntity.MonitoringConfiguration, notificationEndpoint.Id) as IMonitoringConfiguration; if (monitoringConfig != null) { monitoringConfig.Delete(); } } notificationEndpoint.Delete(); } IAsset[] assets = mediaClient.GetEntities(MediaEntity.Asset) as IAsset[]; foreach (IAsset asset in assets) { DeleteAsset(authToken, authUser.MediaAccount.Id, mediaClient, asset); } IAccessPolicy[] accessPolicies = mediaClient.GetEntities(MediaEntity.AccessPolicy) as IAccessPolicy[]; foreach (IAccessPolicy accessPolicy in accessPolicies) { accessPolicy.Delete(); } IAssetDeliveryPolicy[] deliveryPolicies = mediaClient.GetEntities(MediaEntity.DeliveryPolicy) as IAssetDeliveryPolicy[]; foreach (IAssetDeliveryPolicy deliveryPolicy in deliveryPolicies) { deliveryPolicy.Delete(); } IContentKeyAuthorizationPolicy[] contentKeyAuthPolicies = mediaClient.GetEntities(MediaEntity.ContentKeyAuthPolicy) as IContentKeyAuthorizationPolicy[]; foreach (IContentKeyAuthorizationPolicy contentKeyAuthPolicy in contentKeyAuthPolicies) { contentKeyAuthPolicy.Delete(); } IContentKeyAuthorizationPolicyOption[] contentKeyAuthPolicyOptions = mediaClient.GetEntities(MediaEntity.ContentKeyAuthPolicyOption) as IContentKeyAuthorizationPolicyOption[]; foreach (IContentKeyAuthorizationPolicyOption contentKeyAuthPolicyOption in contentKeyAuthPolicyOptions) { contentKeyAuthPolicyOption.Delete(); } IContentKey[] contentKeys = mediaClient.GetEntities(MediaEntity.ContentKey) as IContentKey[]; foreach (IContentKey contentKey in contentKeys) { contentKey.Delete(); } } }
public static MediaJob GetJob(string authToken, MediaClient mediaClient, MediaJob mediaJob, MediaJobInput[] jobInputs) { List <MediaJobTask> jobTasks = new List <MediaJobTask>(); foreach (MediaJobTask jobTask in mediaJob.Tasks) { MediaJobTask[] tasks = null; switch (jobTask.MediaProcessor) { case MediaProcessor.EncoderStandard: case MediaProcessor.EncoderPremium: tasks = GetEncoderTasks(mediaClient, jobTask, jobInputs); break; case MediaProcessor.VideoIndexer: IndexerClient indexerClient = new IndexerClient(authToken); if (indexerClient.IndexerEnabled) { foreach (MediaJobInput jobInput in jobInputs) { IAsset asset = mediaClient.GetEntityById(MediaEntity.Asset, jobInput.AssetId) as IAsset; string documentId = DocumentClient.GetDocumentId(asset, out bool videoIndexer); if (videoIndexer) { indexerClient.ResetIndex(authToken, documentId); } else { indexerClient.IndexVideo(authToken, mediaClient, asset, jobTask.ContentIndexer); } } } break; case MediaProcessor.VideoAnnotation: tasks = GetVideoAnnotationTasks(mediaClient, jobTask, jobInputs); break; case MediaProcessor.VideoSummarization: tasks = GetVideoSummarizationTasks(mediaClient, jobTask, jobInputs); break; case MediaProcessor.FaceDetection: tasks = GetFaceDetectionTasks(mediaClient, jobTask, jobInputs); break; case MediaProcessor.SpeechAnalyzer: tasks = GetSpeechAnalyzerTasks(mediaClient, jobTask, jobInputs); break; case MediaProcessor.MotionDetection: tasks = GetMotionDetectionTasks(mediaClient, jobTask, jobInputs); break; case MediaProcessor.ContentModeration: tasks = GetContentModerationTasks(mediaClient, jobTask, jobInputs); break; case MediaProcessor.CharacterRecognition: tasks = GetCharacterRecognitionTasks(mediaClient, jobTask, jobInputs); break; } if (tasks != null) { jobTasks.AddRange(tasks); } } mediaJob.Tasks = jobTasks.ToArray(); if (string.IsNullOrEmpty(mediaJob.Name)) { mediaJob.Name = jobInputs[0].AssetName; } return(mediaJob); }
public static void ClearAccount(MediaClient mediaClient, bool allEntities) { if (allEntities) { IProgram[] programs = mediaClient.GetEntities(MediaEntity.Program) as IProgram[]; foreach (IProgram program in programs) { program.Delete(); } IChannel[] channels = mediaClient.GetEntities(MediaEntity.Channel) as IChannel[]; foreach (IChannel channel in channels) { channel.Delete(); } IIngestManifest[] manifests = mediaClient.GetEntities(MediaEntity.Manifest) as IIngestManifest[]; foreach (IIngestManifest manifest in manifests) { manifest.Delete(); } } IJob[] jobs = mediaClient.GetEntities(MediaEntity.Job) as IJob[]; foreach (IJob job in jobs) { job.Delete(); } INotificationEndPoint[] notificationEndpoints = mediaClient.GetEntities(MediaEntity.NotificationEndpoint) as INotificationEndPoint[]; foreach (INotificationEndPoint notificationEndpoint in notificationEndpoints) { if (notificationEndpoint.EndPointType == NotificationEndPointType.AzureTable) { IMonitoringConfiguration monitoringConfig = mediaClient.GetEntityById(MediaEntity.MonitoringConfiguration, notificationEndpoint.Id) as IMonitoringConfiguration; if (monitoringConfig != null) { monitoringConfig.Delete(); } } notificationEndpoint.Delete(); } IAsset[] assets = mediaClient.GetEntities(MediaEntity.Asset) as IAsset[]; foreach (IAsset asset in assets) { if (asset.ParentAssets.Count > 0 || allEntities) { DeleteAsset(mediaClient, asset); } } if (allEntities) { IAccessPolicy[] accessPolicies = mediaClient.GetEntities(MediaEntity.AccessPolicy) as IAccessPolicy[]; foreach (IAccessPolicy accessPolicy in accessPolicies) { accessPolicy.Delete(); } IAssetDeliveryPolicy[] deliveryPolicies = mediaClient.GetEntities(MediaEntity.DeliveryPolicy) as IAssetDeliveryPolicy[]; foreach (IAssetDeliveryPolicy deliveryPolicy in deliveryPolicies) { deliveryPolicy.Delete(); } IContentKeyAuthorizationPolicy[] contentKeyAuthPolicies = mediaClient.GetEntities(MediaEntity.ContentKeyAuthPolicy) as IContentKeyAuthorizationPolicy[]; foreach (IContentKeyAuthorizationPolicy contentKeyAuthPolicy in contentKeyAuthPolicies) { contentKeyAuthPolicy.Delete(); } IContentKeyAuthorizationPolicyOption[] contentKeyAuthPolicyOptions = mediaClient.GetEntities(MediaEntity.ContentKeyAuthPolicyOption) as IContentKeyAuthorizationPolicyOption[]; foreach (IContentKeyAuthorizationPolicyOption contentKeyAuthPolicyOption in contentKeyAuthPolicyOptions) { contentKeyAuthPolicyOption.Delete(); } } }