public JsonResult StopEvent(string eventName) { try { string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { mediaClient.StopLiveEvent(eventName); LiveEvent liveEvent = mediaClient.GetEntity <LiveEvent>(MediaEntity.LiveEvent, eventName); MediaLiveEvent mediaLiveEvent = new MediaLiveEvent(mediaClient, liveEvent); foreach (LiveOutput liveOutput in mediaLiveEvent.Outputs) { mediaClient.DeleteEntity(MediaEntity.LiveEventOutput, liveOutput.Name, mediaLiveEvent.Name); } } return(Json(eventName)); } catch (ValidationException ex) { Error error = new Error() { Type = HttpStatusCode.BadRequest, Message = ex.Message }; return(new JsonResult(error) { StatusCode = (int)error.Type }); } catch (ApiErrorException ex) { return(new JsonResult(ex.Response.Content) { StatusCode = (int)ex.Response.StatusCode }); } }
private static void SyncMediaAssets(DatabaseClient databaseClient, ILogger logger) { string collectionId = Constant.Database.Collection.MediaAssets; MediaAssetLink[] assetLinks = databaseClient.GetDocuments <MediaAssetLink>(collectionId); foreach (MediaAssetLink assetLink in assetLinks) { using (MediaClient mediaClient = new MediaClient(assetLink.MediaAccount, assetLink.UserAccount)) { Asset parentAsset = mediaClient.GetEntity <Asset>(MediaEntity.Asset, assetLink.AssetName); if (parentAsset == null) { foreach (KeyValuePair <MediaTransformPreset, string> jobOutput in assetLink.JobOutputs) { if (jobOutput.Key == MediaTransformPreset.VideoIndexer || jobOutput.Key == MediaTransformPreset.AudioIndexer) { string insightId = jobOutput.Value; mediaClient.IndexerDeleteVideo(insightId); } else { string assetName = jobOutput.Value; mediaClient.DeleteEntity(MediaEntity.Asset, assetName); } } string documentId = assetLink.AssetName; databaseClient.DeleteDocument(collectionId, documentId); logger.LogInformation("Asset Link Deleted: {0}", documentId); } else { List <MediaTransformPreset> missingJobOutputs = new List <MediaTransformPreset>(); foreach (KeyValuePair <MediaTransformPreset, string> jobOutput in assetLink.JobOutputs) { if (jobOutput.Key == MediaTransformPreset.VideoIndexer || jobOutput.Key == MediaTransformPreset.AudioIndexer) { string insightId = jobOutput.Value; bool insightExists = mediaClient.IndexerInsightExists(insightId, out JObject insight); if (!insightExists) { missingJobOutputs.Add(jobOutput.Key); logger.LogInformation("Missing Indexer Insight: {0}", insightId); } } else { string assetName = jobOutput.Value; Asset childAsset = mediaClient.GetEntity <Asset>(MediaEntity.Asset, assetName); if (childAsset == null) { missingJobOutputs.Add(jobOutput.Key); logger.LogInformation("Missing Output Asset: {0}", assetName); } } } if (missingJobOutputs.Count > 0) { foreach (MediaTransformPreset missingJobOutput in missingJobOutputs) { assetLink.JobOutputs.Remove(missingJobOutput); } databaseClient.UpsertDocument(collectionId, assetLink); logger.LogInformation("Asset Link Upserted: {0}", assetLink); } } } } }
public JsonResult DeleteEntity(string gridId, string entityName, string parentName) { try { string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { switch (gridId) { case "assets": mediaClient.DeleteEntity(MediaEntity.Asset, entityName); break; case "transforms": mediaClient.DeleteEntity(MediaEntity.Transform, entityName); break; case "transformJobs": mediaClient.DeleteEntity(MediaEntity.TransformJob, entityName, parentName); break; case "contentKeyPolicies": mediaClient.DeleteEntity(MediaEntity.ContentKeyPolicy, entityName); break; case "streamingPolicies": mediaClient.DeleteEntity(MediaEntity.StreamingPolicy, entityName); break; case "streamingEndpoints": mediaClient.DeleteEntity(MediaEntity.StreamingEndpoint, entityName); break; case "streamingLocators": mediaClient.DeleteEntity(MediaEntity.StreamingLocator, entityName); break; case "filtersAccount": mediaClient.DeleteEntity(MediaEntity.FilterAccount, entityName); break; case "filtersAsset": mediaClient.DeleteEntity(MediaEntity.FilterAsset, entityName, parentName); break; case "liveEvents": mediaClient.DeleteEntity(MediaEntity.LiveEvent, entityName); break; case "liveEventOutputs": mediaClient.DeleteEntity(MediaEntity.LiveEventOutput, entityName, parentName); break; case "indexerInsights": mediaClient.IndexerDeleteVideo(entityName); break; } } return(Json(entityName)); } catch (ApiErrorException ex) { return(new JsonResult(ex.Response.Content) { StatusCode = (int)ex.Response.StatusCode }); } }