/// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser dfpUser)
        {
            WorkflowRequestService workflowRequestService =
                (WorkflowRequestService)dfpUser.GetService(DfpService.v201611.WorkflowRequestService);

            // Create a statement to select workflow requests.
            int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("type = :type")
                                                .OrderBy("id ASC")
                                                .Limit(pageSize)
                                                .AddValue("type", WorkflowRequestType.WORKFLOW_EXTERNAL_CONDITION_REQUEST.ToString());

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

            do
            {
                WorkflowRequestPage page = workflowRequestService.getWorkflowRequestsByStatement(
                    statementBuilder.ToStatement());

                // Print out some information for each workflow request.
                if (page.results != null)
                {
                    totalResultSetSize = page.totalResultSetSize;
                    int i = page.startIndex;
                    foreach (WorkflowRequest workflowRequest in page.results)
                    {
                        Console.WriteLine(
                            "{0}) Workflow request with ID {1}, " +
                            "entity type \"{2}\", " +
                            "and entity ID {3} was found.",
                            i++,
                            workflowRequest.id,
                            workflowRequest.entityType,
                            workflowRequest.entityId
                            );
                    }
                }

                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 void Run(DfpUser user)
        {
            WorkflowRequestService workflowRequestService =
                (WorkflowRequestService)user.GetService(DfpService.v201608.WorkflowRequestService);

            // Create a statement to select workflow requests.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("type = :type")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("type", WorkflowRequestType.WORKFLOW_APPROVAL_REQUEST.ToString());

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

            try {
                do
                {
                    page = workflowRequestService.getWorkflowRequestsByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        // Print out some information for each workflow request.
                        int i = page.startIndex;
                        foreach (WorkflowRequest workflowRequest in page.results)
                        {
                            Console.WriteLine("{0}) Workflow request with ID \"{1}\", entity type \"{2}\", "
                                              + "and entity ID \"{3}\" was found.",
                                              i++,
                                              workflowRequest.id,
                                              workflowRequest.entityType,
                                              workflowRequest.entityId);
                        }
                    }

                    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 workflow requests. 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 WorkflowRequestService.
            WorkflowRequestService workflowRequestService =
                (WorkflowRequestService)user.GetService(DfpService.v201602.WorkflowRequestService);

            // Create a statement to select all workflow external condition requests.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("type = :type")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("type", WorkflowRequestType.WORKFLOW_EXTERNAL_CONDITION_REQUEST.ToString());

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

            try {
                do
                {
                    // Get workflow requests by statement.
                    page = workflowRequestService
                           .getWorkflowRequestsByStatement(statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (WorkflowRequest workflowRequest in page.results)
                        {
                            Console.WriteLine("{0}) Workflow external condition request with ID '{1}' for {2} " +
                                              "with ID '{3}' was found.", i++, workflowRequest.id,
                                              workflowRequest.entityType.ToString(), workflowRequest.entityId);
                        }
                    }
                    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 workflow requests by statement. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser user)
        {
            // Get the WorkflowRequestService.
            WorkflowRequestService proposalLineItemService =
                (WorkflowRequestService)user.GetService(DfpService.v201605.WorkflowRequestService);

            // Set the ID of the proposal to trigger workflow external conditions for.c
            long proposalId = long.Parse(_T("INSERT_PROPOSAL_ID_HERE"));

            // Create a statement to select workflow external condition requests for a proposal.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("entityId = :entityId and entityType = :entityType and type = :type")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("entityId", proposalId)
                                                .AddValue("entityType", WorkflowEntityType.PROPOSAL.ToString())
                                                .AddValue("type", WorkflowRequestType.WORKFLOW_EXTERNAL_CONDITION_REQUEST.ToString());

            // Set default for page.
            WorkflowRequestPage page = new WorkflowRequestPage();
            List <long>         workflowRequestIds = new List <long>();

            try {
                do
                {
                    // Get workflow requests by statement.
                    page = proposalLineItemService.getWorkflowRequestsByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        int i = page.startIndex;
                        foreach (WorkflowRequest workflowRequest in page.results)
                        {
                            Console.WriteLine("{0}) Workflow external condition request with ID '{1}'" +
                                              " for {2} with ID '{3}' will be triggered.", i++, workflowRequest.id,
                                              workflowRequest.entityType.ToString(), workflowRequest.entityId);
                            workflowRequestIds.Add(workflowRequest.id);
                        }
                    }

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

                Console.WriteLine("Number of workflow external condition requests to be triggered: {0}",
                                  workflowRequestIds.Count);

                if (workflowRequestIds.Count > 0)
                {
                    // Modify statement.
                    statementBuilder.RemoveLimitAndOffset();

                    // Create action.
                    Google.Api.Ads.Dfp.v201605.TriggerWorkflowExternalConditionRequests action =
                        new Google.Api.Ads.Dfp.v201605.TriggerWorkflowExternalConditionRequests();

                    // Perform action.
                    UpdateResult result = proposalLineItemService.performWorkflowRequestAction(action,
                                                                                               statementBuilder.ToStatement());

                    // Display results.
                    if (result != null && result.numChanges > 0)
                    {
                        Console.WriteLine("Number of workflow external condition requests triggered: {0}",
                                          result.numChanges);
                    }
                    else
                    {
                        Console.WriteLine("No workflow external condition requests were triggered.");
                    }
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to tirgger workflow external condition requests. Exception " +
                                  "says \"{0}\"", e.Message);
            }
        }
Esempio n. 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 WorkflowRequestService.
            WorkflowRequestService workflowRequestService =
                (WorkflowRequestService)user.GetService(DfpService.v201502.WorkflowRequestService);

            // Set the ID of the proposal to approve workflow approval requests for.
            long proposalId = long.Parse(_T("INSERT_PROPOSAL_ID_HERE"));

            // Create a statement to select workflow approval requests for a proposal.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("WHERE entityId = :entityId and entityType = :entityType and type = :type")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("entityId", proposalId)
                                                .AddValue("entityType", WorkflowEntityType.PROPOSAL.ToString())
                                                .AddValue("type", WorkflowRequestType.WORKFLOW_APPROVAL_REQUEST.ToString());

            // Set default for page.
            WorkflowRequestPage page = new WorkflowRequestPage();
            List <long>         worflowRequestIds = new List <long>();

            try {
                do
                {
                    // Get workflow requests by statement.
                    page = workflowRequestService.getWorkflowRequestsByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (WorkflowRequest workflowRequest in page.results)
                        {
                            Console.WriteLine("{0})  Workflow approval request with ID '{1}' will be approved.",
                                              i++, workflowRequest.id);
                            worflowRequestIds.Add(workflowRequest.id);
                        }
                    }

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

                Console.WriteLine("Number of workflow approval requests to be approved: {0}",
                                  worflowRequestIds.Count);

                if (worflowRequestIds.Count > 0)
                {
                    // Modify statement.
                    statementBuilder.RemoveLimitAndOffset();

                    // Create action.
                    Google.Api.Ads.Dfp.v201502.ApproveWorkflowApprovalRequests action =
                        new Google.Api.Ads.Dfp.v201502.ApproveWorkflowApprovalRequests();

                    // Perform action.
                    UpdateResult result = workflowRequestService.performWorkflowRequestAction(action,
                                                                                              statementBuilder.ToStatement());

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