public void TestUpdateLineItem()
        {
            lineItem1.deliveryRateType = DeliveryRateType.AS_FAST_AS_POSSIBLE;

            LineItem localLineItem = null;

            Assert.DoesNotThrow(delegate() {
                localLineItem = lineItemService.updateLineItem(lineItem1);
            });

            Assert.NotNull(localLineItem);
            Assert.AreEqual(localLineItem.id, lineItem1.id);
            Assert.AreEqual(localLineItem.name, lineItem1.name);
            Assert.AreEqual(localLineItem.orderId, lineItem1.orderId);
            Assert.AreEqual(localLineItem.deliveryRateType, lineItem1.deliveryRateType);
        }
Beispiel #2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the LineItemService.
            LineItemService lineItemService = (LineItemService)user.GetService(
                DfpService.v201311.LineItemService);

            // Get the CustomTargetingService.
            CustomTargetingService customTargetingService = (CustomTargetingService)user.GetService(
                DfpService.v201311.CustomTargetingService);

            long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE"));

            long[] customCriteriaIds1 =
                new long[] { long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")),
                             long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")) };
            long[] customCriteriaIds2 =
                new long[] { long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")),
                             long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")) };
            long[] customCriteriaIds3 =
                new long[] { long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")),
                             long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")) };

            // Create custom criteria.
            CustomCriteria customCriteria1 = new CustomCriteria();

            customCriteria1.keyId     = customCriteriaIds1[0];
            customCriteria1.valueIds  = new long[] { customCriteriaIds1[1] };
            customCriteria1.@operator = CustomCriteriaComparisonOperator.IS;

            CustomCriteria customCriteria2 = new CustomCriteria();

            customCriteria2.keyId     = customCriteriaIds2[0];
            customCriteria2.valueIds  = new long[] { customCriteriaIds2[1] };
            customCriteria2.@operator = CustomCriteriaComparisonOperator.IS_NOT;

            CustomCriteria customCriteria3 = new CustomCriteria();

            customCriteria3.keyId     = customCriteriaIds3[0];
            customCriteria3.valueIds  = new long[] { customCriteriaIds3[1] };
            customCriteria3.@operator = CustomCriteriaComparisonOperator.IS;

            // Create the custom criteria set that will resemble:
            //
            // (customCriteria1.key == customCriteria1.value OR
            //     (customCriteria2.key != customCriteria2.value AND
            //         customCriteria3.key == customCriteria3.value))
            CustomCriteriaSet topCustomCriteriaSet = new CustomCriteriaSet();

            topCustomCriteriaSet.logicalOperator = CustomCriteriaSetLogicalOperator.OR;

            CustomCriteriaSet subCustomCriteriaSet = new CustomCriteriaSet();

            subCustomCriteriaSet.logicalOperator = CustomCriteriaSetLogicalOperator.AND;
            subCustomCriteriaSet.children        =
                new CustomCriteriaNode[] { customCriteria2, customCriteria3 };
            topCustomCriteriaSet.children =
                new CustomCriteriaNode[] { customCriteria1, subCustomCriteriaSet };

            try {
                // Set the custom criteria targeting on the line item.
                LineItem lineItem = lineItemService.getLineItem(lineItemId);
                lineItem.targeting.customTargeting = topCustomCriteriaSet;

                // Update the line items on the server.
                lineItem = lineItemService.updateLineItem(lineItem);

                // Display the updated line item.
                Console.WriteLine("Line item with ID {0} updated with custom criteria targeting \n{1}\n",
                                  lineItem.id, getCustomCriteriaSetString(lineItem.targeting.customTargeting, 0));
            } catch (Exception ex) {
                Console.WriteLine("Failed to add custom target criteria. Exception says \"{0}\"",
                                  ex.Message);
            }
        }