Ejemplo n.º 1
0
 public QueueService(
     IQueueQuery queueQueryHelper,
     IQueueCommand queueCommandHelper,
     IQueueLocker queueLocker,
     IGetQueueMessagesQuery queueMessages,
     IQueueMessageRecorder historyRecorder,
     IGetAiringQuery airingQueryHelper,
     IAiringMessagePusherQueueApi messagePusher,
     IQueueSaveCommand queueSaveCommand,
     CurrentAiringsQuery currentAiringQuery,
     IHangfireRecurringJobCommand hangfireCommand,
     IRemoteQueueHandler remoteQueueHandler,
     IQueueDeleteCommand queueDeleteCommand)
 {
     this.queueQueryHelper   = queueQueryHelper;
     this.queueCommandHelper = queueCommandHelper;
     this.queueLocker        = queueLocker;
     this.queueMessages      = queueMessages;
     this.historyRecorder    = historyRecorder;
     this.airingQueryHelper  = airingQueryHelper;
     this.messagePusher      = messagePusher;
     this.queueSaveCommand   = queueSaveCommand;
     this.currentAiringQuery = currentAiringQuery;
     this.hangfireCommand    = hangfireCommand;
     this.remoteQueueHandler = remoteQueueHandler;
     this.queueDeleteCommand = queueDeleteCommand;
 }
Ejemplo n.º 2
0
 public AiringService(IGetAiringQuery airingQueryHelper,
                      AppSettings appSettings,
                      IAiringSaveCommand airingSaveCommandHelper,
                      IAiringDeleteCommand airingDeleteCommandHelper, IAiringMessagePusher airingMessagePusherCommandHelper,
                      IQueueQuery queueQueryHelper,
                      ITaskUpdater taskUpdaterCommand,
                      IFileQuery fileQueryHelper,
                      IDestinationQuery destinationQueryHelper,
                      IPackageQuery packageQueryHelper,
                      IChangeHistoricalAiringQuery changeHistoricalAiringQueryHelper,
                      IChangeDeletedAiringQuery changeDeletedAiringQueryHelper,
                      IDeportExpiredAiring deportExpiredAiringHelper,
                      CurrentAiringsQuery currentAiringsQuery,
                      DeletedAiringsQuery deletedAiringsQuery,
                      IUpdateDeletedAiringQueueDelivery updateDeletedAiringQueueDelivery,
                      IUpdateAiringQueueDelivery updateAiringQueueDelivery,
                      IPackageCommand packagePersist,
                      IPurgeAiringCommand purgeAiringCommand,
                      IChangeNotificationCommands changeNotificaitonCommands,
                      IApplicationContext cntx
                      )
 {
     this.airingQueryHelper                = airingQueryHelper;
     this.airingSaveCommandHelper          = airingSaveCommandHelper;
     this.airingDeleteCommandHelper        = airingDeleteCommandHelper;
     this.airingMessagePusherCommandHelper = airingMessagePusherCommandHelper;
     this.queueQueryHelper                  = queueQueryHelper;
     this.taskUpdaterCommand                = taskUpdaterCommand;
     this.fileQueryHelper                   = fileQueryHelper;
     this.appSettings                       = appSettings;
     this.destinationQueryHelper            = destinationQueryHelper;
     this.packageQueryHelper                = packageQueryHelper;
     this.changeHistoricalAiringQueryHelper = changeHistoricalAiringQueryHelper;
     this.changeDeletedAiringQueryHelper    = changeDeletedAiringQueryHelper;
     this.deportExpiredAiringHelper         = deportExpiredAiringHelper;
     this.currentAiringsQuery               = currentAiringsQuery;
     this.deletedAiringsQuery               = deletedAiringsQuery;
     this.updateAiringQueueDelivery         = updateAiringQueueDelivery;
     this.updateDeletedAiringQueueDelivery  = updateDeletedAiringQueueDelivery;
     this.packagePersist                    = packagePersist;
     this.purgeAiringCommand                = purgeAiringCommand;
     this.changeNotificationCommand         = changeNotificaitonCommands;
     this.cntx = cntx;
 }
