/// <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);

      // Set the ID of the proposal.
      long proposalId = long.Parse(_T("INSERT_PROPOSAL_ID_HERE"));

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

      // Set default for page.
      ProposalPage page = new ProposalPage();
      List<string> proposalIds = new List<string>();
      int i = 0;

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

          if (page.results != null && page.results.Length > 0) {
            foreach (Proposal proposal in page.results) {
              Console.WriteLine("{0}) Proposal with ID = '{1}', name = '{2}', and status ='{3}' " +
                  "will be approved.", i++, proposal.id, proposal.name, proposal.status);
              proposalIds.Add(proposal.id.ToString());
            }
          }

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

        Console.WriteLine("Number of proposals to be approved: {0}", proposalIds.Count);

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

          // Create action.
          Dfp.v201411.SubmitProposalsForApproval action =
              new Dfp.v201411.SubmitProposalsForApproval();

          // Perform action.
          UpdateResult result = proposalService.performProposalAction(action,
              statementBuilder.ToStatement());

          // Display results.
          if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of proposals approved: {0}", result.numChanges);
          } else {
            Console.WriteLine("No proposals were approved.");
          }
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to approve proposals. 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 ProposalService.
            ProposalService proposalService =
                (ProposalService)user.GetService(DfpService.v201411.ProposalService);

            // Set the ID of the proposal.
            long proposalId = long.Parse(_T("INSERT_PROPOSAL_ID_HERE"));

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

            // Set default for page.
            ProposalPage  page        = new ProposalPage();
            List <string> proposalIds = new List <string>();
            int           i           = 0;

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

                    if (page.results != null && page.results.Length > 0)
                    {
                        foreach (Proposal proposal in page.results)
                        {
                            Console.WriteLine("{0}) Proposal with ID = '{1}', name = '{2}', and status ='{3}' " +
                                              "will be approved.", i++, proposal.id, proposal.name, proposal.status);
                            proposalIds.Add(proposal.id.ToString());
                        }
                    }

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

                Console.WriteLine("Number of proposals to be approved: {0}", proposalIds.Count);

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

                    // Create action.
                    Dfp.v201411.SubmitProposalsForApproval action =
                        new Dfp.v201411.SubmitProposalsForApproval();

                    // Perform action.
                    UpdateResult result = proposalService.performProposalAction(action,
                                                                                statementBuilder.ToStatement());

                    // Display results.
                    if (result != null && result.numChanges > 0)
                    {
                        Console.WriteLine("Number of proposals approved: {0}", result.numChanges);
                    }
                    else
                    {
                        Console.WriteLine("No proposals were approved.");
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to approve proposals. Exception says \"{0}\"",
                                  ex.Message);
            }
        }