Google.Api.Ads.AdWords.Examples.CSharp.v201306.UpgradeLegacySitelinks.associateSitelinkFeedItemsWithCampaign C# (CSharp) Method

associateSitelinkFeedItemsWithCampaign() private static method

Associates the sitelink feed items with a campaign.
private static associateSitelinkFeedItemsWithCampaign ( CampaignFeedService campaignFeedService, SiteLinksFeed siteLinksFeed, List siteLinkFeedItemIds, long campaignId ) : void
campaignFeedService Google.Api.Ads.AdWords.v201306.CampaignFeedService The campaign feed service.
siteLinksFeed SiteLinksFeed The feed for holding the sitelinks.
siteLinkFeedItemIds List The list of feed item ids to be /// associated with a campaign as sitelinks.
campaignId long The campaign id to which upgraded sitelinks are /// added.
return void
        private static void associateSitelinkFeedItemsWithCampaign(
        CampaignFeedService campaignFeedService, SiteLinksFeed siteLinksFeed,
        List<long> siteLinkFeedItemIds, long campaignId)
        {
            // Create a custom matching function that matches the given feed items to
              // the campaign.
              RequestContextOperand requestContextOperand = new RequestContextOperand();
              requestContextOperand.contextType = RequestContextOperandContextType.FEED_ITEM_ID;

              Function function = new Function();
              function.lhsOperand = new FunctionArgumentOperand[] {requestContextOperand};
              function.@operator = FunctionOperator.IN;

              List<FunctionArgumentOperand> operands = new List<FunctionArgumentOperand>();
              foreach (long feedItemId in siteLinkFeedItemIds) {
            ConstantOperand constantOperand = new ConstantOperand();
            constantOperand.longValue = feedItemId;
            constantOperand.type = ConstantOperandConstantType.LONG;
            operands.Add(constantOperand);
              }
              function.rhsOperand = operands.ToArray();

              // Create upgraded sitelinks for the campaign. Use the sitelinks feed we
              // created, and restrict feed items by matching function.
              CampaignFeed campaignFeed = new CampaignFeed();
              campaignFeed.feedId = siteLinksFeed.SiteLinksFeedId;
              campaignFeed.campaignId = campaignId;
              campaignFeed.matchingFunction = function;
              campaignFeed.placeholderTypes = new int[] {PLACEHOLDER_SITELINKS};

              CampaignFeedOperation operation = new CampaignFeedOperation();
              operation.operand = campaignFeed;
              operation.@operator = Operator.ADD;
              campaignFeedService.mutate(new CampaignFeedOperation[] {operation});
        }