/// <summary>
        /// Creates a new <see cref="AdGroupCriterion"/> configured for an
        /// <code>ADD</code> operation.
        /// </summary>
        /// <param name="node">The node whose criterion should be added.</param>
        /// <param name="adGroupId">The ad group ID of the criterion.</param>
        /// <param name="idGenerator">The temporary ID generator for new nodes.</param>
        /// <returns>An <see cref="AdGroupCriterion"/> object for <code>ADD</code>
        /// operation.</returns>
        internal static AdGroupCriterion CreateCriterionForAdd(ProductPartitionNode node,
                                                               long adGroupId, TemporaryIdGenerator idGenerator)
        {
            PreconditionUtilities.CheckNotNull(node, ShoppingMessages.NodeCannotBeNull);

            AdGroupCriterion adGroupCriterion;

            if (node.IsExcludedUnit)
            {
                adGroupCriterion = new NegativeAdGroupCriterion();
            }
            else
            {
                adGroupCriterion = new BiddableAdGroupCriterion()
                {
                    biddingStrategyConfiguration = node.GetBiddingConfig()
                };
            }

            adGroupCriterion.adGroupId = adGroupId;
            adGroupCriterion.criterion = node.GetCriterion();

            adGroupCriterion.criterion.id = node.ProductPartitionId;
            if (node.Parent != null)
            {
                (adGroupCriterion.criterion as ProductPartition).parentCriterionId =
                    node.Parent.ProductPartitionId;
            }

            return(adGroupCriterion);
        }
        /// <summary>
        /// Creates a new ProductPartitionTree based on the collection of ad group
        /// criteria provided.
        /// </summary>
        /// <remarks>If retrieving existing criteria for use with this method,
        /// you must include all of the fields in <see cref="REQUIRED_SELECTOR_FIELDS" />
        /// in your selector.</remarks>
        /// <param name="adGroupId">The ad group ID.</param>
        /// <param name="adGroupCriteria">The list of ad group criteria.</param>
        /// <returns></returns>
        public static ProductPartitionTree CreateAdGroupTree(long adGroupId,
                                                             List <AdGroupCriterion> adGroupCriteria)
        {
            PreconditionUtilities.CheckNotNull(adGroupCriteria, ShoppingMessages.CriteriaListNull);

            Dictionary <long, List <AdGroupCriterion> > parentIdMap = CreateParentIdMap(adGroupCriteria);

            return(CreateAdGroupTree(adGroupId, parentIdMap));
        }
