コード例 #1
0
    /// <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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201411.InventoryService);

      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("targetPlatform = :targetPlatform")
          .AddValue("targetPlatform", "WEB");

      try {
        // Get all ad unit sizes.
        AdUnitSize[] adUnitSizes = inventoryService.getAdUnitSizesByStatement(
            statementBuilder.ToStatement());

        // Display results.
        if (adUnitSizes != null) {
          for (int i = 0; i < adUnitSizes.Length; i++) {
            AdUnitSize adUnitSize = adUnitSizes[i];
            Console.WriteLine("{0}) Ad unit size ({1}x{2}) was found.\n", i,
                adUnitSize.size.width, adUnitSize.size.height);
          }
        } else {
          Console.WriteLine("No ad unit sizes found.");
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to get ad unit sizes. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #2
0
    /// <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 CompanyService.
      CompanyService companyService =
          (CompanyService) user.GetService(DfpService.v201411.CompanyService);

      // Set the ID of the company to update.
      int companyId = int.Parse(_T("INSERT_COMPANY_ID_HERE"));

      // Create a statement to select the company by ID.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("id = :companyId")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("id", companyId);

      try {
        // Get the companies by statement.
        CompanyPage page = companyService.getCompaniesByStatement(statementBuilder.ToStatement());

        Company company = page.results[0];

        // Update the company comment
        company.comment = company.comment + " Updated.";

        // Update the company on the server.
        Company[] companies = companyService.updateCompanies(new Company[] {company});

        foreach (Company updatedCompany in companies) {
          Console.WriteLine("Company with ID = {0}, name = {1}, and comment \"{2}\" was updated",
              updatedCompany.id, updatedCompany.name, updatedCompany.comment);
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to update companies. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #3
0
        /// <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 ActivityService.
              ActivityService activityService =
              (ActivityService) user.GetService(DfpService.v201411.ActivityService);

              // Set the ID of the activity to update.
              int activityId = int.Parse(_T("INSERT_ACTIVITY_ID_HERE"));

              try {
            // Get the activity.
            StatementBuilder statemetnBuilder = new StatementBuilder()
            .Where("id = :id")
            .OrderBy("id ASC")
            .Limit(1)
            .AddValue("id", activityId);

            ActivityPage page = activityService.getActivitiesByStatement(
            statemetnBuilder.ToStatement());
            Activity activity = page.results[0];

            // Update the expected URL.
            activity.expectedURL = "https://www.google.com";

            // Update the activity on the server.
            Activity[] activities = activityService.updateActivities(new Activity[] {activity});

            foreach (Activity updatedActivity in activities) {
              Console.WriteLine("Activity with ID \"{0}\" and name \"{1}\" was updated.",
              updatedActivity.id, updatedActivity.name);
            }
              } catch (Exception e) {
            Console.WriteLine("Failed to update activities. Exception says \"{0}\"", e.Message);
              }
        }
コード例 #4
0
        /// <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 PlacementService.
              PlacementService placementService =
              (PlacementService) user.GetService(DfpService.v201411.PlacementService);

              // Create statement to select active placements.
              StatementBuilder statementBuilder = new StatementBuilder()
              .Where("status = :status")
              .OrderBy("id ASC")
              .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
              .AddValue("status", InventoryStatus.ACTIVE.ToString());

              // Sets default for page.
              PlacementPage page = new PlacementPage();
              List<string> placementIds = new List<string>();

              try {
            do {
              // Get placements by statement.
              page = placementService.getPlacementsByStatement(statementBuilder.ToStatement());

              if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Placement placement in page.results) {
              Console.WriteLine("{0}) Placement with ID ='{1}', name ='{2}', and status ='{3}'" +
                  " will be deactivated.", i, placement.id, placement.name, placement.status);
              placementIds.Add(placement.id.ToString());
              i++;
            }
              }

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

            Console.WriteLine("Number of placements to be deactivated: {0}", placementIds.Count);

            if (placementIds.Count > 0) {
              // Modify statement for action.
              statementBuilder.RemoveLimitAndOffset();

              // Create action.
              DeactivatePlacements action = new DeactivatePlacements();

              // Perform action.
              UpdateResult result = placementService.performPlacementAction(action,
              statementBuilder.ToStatement());

              // Display results.
              if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of placements deactivated: {0}", result.numChanges);
              } else {
            Console.WriteLine("No placements were deactivated.");
              }
            }
              } catch (Exception e) {
            Console.WriteLine("Failed to deactivate placements. Exception says \"{0}\"",
            e.Message);
              }
        }
