Пример #1
0
        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;
                }
            }
        }
        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;
            }
        }
Пример #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;
        }
Пример #4
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;
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of this class with the specified file details.
        /// </summary>
        /// <param name="filePath">The path of the bulk file to read.</param>
        /// <param name="resultFileType">The result file type.</param>
        /// <param name="fileFormat">The bulk file format.</param>
        public BulkFileReader(string filePath, ResultFileType resultFileType, Bulk.DownloadFileType fileFormat)
        {
            _bulkFilePath = filePath;

            _isForFullDownload = resultFileType == ResultFileType.FullDownload;

            _bulkStreamReader = new BulkStreamReader(filePath, fileFormat);
        }
Пример #6
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <param name="disposing">Disposes of the stream reader if set to true.</param>
        /// <remarks>You should use this method when finished with an instance of <see cref="BulkFileReader"/>.</remarks>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_bulkStreamReader != null)
                {
                    _bulkStreamReader.Dispose();

                    _bulkStreamReader = null;
                }
            }
        }
        /// <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);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// For unit testing
        /// </summary>
        internal BulkFileReader(IBulkStreamReader streamReader, bool isForFullDownload)
        {
            _isForFullDownload = isForFullDownload;

            _bulkStreamReader = streamReader;
        }
Пример #10
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <param name="disposing">Disposes of the stream reader if set to true.</param>
        /// <remarks>You should use this method when finished with an instance of <see cref="BulkFileReader"/>.</remarks>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_bulkStreamReader != null)
                {
                    _bulkStreamReader.Dispose();

                    _bulkStreamReader = null;
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of this class with the specified file details.
        /// </summary>
        /// <param name="filePath">The path of the bulk file to read.</param>
        /// <param name="resultFileType">The result file type.</param>
        /// <param name="fileFormat">The bulk file format.</param>
        public BulkFileReader(string filePath, ResultFileType resultFileType, Bulk.DownloadFileType fileFormat)
        {
            _bulkFilePath = filePath;

            _isForFullDownload = resultFileType == ResultFileType.FullDownload;

            _bulkStreamReader = new BulkStreamReader(filePath, fileFormat);
        }
Пример #12
0
 /// <summary>
 /// Reads object data from consecutive rows.
 /// </summary>
 /// <example>
 /// SingleLineBulkEntity: reads entity errors.
 /// MultilineBulkEntity: reads child entities.
 /// </example>
 /// <param name="reader"></param>
 internal virtual void ReadRelatedDataFromStream(IBulkStreamReader reader)
 {
 }
Пример #13
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;
        }
Пример #14
0
        /// <summary>
        /// For unit testing
        /// </summary>        
        internal BulkFileReader(IBulkStreamReader streamReader, bool isForFullDownload)
        {
            _isForFullDownload = isForFullDownload;

            _bulkStreamReader = streamReader;
        }
        /// <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;
        }
Пример #16
0
 /// <summary>
 /// Reads object data from consecutive rows.        
 /// </summary>
 /// <example>
 /// SingleLineBulkEntity: reads entity errors.
 /// MultilineBulkEntity: reads child entities.
 /// </example>
 /// <param name="reader"></param>
 internal virtual void ReadRelatedDataFromStream(IBulkStreamReader reader) { }
Пример #17
0
        /// <summary>
        /// Initializes a new instance of this class with the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read.</param>
        /// <param name="resultFileType">The result file type.</param>
        /// <param name="fileFormat">The bulk file format.</param>
        public BulkFileReader(Stream stream, ResultFileType resultFileType, Bulk.DownloadFileType fileFormat)
        {
            _isForFullDownload = resultFileType == ResultFileType.FullDownload;

            _bulkStreamReader = new BulkStreamReader(stream, fileFormat);
        }
        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;
            }
        }
 /// <summary>
 /// Reads additional data for entity if any.
 /// </summary>
 /// <param name="reader">Reader object, allowing to read consecutive bulk rows</param>
 internal virtual void ReadAdditionalData(IBulkStreamReader reader)
 {
 }
        /// <summary>
        /// Reads additional data for entity (if any) and errors
        /// </summary>
        /// <param name="reader">Reader object, allowing to read consecutive bulk rows</param>
        internal sealed override void ReadRelatedDataFromStream(IBulkStreamReader reader)
        {
            ReadAdditionalData(reader);

            ReadErrors(reader);
        }
Пример #21
0
        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 additional data for entity (if any) and errors
        /// </summary>
        /// <param name="reader">Reader object, allowing to read consecutive bulk rows</param>
        internal sealed override void ReadRelatedDataFromStream(IBulkStreamReader reader)
        {
            ReadAdditionalData(reader);

            ReadErrors(reader);
        }
        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;
        }
 /// <summary>
 /// Reads additional data for entity if any.
 /// </summary>
 /// <param name="reader">Reader object, allowing to read consecutive bulk rows</param>
 internal virtual void ReadAdditionalData(IBulkStreamReader reader) { }