/// <summary>
    /// Gets the list of feed items that are used by a campaign through a given
    /// campaign feed.
    /// </summary>
    /// <param name="campaignFeed">The campaign feed.</param>
    /// <returns>The list of feed items.</returns>
    private List<long> GetFeedItemsForCampaign(CampaignFeed campaignFeed) {
      List<long> feedItems = new List<long>();

      switch (campaignFeed.matchingFunction.@operator) {
        case FunctionOperator.IN:
          // Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
          // Extract feedItems if applicable.
          feedItems.AddRange(GetFeedItemsFromArgument(campaignFeed.matchingFunction));

          break;

        case FunctionOperator.AND:
          // Check each condition.

          foreach (FunctionArgumentOperand argument in campaignFeed.matchingFunction.lhsOperand) {
            // Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
            // Extract feedItems if applicable.
            if (argument is FunctionOperand) {
              FunctionOperand operand = (argument as FunctionOperand);
              if (operand.value.@operator == FunctionOperator.IN) {
                feedItems.AddRange(GetFeedItemsFromArgument(operand.value));
              }
            }
          }
          break;

        default:
          // There are no other matching functions involving feeditem ids.
          break;
      }

      return feedItems;
    }
    /// <summary>
    /// Deletes a campaign feed.
    /// </summary>
    /// <param name="user">The user.</param>
    /// <param name="campaignFeed">The campaign feed.</param>
    /// <returns></returns>
    private CampaignFeed DeleteCampaignFeed(AdWordsUser user, CampaignFeed campaignFeed) {
      CampaignFeedService campaignFeedService = (CampaignFeedService) user.GetService(
          AdWordsService.v201506.CampaignFeedService);

      CampaignFeedOperation operation = new CampaignFeedOperation() {
        operand = campaignFeed,
        @operator = Operator.REMOVE
      };

      return campaignFeedService.mutate(new CampaignFeedOperation[] { operation }).value[0];
    }
    /// <summary>
    /// Gets the platform restrictions for sitelinks in a campaign.
    /// </summary>
    /// <param name="campaignFeed">The campaign feed.</param>
    /// <returns>The platform restrictions.</returns>
    private ExtensionSettingPlatform GetPlatformRestrictionsForCampaign(
          CampaignFeed campaignFeed) {
      string platformRestrictions = "NONE";

      if (campaignFeed.matchingFunction.@operator == FunctionOperator.AND) {
        foreach (FunctionArgumentOperand argument in campaignFeed.matchingFunction.lhsOperand) {
          // Check if matchingFunction is of the form EQUALS(CONTEXT.DEVICE, 'Mobile').
          if (argument is FunctionOperand) {
            FunctionOperand operand = (argument as FunctionOperand);
            if (operand.value.@operator == FunctionOperator.EQUALS) {
              RequestContextOperand requestContextOperand = operand.value.lhsOperand[0] as
                  RequestContextOperand;
              if (requestContextOperand != null && requestContextOperand.contextType ==
                  RequestContextOperandContextType.DEVICE_PLATFORM) {
                platformRestrictions = (operand.value.rhsOperand[0] as ConstantOperand)
                      .stringValue;
              }
            }
          }
        }
      }

      return (ExtensionSettingPlatform) Enum.Parse(typeof(ExtensionSettingPlatform),
              platformRestrictions, true);
    }
    private static void createSitelinksCampaignFeed(AdWordsUser user,
      SitelinksDataHolder sitelinksData, long campaignId) {
      // Get the CampaignFeedService.
      CampaignFeedService campaignFeedService =
        (CampaignFeedService) user.GetService(AdWordsService.v201506.CampaignFeedService);

      // Construct a matching function that associates the sitelink feeditems
      // to the campaign, and set the device preference to Mobile. See the
      // matching function guide at
      // https://developers.google.com/adwords/api/docs/guides/feed-matching-functions
      // for more details.
      string matchingFunctionString = string.Format(@"
          AND(
            IN(FEED_ITEM_ID, {{{0}}}),
            EQUALS(CONTEXT.DEVICE, 'Mobile')
          )",
          string.Join(",", sitelinksData.FeedItemIds));


      CampaignFeed campaignFeed = new CampaignFeed() {
        feedId = sitelinksData.FeedId,
        campaignId = campaignId,
        matchingFunction = new Function() {
          functionString = matchingFunctionString
        },
        // Specifying placeholder types on the CampaignFeed allows the same feed
        // to be used for different placeholders in different Campaigns.
        placeholderTypes = new int[] { PLACEHOLDER_SITELINKS }
      };

      CampaignFeedOperation operation = new CampaignFeedOperation();
      operation.operand = campaignFeed;
      operation.@operator = Operator.ADD;
      CampaignFeedReturnValue result =
          campaignFeedService.mutate(new CampaignFeedOperation[] {operation});
      foreach (CampaignFeed savedCampaignFeed in result.value) {
        Console.WriteLine("Campaign with ID {0} was associated with feed with ID {1}",
            savedCampaignFeed.campaignId, savedCampaignFeed.feedId);
      }
    }