Ejemplo n.º 3
0
        public PackageValidator(IGetAiringQuery airingQuery)
        {
            _airingQuery = airingQuery;

            RuleSet(PackageValidatorRuleSet.PostPackage.ToString(), () =>
            {
                // Verify required fields are provided
                RuleFor(c => c)
                .Must(c => (!string.IsNullOrEmpty(c.AiringId) || c.TitleIds.Any() || (c.ContentIds.Any() && !c.ContentIds.All(x => string.IsNullOrEmpty(x)))))
                .WithMessage("At least one AiringId or  TitleId or ContentId is required")
                .Must(c => !(c.ContentIds.Any() && c.TitleIds.Any() && string.IsNullOrEmpty(c.AiringId)) &&
                      !(!string.IsNullOrEmpty(c.AiringId) && c.ContentIds.Any() && c.TitleIds.Any()) &&
                      !(!string.IsNullOrEmpty(c.AiringId) && c.ContentIds.Any() && !c.TitleIds.Any()) &&
                      !(!string.IsNullOrEmpty(c.AiringId) && c.TitleIds.Any() && !c.ContentIds.Any()))
                .WithMessage("Cannot register package. Must only provide either AiringId or TitleId or ContentId")
                .Must(c => !string.IsNullOrEmpty(c.Type))
                .WithMessage("Type field must be provided")
                .Must(c => (c.PackageData != null))
                .WithMessage("PackageData must contain valid JSON")
                .Must(c => (c.PackageData != null && !string.IsNullOrEmpty(c.PackageData.ToString()) && !c.PackageData.ToString().Equals("{}")))
                .WithMessage("PackageData cannot be empty")
                .DependentRules(dr =>
                {
                    // Verify that the given airingId exist
                    Func <String, bool> airingIdExistRule = new Func <String, bool>((airingId) =>
                    {
                        try
                        {
                            return((string.IsNullOrEmpty(airingId)) ? true : _airingQuery.IsAiringExists(airingId));
                        }
                        catch (Exception)
                        {
                            return(false);
                        }
                    });

                    dr.RuleFor(c => c.AiringId)
                    .Must(airingIdExistRule)
                    .WithMessage("Provided AiringId does not exist/expired.");
                });
            });

            RuleSet(PackageValidatorRuleSet.DeletePackage.ToString(), () =>
            {
                // Verify required fields are provided
                RuleFor(c => c)
                .Must(c => (!string.IsNullOrEmpty(c.AiringId) || c.TitleIds.Any() || c.ContentIds.Any()))
                .WithMessage("At least one AiringId or  TitleId or ContentId is required")
                .Must(c => !(c.ContentIds.Any() && c.TitleIds.Any() && string.IsNullOrEmpty(c.AiringId)) &&
                      !(!string.IsNullOrEmpty(c.AiringId) && c.ContentIds.Any() && c.TitleIds.Any()) &&
                      !(!string.IsNullOrEmpty(c.AiringId) && c.ContentIds.Any() && !c.TitleIds.Any()) &&
                      !(!string.IsNullOrEmpty(c.AiringId) && c.TitleIds.Any() && !c.ContentIds.Any()))
                .WithMessage("Cannot delete package. Must only provide either AiringId or TitleId or ContentId")
                .Must(c => !string.IsNullOrEmpty(c.Type))
                .WithMessage("Type field must be provided")
                .DependentRules(dr =>
                {
                    // Verify that the given airingId exist
                    Func <String, bool> airingIdExistRule = new Func <String, bool>((airingId) =>
                    {
                        try
                        {
                            return((string.IsNullOrEmpty(airingId)) ? true : _airingQuery.IsAiringExists(airingId));
                        }
                        catch (Exception)
                        {
                            return(false);
                        }
                    });

                    dr.RuleFor(c => c.AiringId)
                    .Must(airingIdExistRule)
                    .WithMessage("Provided AiringId does not exist/expired.");
                });
            });
        }
Ejemplo n.º 4
0
 public AiringSaveCommand(IODTDatastore connection, IGetAiringQuery getAiringQueryPrimaryDb, IDfStatusMover dfStatusMover)
 {
     _database       = connection.GetDatabase();
     _getAiringQuery = getAiringQueryPrimaryDb;
     _dfStatusMover  = dfStatusMover;
 }
