/// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (AdjustmentService adjustmentService = user.GetService <AdjustmentService>())
            {
                // Create a statement to select adjustments.
                int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
                StatementBuilder statementBuilder =
                    new StatementBuilder().OrderBy("id ASC").Limit(pageSize);

                // Retrieve a small amount of adjustments at a time, paging through until all
                // adjustments have been retrieved.
                int totalResultSetSize = 0;
                do
                {
                    TrafficForecastAdjustmentPage page =
                        adjustmentService.getTrafficAdjustmentsByStatement(
                            statementBuilder.ToStatement());

                    // Print out some information for each adjustment.
                    if (page.results != null)
                    {
                        totalResultSetSize = page.totalResultSetSize;
                        int i = page.startIndex;
                        foreach (TrafficForecastAdjustment adjustment in page.results)
                        {
                            Console.WriteLine("Forecast adjustment with ID {0} containing {1} "
                                              + "segments was found.",
                                              adjustment.id,
                                              adjustment.forecastAdjustmentSegments != null ?
                                              adjustment.forecastAdjustmentSegments.Length : 0);
                        }
                    }

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

                Console.WriteLine("Number of results found: {0}", totalResultSetSize);
            }
        }
Пример #2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (AdjustmentService adjustmentService = user.GetService <AdjustmentService>())
            {
                // Set the ID of the adjustment to update.
                long adjustmentId = long.Parse(_T("INSERT_ADJUSTMENT_ID_HERE"));

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

                TrafficForecastAdjustmentPage page = adjustmentService
                                                     .getTrafficAdjustmentsByStatement(statementBuilder.ToStatement());

                TrafficForecastAdjustment adjustment = page.results[0];

                // Create a new historical adjustment segment for New Years Day.
                TrafficForecastAdjustmentSegment segment = new TrafficForecastAdjustmentSegment()
                {
                    basisType            = BasisType.HISTORICAL,
                    historicalAdjustment = new HistoricalAdjustment()
                    {
                        referenceDateRange = new DateRange()
                        {
                            startDate = new Date()
                            {
                                year  = System.DateTime.Now.Year,
                                month = 1,
                                day   = 1
                            },
                            endDate = new Date()
                            {
                                year  = System.DateTime.Now.Year,
                                month = 1,
                                day   = 1
                            }
                        },
                        targetDateRange = new DateRange()
                        {
                            startDate = new Date()
                            {
                                year  = System.DateTime.Now.Year + 1,
                                month = 1,
                                day   = 1
                            },
                            endDate = new Date()
                            {
                                year  = System.DateTime.Now.Year + 1,
                                month = 1,
                                day   = 1
                            }
                        },
                        milliPercentMultiplier = 110_000L
                    }
                };

                // Add the new historical segment to the adjustment.
                adjustment.forecastAdjustmentSegments = adjustment.forecastAdjustmentSegments
                                                        .Concat(new TrafficForecastAdjustmentSegment[] { segment }).ToArray();

                TrafficForecastAdjustment[] adjustments =
                    adjustmentService.updateTrafficAdjustments(
                        new TrafficForecastAdjustment[] { adjustment });

                foreach (TrafficForecastAdjustment updatedAdjustment in adjustments)
                {
                    Console.WriteLine("Adjustment with ID {0} and {1} segments was found.",
                                      updatedAdjustment.id,
                                      updatedAdjustment.forecastAdjustmentSegments.Length);
                }
            }
        }