/// <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.v201508.ProposalService);

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

      // 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: {0}", page.totalResultSetSize);
      } catch (Exception e) {
        Console.WriteLine("Failed to get all proposals. Exception says \"{0}\"",
            e.Message);
      }
    }
Beispiel #2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (ProposalService proposalService =
                       (ProposalService)user.GetService(DfpService.v201805.ProposalService))
            {
                long proposalId = long.Parse(_T("INSERT_PROPOSAL_ID_HERE"));

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

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

                    Proposal proposal = page.results[0];

                    // Update the proposal object by changing its note.
                    proposal.internalNotes = "Proposal needs further review before approval.";

                    // Update the proposals on the server.
                    Proposal[] proposals = proposalService.updateProposals(new Proposal[]
                    {
                        proposal
                    });

                    if (proposals != null)
                    {
                        foreach (Proposal updatedProposal in proposals)
                        {
                            Console.WriteLine(
                                "Proposal with ID = '{0}', name = '{1}', and notes = '{2}' was " +
                                "updated.", updatedProposal.id, updatedProposal.name,
                                updatedProposal.internalNotes);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No proposals updated.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to update proposals. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser dfpUser)
        {
            ProposalService proposalService =
                (ProposalService)dfpUser.GetService(DfpService.v201702.ProposalService);

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

            // Retrieve a small amount of proposals at a time, paging through until all
            // proposals have been retrieved.
            int totalResultSetSize = 0;

            do
            {
                ProposalPage page = proposalService.getProposalsByStatement(
                    statementBuilder.ToStatement());

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

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

            Console.WriteLine("Number of results found: {0}", totalResultSetSize);
        }
Beispiel #4
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            ProposalService proposalService =
                (ProposalService)user.GetService(DfpService.v201605.ProposalService);

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

            // Retrieve a small amount of proposals at a time, paging through
            // until all proposals have been retrieved.
            ProposalPage page = new ProposalPage();

            try {
                do
                {
                    page = proposalService.getProposalsByStatement(statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        // Print out some information for each proposal.
                        int i = page.startIndex;
                        foreach (Proposal proposal in page.results)
                        {
                            Console.WriteLine("{0}) Proposal with ID \"{1}\" and 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: {0}", page.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get proposals. 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 ProposalService.
            ProposalService proposalService =
                (ProposalService)user.GetService(DfpService.v201502.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 e) {
                Console.WriteLine("Failed to get proposals. Exception says \"{0}\"",
                                  e.Message);
            }
        }
Beispiel #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 ProposalService.
            ProposalService proposalService =
                (ProposalService)user.GetService(DfpService.v201411.ProposalService);

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

            // 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: {0}", page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get all proposals. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            // Get the ProposalService.
            ProposalService proposalService =
                (ProposalService)user.GetService(DfpService.v201705.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)
                    {
                        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.
                    SubmitProposalsForApproval action = new 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 e) {
                Console.WriteLine("Failed to approve proposals. Exception says \"{0}\"",
                                  e.Message);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user, long proposalId)
        {
            using (ProposalService proposalService = user.GetService <ProposalService>())
            {
                // 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)
                        {
                            foreach (Proposal proposal in page.results)
                            {
                                Console.WriteLine(
                                    "{0}) Proposal with ID = '{1}', name = '{2}', " +
                                    "and status = '{3}' will be sent to Marketplace for buyer " +
                                    "acceptance.",
                                    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 sent to Marketplace: {0}",
                                      proposalIds.Count);

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

                        // Create action.
                        Google.Api.Ads.AdManager.v201802.RequestBuyerAcceptance action =
                            new Google.Api.Ads.AdManager.v201802.RequestBuyerAcceptance();

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

                        // Display results.
                        if (result != null && result.numChanges > 0)
                        {
                            Console.WriteLine(
                                "Number of proposals that were sent to Marketplace: {0}",
                                result.numChanges);
                        }
                        else
                        {
                            Console.WriteLine("No proposals were sent to Marketplace.");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(
                        "Failed to send proposals to Marketplace. 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 ProposalService.
              ProposalService proposalService =
              (ProposalService) user.GetService(DfpService.v201508.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.v201508.SubmitProposalsForApproval action =
              new Dfp.v201508.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 e) {
            Console.WriteLine("Failed to approve proposals. Exception says \"{0}\"",
            e.Message);
              }
        }