private void SetVariationContext(string culture)
        {
            VariationContext variationContext = _variationContextAccessor.VariationContext;

            if (variationContext != null && variationContext.Culture == culture)
            {
                return;
            }

            _variationContextAccessor.VariationContext = new VariationContext(culture);
        }
示例#2
0
        /// <summary>
        /// Constructor for MSBuildStep Logger Wrapper class
        /// </summary>
        public CTRLogger()
        {
            // Harness.Current.Publish();

            log = TestLog.Current;
            if (log == null)
            {
                vctx = new VariationContext("CompilationContext");
                log  = new TestLog("MSBuildStep Log");
            }

            self = this;
        }
示例#3
0
        private PublishedContentQuery CreatePublishedContentQuery(IIndex indexer)
        {
            var    examineManager = new Mock <IExamineManager>();
            IIndex outarg         = indexer;

            examineManager.Setup(x => x.TryGetIndex("TestIndex", out outarg)).Returns(true);

            var contentCache = new Mock <IPublishedContentCache>();

            contentCache.Setup(x => x.GetById(It.IsAny <int>())).Returns((int intId) => Mock.Of <IPublishedContent>(x => x.Id == intId));
            var snapshot                 = Mock.Of <IPublishedSnapshot>(x => x.Content == contentCache.Object);
            var variationContext         = new VariationContext();
            var variationContextAccessor = Mock.Of <IVariationContextAccessor>(x => x.VariationContext == variationContext);

            return(new PublishedContentQuery(snapshot, variationContextAccessor, examineManager.Object));
        }
示例#4
0
        public static string GetArticulateCropUrl(this IPublishedContent content, string propertyAlias, VariationContext variationContext)
        {
            if (!content.ContentType.VariesByCulture())
            {
                return(content.GetCropUrl(propertyAlias: propertyAlias, imageCropMode: ImageCropMode.Max));
            }

            var property = content.GetProperty(propertyAlias);

            if (property == null)
            {
                return(string.Empty);
            }

            var culture = property.PropertyType.VariesByCulture()
                ? variationContext?.Culture
                : string.Empty; // must be string empty, not null since that won't work :/

            var url     = content.MediaUrl(culture, UrlMode.Default, "blogBanner");
            var cropUrl = content.Value <ImageCropperValue>("blogBanner", culture);

            if (cropUrl != null)
            {
                return(url.GetCropUrl(cropUrl, imageCropMode: ImageCropMode.Max));
            }

            return(string.Empty);
        }
示例#5
0
        private void AndThePreviousSnapShotFundingLines(params FundingLine[] fundingLines)
        {
            PublishedProvider previousSnapshot = VariationContext.GetPublishedProviderOriginalSnapShot(VariationContext.ProviderId);

            previousSnapshot.Current.FundingLines = fundingLines;
        }
 public CultureContextualSearchResultsEnumerator(IEnumerator <PublishedSearchResult> wrapped, IVariationContextAccessor variationContextAccessor, VariationContext originalContext)
 {
     _wrapped = wrapped;
     _variationContextAccessor = variationContextAccessor;
     _originalContext          = originalContext;
 }
        protected override void MakeAdjustmentsFromProfileVariationPointer(ProfileVariationPointer variationPointer)
        {
            PublishedProvider previousSnapshot = VariationContext.GetPublishedProviderOriginalSnapShot(ProviderId);

            if (previousSnapshot == null)
            {
                return;
            }

            string fundingLineId = variationPointer.FundingLineId;

            FundingLine latestFundingLine = RefreshState.FundingLines?
                                            .SingleOrDefault(_ => _.FundingLineCode == fundingLineId);
            FundingLine previousFundingLine = previousSnapshot.Current?.FundingLines?
                                              .SingleOrDefault(_ => _.FundingLineCode == fundingLineId);

            if (latestFundingLine == null || previousFundingLine == null)
            {
                RecordErrors($"Did not locate all funding lines for variation pointer with fundingLineId {fundingLineId}");

                return;
            }

            if (latestFundingLine.Value == null && previousFundingLine.Value == null)
            {
                return;
            }

            ProfilePeriod[] orderedRefreshProfilePeriods = new YearMonthOrderedProfilePeriods(latestFundingLine)
                                                           .ToArray();
            ProfilePeriod[] orderedSnapShotProfilePeriods = new YearMonthOrderedProfilePeriods(previousFundingLine)
                                                            .ToArray();

            int variationPointerIndex = GetProfilePeriodIndexForVariationPoint(variationPointer, orderedRefreshProfilePeriods);

            decimal previousFundingLineValuePaid = orderedSnapShotProfilePeriods.Take(variationPointerIndex).Sum(_ => _.ProfiledValue);
            decimal latestFundingLineValuePaid   = orderedRefreshProfilePeriods.Take(variationPointerIndex).Sum(_ => _.ProfiledValue);
            decimal latestFundingLineValue       = latestFundingLine.Value.GetValueOrDefault();

            decimal fundingChange      = latestFundingLineValuePaid - previousFundingLineValuePaid;
            decimal latestPeriodAmount = (int)(latestFundingLineValue / orderedRefreshProfilePeriods.Length);

            AdjustPeriodsForFundingAlreadyReleased(variationPointerIndex,
                                                   orderedSnapShotProfilePeriods,
                                                   orderedRefreshProfilePeriods);

            if (fundingChange < 0)
            {
                if (AdjustingPeriodsForOverPaymentLeavesRemainder(variationPointerIndex,
                                                                  latestPeriodAmount,
                                                                  orderedSnapShotProfilePeriods,
                                                                  orderedRefreshProfilePeriods,
                                                                  out decimal remainingOverPayment))
                {
                    if (remainingOverPayment > 0)
                    {
                        RefreshState.AddCarryOver(fundingLineId, ProfilingCarryOverType.DSGReProfiling, remainingOverPayment);
                    }
                }
            }
            else if (fundingChange > 0)
            {
                AdjustPeriodsForUnderPayment(variationPointerIndex,
                                             latestPeriodAmount,
                                             orderedSnapShotProfilePeriods,
                                             orderedRefreshProfilePeriods);
            }
            else
            {
                AdjustPeriodsForNoTotalAllocationChange(variationPointerIndex,
                                                        latestPeriodAmount,
                                                        orderedSnapShotProfilePeriods,
                                                        orderedRefreshProfilePeriods,
                                                        fundingLineId);
            }
        }