/// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (ContentMetadataKeyHierarchyService contentMetadataKeyHierarchyService =
                       (ContentMetadataKeyHierarchyService)user.GetService(
                           DfpService.v201708.ContentMetadataKeyHierarchyService)) {
                // Set the ID of the content metadata key hierarchy to update.
                long contentMetadataKeyHierarchyId =
                    long.Parse(_T("INSERT_CONTENT_METADATA_KEY_HIERARCHY_ID_HERE"));

                // Set the ID of the custom targeting key to be added as a hierarchy level
                long customTargetingKeyId = long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE"));

                // Create a statement to get content metadata key hierarchies.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("WHERE id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("id", contentMetadataKeyHierarchyId);

                try {
                    ContentMetadataKeyHierarchyPage page = contentMetadataKeyHierarchyService
                                                           .getContentMetadataKeyHierarchiesByStatement(statementBuilder.ToStatement());

                    ContentMetadataKeyHierarchy contentMetadataKeyHierarchy = page.results[0];

                    // Update the content metadata key hierarchy by adding a hierarchy level.
                    ContentMetadataKeyHierarchyLevel[] hierarchyLevels = contentMetadataKeyHierarchy
                                                                         .hierarchyLevels;

                    ContentMetadataKeyHierarchyLevel hierarchyLevel = new ContentMetadataKeyHierarchyLevel();
                    hierarchyLevel.customTargetingKeyId = customTargetingKeyId;
                    hierarchyLevel.hierarchyLevel       = hierarchyLevels.Length + 1;

                    List <ContentMetadataKeyHierarchyLevel> updatedHieratchyLevels =
                        new List <ContentMetadataKeyHierarchyLevel>();
                    updatedHieratchyLevels.AddRange(hierarchyLevels);
                    updatedHieratchyLevels.Add(hierarchyLevel);

                    contentMetadataKeyHierarchy.hierarchyLevels = updatedHieratchyLevels.ToArray();

                    // Update the content hierarchy on the server.
                    ContentMetadataKeyHierarchy[] contentMetadataKeyHierarchies =
                        contentMetadataKeyHierarchyService.updateContentMetadataKeyHierarchies(
                            new ContentMetadataKeyHierarchy[] { contentMetadataKeyHierarchy });

                    foreach (ContentMetadataKeyHierarchy updatedContentMetadataKeyHierarchy in
                             contentMetadataKeyHierarchies)
                    {
                        Console.WriteLine("Content metadata key hierarchy with ID \"{0}\", name " +
                                          "\"{1}\" was updated.", updatedContentMetadataKeyHierarchy.id,
                                          updatedContentMetadataKeyHierarchy.name);
                    }
                } catch (Exception e) {
                    Console.WriteLine("Failed to update content metadata key hierarchies. Exception " +
                                      "says \"{0}\"", e.Message);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (ContentMetadataKeyHierarchyService contentMetadataKeyHierarchyService =
                       (ContentMetadataKeyHierarchyService)user.GetService(DfpService.v201802
                                                                           .ContentMetadataKeyHierarchyService))
            {
                // Set the ID of the content metadata key hierarchy to delete.
                long contentMetadataKeyHierarchyId =
                    long.Parse(_T("INSERT_CONTENT_METADATA_KEY_HIERARCHY_ID_HERE"));

                // Create a statement to select a content metadata key hierarchy.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("WHERE id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("id", contentMetadataKeyHierarchyId);

                try
                {
                    // Get content metadata key hierarchies by statement.
                    ContentMetadataKeyHierarchyPage page =
                        contentMetadataKeyHierarchyService
                        .getContentMetadataKeyHierarchiesByStatement(statementBuilder
                                                                     .ToStatement());

                    ContentMetadataKeyHierarchy contentMetadataKeyHierarchy = page.results[0];

                    Console.WriteLine(
                        "Content metadata key hierarchy with ID \"{0}\" will be deleted.",
                        contentMetadataKeyHierarchy.id);

                    statementBuilder.RemoveLimitAndOffset();

                    // Create action.
                    Google.Api.Ads.Dfp.v201802.DeleteContentMetadataKeyHierarchies action =
                        new Google.Api.Ads.Dfp.v201802.DeleteContentMetadataKeyHierarchies();

                    // Perform action.
                    UpdateResult result =
                        contentMetadataKeyHierarchyService.performContentMetadataKeyHierarchyAction(
                            action, statementBuilder.ToStatement());

                    Console.WriteLine("Number of content metadata key hierarchies deleted: {0}",
                                      result.numChanges);
                }
                catch (Exception e)
                {
                    Console.WriteLine(
                        "Failed to delete content metadata key hierarchies. " +
                        "Exception says \"{0}\"", e.Message);
                }
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            ContentMetadataKeyHierarchyService contentMetadataKeyHierarchyService =
                (ContentMetadataKeyHierarchyService)user.GetService(
                    DfpService.v201605.ContentMetadataKeyHierarchyService);

            // Create a statement to select content metadata key hierarchies.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

            // Retrieve a small amount of content metadata key hierarchies at a time, paging through
            // until all content metadata key hierarchies have been retrieved.
            ContentMetadataKeyHierarchyPage page = new ContentMetadataKeyHierarchyPage();

            try {
                do
                {
                    page = contentMetadataKeyHierarchyService.getContentMetadataKeyHierarchiesByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        // Print out some information for each content metadata key hierarchy.
                        int i = page.startIndex;
                        foreach (ContentMetadataKeyHierarchy contentMetadataKeyHierarchy in page.results)
                        {
                            Console.WriteLine("{0}) Content metadata key hierarchy with ID \"{1}\" "
                                              + "and name \"{2}\" was found.",
                                              i++,
                                              contentMetadataKeyHierarchy.id,
                                              contentMetadataKeyHierarchy.name);
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get content metadata key hierarchies. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser dfpUser)
        {
            using (ContentMetadataKeyHierarchyService contentMetadataKeyHierarchyService =
                       (ContentMetadataKeyHierarchyService)dfpUser.GetService(DfpService.v201805
                                                                              .ContentMetadataKeyHierarchyService))
            {
                // Create a statement to select content metadata key hierarchies.
                int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
                StatementBuilder statementBuilder =
                    new StatementBuilder().OrderBy("id ASC").Limit(pageSize);

                // Retrieve a small amount of content metadata key hierarchies at a time, paging
                // through until all content metadata key hierarchies have been retrieved.
                int totalResultSetSize = 0;
                do
                {
                    ContentMetadataKeyHierarchyPage page =
                        contentMetadataKeyHierarchyService
                        .getContentMetadataKeyHierarchiesByStatement(statementBuilder
                                                                     .ToStatement());

                    // Print out some information for each content metadata key hierarchy.
                    if (page.results != null)
                    {
                        totalResultSetSize = page.totalResultSetSize;
                        int i = page.startIndex;
                        foreach (ContentMetadataKeyHierarchy contentMetadataKeyHierarchy in page
                                 .results)
                        {
                            Console.WriteLine(
                                "{0}) Content metadata key hierarchy with ID {1} and name " +
                                "\"{2}\" was found.",
                                i++, contentMetadataKeyHierarchy.id,
                                contentMetadataKeyHierarchy.name);
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(pageSize);
                } while (statementBuilder.GetOffset() < totalResultSetSize);

                Console.WriteLine("Number of results found: {0}", totalResultSetSize);
            }
        }
        /// <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 ContentMetadataKeyHierarchy service.
            ContentMetadataKeyHierarchyService contentMetadataKeyHierarchyService =
                (ContentMetadataKeyHierarchyService)user.GetService(
                    DfpService.v201502.ContentMetadataKeyHierarchyService);

            // Create a statement to get all content metadata key hierarchies
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

            try {
                int totalResultSetSize = 0;
                do
                {
                    // Get content metadata key hierarchies by statement.
                    ContentMetadataKeyHierarchyPage page = contentMetadataKeyHierarchyService
                                                           .getContentMetadataKeyHierarchiesByStatement(statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        totalResultSetSize = page.totalResultSetSize;
                        int i = page.startIndex;
                        foreach (ContentMetadataKeyHierarchy contentMetadataKeyHierarchy in page.results)
                        {
                            Console.WriteLine("{0}) Content metadata key hierarchy with ID \"{1}\", " +
                                              "and name \"{2}\" was found.", i++, contentMetadataKeyHierarchy.id,
                                              contentMetadataKeyHierarchy.name);
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < totalResultSetSize);
                Console.WriteLine("Number of results found: {0}", totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get content metadata key hierarchies. Exception " +
                                  "says \"{0}\"", ex.Message);
            }
        }