/// <summary>
    /// Creates the Product Ad.
    /// </summary>
    /// <param name="adGroupAdService">The AdGroupAdService instance.</param>
    /// <param name="adGroup">The ad group.</param>
    /// <returns>The Product Ad.</returns>
    private static AdGroupAd CreateProductAd(AdGroupAdService adGroupAdService, AdGroup adGroup) {
      // Create product ad.
      ProductAd productAd = new ProductAd();

      // Create ad group ad.
      AdGroupAd adGroupAd = new AdGroupAd();
      adGroupAd.adGroupId = adGroup.id;
      adGroupAd.ad = productAd;

      // Create operation.
      AdGroupAdOperation operation = new AdGroupAdOperation();
      operation.operand = adGroupAd;
      operation.@operator = Operator.ADD;

      // Make the mutate request.
      AdGroupAdReturnValue retval = adGroupAdService.mutate(
          new AdGroupAdOperation[] { operation });

      return retval.value[0];
    }
    /// <summary>
    /// Gets the ad group ad by ID.
    /// </summary>
    /// <param name="adGroupAdService">The AdGroupAdService instance.</param>
    /// <param name="adGroupId">ID of the ad group.</param>
    /// <param name="adId">ID of the ad to be retrieved.</param>
    /// <returns>The AdGroupAd if the item could be retrieved, null otherwise.
    /// </returns>
    private AdGroupAd GetAdGroupAd(AdGroupAdService adGroupAdService, long adGroupId, long adId) {
      // Create a selector.
      Selector selector = new Selector();
      selector.fields = new string[] { "Id", "Url" };

      // Restrict the fetch to only the selected ad group ID and ad ID.
      Predicate adGroupPredicate = new Predicate();
      adGroupPredicate.field = "AdGroupId";
      adGroupPredicate.@operator = PredicateOperator.EQUALS;
      adGroupPredicate.values = new string[] { adGroupId.ToString() };

      Predicate adPredicate = new Predicate();
      adPredicate.field = "Id";
      adPredicate.@operator = PredicateOperator.EQUALS;
      adPredicate.values = new string[] { adId.ToString() };

      selector.predicates = new Predicate[] { adGroupPredicate, adPredicate };

      // Get the ad.
      AdGroupAdPage page = adGroupAdService.get(selector);

      if (page != null && page.entries != null && page.entries.Length > 0) {
        return page.entries[0];
      } else {
        return null;
      }
    }
        /// <summary>
        /// Gets the ad group ad by ID.
        /// </summary>
        /// <param name="adGroupAdService">The AdGroupAdService instance.</param>
        /// <param name="adGroupId">ID of the ad group.</param>
        /// <param name="adId">ID of the ad to be retrieved.</param>
        /// <returns>The AdGroupAd if the item could be retrieved, null otherwise.
        /// </returns>
        private AdGroupAd GetAdGroupAd(AdGroupAdService adGroupAdService, long adGroupId, long adId)
        {
            // Create a selector.
              Selector selector = new Selector() {
            fields = new string[] { Ad.Fields.Id, Ad.Fields.Url },
            predicates = new Predicate[] {
              // Restrict the fetch to only the selected ad group ID and ad ID.
              Predicate.Equals(AdGroupAd.Fields.AdGroupId, adGroupId),
              Predicate.Equals(Ad.Fields.Id, adId)
            }
              };

              // Get the ad.
              AdGroupAdPage page = adGroupAdService.get(selector);

              if (page != null && page.entries != null && page.entries.Length > 0) {
            return page.entries[0];
              } else {
            return null;
              }
        }