Ejemplo n.º 5
0
        public AiringValidator(IGetAiringQuery airingQuery, IDestinationQuery desQuery)
        {
            _airingQuery = airingQuery;
            _desQuery    = desQuery;


            RuleSet(AiringValidationRuleSet.PostAiring.ToString(), () =>
            {
                // Verify required fields are provided
                RuleFor(c => c)
                .Must(c => !String.IsNullOrEmpty(c.Network))
                .WithMessage("Brand required")
                .Must(c => c.Flights.Any())
                .WithMessage("Flight information required")
                .Must(c => !String.IsNullOrEmpty(c.ReleaseBy))
                .WithMessage("ReleaseBy field required");

                // Detect deleted airing
                RuleFor(c => c.AssetId)
                .Must(x =>
                {
                    return((String.IsNullOrEmpty(x)) ? true : !_airingQuery.IsAiringDeleted(x));
                })
                .WithMessage("Airing previously deleted. Cannot reuse airing id: {0}", c => c.AssetId);

                // Validate flight information
                RuleForEach(c => c.Flights)
                .SetValidator(new FlightValidator(_desQuery));
            });



            RuleSet(AiringValidationRuleSet.DeleteAiring.ToString(), () =>
            {
                // Verify required fields are provided
                RuleFor(c => c)
                .Must(c => !String.IsNullOrEmpty(c.AssetId))
                .WithMessage("Airing Id required")
                .Must(c => !String.IsNullOrEmpty(c.ReleaseBy))
                .WithMessage("ReleaseBy field required")
                .DependentRules(dr =>
                {
                    // Verify that the given airingId exist
                    Func <String, bool> airingIdExistRule = new Func <String, bool>((airingId) =>
                    {
                        try
                        {
                            return(_airingQuery.GetBy(airingId) != null);
                        }
                        catch (Exception)
                        {
                            return(false);
                        }
                    });

                    dr.RuleFor(c => c.AssetId)
                    .Must(airingIdExistRule)
                    .WithMessage("Provided AiringId does not exist.");
                });
            });

            RuleSet(AiringValidationRuleSet.PostPlaylist.ToString(), () =>
            {
                // Verify required fields are provided
                RuleFor(c => c)
                .Must(c => !String.IsNullOrEmpty(c.AssetId))
                .WithMessage("AiringId is required OR AiringId does not exist.")
                .Must(c => !String.IsNullOrEmpty(c.ReleaseBy))
                .WithMessage("ReleaseBy field required")
                .Must(c => (c.Versions != null && c.Versions.Any()))
                .WithMessage("Version not exists in existing airing.")
                .Must(c => (c.PlayList != null && c.PlayList.Any()))
                .WithMessage("Playlist is required")
                .DependentRules(pl =>
                {
                    // Verify that the given airingId exist
                    Func <BLModel.Airing, bool> playlistRule = new Func <BLModel.Airing, bool>((airing) =>
                    {
                        try
                        {
                            var foundCids = new List <string>();

                            foreach (var segment in airing.PlayList.Where(e => e.ItemType == "Segment"))
                            {
                                var versionFound = false;
                                foreach (var version in airing.Versions)
                                {
                                    if (segment.Id.StartsWith(version.ContentId))
                                    {
                                        versionFound = true;

                                        if (!foundCids.Contains(version.ContentId))
                                        {
                                            foundCids.Add(version.ContentId);
                                        }

                                        break;
                                    }
                                }

                                //Return validation error if Segment CID's not matches with Version CID's
                                if (!versionFound)
                                {
                                    return(false);
                                }
                            }


                            //Returns true if all version matches with Segements, if not then it will return false.
                            return(foundCids.Count == airing.Versions.Count);
                        }
                        catch (Exception)
                        {
                            return(false);
                        }
                    });

                    pl.RuleFor(c => c)
                    .Must(playlistRule)
                    .WithMessage("Provided Segment CID(s) does not match with Version CID(s) {0}.",
                                 c => string.Join(",", c.Versions.Select(e => e.ContentId)));
                });
            });
        }