internal override void ReadRelatedDataFromStream(IBulkStreamReader reader)
        {
            var hasMoreRows = true;

            while (hasMoreRows)
            {
                BulkSiteLink nextSiteLink;

                SiteLinkAdExtensionIdentifier identitifier;

                if (reader.TryRead(x => x.Identifier.Equals(_identifier), out nextSiteLink))
                {
                    _bulkSiteLinkResults.Add(nextSiteLink);
                }
                else if (reader.TryRead(x => x.Equals(_identifier) && x.IsDeleteRow, out identitifier))
                {
                    _hasDeleteAllRow = true;
                }
                else
                {
                    hasMoreRows = false;
                }
            }

            if (_bulkSiteLinkResults.Count > 0)
            {
                SiteLinksAdExtension.SiteLinks = _bulkSiteLinkResults.OrderBy(s => s.Order).Select(s => s.SiteLink).ToList();
                SiteLinksAdExtension.Status    = AdExtensionStatus.Active;
            }
            else
            {
                SiteLinksAdExtension.Status = AdExtensionStatus.Deleted;
            }
        }
Example #2
0
        internal override void ReadRelatedDataFromStream(IBulkStreamReader reader)
        {
            var hasMoreRows = true;

            while (hasMoreRows)
            {
                BulkProductConditionCollection nextProductCollection;

                BulkProductAdExtensionIdentifier identitifier;

                if (reader.TryRead(x => x.Identifier.Equals(_identifier), out nextProductCollection))
                {
                    AddProductCollection(nextProductCollection);
                }
                else if (reader.TryRead(x => x.Equals(_identifier), out identitifier))
                {
                    if (identitifier.Status == AdExtensionStatus.Deleted)
                    {
                        _hasDeleteAllRow = true;
                    }
                }
                else
                {
                    hasMoreRows = false;
                }
            }

            // API returns empty collection instead of null. Keeping the same behavior
            ProductAdExtension.ProductSelection = _productConditionCollections.Select(s => s.ProductConditionCollection).ToList();

            ProductAdExtension.Status = _productConditionCollections.Count > 0 ? AdExtensionStatus.Active : AdExtensionStatus.Deleted;
        }
Example #3
0
        internal override void ReadRelatedDataFromStream(IBulkStreamReader reader)
        {
            var hasMoreRows = true;

            while (hasMoreRows)
            {
                TNegativeSite nextSite;

                TIdentifier identifier;

                if (reader.TryRead(x => x.Identifier.Equals(_firstRowIdentifier), out nextSite))
                {
                    _bulkNegativeSites.Add(nextSite);
                }
                else if (reader.TryRead(x => x.Equals(_firstRowIdentifier) && x.IsDeleteRow, out identifier))
                {
                    _hasDeleteAllRow = true;
                }
                else
                {
                    hasMoreRows = false;
                }
            }

            ReconstructApiObjects();

            Status = _bulkNegativeSites.Count > 0
                ? BingAds.Bulk.Entities.Status.Active
                : BingAds.Bulk.Entities.Status.Deleted;
        }
        internal override void ReadAdditionalData(IBulkStreamReader reader)
        {
            BulkKeywordBidSuggestion nextBidSuggestion;

            while (reader.TryRead(out nextBidSuggestion))
            {
                if (BidSuggestions == null)
                {
                    BidSuggestions = new BidSuggestionData();
                }

                if (nextBidSuggestion is BulkKeywordBestPositionBid)
                {
                    BidSuggestions.BestPosition = nextBidSuggestion;
                }
                else if (nextBidSuggestion is BulkKeywordMainLineBid)
                {
                    BidSuggestions.MainLine = nextBidSuggestion;
                }
                else if (nextBidSuggestion is BulkKeywordFirstPageBid)
                {
                    BidSuggestions.FirstPage = nextBidSuggestion;
                }
            }
        }
        /// <summary>
        /// Reads errors immediately after the current row
        /// </summary>
        /// <param name="reader">Reader object, allowing to read consecutive bulk rows</param>
        /// <remarks>
        /// No checks are made for the error type. It's assumed that an entity row can only be followed by errors of the same type
        /// </remarks>
        private void ReadErrors(IBulkStreamReader reader)
        {
            var errors = new List <BulkError>();

            BulkError error;

            while (reader.TryRead(out error))
            {
                errors.Add(error);
            }

            Errors = errors;
        }
        internal override void ReadRelatedDataFromStream(IBulkStreamReader reader)
        {
            // If this is a delete all row, just skip any error rows after this delete row
            if (IsDeleteRow)
            {
                var hasMoreErrors = true;

                while (hasMoreErrors)
                {
                    BulkError error;

                    hasMoreErrors = reader.TryRead(out error);
                }
            }
        }
