/// <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();
            }
        }
Пример #2
0
        /// <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>
        /// <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>
        /// Converts a System.DateTime object to a AdManager DateTime object with the specified
        /// timeZoneId. Does not perform time zone conversion. This means the returned DateTime
        /// value may not represent the same instant as the System.DateTime value.
        /// </summary>
        /// <param name="dateTime">The DateTime object.</param>
        /// <param name="timeZoneId">The timeZoneId to use.</param>
        /// <returns>A AdManager Datetime object.</returns>
        public static AdManagerDateTime FromDateTime(System.DateTime dateTime, string timeZoneId)
        {
            PreconditionUtilities.CheckArgumentNotNull(dateTime, "dateTime");
            PreconditionUtilities.CheckArgumentNotNull(timeZoneId, "timeZoneId");

            AdManagerDateTime retval = new AdManagerDateTime();

            retval.date       = new Date();
            retval.date.year  = dateTime.Year;
            retval.date.month = dateTime.Month;
            retval.date.day   = dateTime.Day;
            retval.hour       = dateTime.Hour;
            retval.minute     = dateTime.Minute;
            retval.second     = dateTime.Second;
            retval.timeZoneID = timeZoneId;
            return(retval);
        }
        /// <summary>
        /// Converts a NodaTime.ZonedDateTime object to a Dfp DateTime object with its
        /// intrinsic timezone.
        /// </summary>
        /// <param name="dateTime">The ZonedDateTime object.</param>
        /// <returns>A Dfp Datetime object.</returns>
        public static DfpDateTime FromDateTime(ZonedDateTime dateTime)
        {
            PreconditionUtilities.CheckArgumentNotNull(dateTime, "dateTime");

            DfpDateTime retval = new DfpDateTime();

            retval.date       = new Date();
            retval.date.year  = dateTime.Year;
            retval.date.month = dateTime.Month;
            retval.date.day   = dateTime.Day;
            retval.hour       = dateTime.Hour;
            retval.minute     = dateTime.Minute;
            retval.second     = dateTime.Second;
            retval.timeZoneID = dateTime.Zone.ToString();

            return(retval);
        }
        /// <summary>
        /// Returns a new tree based on a non-empty collection of ad group criteria.
        /// </summary>
        /// <param name="adGroupId">The ad group ID.</param>
        /// <param name="parentIdMap">The multimap from parent product partition ID
        /// to child criteria.</param>
        /// <returns>a new product partition tree.</returns>
        private static ProductPartitionTree CreateAdGroupTree(long adGroupId,
                                                              Dictionary <long, List <AdGroupCriterion> > parentIdMap)
        {
            ProductPartitionNode rootNode = null;

            if (parentIdMap.Count == 0)
            {
                rootNode = new ProductPartitionNode(null, null, NEW_ROOT_ID);
            }
            else
            {
                List <AdGroupCriterion> root =
                    CollectionUtilities.TryGetValue(parentIdMap, ROOT_PARENT_ID);

                PreconditionUtilities.CheckState(root != null,
                                                 string.Format(ShoppingMessages.RootCriteriaNotFoundInCriteriaList, adGroupId));

                PreconditionUtilities.CheckState(root.Count == 1,
                                                 string.Format(ShoppingMessages.MoreThanOneRootFound, adGroupId));

                AdGroupCriterion rootCriterion = root[0];

                PreconditionUtilities.CheckState(rootCriterion is BiddableAdGroupCriterion,
                                                 string.Format(ShoppingMessages.RootCriterionIsNotBiddable, adGroupId));

                BiddableAdGroupCriterion biddableRootCriterion =
                    (BiddableAdGroupCriterion)rootCriterion;

                rootNode = new ProductPartitionNode(null, null, rootCriterion.criterion.id,
                                                    new ProductDimensionEqualityComparer());

                // Set the root's bid if a bid exists on the BiddableAdGroupCriterion.
                Money rootNodeBid = GetBid(biddableRootCriterion);

                if (rootNodeBid != null)
                {
                    rootNode.AsBiddableUnit().CpcBid = rootNodeBid.microAmount;
                }

                AddChildNodes(rootNode, parentIdMap);
            }

            return(new ProductPartitionTree(adGroupId, rootNode));
        }
        /// <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);
        }
 /// <summary>
 /// Sets the statement ORDER BY clause in the form of
 /// <code>"ORDER BY &lt;property&gt; [ASC | DESC]"</code>
 /// e.g. "type ASC, lastModifiedDateTime DESC".
 /// The "ORDER BY " keyword will be ignored.
 /// </summary>
 /// <param name="orderBy">the statement order by without "ORDER BY"</param>
 /// <returns>The statement builder, for chaining method calls.</returns>
 public StatementBuilder OrderBy(String orderBy)
 {
     PreconditionUtilities.CheckArgumentNotNull(orderBy, "orderBy");
     this.orderBy = RemoveKeyword(orderBy, ORDER_BY);
     return(this);
 }
 /// <summary>
 /// Sets the statement WHERE clause in the form of
 /// <code>
 /// "WHERE &lt;condition&gt; {[AND | OR] &lt;condition&gt; ...}"
 /// </code>
 /// e.g. "a = b OR b = c". The "WHERE " keyword will be ignored.
 /// </summary>
 /// <param name="conditions">The statement query without "WHERE"</param>
 /// <returns>The statement builder, for chaining method calls.</returns>
 public StatementBuilder Where(String conditions)
 {
     PreconditionUtilities.CheckArgumentNotNull(conditions, "conditions");
     this.where = RemoveKeyword(conditions, WHERE);
     return(this);
 }
 /// <summary>
 /// Sets the statement FROM clause in the form of "table".
 /// Only necessary for statements being sent to the
 /// <see cref="PublisherQueryLanguageService"/>.
 /// The "FROM " keyword will be ignored.
 /// </summary>
 /// <param name="table">The statement from clause without "FROM"</param>
 /// <returns>The statement builder, for chaining method calls.</returns>
 public StatementBuilder From(String table)
 {
     PreconditionUtilities.CheckArgumentNotNull(table, "table");
     this.from = RemoveKeyword(table, FROM);
     return(this);
 }
 /// <summary>
 /// Sets the statement SELECT clause in the form of "a,b".
 /// Only necessary for statements being sent to the
 /// <see cref="PublisherQueryLanguageService"/>.
 /// The "SELECT " keyword will be ignored.
 /// </summary>
 /// <param name="columns">
 /// The statement serlect clause without "SELECT".
 /// </param>
 /// <returns>The statement builder, for chaining method calls.</returns>
 public StatementBuilder Select(String columns)
 {
     PreconditionUtilities.CheckArgumentNotNull(columns, "columns");
     this.select = RemoveKeyword(columns, SELECT);
     return(this);
 }