コード例 #5
0
        /// <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 PublisherQueryLanguageService.
              PublisherQueryLanguageService pqlService =
              (PublisherQueryLanguageService) user.GetService(
              DfpService.v201411.PublisherQueryLanguageService);

              try {
            StatementBuilder lineItemStatementBuilder = new StatementBuilder()
            .Select("Id, Name, Status")
            .From("Line_Item")
            .OrderBy("Id ASC")
            .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
            string lineItemFilePath = "Line-Item-Matchtable.csv";
            fetchMatchTables(pqlService, lineItemStatementBuilder, lineItemFilePath);

            StatementBuilder adUnitStatementBuilder = new StatementBuilder()
            .Select("Id, Name")
            .From("Ad_Unit")
            .OrderBy("Id ASC")
            .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
            string adUnitFilePath = "Ad-Unit-Matchtable.csv";
            fetchMatchTables(pqlService, adUnitStatementBuilder, adUnitFilePath);

            Console.WriteLine("Ad units saved to %s", adUnitFilePath);
            Console.WriteLine("Line items saved to %s\n", lineItemFilePath);
              } catch (Exception e) {
            Console.WriteLine("Failed to get match tables. Exception says \"{0}\"", e.Message);
              }
        }
コード例 #6
0
    /// <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 CompanyService.
      CompanyService companyService =
          (CompanyService) user.GetService(DfpService.v201411.CompanyService);

      // Set defaults for page and statement.
      CompanyPage page = new CompanyPage();
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      try {
        do {
          // Get companies by statement.
          page = companyService.getCompaniesByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Company company in page.results) {
              Console.WriteLine("{0}) Company with ID = {1}, name = {2} and type = {3} was found",
                  i, company.id, company.name, company.type);
              i++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get companies. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #7
0
        /// <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 ActivityGroupService.
              ActivityGroupService activityGroupService =
              (ActivityGroupService) user.GetService(DfpService.v201411.ActivityGroupService);

              ActivityGroupPage page;
              StatementBuilder statementBuilder = new StatementBuilder()
              .OrderBy("id ASC")
              .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

              try {
            do {
              // Get activity groups by statement.
              page = activityGroupService.getActivityGroupsByStatement(statementBuilder.ToStatement());

              // Display results.
              if (page.results != null) {
            int i = page.startIndex;

            foreach (ActivityGroup activityGroup in page.results) {
              Console.WriteLine("{0}) Activity group with ID \"{1}\" and name \"{2}\" was " +
                  "found.", i, activityGroup.id, activityGroup.name);
              i++;
            }
              }

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

            Console.WriteLine("Number of results found: " + page.totalResultSetSize);
              } catch (Exception e) {
            Console.WriteLine("Failed to get activity groups. Exception says \"{0}\"", e.Message);
              }
        }
コード例 #8
0
        /// <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 SuggestedAdUnitService.
              SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService) user.GetService(
              DfpService.v201411.SuggestedAdUnitService);

              // Set the number of requests for suggested ad units greater than which to approve.
              long NUMBER_OF_REQUESTS = 50L;

              // Create statement to select all suggested ad units that are highly requested.
              StatementBuilder statementBuilder = new StatementBuilder()
              .Where("numRequests > :numRequests")
              .OrderBy("id ASC")
              .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
              .AddValue("numRequests", NUMBER_OF_REQUESTS);

              // Set default for page.
              SuggestedAdUnitPage page = new SuggestedAdUnitPage();

              try {
            do {
              // Get suggested ad units by statement.
              page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(
              statementBuilder.ToStatement());

              int i = 0;
              if (page != null && page.results != null) {
            foreach (SuggestedAdUnit suggestedAdUnit in page.results) {
              Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and \"{2}\" will be " +
                  "approved.", i, suggestedAdUnit.id, suggestedAdUnit.numRequests);
              i++;
            }
              }
              statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
            } while(statementBuilder.GetOffset() < page.totalResultSetSize);

            Console.WriteLine("Number of suggested ad units to be approved: " +
            page.totalResultSetSize);

            // Modify statement for action.
            statementBuilder.RemoveLimitAndOffset();

            // Create action.
            ApproveSuggestedAdUnit action = new ApproveSuggestedAdUnit();

            // Perform action.
            SuggestedAdUnitUpdateResult result = suggestedAdUnitService.performSuggestedAdUnitAction(
            action, statementBuilder.ToStatement());

            // Display results.
            if (result != null && result.numChanges > 0) {
              Console.WriteLine("Number of new ad units created: " + result.newAdUnitIds.Length);
            } else {
              Console.WriteLine("No suggested ad units were approved.");
            }
              } catch (Exception e) {
            Console.WriteLine("Failed to approve suggested ad units. Exception says \"{0}\"",
            e.Message);
              }
        }
