예제 #1
0
 public ProductService(IProductQuery productHelper,
                       IDestinationQuery destionationQueryHelper,
                       IProductCommand productCommand
                       )
 {
     this.productHelper           = productHelper;
     this.destionationQueryHelper = destionationQueryHelper;
     this.productCommand          = productCommand;
 }
예제 #2
0
        public FlightValidator(IDestinationQuery desQuery)
        {
            RuleSet(AiringValidationRuleSet.PostAiring.ToString(), () =>
            {
                RuleFor(c => c)
                .Must(c => !c.Destinations.IsNullOrEmpty() ^ !c.Products.IsNullOrEmpty())
                .WithMessage("Either products or destinations are required, not both");

                RuleForEach(c => c.Products)
                .SetValidator(new ProductValidator(desQuery));
            });
        }
예제 #3
0
 public ProductValidator(IDestinationQuery desQuery)
 {
     RuleSet(AiringValidationRuleSet.PostAiring.ToString(), () =>
     {
         // Verify that product has destination
         RuleFor(c => c)
         .Must(c =>
         {
             return(!desQuery
                    .GetByProductIds(new List <Guid> {
                 c.ExternalId
             })
                    .IsNullOrEmpty());
         })
         .WithMessage("Product {0} doesn't have a destination. Products require one or more destination before content can be fulfilled. Please contact ODT team - [email protected]", c => c.ExternalId);
     });
 }
예제 #4
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;
 }
예제 #5
0
 public DestinationService(IDestinationQuery destinationHelper, IDestinationCommand destinationCommand, AppSettings appSettings)
 {
     this.destinationHelper  = destinationHelper;
     this.destinationCommand = destinationCommand;
     this.appSettings        = appSettings;
 }
예제 #6
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)));
                });
            });
        }