Пример #3
0
        /// <summary>
        /// Gets the report response.
        /// </summary>
        /// <returns>The report response.</returns>
        protected override ReportResponse GetReport()
        {
            PreconditionUtilities.CheckNotNull(reportDownloadOptions,
                                               "reportDownloadOptions cannot be null");
            WebResponse response = null;
            WebRequest  request  = BuildRequest(reportService.getReportDownloadUrlWithOptions(
                                                    reportJobId, reportDownloadOptions));

            response = request.GetResponse();
            return(new ReportResponse(response));
        }
        /// <summary>
        /// Creates a new ProductPartitionTree based on the collection of ad group
        /// criteria provided.
        /// </summary>
        /// <remarks>If retrieving existing criteria for use with this method,
        /// you must include all of the fields in <see cref="REQUIRED_SELECTOR_FIELD_ENUMS" />
        /// in your selector.</remarks>
        /// <param name="adGroupId">The ad group ID.</param>
        /// <param name="adGroupCriteria">The list of ad group criteria.</param>
        /// <returns></returns>
        public static ProductPartitionTree CreateAdGroupTree(long adGroupId,
                                                             List <AdGroupCriterion> adGroupCriteria)
        {
            PreconditionUtilities.CheckNotNull(adGroupCriteria, ShoppingMessages.CriteriaListNull);

            Dictionary <long, List <AdGroupCriterion> > parentIdMap = CreateParentIdMap(adGroupCriteria);

            ProductPartitionTree retval = CreateAdGroupTree(adGroupId, parentIdMap);

            // Mark the usage.
            retval.featureUsageRegistry.MarkUsage(FEATURE_ID);
            return(retval);
        }
        /// <summary>
        /// Creates a new AdGroupCriterion configured for a REMOVE operation.
        /// </summary>
        /// <param name="node">The node whose criterion should be removed.</param>
        /// <param name="adGroupId">The ad group ID of the criterion.</param>
        /// <returns>The AdGroupCriterion to be removed.</returns>
        internal static AdGroupCriterion CreateCriterionForRemove(ProductPartitionNode node,
                                                                  long adGroupId)
        {
            PreconditionUtilities.CheckNotNull(node, ShoppingMessages.NodeCannotBeNull);

            return(new AdGroupCriterion()
            {
                adGroupId = adGroupId,
                criterion = new ProductPartition()
                {
                    id = node.ProductPartitionId
                }
            });
        }
        /// <summary>
        /// Creates a new AdGroupCriterion configured for a SET operation that will
        /// set the criterion's bid.
        /// </summary>
        /// <param name="node">The node whose criterion should be updated.</param>
        /// <param name="adGroupId">The ad group ID of the criterion.</param>
        /// <param name="biddingConfig">The bidding strategy configuration of the
        /// criterion.</param>
        /// <returns>The AdGroupCriterion for SET operation.</returns>
        internal static AdGroupCriterion CreateCriterionForSetBid(ProductPartitionNode node,
                                                                  long adGroupId)
        {
            PreconditionUtilities.CheckNotNull(node, ShoppingMessages.NodeCannotBeNull);
            PreconditionUtilities.CheckArgument(node.IsBiddableUnit,
                                                string.Format(ShoppingMessages.NodeForBidUpdateIsNotBiddable, node.ProductPartitionId));

            return(new BiddableAdGroupCriterion()
            {
                adGroupId = adGroupId,
                criterion = node.GetCriterion(),
                biddingStrategyConfiguration = node.GetBiddingConfig()
            });
        }
        /// <summary>
        /// Constructor that initializes the temp ID generator based on the ID of
        /// the root node.
        /// </summary>
        /// <param name="adGroupId">the ID of the ad group.</param>
        /// <param name="root">The root node of the tree.</param>
        private ProductPartitionTree(long adGroupId, ProductPartitionNode root)
        {
            PreconditionUtilities.CheckNotNull(root, ShoppingMessages.RootNodeCannotBeNull);

            this.adGroupId           = adGroupId;
            this.root                = root;
            this.dimensionComparator = new ProductDimensionEqualityComparer();

            // If this is an existing node in an ad group, then the tree should be
            // cloned so that we can keep track of the original state of the tree.
            if (this.Root.ProductPartitionId > 0)
            {
                originalRoot = this.Root.Clone();
            }
        }
        /// <summary>
        /// Creates a map with key as the parent criterion ID and value as the list of child nodes.
        /// </summary>
        /// <param name="adGroupCriteria">The list of ad group criteria.</param>
        /// <returns>A criteria map.</returns>
        private static Dictionary <long, List <AdGroupCriterion> > CreateParentIdMap(
            List <AdGroupCriterion> adGroupCriteria)
        {
            PreconditionUtilities.CheckNotNull(adGroupCriteria, ShoppingMessages.CriteriaListNull);

            Dictionary <long, List <AdGroupCriterion> > parentIdMap =
                new Dictionary <long, List <AdGroupCriterion> >();

            foreach (AdGroupCriterion adGroupCriterion in adGroupCriteria)
            {
                PreconditionUtilities.CheckNotNull(adGroupCriterion.criterion,
                                                   ShoppingMessages.AdGroupCriterionNull);
                if (adGroupCriterion is BiddableAdGroupCriterion)
                {
                    BiddableAdGroupCriterion biddableCriterion =
                        (BiddableAdGroupCriterion)adGroupCriterion;

                    PreconditionUtilities.CheckState(biddableCriterion.userStatusSpecified,
                                                     string.Format(ShoppingMessages.UserStatusNotSpecified,
                                                                   biddableCriterion.criterion.id));

                    if (biddableCriterion.userStatus == UserStatus.REMOVED)
                    {
                        continue;
                    }
                }

                if (adGroupCriterion.criterion is ProductPartition)
                {
                    ProductPartition        partition = (ProductPartition)adGroupCriterion.criterion;
                    List <AdGroupCriterion> children  = null;
                    if (!parentIdMap.TryGetValue(partition.parentCriterionId, out children))
                    {
                        children = new List <AdGroupCriterion>();
                        parentIdMap[partition.parentCriterionId] = children;
                    }

                    children.Add(adGroupCriterion);
                }
            }

            return(parentIdMap);
        }