コード例 #1
0
 /// <summary>
 /// Determines whether the specified <see cref="ProductCanonicalCondition"/> objects
 /// are equal.
 /// </summary>
 /// <param name="x">The first object to compare.</param>
 /// <param name="y">The second object to compare.</param>
 /// <returns>
 /// True if the specified objects are equal; otherwise, false.
 /// </returns>
 private bool Equals(ProductCanonicalCondition x, ProductCanonicalCondition y)
 {
     return(x.conditionSpecified == y.conditionSpecified && x.condition == y.condition);
 }
コード例 #2
0
 /// <summary>
 /// Gets the hash code for a <see cref="ProductCanonicalCondition"/>.
 /// </summary>
 /// <param name="obj">The object to calculate hash code for.</param>
 /// <returns>The hash code.</returns>
 private int GetHashCodeInternal(ProductCanonicalCondition obj)
 {
     return(Tuple
            .Create <bool, ProductCanonicalConditionCondition>(obj.conditionSpecified,
                                                               obj.condition).GetHashCode());
 }
コード例 #3
0
        public void TestNavigation()
        {
            rootNode = rootNode.AsSubdivision();
            ProductBrand brandGoogle = ProductDimensions.CreateBrand("google");
            ProductBrand brandOther  = ProductDimensions.CreateBrand(null);
            ProductCanonicalCondition conditionNew =
                ProductDimensions.CreateCanonicalCondition(ProductCanonicalConditionCondition.NEW);
            ProductCanonicalCondition conditionUsed =
                ProductDimensions.CreateCanonicalCondition(ProductCanonicalConditionCondition.USED);
            ProductCanonicalCondition conditionOther = ProductDimensions.CreateCanonicalCondition();

            // Build up the brand = Google node under the root.
            ProductPartitionNode brandGoogleNode = rootNode.AddChild(brandGoogle).AsSubdivision();

            brandGoogleNode.AddChild(conditionNew);
            brandGoogleNode.AddChild(conditionUsed);
            brandGoogleNode.AddChild(conditionOther);

            Assert.True(brandGoogleNode.HasChild(conditionNew),
                        "HasChild should return true for existing child dimension.");
            Assert.AreSame(brandGoogleNode, brandGoogleNode.GetChild(conditionNew).Parent,
                           "parent->GetChild->getParent should return parent.");
            Assert.True(brandGoogleNode.HasChild(conditionUsed),
                        "HasChild should return true for existing child dimension.");
            Assert.AreSame(brandGoogleNode, brandGoogleNode.GetChild(conditionUsed).Parent,
                           "parent->GetChild->getParent should return parent.");
            Assert.True(brandGoogleNode.HasChild(conditionOther),
                        "HasChild should return true for existing child dimension.");
            Assert.AreSame(brandGoogleNode, brandGoogleNode.GetChild(conditionOther).Parent,
                           "parent->GetChild->getParent should return parent.");

            // Build up the brand = null (other) node under the root.
            ProductPartitionNode brandOtherNode = rootNode.AddChild(brandOther).AsSubdivision();

            brandOtherNode.AddChild(conditionNew);
            Assert.True(brandOtherNode.HasChild(conditionNew),
                        "HasChild should return true for existing child dimension.");
            Assert.AreSame(brandOtherNode, brandOtherNode.GetChild(conditionNew).Parent,
                           "parent->GetChild->getParent should return parent.");
            Assert.False(brandOtherNode.HasChild(conditionUsed),
                         "HasChild should return false for nonexistent child dimension.");
            Assert.False(brandOtherNode.HasChild(conditionOther),
                         "HasChild should return false for nonexistent child dimension.");
            brandOtherNode.AddChild(conditionOther);
            Assert.True(brandOtherNode.HasChild(conditionOther),
                        "HasChild should return true for existing child dimension.");
            Assert.AreSame(brandOtherNode, brandOtherNode.GetChild(conditionOther).Parent,
                           "parent->GetChild->getParent should return parent.");

            // Remove one of the children of brand = null.
            brandOtherNode.RemoveChild(conditionOther);
            Assert.False(brandOtherNode.HasChild(conditionOther),
                         "HasChild should return false for a removed child dimension.");

            // Remove the rest of the children of brand = null.
            brandOtherNode.RemoveAllChildren();
            Assert.False(brandOtherNode.HasChild(conditionNew),
                         "HasChild should return false for any removed child dimension.");
            Assert.False(brandOtherNode.HasChild(conditionUsed),
                         "HasChild should return false for any removed child dimension.");
        }
