コード例 #1
0
        /// <summary>
        /// Reserved for internal use.
        /// </summary>
        protected void ConvertBidsFromApi <TApiBid, TTarget>(
            LocationTargetType locationType,
            IList <TBid> bids,
            Func <TTarget> getTarget,
            Func <TTarget, IList <TApiBid> > getBids,
            Func <TApiBid, string> getLocation,
            Func <TApiBid, bool> shouldConvertBid
            )
            where TTarget : class
        {
            ConvertBidsFromApi(bids, getTarget, getBids, (bulkBid, apiBid) =>
            {
                bulkBid.LocationType = locationType;
                bulkBid.Location     = getLocation(apiBid);

                if (!(
                        TrySetBulkBidAdditionalProperties(bulkBid, apiBid as CityTargetBid, SetBulkCityBidAdditionalProperties) ||
                        TrySetBulkBidAdditionalProperties(bulkBid, apiBid as MetroAreaTargetBid, SetBulkMetroAreaBidAdditionalProperties) ||
                        TrySetBulkBidAdditionalProperties(bulkBid, apiBid as StateTargetBid, SetBulkStateBidAdditionalProperties) ||
                        TrySetBulkBidAdditionalProperties(bulkBid, apiBid as CountryTargetBid, SetBulkCountryBidAdditionalProperties) ||
                        TrySetBulkBidAdditionalProperties(bulkBid, apiBid as PostalCodeTargetBid, SetBulkPostalCodeBidAdditionalProperties)
                        ))
                {
                    throw new NotImplementedException("Unknown target bid type.");
                }
            }, shouldConvertBid);
        }
コード例 #2
0
 /// <summary>
 /// Reserved for internal use.
 /// </summary>
 protected void ReconstructApiBids <TApiBid, TTarget>(
     LocationTargetType locationType,
     Func <TBid, TApiBid> createBid,
     Func <TTarget> getTarget,
     Func <TTarget> createNewTarget,
     Action <TTarget> setTarget,
     Func <IList <TApiBid> > getBids,
     Action <IList <TApiBid> > setBids
     )
     where TApiBid : new()
     where TTarget : class, new()
 {
     ReconstructApiBids(Bids.Where(t => t.LocationType == locationType).ToList(), createBid, getTarget, createNewTarget, setTarget, getBids, setBids);
 }
コード例 #3
0
        public static string ToLocationTargetTypeBulkString(this LocationTargetType locationTargetType)
        {
            switch (locationTargetType)
            {
            case LocationTargetType.MetroArea:
                return("Metro Area");

            case LocationTargetType.PostalCode:
                return("Postal Code");

            default:
                return(locationTargetType.ToBulkString());
            }
        }
コード例 #4
0
        private void ReconstructApiBids <TApiBid, TTarget>(LocationTargetType locationType, Func <TBid, TApiBid> createBid, Func <TTarget> getTarget, Action <TTarget> setTarget, Func <IList <TApiBid> > getBids, Action <IList <TApiBid> > setBids)
            where TApiBid : new()
            where TTarget : class, new()
        {
            var bidsFromFile = Bids.Where(t => t.LocationType == locationType).Select(createBid).ToList();

            if (bidsFromFile.Count > 0)
            {
                if (getTarget() == null)
                {
                    setTarget(new TTarget());

                    setBids(new List <TApiBid>());
                }

                getBids().AddRange(bidsFromFile);
            }
        }
コード例 #5
0
        private void AddBids <T, TTarget>(IList <TBid> bids, Func <TTarget> getTarget, Func <TTarget, IList <T> > getBids, LocationTargetType locationType, Func <T, string> location, Func <T, bool> isExcluded, IntentOption?intentOption)
        {
            var target = getTarget();

            if (target == null)
            {
                return;
            }

            var v9Bids = getBids(target);

            if (v9Bids == null)
            {
                return;
            }

            bids.AddRange(v9Bids.Where(isExcluded).Select(b => CreateAndPopulateBid(x =>
            {
                x.Location     = location(b);
                x.LocationType = locationType;
            })));
        }
コード例 #6
0
        private void ConvertBidsFromApi <T, TTarget>(IList <TBid> bids, Func <TTarget> getTarget, Func <TTarget, IList <T> > getBids, LocationTargetType locationType, Func <T, string> location, Func <T, int> bidAdjustment, Func <T, bool> isExcluded, IntentOption?intentOption)
        {
            var target = getTarget();

            if (target == null)
            {
                return;
            }

            var rawBids = getBids(target);

            if (rawBids == null)
            {
                return;
            }

            bids.AddRange(rawBids.Where(x => !isExcluded(x)).Select(b =>
            {
                var bid = CreateBid();

                bid.TargetId         = TargetId;
                bid.EntityId         = EntityId;
                bid.EntityName       = EntityName;
                bid.ParentEntityName = ParentEntityName;
                bid.LocationType     = locationType;
                bid.Location         = location(b);
                bid.IntentOption     = intentOption;
                bid.BidAdjustment    = bidAdjustment(b);

                return(bid);
            }));
        }