Example #7
0
        internal override void ReadRelatedDataFromStream(IBulkStreamReader reader)
        {
            var hasMoreRows = true;

            while (hasMoreRows)
            {
                BulkTargetBid bidRow;

                TIdentifier identifierRow;

                if (reader.TryRead(x => x.Identifier.EntityId == EntityId, out bidRow))
                {
                    _bids.Add(bidRow);
                }
                else if (reader.TryRead(x => x.EntityId == EntityId && x.IsDeleteRow, out identifierRow))
                {
                    _deleteAllRows.Add(identifierRow);
                }
                else
                {
                    hasMoreRows = false;
                }

                // Delta download sends delete-all rows first, which don't have targetId. Have to look at all rows and set first non-null Id.
                if (Target.Id == null && bidRow != null && bidRow.TargetId != null)
                {
                    Target.Id = bidRow.TargetId;
                }
            }

            Status = _bids.Count > 0 ? BingAds.Bulk.Entities.Status.Active : BingAds.Bulk.Entities.Status.Deleted;

            var bidGroups = _bids.GroupBy(r => r.GetType()).ToDictionary(x => x.Key, x => x.ToList());

            var location = new LocationTarget2();

            LocationTarget.Location         = location;
            NegativeLocationTarget.Location = location;
            RadiusTarget.Location           = location;

            PopulateChildTargetBids(LocationTarget, bidGroups);
            PopulateChildTargetBids(AgeTarget, bidGroups);
            PopulateChildTargetBids(GenderTarget, bidGroups);
            PopulateChildTargetBids(DayTimeTarget, bidGroups);
            PopulateChildTargetBids(DeviceOsTarget, bidGroups);
            PopulateChildTargetBids(NegativeLocationTarget, bidGroups);
            PopulateChildTargetBids(RadiusTarget, bidGroups);

            var deleteAllGroups = _deleteAllRows.GroupBy(r => r.TargetBidType).ToDictionary(x => x.Key, x => x.ToList());

            PopulateChildTargetIdentities(LocationTarget, deleteAllGroups);
            PopulateChildTargetIdentities(AgeTarget, deleteAllGroups);
            PopulateChildTargetIdentities(GenderTarget, deleteAllGroups);
            PopulateChildTargetIdentities(DayTimeTarget, deleteAllGroups);
            PopulateChildTargetIdentities(DeviceOsTarget, deleteAllGroups);
            PopulateChildTargetIdentities(NegativeLocationTarget, deleteAllGroups);
            PopulateChildTargetIdentities(RadiusTarget, deleteAllGroups);

            if (new object[] { location.CityTarget, location.MetroAreaTarget, location.StateTarget, location.CountryTarget, location.PostalCodeTarget, location.RadiusTarget }.Any(x => x != null))
            {
                Target.Location = location;
            }

            Target.Age      = AgeTarget.AgeTarget;
            Target.Gender   = GenderTarget.GenderTarget;
            Target.DayTime  = DayTimeTarget.DayTimeTarget;
            Target.DeviceOS = DeviceOsTarget.DeviceOsTarget;
        }
        internal override void ReadAdditionalData(IBulkStreamReader reader)
        {
            BulkKeywordBidSuggestion nextBidSuggestion;

            while (reader.TryRead(out nextBidSuggestion))
            {
                if (BidSuggestions == null)
                {
                    BidSuggestions = new BidSuggestionData();
                }

                if (nextBidSuggestion is BulkKeywordBestPositionBid)
                {
                    BidSuggestions.BestPosition = nextBidSuggestion;
                }
                else if (nextBidSuggestion is BulkKeywordMainLineBid)
                {
                    BidSuggestions.MainLine = nextBidSuggestion;
                }
                else if (nextBidSuggestion is BulkKeywordFirstPageBid)
                {
                    BidSuggestions.FirstPage = nextBidSuggestion;
                }
            }            
        }
        /// <summary>
        /// Reads errors immediately after the current row
        /// </summary>
        /// <param name="reader">Reader object, allowing to read consecutive bulk rows</param>
        /// <remarks>
        /// No checks are made for the error type. It's assumed that an entity row can only be followed by errors of the same type
        /// </remarks>
        private void ReadErrors(IBulkStreamReader reader)
        {
            var errors = new List<BulkError>();

            BulkError error;

            while (reader.TryRead(out error))
            {
                errors.Add(error);
            }

            Errors = errors;
        }
        internal override void ReadRelatedDataFromStream(IBulkStreamReader reader)
        {
            var hasMoreRows = true;

            while (hasMoreRows)
            {
                BulkSiteLink nextSiteLink;

                SiteLinkAdExtensionIdentifier identitifier;

                if (reader.TryRead(x => x.Identifier.Equals(_identifier), out nextSiteLink))
                {
                    _bulkSiteLinkResults.Add(nextSiteLink);
                }
                else if (reader.TryRead(x => x.Equals(_identifier) && x.IsDeleteRow, out identitifier))
                {
                    _hasDeleteAllRow = true;
                }
                else
                {
                    hasMoreRows = false;
                }
            }

            if (_bulkSiteLinkResults.Count > 0)
            {
                SiteLinksAdExtension.SiteLinks = _bulkSiteLinkResults.OrderBy(s => s.Order).Select(s => s.SiteLink).ToList();
                SiteLinksAdExtension.Status = AdExtensionStatus.Active;
            }
            else
            {
                SiteLinksAdExtension.Status = AdExtensionStatus.Deleted;
            }
        }
        internal override void ReadRelatedDataFromStream(IBulkStreamReader reader)
        {
            var hasMoreRows = true;

            while (hasMoreRows)
            {
                BulkProductConditionCollection nextProductCollection;

                BulkProductAdExtensionIdentifier identitifier;

                if (reader.TryRead(x => x.Identifier.Equals(_identifier), out nextProductCollection))
                {
                    AddProductCollection(nextProductCollection);
                }
                else if (reader.TryRead(x => x.Equals(_identifier) && x.IsDeleteRow, out identitifier))
                {
                    _hasDeleteAllRow = true;                    
                }
                else
                {
                    hasMoreRows = false;
                }
            }

            // API returns empty collection instead of null. Keeping the same behavior
            ProductAdExtension.ProductSelection = _productConditionCollections.Select(s => s.ProductConditionCollection).ToList();

            ProductAdExtension.Status = _productConditionCollections.Count > 0 ? AdExtensionStatus.Active : AdExtensionStatus.Deleted;
        }