コード例 #4
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">The campaign id to add product scope.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201609.CampaignCriterionService);

            ProductScope productScope = new ProductScope();
            // This set of dimensions is for demonstration purposes only. It would be
            // extremely unlikely that you want to include so many dimensions in your
            // product scope.
            ProductBrand nexusBrand = new ProductBrand();

            nexusBrand.value = "Nexus";

            ProductCanonicalCondition newProducts = new ProductCanonicalCondition();

            newProducts.condition = ProductCanonicalConditionCondition.NEW;

            ProductCustomAttribute customAttribute = new ProductCustomAttribute();

            customAttribute.type  = ProductDimensionType.CUSTOM_ATTRIBUTE_0;
            customAttribute.value = "my attribute value";

            ProductOfferId bookOffer = new ProductOfferId();

            bookOffer.value = "book1";

            ProductType mediaProducts = new ProductType();

            mediaProducts.type  = ProductDimensionType.PRODUCT_TYPE_L1;
            mediaProducts.value = "Media";

            ProductType bookProducts = new ProductType();

            bookProducts.type  = ProductDimensionType.PRODUCT_TYPE_L2;
            bookProducts.value = "Books";

            // The value for the bidding category is a fixed ID for the
            // 'Luggage & Bags' category. You can retrieve IDs for categories from
            // the ConstantDataService. See the 'GetProductCategoryTaxonomy' example
            // for more details.
            ProductBiddingCategory luggageBiddingCategory = new ProductBiddingCategory();

            luggageBiddingCategory.type  = ProductDimensionType.BIDDING_CATEGORY_L1;
            luggageBiddingCategory.value = -5914235892932915235;

            productScope.dimensions = new ProductDimension[] { nexusBrand, newProducts, bookOffer,
                                                               mediaProducts, luggageBiddingCategory };

            CampaignCriterion campaignCriterion = new CampaignCriterion();

            campaignCriterion.campaignId = campaignId;
            campaignCriterion.criterion  = productScope;

            // Create operation.
            CampaignCriterionOperation operation = new CampaignCriterionOperation();

            operation.operand   = campaignCriterion;
            operation.@operator = Operator.ADD;

            try {
                // Make the mutate request.
                CampaignCriterionReturnValue result = campaignCriterionService.mutate(
                    new CampaignCriterionOperation[] { operation });

                Console.WriteLine("Created a ProductScope criterion with ID '{0}'",
                                  result.value[0].criterion.id);
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to set shopping product scope.", e);
            }
        }
コード例 #5
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">The ad group to which product partition is
        /// added.</param>
        public void Run(AdWordsUser user, long adGroupId)
        {
            // Get the AdGroupCriterionService.
            AdGroupCriterionService adGroupCriterionService =
                (AdGroupCriterionService)user.GetService(
                    AdWordsService.v201506.AdGroupCriterionService);

            ProductPartitionHelper helper = new ProductPartitionHelper(adGroupId);

            // The most trivial partition tree has only a unit node as the root:
            //   helper.createUnit(null, null, 100000);

            ProductPartition root = helper.CreateSubdivision(null, null);

            ProductCanonicalCondition newCondition = new ProductCanonicalCondition();

            newCondition.condition = ProductCanonicalConditionCondition.NEW;
            ProductPartition newPartition = helper.CreateUnit(root, newCondition, 200000, false);

            ProductCanonicalCondition usedCondition = new ProductCanonicalCondition();

            usedCondition.condition = ProductCanonicalConditionCondition.USED;
            ProductPartition usedPartition = helper.CreateUnit(root, usedCondition, 100000, false);

            ProductPartition otherCondition = helper.CreateSubdivision(root,
                                                                       new ProductCanonicalCondition());

            ProductBrand coolBrand = new ProductBrand();

            coolBrand.value = "CoolBrand";
            helper.CreateUnit(otherCondition, coolBrand, 900000, false);

            ProductBrand cheapBrand = new ProductBrand();

            cheapBrand.value = "CheapBrand";
            helper.CreateUnit(otherCondition, cheapBrand, 10000, false);

            ProductPartition otherBrand =
                helper.CreateSubdivision(otherCondition, new ProductBrand());

            // The value for the bidding category is a fixed ID for the 'Luggage & Bags'
            // category. You can retrieve IDs for categories from the ConstantDataService.
            // See the 'GetProductCategoryTaxonomy' example for more details.

            ProductBiddingCategory luggageAndBags = new ProductBiddingCategory();

            luggageAndBags.type  = ProductDimensionType.BIDDING_CATEGORY_L1;
            luggageAndBags.value = -5914235892932915235;
            helper.CreateUnit(otherBrand, luggageAndBags, 750000, false);

            ProductBiddingCategory everythingElse = new ProductBiddingCategory();

            everythingElse.type = ProductDimensionType.BIDDING_CATEGORY_L1;

            helper.CreateUnit(otherBrand, everythingElse, 110000, false);

            try {
                // Make the mutate request.
                AdGroupCriterionReturnValue retval = adGroupCriterionService.mutate(helper.Operations);

                Dictionary <long, List <ProductPartition> > children =
                    new Dictionary <long, List <ProductPartition> >();
                ProductPartition rootNode = null;
                // For each criterion, make an array containing each of its children
                // We always create the parent before the child, so we can rely on that here.
                foreach (AdGroupCriterion adGroupCriterion in retval.value)
                {
                    ProductPartition newCriterion = (ProductPartition)adGroupCriterion.criterion;
                    children[newCriterion.id] = new List <ProductPartition>();

                    if (newCriterion.parentCriterionIdSpecified)
                    {
                        children[newCriterion.parentCriterionId].Add(newCriterion);
                    }
                    else
                    {
                        rootNode = (ProductPartition)adGroupCriterion.criterion;
                    }
                }

                // Show the tree
                StringWriter writer = new StringWriter();
                DisplayTree(rootNode, children, 0, writer);
                Console.WriteLine(writer.ToString());
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to set shopping product partition.", ex);
            }
        }