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

getExistingFeed() private static method

Retrieve an existing feed that is mapped to hold sitelinks. The first active sitelinks feed is retrieved by this method.
private static getExistingFeed ( FeedMappingService feedMappingService ) : SiteLinksFeed
feedMappingService Google.Api.Ads.AdWords.v201306.FeedMappingService The feed mapping service.
return SiteLinksFeed
        private static SiteLinksFeed getExistingFeed(FeedMappingService feedMappingService)
        {
            Selector selector = new Selector();
              selector.fields = new string[] {"FeedId", "FeedMappingId", "PlaceholderType", "Status",
            "AttributeFieldMappings"};

              Predicate placeHolderPredicate = new Predicate();
              placeHolderPredicate.field = "PlaceholderType";
              placeHolderPredicate.@operator = PredicateOperator.EQUALS;
              placeHolderPredicate.values = new string[] {PLACEHOLDER_SITELINKS.ToString()};

              Predicate statusPredicate = new Predicate();
              statusPredicate.field = "Status";
              statusPredicate.@operator = PredicateOperator.EQUALS;
              statusPredicate.values = new string[] {"ACTIVE"};

              selector.predicates = new Predicate[] {placeHolderPredicate, statusPredicate};

              FeedMappingPage page = feedMappingService.get(selector);

              if (page != null && page.entries != null && page.entries.Length > 0) {
            foreach (FeedMapping feedMapping in page.entries) {
              long? feedId = feedMapping.feedId;
              long? textAttributeId = null;
              long? urlAttributeId = null;
              foreach (AttributeFieldMapping attributeMapping in feedMapping.attributeFieldMappings) {
            if (attributeMapping.fieldId == PLACEHOLDER_FIELD_SITELINK_LINK_TEXT) {
              textAttributeId = attributeMapping.feedAttributeId;
            } else if (attributeMapping.fieldId == PLACEHOLDER_FIELD_SITELINK_URL) {
              urlAttributeId = attributeMapping.feedAttributeId;
            }
              }

              if (feedId != null && textAttributeId != null && urlAttributeId != null) {
            SiteLinksFeed siteLinksFeed = new SiteLinksFeed();
            siteLinksFeed.SiteLinksFeedId = feedId.Value;
            siteLinksFeed.LinkTextFeedAttributeId = textAttributeId.Value;
            siteLinksFeed.LinkUrlFeedAttributeId = urlAttributeId.Value;
            return siteLinksFeed;
              }
            }
              }
              return null;
        }