コード例 #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 ForecastService.
      ForecastService forecastService =
          (ForecastService) user.GetService(DfpService.v201502.ForecastService);

      // Set the line item to get a forecast for.
      long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE"));

      try {
        // Get forecast for line item.
        AvailabilityForecastOptions options = new AvailabilityForecastOptions();
        options.includeContendingLineItems = true;
        options.includeTargetingCriteriaBreakdown = true;
        AvailabilityForecast forecast =
            forecastService.getAvailabilityForecastById(lineItemId, options);

        // Display results.
        long matched = forecast.matchedUnits;
        double availablePercent = (double) (forecast.availableUnits / (matched * 1.0)) * 100;
        String unitType = forecast.unitType.ToString().ToLower();

        Console.WriteLine("{0} {1} matched.\n{2} % {3} available.", matched, unitType,
            availablePercent, unitType);
        if (forecast.possibleUnitsSpecified) {
          double possiblePercent = (double) (forecast.possibleUnits / (matched * 1.0)) * 100;
          Console.WriteLine(possiblePercent + "% " + unitType + " possible.\n");
        }
        Console.WriteLine("{0} contending line items.", (forecast.contendingLineItems != null)?
            forecast.contendingLineItems.Length : 0);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get forecast by id. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #2
0
 public virtual AvailabilityForecast getAvailabilityForecastById(long lineItemId, AvailabilityForecastOptions forecastOptions) {
   object[] results = this.Invoke("getAvailabilityForecastById", new object[] { lineItemId, forecastOptions });
   return ((AvailabilityForecast) (results[0]));
 }
コード例 #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 ForecastService.
      ForecastService forecastService =
          (ForecastService)user.GetService(DfpService.v201502.ForecastService);

      // Set the placement that the prospective line item will target.
      long[] targetPlacementIds = new long[] {long.Parse(_T("INSERT_PLACEMENT_ID_HERE"))};

      // Set the end date time to have the line line item run till.
      string endDateTime = "INSERT_END_DATE_TIME_HERE (yyyyMMdd HH:mm:ss)";

      // Create prospective line item.
      LineItem lineItem = new LineItem();

      lineItem.targeting = new Targeting();
      lineItem.targeting.inventoryTargeting = new InventoryTargeting();
      lineItem.targeting.inventoryTargeting.targetedPlacementIds = targetPlacementIds;

      Size size = new Size();
      size.width = 300;
      size.height = 250;

      // Create the creative placeholder.
      CreativePlaceholder creativePlaceholder = new CreativePlaceholder();
      creativePlaceholder.size = size;

      lineItem.creativePlaceholders = new CreativePlaceholder[] {creativePlaceholder};

      lineItem.lineItemType = LineItemType.SPONSORSHIP;
      lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY;

      lineItem.endDateTime = DateTimeUtilities.FromString(endDateTime);

      // Set the cost type to match the unit type.
      lineItem.costType = CostType.CPM;
      Goal goal = new Goal();
      goal.goalType = GoalType.DAILY;
      goal.unitType = UnitType.IMPRESSIONS;
      goal.units = 50L;
      lineItem.primaryGoal = goal;

      try {
        // Get availability forecast.
        AvailabilityForecastOptions options = new AvailabilityForecastOptions();
        options.includeContendingLineItems = true;
        options.includeTargetingCriteriaBreakdown = true;
        ProspectiveLineItem prospectiveLineItem = new ProspectiveLineItem();
        prospectiveLineItem.lineItem = lineItem;
        AvailabilityForecast forecast =
            forecastService.getAvailabilityForecast(prospectiveLineItem, options);

        // Display results.
        long matched = forecast.matchedUnits;
        double availablePercent = (double) (forecast.availableUnits / (matched * 1.0)) * 100;
        String unitType = forecast.unitType.ToString().ToLower();
        Console.WriteLine("{0} {1} matched.\n{2}%  available.", matched, unitType,
            availablePercent, unitType);

        if (forecast.possibleUnitsSpecified) {
          double possiblePercent = (double) (forecast.possibleUnits / (matched * 1.0)) * 100;
          Console.WriteLine("{0}% {1} possible.\n", possiblePercent, unitType);
        }
        Console.WriteLine("{0} contending line items.", (forecast.contendingLineItems != null) ?
            forecast.contendingLineItems.Length : 0);
      } catch (Exception e) {
        Console.WriteLine("Failed to get forecast. Exception says \"{0}\"", e.Message);
      }
    }
コード例 #4
0
 public virtual AvailabilityForecast getAvailabilityForecast(ProspectiveLineItem lineItem, AvailabilityForecastOptions forecastOptions) {
   object[] results = this.Invoke("getAvailabilityForecast", new object[] { lineItem, forecastOptions });
   return ((AvailabilityForecast) (results[0]));
 }