Exemplo n.º 1
0
        public override async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (Options.DaysAfter == 0)
            {
                _logger.LogInformation($"Configuration parameters hasn't been specified, execution skipped.");

                return;
            }

            var thresholdDate = _clock.GetCurrentInstant().ToDateTimeUtc().AddDays(-Options.DaysAfter);

            var externalRefs = await(
                from spot in _dbContext.Query <Persistence.SqlServer.Entities.Tenant.Spot>()
                join campaignJoin in _dbContext.Query <Campaign>() on spot.ExternalCampaignNumber equals campaignJoin
                .ExternalId into cJoin
                from camp in cJoin.DefaultIfEmpty()
                where spot.StartDateTime < thresholdDate && (camp == null || camp.EndDateTime < thresholdDate)
                select spot.ExternalSpotRef
                ).ToArrayAsync(cancellationToken).ConfigureAwait(false);

            LogInitialState(thresholdDate, externalRefs.LongLength);

            await _spotCleaner.ExecuteAsync(
                externalRefs,
                (string message) => _logger.LogDebug(message),
                thresholdDate,
                cancellationToken).ConfigureAwait(false);

            _logger.LogDebug("Finish removing spots");

            _logger.LogDebug("Start removing spot placements");
            _spotPlacement.DeleteBefore(thresholdDate);
            _logger.LogDebug("Finish removing spot placements");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prepares <see cref="RestrictionSearchDto"/> query taking into account
        /// Landmark Product related data by its active periods.
        /// </summary>
        /// <returns></returns>
        protected override IQueryable <RestrictionSearchDto> GetRestrictionSearchQueryable()
        {
            var advertiserSubQuery =
                from productAdvertiser in _dbContext.Query <ProductAdvertiser>()
                join product in _dbContext.Query <Product>() on productAdvertiser.ProductId equals product.Uid
                join restriction in _dbContext.Query <RestrictionEntity>() on product.Externalidentifier equals
                restriction.ProductCode.ToString()
                join advertiser in _dbContext.Query <Advertiser>() on productAdvertiser.AdvertiserId equals advertiser.Id
                    where productAdvertiser.StartDate <= restriction.StartDate &&
                productAdvertiser.EndDate > restriction.StartDate
                select new { productAdvertiser.ProductId, advertiser, RestrictionId = restriction.Id };

            return
                (from restriction in _dbContext.Query <RestrictionEntity>()
                 join productJoin in _dbContext.Query <Product>() on restriction.ProductCode.ToString() equals
                 productJoin
                 .Externalidentifier into products
                 from product in products.DefaultIfEmpty()
                 join clashJoin in _dbContext.Query <Clash>() on restriction.ClashCode equals clashJoin.Externalref
                 into clashes
                 from clash in clashes.DefaultIfEmpty()

                 let programme = _dbContext.Query <ProgrammeDictionary>()
                                 .FirstOrDefault(x => restriction.ExternalProgRef == x.ExternalReference)
                                 let advertiser = advertiserSubQuery
                                                  .Where(x => x.ProductId == product.Uid && x.RestrictionId == restriction.Id)
                                                  .Select(x => x.advertiser)
                                                  .FirstOrDefault()

                                                  select new RestrictionSearchDto
            {
                Id = restriction.Id,
                Uid = restriction.Uid,
                StartDate = restriction.StartDate,
                EndDate = restriction.EndDate,
                StartTime = restriction.StartTime,
                EndTime = restriction.EndTime,
                RestrictionDays = restriction.RestrictionDays,
                SchoolHolidayIndicator = restriction.SchoolHolidayIndicator,
                PublicHolidayIndicator = restriction.PublicHolidayIndicator,
                LiveProgrammeIndicator = restriction.LiveProgrammeIndicator,
                RestrictionType = restriction.RestrictionType,
                RestrictionBasis = restriction.RestrictionBasis,
                ExternalProgRef = restriction.ExternalProgRef,
                ProgrammeCategory = restriction.ProgrammeCategory,
                ProgrammeClassification = restriction.ProgrammeClassification,
                ProgrammeClassificationIndicator = restriction.ProgrammeClassificationIndicator,
                TimeToleranceMinsBefore = restriction.TimeToleranceMinsBefore,
                TimeToleranceMinsAfter = restriction.TimeToleranceMinsAfter,
                IndexType = restriction.IndexType,
                IndexThreshold = restriction.IndexThreshold,
                ProductCode = restriction.ProductCode,
                ClashCode = restriction.ClashCode,
                ClearanceCode = restriction.ClearanceCode,
                ClockNumber = restriction.ClockNumber,
                ExternalIdentifier = restriction.ExternalIdentifier,
                SalesAreas = restriction.SalesAreas,
                ProgrammeDescription = programme.Name,
                ProductDescription = product.Name,
                AdvertiserName = advertiser.Name,
                ClashDescription = clash.Description
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Prepares <see cref="CampaignSearchDto"/> query takin into account
        /// Landmark Product related data by its active periods.
        /// </summary>
        /// <param name="queryModel">The query model.</param>
        /// <returns></returns>
        protected override IQueryable <CampaignSearchDto> GetSearchDtoQuery(CampaignSearchQueryModel queryModel)
        {
            var query =
                from campaign in _dbContext.Query <Entities.Tenant.Campaigns.Campaign>()
                join campaignWithProductRelations in _dbContext.Specific.View <CampaignWithProductRelations>() on
                campaign.Id equals campaignWithProductRelations.CampaignId
                join productJoin in _dbContext.Query <Product>() on campaignWithProductRelations.ProductId equals
                productJoin.Uid into products
                from product in products.DefaultIfEmpty()
                join demographicJoin in _dbContext.Query <Demographic>() on campaign.Demographic equals demographicJoin
                .ExternalRef into demographics
                from demographic in demographics.DefaultIfEmpty()
                join clashCodeJoin in _dbContext.Query <Clash>() on product.ClashCode equals clashCodeJoin.Externalref
                into clashes
                from clash in clashes.DefaultIfEmpty()
                join advertiserJoin in _dbContext.Query <Advertiser>() on campaignWithProductRelations.AdvertiserId
                equals advertiserJoin.Id into advertisers
                from advertiser in advertisers.DefaultIfEmpty()
                join agencyJoin in _dbContext.Query <Agency>() on campaignWithProductRelations.AgencyId equals agencyJoin
                .Id into agencies
                from agency in agencies.DefaultIfEmpty()
                join agencyGroupJoin in _dbContext.Query <AgencyGroup>() on campaignWithProductRelations.AgencyGroupId
                equals agencyGroupJoin.Id into agencyGroups
                from agencyGroup in agencyGroups.DefaultIfEmpty()
                join personJoin in _dbContext.Query <Person>() on campaignWithProductRelations.PersonId equals personJoin
                .Id into persons
                from person in persons.DefaultIfEmpty()

                select new CampaignEntitySearchQueryModel
            {
                Campaign    = campaign,
                Product     = product,
                Demographic = demographic,
                Clash       = clash,
                Advertiser  = advertiser,
                Agency      = agency,
                AgencyGroup = agencyGroup,
                Person      = person
            };

            ApplyCampaignStatusFilter();
            ApplyCampaignPeriodFilter();
            ApplyCampaignSearchFilter();

            return(query.Select(q => new CampaignSearchDto
            {
                Uid = q.Campaign.Id,
                CustomId = q.Campaign.CustomId,
                Status = q.Campaign.Status,
                Name = q.Campaign.Name,
                ExternalId = q.Campaign.ExternalId,
                CampaignGroup = q.Campaign.CampaignGroup,
                StartDateTime = q.Campaign.StartDateTime,
                EndDateTime = q.Campaign.EndDateTime,
                ProductExternalRef = q.Product.Externalidentifier,
                ProductName = q.Product.Name,
                AdvertiserName = q.Advertiser.Name,
                AgencyName = q.Agency.Name,
                ReportingCategory = q.Product.ReportingCategory,
                MediaGroupCode = q.AgencyGroup.Code,
                MediaGroupShortName = q.AgencyGroup.ShortName,
                ProductAssigneeName = q.Person.Name,
                BusinessType = q.Campaign.BusinessType,
                DeliveryType = q.Campaign.DeliveryType,
                Demographic = q.Demographic.ExternalRef,
                RevenueBudget = q.Campaign.RevenueBudget,
                TargetRatings = q.Campaign.TargetRatings,
                ActualRatings = q.Campaign.ActualRatings,
                IsPercentage = q.Campaign.IsPercentage,
                IncludeOptimisation = q.Campaign.IncludeOptimisation,
                TargetZeroRatedBreaks = q.Campaign.TargetZeroRatedBreaks,
                InefficientSpotRemoval = q.Campaign.InefficientSpotRemoval,
                IncludeRightSizer = q.Campaign.IncludeRightSizer,
                RightSizerLevel = q.Campaign.RightSizerLevel,
                CampaignPassPriority = q.Campaign.CampaignPassPriority,
                ClashCode = q.Clash.Externalref,
                ClashDescription = q.Clash.Description,
                StopBooking = q.Campaign.StopBooking,
                TargetXP = q.Campaign.TargetXP,
                RevenueBooked = q.Campaign.RevenueBooked,
                CreationDate = q.Campaign.CreationDate,
                AutomatedBooked = q.Campaign.AutomatedBooked,
                TopTail = q.Campaign.TopTail,
                Spots = q.Campaign.Spots,
                CampaignPaybacks = q.Campaign.CampaignPaybacks,
                ActiveLength = q.Campaign.ActiveLength,
                RatingsDifferenceExcludingPayback = q.Campaign.RatingsDifferenceExcludingPayback,
                ValueDifference = q.Campaign.ValueDifference,
                ValueDifferenceExcludingPayback = q.Campaign.ValueDifferenceExcludingPayback,
                AchievedPercentageTargetRatings = q.Campaign.AchievedPercentageTargetRatings,
                AchievedPercentageRevenueBudget = q.Campaign.AchievedPercentageRevenueBudget
            }));

            void ApplyCampaignStatusFilter()
            {
                if (queryModel is null)
                {
                    return;
                }

                // add query condition for the specified campaign status
                if (queryModel.Status != Domain.Campaigns.CampaignStatus.All)
                {
                    query = query.Where(q => q.Campaign.Status == (CampaignStatus)(int)queryModel.Status);
                }
            }

            void ApplyCampaignPeriodFilter()
            {
                if (queryModel is null)
                {
                    return;
                }

                // add query condition if start and end dates are defined and start less than end
                if (queryModel.StartDate != default && queryModel.EndDate != default &&
                    queryModel.StartDate <= queryModel.EndDate)
                {
                    query = query.Where(q =>
                                        q.Campaign.StartDateTime <= queryModel.EndDate.AddDays(1) &&
                                        q.Campaign.EndDateTime >= queryModel.StartDate.Date);
                }
            }

            void ApplyCampaignSearchFilter()
            {
                if (queryModel is null)
                {
                    return;
                }

                query = ApplyCampaignSearchFilters(queryModel, query);
            }
        }
Exemplo n.º 4
0
 public IEnumerable <Campaign> GetAll() =>
 FindByRefs(_dbContext.Query <Entities.Tenant.Campaigns.Campaign>()
            .Select(x => x.ExternalId)
            .AsNoTracking().ToList());