コード例 #9
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Create the CreativeWrapperService.
      CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService(
          DfpService.v201411.CreativeWrapperService);

      long creativeWrapperId = long.Parse(_T("INSERT_CREATIVE_WRAPPER_ID_HERE"));

      try {
        StatementBuilder statementBuilder = new StatementBuilder()
            .Where("id = :id")
            .OrderBy("id ASC")
            .Limit(1)
            .AddValue("id", creativeWrapperId);
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(
            statementBuilder.ToStatement());
        CreativeWrapper wrapper = page.results[0];

        wrapper.ordering = CreativeWrapperOrdering.OUTER;
        // Update the creative wrappers on the server.
        CreativeWrapper[] creativeWrappers = creativeWrapperService.updateCreativeWrappers(
            new CreativeWrapper[] {wrapper});

        // Display results.
        foreach (CreativeWrapper createdCreativeWrapper in creativeWrappers) {
          Console.WriteLine("Creative wrapper with ID '{0}' and wrapping order '{1}' was " +
              "updated.", createdCreativeWrapper.id, createdCreativeWrapper.ordering);
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to update creative wrappers. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #10
0
    /// <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 BaseRateService.
      BaseRateService baseRateService =
          (BaseRateService) user.GetService(DfpService.v201411.BaseRateService);

      // Create a statement to get all base rates.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Sets default for page.
      BaseRatePage page = new BaseRatePage();
      try {
        do {
          // Get base rates by statement.
          page = baseRateService.getBaseRatesByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (BaseRate baseRate in page.results) {
              Console.WriteLine("{0}) Base rate with ID ='{1}' and type '{2}' belonging to rate " +
                  "card '{3}' was found.", i++, baseRate.id, baseRate.BaseRateType,
                  baseRate.rateCardId);
            }
          }

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

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get base rates. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #11
0
    /// <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 CompanyService.
      CompanyService companyService =
          (CompanyService) user.GetService(DfpService.v201411.CompanyService);

      // Create a statement to only select companies that are advertisers sorted
      // by name.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("type = :advertiser")
          .OrderBy("name ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("advertiser", CompanyType.ADVERTISER.ToString());

      CompanyPage page = new CompanyPage();

      try {
        do {
          // Get companies by statement.
          page = companyService.getCompaniesByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Company company in page.results) {
              Console.WriteLine("{0}) Company with ID = {1}, name = {2} and type = {3} was found",
                  i, company.id, company.name, company.type);
              i++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);
        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get companies. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #12
0
    /// <summary>
    /// Run the sample code.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201411.InventoryService);

      // Set the ID of the ad unit to update.
      int adUnitId = int.Parse(_T("INSERT_AD_UNIT_ID_HERE"));

      // Create a statement to get the ad unit.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("id = :id")
          .OrderBy("id ASC")
          .Limit(1)
          .AddValue("id", adUnitId);

      try {
        // Get ad units by statement.
        AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

        AdUnit adUnit = page.results[0];
        adUnit.inheritedAdSenseSettings.value.adSenseEnabled = true;

        // Update the ad units on the server.
        AdUnit[] updatedAdUnits = inventoryService.updateAdUnits(new AdUnit[] {adUnit});

        foreach (AdUnit updatedAdUnit in updatedAdUnits) {
          Console.WriteLine("Ad unit with ID \"{0}\", name \"{1}\", and is AdSense enabled " +
              "\"{2}\" was updated.", updatedAdUnit.id, updatedAdUnit.name,
              updatedAdUnit.inheritedAdSenseSettings.value.adSenseEnabled);
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to update ad units. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #13
0
        /// <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 TeamService.
              TeamService teamService = (TeamService) user.GetService(DfpService.v201411.TeamService);

              // Create a statement to order teams by name.
              StatementBuilder statementBuilder = new StatementBuilder()
              .OrderBy("name ASC")
              .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

              // Set default for page.
              TeamPage page = new TeamPage();

              try {
            do {
              // Get teams by statement.
              page = teamService.getTeamsByStatement(statementBuilder.ToStatement());

              // Display results.
              if (page.results != null) {
            int i = page.startIndex;
            foreach (Team team in page.results) {
              Console.WriteLine("{0}) Team with ID \"{1}\" and name \"{2}\" was found.",
                  i, team.id, team.name);
              i++;
            }
              }

              statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
            } while(statementBuilder.GetOffset() < page.totalResultSetSize);
              Console.WriteLine("Number of results found: " + page.totalResultSetSize);
              } catch (Exception e) {
            Console.WriteLine("Failed to get teams by statement. Exception says \"{0}\"", e.Message);
              }
        }
コード例 #14
0
        /// <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 InventoryService.
              InventoryService inventoryService =
              (InventoryService) user.GetService(DfpService.v201411.InventoryService);

              // Create a statement to get all ad units.
              StatementBuilder statementBuilder = new StatementBuilder()
              .OrderBy("id ASC")
              .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

              // Set default for page.
              AdUnitPage page = new AdUnitPage();

              try {
            do {
              // Get ad units by statement.
              page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

              if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (AdUnit adUnit in page.results) {
              Console.WriteLine("{0}) Ad unit with ID = '{1}', name = '{2}' and status = '{3}' " +
                  "was found.", i, adUnit.id, adUnit.name, adUnit.status);
              i++;
            }
              }
              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 ad unit. Exception says \"{0}\"", e.Message);
              }
        }
コード例 #15
0
    /// <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 ProposalService.
      ProposalService proposalService =
          (ProposalService) user.GetService(DfpService.v201411.ProposalService);

      // Create a statement to only select proposals that are pending approval.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("status = :status")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("status", ProposalStatus.PENDING_APPROVAL.ToString());

      // Set default for page.
      ProposalPage page = new ProposalPage();

      try {
        do {
          // Get proposals by statement.
          page = proposalService.getProposalsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Proposal proposal in page.results) {
              Console.WriteLine("{0}) Proposal with ID = '{1}', name = '{2}' was found.",
                  i++, proposal.id, proposal.name);
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while(statementBuilder.GetOffset() < page.totalResultSetSize);
        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get proposals. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #16
0
    /// <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 ActivityService.
      ActivityService activityService =
          (ActivityService) user.GetService(DfpService.v201411.ActivityService);

      int totalResultsCounter = 0;

      try {
        StatementBuilder statementBuilder = new StatementBuilder()
            .OrderBy("id ASC")
            .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

        ActivityPage page = new ActivityPage();

        do {
          // Get activities by statement.
          page = activityService.getActivitiesByStatement(statementBuilder.ToStatement());

          // Display results.
          if (page.results != null) {
            foreach (Activity activity in page.results) {
              Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\" and type \"{3}\" " +
                  "was found.\n", totalResultsCounter, activity.id, activity.name,
                  activity.type);
              totalResultsCounter++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);
        Console.WriteLine("Number of results found: {0}.", totalResultsCounter);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get contacts. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #17
0
    /// <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 RateCardService.
      RateCardService rateCardService =
          (RateCardService) user.GetService(DfpService.v201411.RateCardService);

      // Create a statement to get all rate cards.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Sets default for page.
      RateCardPage page = new RateCardPage();
      try {
        do {
          // Get rate cards by statement.
          page = rateCardService.getRateCardsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (RateCard rateCard in page.results) {
              Console.WriteLine("{0}) Rate card with ID = '{1}' and name '{2}' was" +
                  " found.", i++, rateCard.id, rateCard.name);
            }
          }

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

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get rate cards. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #18
0
    /// <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 CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201411.CreativeService);

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

      // Set default for page.
      CreativePage page = new CreativePage();

      try {
        do {
          // Get creatives by statement.
          page = creativeService.getCreativesByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Creative creative in page.results) {
              Console.WriteLine("{0}) Creative with ID ='{1}', name ='{2}' and type ='{3}' " +
                  "was found.", i, creative.id, creative.name, creative.CreativeType);
              i++;
            }
          }

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

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get all creatives. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #19
0
        /// <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 UserService.
              UserService userService = (UserService) user.GetService(DfpService.v201411.UserService);

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

              // Sets defaults for page and statement.
              UserPage page = new UserPage();

              try {
            do {
              // Get users by statement.
              page = userService.getUsersByStatement(statementBuilder.ToStatement());

              if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (User usr in page.results) {
              Console.WriteLine("{0}) User with ID = '{1}', email = '{2}', and role = '{3}'" +
                  " was found.", i, usr.id, usr.email, usr.roleName);
              i++;
            }
              }
              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 all users. Exception says \"{0}\"",
            e.Message);
              }
        }
コード例 #20
0
    /// <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 ContactService.
      ContactService contactService =
          (ContactService) user.GetService(DfpService.v201411.ContactService);

      // Set the ID of the contact to update.
      long contactId = long.Parse(_T("INSERT_CONTACT_ID_HERE"));

      try {
        StatementBuilder statementBuilder = new StatementBuilder()
            .Where("id = :id")
            .OrderBy("id ASC")
            .Limit(1)
            .AddValue("id", contactId);

        // Get the contact.
        ContactPage page = contactService.getContactsByStatement(statementBuilder.ToStatement());
        Contact contact = page.results[0];

        // Update the address of the contact.
        contact.address = "123 New Street, New York, NY, 10011";

        // Update the contact on the server.
        Contact[] contacts = contactService.updateContacts(new Contact[] {contact});

        // Display results.
        foreach (Contact updatedContact in contacts) {
          Console.WriteLine("Contact with ID \"{0}\", name \"{1}\", and comment \"{2}\" was " +
              "updated.", updatedContact.id, updatedContact.name, updatedContact.comment);
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to update contacts. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #21
0
    /// <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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201411.InventoryService);

      // Set the ID of the ad unit to deactivate.
      int adUnitId = int.Parse(_T("INSERT_AD_UNIT_ID_HERE"));

      // Create a statement to select the ad unit.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("id = :id")
          .OrderBy("id ASC")
          .Limit(1)
          .AddValue("id", adUnitId);

      // Set default for page.
      AdUnitPage page = new AdUnitPage();
      List<string> adUnitIds = new List<string>();

      try {
        do {
          // Get ad units by statement.
          page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (AdUnit adUnit in page.results) {
              Console.WriteLine("{0}) Ad unit with ID ='{1}', name = {2} and status = {3} will" +
                  " be deactivated.", i, adUnit.id, adUnit.name, adUnit.status);
              adUnitIds.Add(adUnit.id);
              i++;
            }
          }

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

        Console.WriteLine("Number of ad units to be deactivated: {0}", adUnitIds.Count);

        // Modify statement for action.
        statementBuilder.RemoveLimitAndOffset();

        // Create action.
        DeactivateAdUnits action = new DeactivateAdUnits();

        // Perform action.
        UpdateResult result = inventoryService.performAdUnitAction(action,
            statementBuilder.ToStatement());

        // Display results.
        if (result != null && result.numChanges > 0) {
          Console.WriteLine("Number of ad units deactivated: {0}", result.numChanges);
        } else {
          Console.WriteLine("No ad units were deactivated.");
        }

      } catch (Exception ex) {
        Console.WriteLine("Failed to deactivate ad units. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #22
0
    /// <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 SuggestedAdUnitService.
      SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService) user.GetService(
          DfpService.v201411.SuggestedAdUnitService);

      // Set default for page.
      SuggestedAdUnitPage page = new SuggestedAdUnitPage();

      // Create a statement to get all suggested ad units.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      try {
        do {
          // Get suggested ad units by statement.
          page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(
              statementBuilder.ToStatement());

          if (page.results != null) {
            int i = page.startIndex;
            foreach (SuggestedAdUnit suggestedAdUnit in page.results) {
              Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and number of requests " +
                  "\"{2}\" was found.", i++, suggestedAdUnit.id, suggestedAdUnit.numRequests);
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get suggested ad units. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #23
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            ReportService reportService = (ReportService) user.GetService(
              DfpService.v201411.ReportService);

              // Get the NetworkService.
              NetworkService networkService = (NetworkService) user.GetService(
            DfpService.v201411.NetworkService);

              // Get the root ad unit ID to filter on.
              String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

              // Create statement to filter on an ancestor ad unit with the root ad unit ID to include all
              // ad units in the network.
              StatementBuilder statementBuilder = new StatementBuilder()
              .Where("PARENT_AD_UNIT_ID = :parentAdUnitId")
              .AddValue("parentAdUnitId", long.Parse(rootAdUnitId));

              // Create report query.
              ReportQuery reportQuery = new ReportQuery();
              reportQuery.dimensions =
              new Dimension[] {Dimension.AD_UNIT_ID, Dimension.AD_UNIT_NAME};
              reportQuery.columns = new Column[] {Column.AD_SERVER_IMPRESSIONS,
            Column.AD_SERVER_CLICKS, Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_IMPRESSIONS,
            Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_CLICKS,
            Column.TOTAL_INVENTORY_LEVEL_IMPRESSIONS,
            Column.TOTAL_INVENTORY_LEVEL_CPM_AND_CPC_REVENUE};

              // Set the filter statement.
              reportQuery.statement = statementBuilder.ToStatement();

              reportQuery.adUnitView = ReportQueryAdUnitView.HIERARCHICAL;
              reportQuery.dateRangeType = DateRangeType.LAST_WEEK;

              // Create report job.
              ReportJob reportJob = new ReportJob();
              reportJob.reportQuery = reportQuery;

              try {
            // Run report.
            reportJob = reportService.runReportJob(reportJob);
            // Wait for report to complete.
            while (reportJob.reportJobStatus == ReportJobStatus.IN_PROGRESS) {
              Console.WriteLine("Report job with id = '{0}' is still running.", reportJob.id);
              Thread.Sleep(30000);
              // Get report job.
              reportJob = reportService.getReportJob(reportJob.id);
            }

            if (reportJob.reportJobStatus == ReportJobStatus.COMPLETED) {
              Console.WriteLine("Report job with id = '{0}' completed successfully.", reportJob.id);
            } else if (reportJob.reportJobStatus == ReportJobStatus.FAILED) {
              Console.WriteLine("Report job with id = '{0}' failed to complete successfully.",
              reportJob.id);
            }
              } catch (Exception e) {
            Console.WriteLine("Failed to run inventory report. Exception says \"{0}\"",
            e.Message);
              }
        }
コード例 #24
0
    /// <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 ContactService.
      ContactService contactService =
          (ContactService) user.GetService(DfpService.v201411.ContactService);

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

      // Set default for page.
      ContactPage page = new ContactPage();

      try {
        do {
          // Get contacts by statement.
          page = contactService.getContactsByStatement(statementBuilder.ToStatement());

          if (page.results != null) {
            int i = page.startIndex;
            foreach (Contact contact in page.results) {
              Console.WriteLine("{0}) Contact with ID \"{1}\" and name \"{2}\" was found.",
                  i, contact.id, contact.name);
              i++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get contacts. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #25
0
        /// <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 LabelService.
              LabelService labelService =
              (LabelService) user.GetService(DfpService.v201411.LabelService);

              // Set the ID of the label to deactivate.
              int labelId = int.Parse(_T("INSERT_LABEL_ID_HERE"));

              // Create statement text to select the label.
              StatementBuilder statementBuilder = new StatementBuilder()
              .Where("id = :id")
              .OrderBy("id ASC")
              .Limit(1)
              .AddValue("id", labelId);

              // Set default for page.
              LabelPage page = new LabelPage();

              try {
            do {
              // Get labels by statement.
              page = labelService.getLabelsByStatement(statementBuilder.ToStatement());

              if (page.results != null) {
            int i = page.startIndex;
            foreach (Label label in page.results) {
              Console.WriteLine("{0}) Label with ID '{1}', name '{2}' will be deactivated.",
                  i, label.id, label.name);
              i++;
            }
              }
              statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
            } while (statementBuilder.GetOffset() < page.totalResultSetSize);

            Console.WriteLine("Number of labels to be deactivated: " + page.totalResultSetSize);

            // Modify statement for action.
            statementBuilder.RemoveLimitAndOffset();

            // Create action.
            DeactivateLabels action = new DeactivateLabels();

            // Perform action.
            UpdateResult result = labelService.performLabelAction(action,
            statementBuilder.ToStatement());

            // Display results.
            if (result != null && result.numChanges > 0) {
              Console.WriteLine("Number of labels deactivated: " + result.numChanges);
            } else {
              Console.WriteLine("No labels were deactivated.");
            }
              } catch (Exception e) {
            Console.WriteLine("Failed to deactivate labels. Exception says \"{0}\"", e.Message);
              }
        }
コード例 #26
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Create the CreativeWrapperService.
              CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService(
              DfpService.v201411.CreativeWrapperService);

              long labelId = long.Parse(_T("INSERT_CREATIVE_WRAPPER_LABEL_ID_HERE"));

              try {
            // Create a query to select the active creative wrapper for the given
            // label.
            StatementBuilder statementBuilder = new StatementBuilder()
            .Where ("labelId = :labelId AND status = :status")
            .OrderBy("id ASC")
            .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
            .AddValue("status", CreativeWrapperStatus.ACTIVE.ToString())
            .AddValue("labelId", labelId);

            // Set default for page.
            CreativeWrapperPage page = new CreativeWrapperPage();

            do {
              page =
              creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.ToStatement());
              CreativeWrapper[] creativeWrappers = page.results;
              if (creativeWrappers != null) {
            foreach (CreativeWrapper wrapper in creativeWrappers) {
              Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " +
                  "status \'{2}\' will be deactivated.", wrapper.id, wrapper.labelId,
                   wrapper.status);
            }
              }
              statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
            } while (statementBuilder.GetOffset() < page.totalResultSetSize);

            Console.WriteLine("Number of creative wrappers to be deactivated: {0}",
            page.totalResultSetSize);

            // Modify statement for action.
            statementBuilder.RemoveLimitAndOffset();

            // Perform action.
            CreativeWrapperAction action = new DeactivateCreativeWrappers();
            UpdateResult result = creativeWrapperService.performCreativeWrapperAction(action,
            statementBuilder.ToStatement());

            // Display results.
            if (result.numChanges > 0) {
              Console.WriteLine("Number of creative wrappers deactivated: {0}", result.numChanges);
            } else {
              Console.WriteLine("No creative wrappers were deactivated.");
            }

              } catch (Exception e) {
            Console.WriteLine("Failed to create creative wrappers. Exception says \"{0}\"", e.Message);
              }
        }
    /// <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.v201411.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 ex) {
        Console.WriteLine("Failed to update content metadata key hierarchies. Exception " +
            "says \"{0}\"", ex.Message);
      }
    }
コード例 #28
0
        /// <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 PremiumRateService.
              PremiumRateService premiumRateService =
              (PremiumRateService) user.GetService(DfpService.v201411.PremiumRateService);

              long premiumRateId = long.Parse(_T("INSERT_PREMIUM_RATE_ID_HERE"));

              // Create a statement to get the premium rate.
              StatementBuilder statementBuilder = new StatementBuilder()
              .Where("id = :id")
              .OrderBy("id ASC")
              .Limit(1)
              .AddValue("id", premiumRateId);

              try {
            // Get premium rates by statement.
            PremiumRatePage page =
            premiumRateService.getPremiumRatesByStatement(statementBuilder.ToStatement());

            PremiumRate premiumRate = page.results[0];

            // Create a flat fee based premium rate value with a 10% increase.
            PremiumRateValue flatFeePremiumRateValue = new PremiumRateValue();
            flatFeePremiumRateValue.premiumFeature = premiumRate.premiumFeature;
            flatFeePremiumRateValue.rateType = RateType.CPM;
            flatFeePremiumRateValue.adjustmentSize = 10000L;
            flatFeePremiumRateValue.adjustmentType = PremiumAdjustmentType.PERCENTAGE;

            // Update the premium rate's values to include a flat fee premium rate.
            List<PremiumRateValue> existingPremiumRateValues = (premiumRate.premiumRateValues != null)
            ? new List<PremiumRateValue>(premiumRate.premiumRateValues)
            : new List<PremiumRateValue>();

            existingPremiumRateValues.Add(flatFeePremiumRateValue);
            premiumRate.premiumRateValues = existingPremiumRateValues.ToArray();

            // Update the premium rates on the server.
            PremiumRate[] premiumRates =
            premiumRateService.updatePremiumRates(new PremiumRate[] {premiumRate});

            if (premiumRates != null) {
              foreach (PremiumRate updatedPremiumRate in premiumRates) {
            Console.WriteLine("Premium rate with ID '{1}' associated with rate card ID '{2}' " +
                "was updated.", updatedPremiumRate.id,
                updatedPremiumRate.premiumFeature.PremiumFeatureType,
                updatedPremiumRate.rateCardId);
              }
            } else {
              Console.WriteLine("No premium rates updated.");
            }
              } catch (Exception e) {
            Console.WriteLine("Failed to update premium rates. Exception says \"{0}\"",
            e.Message);
              }
        }
コード例 #29
0
    /// <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 PublisherQueryLanguageService.
      PublisherQueryLanguageService pqlService =
          (PublisherQueryLanguageService) user.GetService(
              DfpService.v201411.PublisherQueryLanguageService);

      string geoType = "City";

      // Create statement to select all targetable cities.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Select("Id, Name, CanonicalParentId, ParentIds, CountryCode")
          .From("Geo_Target")
          .Where("Type = :type and Targetable = true")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("type", geoType);

      int resultSetSize = 0;
      List<Row> allRows = new List<Row>();
      ResultSet resultSet;

      try {
        do {
          // Get all cities.
          resultSet = pqlService.select(statementBuilder.ToStatement());

          // Collect all cities from each page.
          allRows.AddRange(resultSet.rows);

          // Display results.
          Console.WriteLine(PqlUtilities.ResultSetToString(resultSet));

          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
          resultSetSize = resultSet.rows == null ? 0 : resultSet.rows.Length;
        } while (resultSetSize == StatementBuilder.SUGGESTED_PAGE_LIMIT);

        Console.WriteLine("Number of results found: " + allRows.Count);

        // Optionally, save all rows to a CSV.
        // Get a string array representation of the data rows.
        resultSet.rows = allRows.ToArray();
        List<String[]> rows = PqlUtilities.ResultSetToStringArrayList(resultSet);

        // Write the contents to a csv file.
        CsvFile file = new CsvFile();
        file.Headers.AddRange(rows[0]);
        file.Records.AddRange(rows.GetRange(1, rows.Count - 1).ToArray());
        file.Write(geoType + "_" + this.GetTimeStamp() + ".csv");
      } catch (Exception ex) {
        Console.WriteLine("Failed to get Geo type = '{0}'. Exception says \"{1}\"",
            geoType, ex.Message);
      }
    }
コード例 #30
0
        /// <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 CreativeService.
              CreativeService creativeService =
              (CreativeService) user.GetService(DfpService.v201411.CreativeService);

              long creativeId = long.Parse(_T("INSERT_IMAGE_CREATIVE_ID_HERE"));

              // Create a statement to get the image creative.
              StatementBuilder statementBuilder = new StatementBuilder()
              .Where("id = :id")
              .OrderBy("id ASC")
              .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
              .AddValue("id", creativeId);

              try {
            // Get the creative.
            CreativePage page = creativeService.getCreativesByStatement(statementBuilder.ToStatement());

            if (page.results != null) {
              ImageCreative imageCreative = (ImageCreative) page.results[0];
              // Since we cannot set id to null, we mark it as not specified.
              imageCreative.idSpecified = false;

              imageCreative.advertiserId = imageCreative.advertiserId;
              imageCreative.name = imageCreative.name + " (Copy #" + GetTimeStamp() + ")";

              // Create image asset.
              CreativeAsset creativeAsset = new CreativeAsset();
              creativeAsset.fileName = "image.jpg";
              creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
              imageCreative.primaryImageAsset.assetUrl);

              creativeAsset.size = imageCreative.primaryImageAsset.size;
              imageCreative.primaryImageAsset = creativeAsset;

              // Create the copied creative.
              Creative[] creatives = creativeService.createCreatives(new Creative[] {imageCreative});

              // Display copied creatives.
              foreach (Creative copiedCreative in creatives) {
            Console.WriteLine("Image creative with ID \"{0}\", name \"{1}\", and type \"{2}\" " +
                "was created and can be previewed at {3}", copiedCreative.id, copiedCreative.name,
                 copiedCreative.CreativeType, copiedCreative.previewUrl);
              }
            } else {
              Console.WriteLine("No creatives were copied.");
            }
              } catch (Exception e) {
            Console.WriteLine("Failed to copy creatives. Exception says \"{0}\"", e.Message);
              }
        }