/// <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 BaseRateService.
      BaseRateService baseRateService =
          (BaseRateService) user.GetService(DfpService.v201502.BaseRateService);

      long baseRateId = long.Parse(_T("INSERT_BASE_RATE_ID_HERE"));

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

      try {
        // Get base rates by statement.
        BaseRatePage page =
            baseRateService.getBaseRatesByStatement(statementBuilder.ToStatement());

        BaseRate baseRate = page.results[0];

        // Update base rate value to $3 USD.
        Money newRate = new Money() {currencyCode = "USD", microAmount = 3000000L};

        if (baseRate is ProductTemplateBaseRate) {
          ((ProductTemplateBaseRate) baseRate).rate = newRate;
        } else if (baseRate is ProductBaseRate) {
          ((ProductBaseRate) baseRate).rate = newRate;
        }

        // Update the base rates on the server.
        BaseRate[] baseRates = baseRateService.updateBaseRates(new BaseRate[] {baseRate});

        if (baseRates != null) {
          foreach (BaseRate updatedBaseRate in baseRates) {
            Console.WriteLine("Base rate with ID ='{0}' and type '{1}' belonging to rate " +
                "card '{2}' was found.", baseRate.id, baseRate.GetType().Name, baseRate.rateCardId);
          }
        } else {
          Console.WriteLine("No base rates updated.");
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to update base rates. Exception says \"{0}\"",
            ex.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 LineItemService.
      LineItemService lineItemService =
          (LineItemService) user.GetService(DfpService.v201502.LineItemService);

      // Set the order that all created line items will belong to and the
      // video ad unit ID to target.
      long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));
      string targetedVideoAdUnitId = _T("INSERT_TARGETED_VIDEO_AD_UNIT_ID_HERE");

      // Set the custom targeting value ID representing the metadata
      // on the content to target. This would typically be from a key representing
      // a "genre" and a value representing something like "comedy". The value must
      // be from a key in a content metadata key hierarchy.
      long contentCustomTargetingValueId =
          long.Parse(_T("INSERT_CONTENT_CUSTOM_TARGETING_VALUE_ID_HERE"));

      // Create content targeting.
      ContentMetadataKeyHierarchyTargeting contentMetadataTargeting =
          new ContentMetadataKeyHierarchyTargeting();
      contentMetadataTargeting.customTargetingValueIds =
          new long[] {contentCustomTargetingValueId};

      ContentTargeting contentTargeting = new ContentTargeting();
      contentTargeting.targetedContentMetadata =
          new ContentMetadataKeyHierarchyTargeting[] {contentMetadataTargeting};

      // Create inventory targeting.
      InventoryTargeting inventoryTargeting = new InventoryTargeting();
      AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
      adUnitTargeting.adUnitId = targetedVideoAdUnitId;
      adUnitTargeting.includeDescendants = true;
      inventoryTargeting.targetedAdUnits = new AdUnitTargeting[] {adUnitTargeting};

      // Create video position targeting.
      VideoPosition videoPosition = new VideoPosition();
      videoPosition.positionType = VideoPositionType.PREROLL;
      VideoPositionTarget videoPositionTarget = new VideoPositionTarget();
      videoPositionTarget.videoPosition = videoPosition;
      VideoPositionTargeting videoPositionTargeting = new VideoPositionTargeting();
      videoPositionTargeting.targetedPositions = new VideoPositionTarget[] {videoPositionTarget};

      // Create targeting.
      Targeting targeting = new Targeting();
      targeting.contentTargeting = contentTargeting;
      targeting.inventoryTargeting = inventoryTargeting;
      targeting.videoPositionTargeting = videoPositionTargeting;

      // Create local line item object.
      LineItem lineItem = new LineItem();
      lineItem.name = "Video line item - " + this.GetTimeStamp();
      lineItem.orderId = orderId;
      lineItem.targeting = targeting;
      lineItem.lineItemType = LineItemType.SPONSORSHIP;
      lineItem.allowOverbook = true;

      // Set the environment type to video.
      lineItem.environmentType = EnvironmentType.VIDEO_PLAYER;

      // Set the creative rotation type to optimized.
      lineItem.creativeRotationType = CreativeRotationType.OPTIMIZED;

      // Create the master creative placeholder.
      CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder();
      Size size1 = new Size();
      size1.width = 400;
      size1.height = 300;
      size1.isAspectRatio = false;
      creativeMasterPlaceholder.size = size1;

      // Create companion creative placeholders.
      CreativePlaceholder companionCreativePlaceholder1 = new CreativePlaceholder();
      Size size2 = new Size();
      size2.width = 300;
      size2.height = 250;
      size2.isAspectRatio = false;
      companionCreativePlaceholder1.size = size2;

      CreativePlaceholder companionCreativePlaceholder2 = new CreativePlaceholder();
      Size size3 = new Size();
      size3.width = 728;
      size3.height = 90;
      size3.isAspectRatio = false;
      companionCreativePlaceholder2.size = size3;

      // Set companion creative placeholders.
      creativeMasterPlaceholder.companions = new CreativePlaceholder[] {
          companionCreativePlaceholder1, companionCreativePlaceholder2};

      // Set the size of creatives that can be associated with this line item.
      lineItem.creativePlaceholders = new CreativePlaceholder[] {creativeMasterPlaceholder};

      // Set delivery of video companions to optional.
      lineItem.companionDeliveryOption = CompanionDeliveryOption.OPTIONAL;

      // Set the length of the line item to run.
      lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY;
      lineItem.endDateTime = DateTimeUtilities.FromString("20120901 00:00:00");

      // Set the cost per day to $1.
      lineItem.costType = CostType.CPD;
      Money money = new Money();
      money.currencyCode = "USD";
      money.microAmount = 1000000L;
      lineItem.costPerUnit = money;

      // Set the percentage to be 100%.
      Goal goal = new Goal();
      goal.goalType = GoalType.DAILY;
      goal.unitType = UnitType.IMPRESSIONS;
      goal.units = 100;
      lineItem.primaryGoal = goal;

      try {
        // Create the line item on the server.
        LineItem[] createdLineItems = lineItemService.createLineItems(new LineItem[] {lineItem});

        foreach (LineItem createdLineItem in createdLineItems) {
          Console.WriteLine("A line item with ID \"{0}\", belonging to order ID \"{1}\", and " +
              "named \"{2}\" was created.", createdLineItem.id, createdLineItem.orderId,
              createdLineItem.name);
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to create line items. Exception says \"{0}\"",
            ex.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);

      // Get the NetworkService.
      NetworkService networkService =
          (NetworkService) user.GetService(DfpService.v201502.NetworkService);

      // Set the advertiser, salesperson, and trafficker to assign to each
      // order.
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
      long primarySalespersonId = long.Parse(_T("INSERT_PRIMARY_SALESPERSON_ID_HERE"));
      long secondarySalespersonId = long.Parse(_T("INSERT_SECONDARY_SALESPERSON_ID_HERE"));
      long primaryTraffickerId = long.Parse(_T("INSERT_PRIMARY_TRAFFICKER_ID_HERE"));
      long secondaryTraffickerId = long.Parse(_T("INSERT_SECONDARY_TRAFFICKER_ID_HERE"));

      // Create a proposal.
      Proposal proposal = new Proposal();
      proposal.name = "Proposal #" + new Random().Next(int.MaxValue);

      // Create a proposal company association.
      ProposalCompanyAssociation proposalCompanyAssociation = new ProposalCompanyAssociation();
      proposalCompanyAssociation.companyId = advertiserId;
      proposalCompanyAssociation.type = ProposalCompanyAssociationType.ADVERTISER;
      proposal.advertiser = proposalCompanyAssociation;

      // Create salesperson splits for the primary salesperson and secondary salespeople.
      SalespersonSplit primarySalesperson = new SalespersonSplit();
      primarySalesperson.userId = primarySalespersonId;
      primarySalesperson.split = 75000;
      proposal.primarySalesperson = primarySalesperson;

      SalespersonSplit secondarySalesperson = new SalespersonSplit();
      secondarySalesperson.userId = secondarySalespersonId;
      secondarySalesperson.split = 25000;
      proposal.secondarySalespeople = new SalespersonSplit[] {secondarySalesperson};

      // Set the probability to close to 100%.
      proposal.probabilityOfClose = 100000L;

      // Set the primary trafficker on the proposal for when it becomes an order.
      proposal.primaryTraffickerId = primaryTraffickerId;

      // Create a budget for the proposal worth 100 in the network local currency.
      Money budget = new Money();
      budget.microAmount = 100000000L;
      budget.currencyCode = networkService.getCurrentNetwork().currencyCode;
      proposal.budget = budget;

      proposal.billingCap = BillingCap.CAPPED_CUMULATIVE;
      proposal.billingSource = BillingSource.DFP_VOLUME;

      try {
        // Create the proposal on the server.
        Proposal[] proposals = proposalService.createProposals(new Proposal[] {proposal});

        foreach (Proposal createdProposal in proposals) {
          Console.WriteLine("A proposal with ID \"{0}\" and name \"{1}\" was created.",
              createdProposal.id, createdProposal.name);
        }
      } catch (Exception e) {
          Console.WriteLine("Failed to create proposals. Exception says \"{0}\"",
                            e.Message);
      }
    }