/// <summary> /// Publish notification to all queues that are /// subscribed to recieve notification in the event /// any video file is created or updated. /// </summary> /// <param name="file"></param> private void PublishVideoNotification(BLFileModel.File file) { //Airings to be notified about. //Our assumption is that the provided file doesn't contain //AiringId information, but does contain MediaId. If that's the case //retrieve the corresponding AiringId before proceeding List <String> airingIds = _airingSvc.GetByMediaId(file.MediaId) .Select(c => c.AssetId).ToList(); // Queues that needs to be notified var videoQueueNames = _queueSvc .GetByStatus(true) .Where(q => q.DetectVideoChanges) .Select(q => q.Name).ToList(); // Publish notification _queueSvc.FlagForRedelivery(videoQueueNames, airingIds, ChangeNotificationType.File); }
/// <summary> // Send notifications to all subscribed consumers /// </summary> private void SendNotification(BLFileModel.File file) { List <string> statusList = file.Contents.FirstOrDefault().MediaCollection.Select(c => c.Type.Replace("_", "").Replace("-", "").ToUpper()).ToList(); List <Airing> airingIds = _airingSvc.GetByMediaId(file.MediaId); // For each airing associated with the media id, do the following foreach (Airing airing in airingIds) { // Persist statuses foreach (string status in statusList) { airing.Status[status] = true; } // Finally, persist the airing data _airingSvc.Save(airing, false, true); // Retrieve full list of notification changes List <ChangeNotification> notifications = GetNotificationList(airing, statusList); // Update the status notification _airingSvc.CreateNotificationForStatusChange(airing.AssetId, notifications); } }
public HandlerRoutes( IAiringService airingSvc, IDestinationService destinationSvc, IPathingService pathingSvc, IFileService fileSvc, IHandlerHistoryService handlerHistorySvc, IQueueService queueSvc, IReportingService reporterSvc, EncodingFileContentValidator encodingFileValidator, Serilog.ILogger logger ) : base("v1") { _airingSvc = airingSvc; _destinationSvc = destinationSvc; _pathingSvc = pathingSvc; _fileSvc = fileSvc; _handlerHistorySvc = handlerHistorySvc; _queueSvc = queueSvc; _encodingFileValidator = encodingFileValidator; _reporterSvc = reporterSvc; _logger = logger; /// Persist Encoding related data through POST operation. /// The correlation between an existing airing and the provided payload /// is performed using the provided odt-media-id data point. As a result, /// odt-media-id is a required field in the payload. Post("/handler/encoding", _ => { BLFileModel.File file = default(BLFileModel.File); try { // Perform preliminary authorization this.RequiresAuthentication(); this.RequiresClaims(c => c.Type == HttpMethod.Post.Verb()); // Deserealize JSON request to DataContracts. EncodingFileContentViewModel encodingPayLoad = this.Bind <EncodingFileContentViewModel>(); // Retrieve encoding destination details DF_ENCOM_DESTINATION_CODE = _destinationSvc.GetByDestinationNames(new List <String> { "ENCOM" }).First().ExternalId; // Persist encoding raw JSON data before proceeding this.Request.Body.Seek(0, SeekOrigin.Begin); _handlerHistorySvc.Save(this.Request.Body.AsString(), encodingPayLoad.MediaId); // Validate provided data contract. If validation errors are found // then inform user, else continue var validationResult = _encodingFileValidator.Validate(encodingPayLoad); if (!validationResult.IsValid) { // Report error status (for encoding destination) to monitoring system ReportStatusToMonitoringSystem(encodingPayLoad.MediaId, "Ingestion of encoding data failed due to validation errors in payload", DF_ERROR_STATUS_CODE, DF_ENCOM_DESTINATION_CODE); // Return status return(Negotiate.WithModel(validationResult.Errors.Select(c => c.ErrorMessage)) .WithStatusCode(HttpStatusCode.BadRequest)); } ApplyPathTranslationInformation(encodingPayLoad); // Translate DataContracts to Business Models file = encodingPayLoad.ToBusinessModel <EncodingFileContentViewModel, BLFileModel.File>(); // Perform CRUD _fileSvc.PersistVideoFile(file); // Send notification to all subscribed consumers SendNotification(file); // Report completed status (for Encoding destination) to monitoring system ReportStatusToMonitoringSystem(file.MediaId, "Successfully ingested encoding data", DF_COMPLETED_STATUS_CODE, DF_ENCOM_DESTINATION_CODE); // Return return(Response.AsJson(new { result = "success" }, HttpStatusCode.OK)); } catch (Exception ex) { // Log error logger.Error(ex, ex.Message); throw; } }); }
public List <BLModel.Content> Resolve(RQModel.EncodingFileContentViewModel source, BLModel.File des, List <BLModel.Content> d, ResolutionContext context) { List <BLModel.Content> contents = new List <BLModel.Content>(); BLModel.Content c = new BLModel.Content(); contents.Add(c); c.MediaCollection = Mapper.Map <List <RQModel.MediaViewModel>, List <BLModel.Media> >(source.MediaCollection); c.Name = c.MediaCollection.FirstOrDefault().Type; return(contents); }
public void PersistVideoFile(BLModel.File file) { fileCommand.PersistVideoFile(file.ToDataModel <BLModel.File, DLModel.File>(), cntx.GetUser().UserName); }