public void TestCreateAdUnits() {
      // Create ad unit 1.
      AdUnit localAdUnit1 = new AdUnit();
      localAdUnit1.name = string.Format("Ad_Unit_{0}", new TestUtils().GetTimeStamp());
      localAdUnit1.parentId = adUnit1.id;

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

      AdUnitSize adUnitSize1 = new AdUnitSize();
      adUnitSize1.size = size1;
      adUnitSize1.environmentType = EnvironmentType.BROWSER;

      localAdUnit1.adUnitSizes = new AdUnitSize[] {adUnitSize1};

      // Create ad unit 2.
      AdUnit localAdUnit2 = new AdUnit();
      localAdUnit2.name = string.Format("Ad_Unit_{0}", new TestUtils().GetTimeStamp());
      localAdUnit2.parentId = adUnit1.id;

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

      AdUnitSize adUnitSize2 = new AdUnitSize();
      adUnitSize2.size = size2;
      adUnitSize2.environmentType = EnvironmentType.BROWSER;

      localAdUnit2.adUnitSizes = new AdUnitSize[] {adUnitSize2};

      AdUnit[] newAdUnits = null;

      Assert.DoesNotThrow(delegate() {
        newAdUnits = inventoryService.createAdUnits(new AdUnit[] {localAdUnit1, localAdUnit2});
      });

      Assert.NotNull(newAdUnits);
      Assert.AreEqual(newAdUnits.Length, 2);

      Assert.AreEqual(newAdUnits[0].name, localAdUnit1.name);
      Assert.AreEqual(newAdUnits[0].parentId, localAdUnit1.parentId);
      Assert.AreEqual(newAdUnits[0].parentId, adUnit1.id);
      Assert.AreEqual(newAdUnits[0].status, localAdUnit1.status);
      Assert.AreEqual(newAdUnits[0].targetWindow, localAdUnit1.targetWindow);

      Assert.AreEqual(newAdUnits[1].name, localAdUnit2.name);
      Assert.AreEqual(newAdUnits[1].parentId, localAdUnit2.parentId);
      Assert.AreEqual(newAdUnits[1].parentId, adUnit1.id);
      Assert.AreEqual(newAdUnits[1].status, localAdUnit2.status);
      Assert.AreEqual(newAdUnits[1].targetWindow, localAdUnit2.targetWindow);
    }
    /// <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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201505.InventoryService);

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

      string effectiveRootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

      // Create an array to store local ad unit objects.
      AdUnit[] adUnits = new AdUnit[5];

      for (int i = 0; i < 5; i++) {
        AdUnit adUnit = new AdUnit();
        adUnit.name = string.Format("Ad_Unit_{0}", i);
        adUnit.parentId = effectiveRootAdUnitId;

        adUnit.description = "Ad unit description.";
        adUnit.targetWindow = AdUnitTargetWindow.BLANK;

        // Set the size of possible creatives that can match this ad unit.
        Size size = new Size();
        size.width = 300;
        size.height = 250;

        // Create ad unit size.
        AdUnitSize adUnitSize = new AdUnitSize();
        adUnitSize.size = size;
        adUnitSize.environmentType = EnvironmentType.BROWSER;

        adUnit.adUnitSizes = new AdUnitSize[] {adUnitSize};
        adUnits[i] = adUnit;
      }

      try {
        // Create the ad units on the server.
        adUnits = inventoryService.createAdUnits(adUnits);

        if (adUnits != null) {
          foreach (AdUnit adUnit in adUnits) {
            Console.WriteLine("An ad unit with ID = '{0}' was created under parent with " +
                "ID = '{1}'.", adUnit.id, adUnit.parentId);
          }
        } else {
          Console.WriteLine("No ad units created.");
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create ad units. 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 CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201505.CreativeService);

      // Set the ID of the advertiser (company) that all creatives will be
      // assigned to.
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));

      // Create the local custom creative object.
      CustomCreative customCreative = new CustomCreative();
      customCreative.name = "Custom creative " + GetTimeStamp();
      customCreative.advertiserId = advertiserId;
      customCreative.destinationUrl = "http://google.com";

      // Set the custom creative image asset.
      CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
      customCreativeAsset.macroName = "IMAGE_ASSET";
      customCreativeAsset.fileName = string.Format("inline{0}.jpg", GetTimeStamp());
      customCreativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
          "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
      customCreative.customCreativeAssets = new CustomCreativeAsset[] {customCreativeAsset};

      // Set the HTML snippet using the custom creative asset macro.
      customCreative.htmlSnippet = "<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>" +
          "<img src='%%FILE:" + customCreativeAsset.macroName + "%%'/>" +
          "</a><br>Click above for great deals!";

      // Set the creative size.
      Size size = new Size();
      size.width = 300;
      size.height = 250;
      size.isAspectRatio = false;

      customCreative.size = size;

      try {
        // Create the custom creative on the server.
        Creative[] createdCreatives = creativeService.createCreatives(
            new Creative[] {customCreative});

        foreach (Creative createdCreative in createdCreatives) {
          Console.WriteLine("A custom creative with ID \"{0}\", name \"{1}\", and size ({2}, " +
              "{3}) was created and can be previewed at {4}", createdCreative.id,
              createdCreative.name, createdCreative.size.width, createdCreative.size.height,
              createdCreative.previewUrl);
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create custom creatives. Exception says \"{0}\"", e.Message);
      }
    }
    public void TestCreateCreatives() {
      // Create an array to store local image creative objects.
      Creative[] imageCreatives = new ImageCreative[2];

      for (int i = 0; i < 2; i++) {
        // Create creative size.
        Size size = new Size();
        size.width = 300;
        size.height = 250;

        // Create an image creative.
        ImageCreative imageCreative = new ImageCreative();
        imageCreative.name = string.Format("Image creative #{0}", i);
        imageCreative.advertiserId = advertiserId;
        imageCreative.destinationUrl = "http://www.google.com";
        imageCreative.size = size;

        // Create image asset.
        CreativeAsset creativeAsset = new CreativeAsset();
        creativeAsset.fileName = "image.jpg";
        creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
            "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
        creativeAsset.size = size;
        imageCreative.primaryImageAsset = creativeAsset;

        imageCreatives[i] = imageCreative;
      }

      Creative[] newCreatives = null;

      Assert.DoesNotThrow(delegate() {
        newCreatives = creativeService.createCreatives(imageCreatives);
      });

      Assert.NotNull(newCreatives);
      Assert.AreEqual(newCreatives.Length, 2);
      Assert.NotNull(newCreatives[0]);
      Assert.That(newCreatives[0] is ImageCreative);
      Assert.AreEqual(newCreatives[0].advertiserId, advertiserId);
      Assert.AreEqual(newCreatives[0].name, "Image creative #0");
      Assert.NotNull(newCreatives[1]);
      Assert.That(newCreatives[1] is ImageCreative);
      Assert.AreEqual(newCreatives[1].advertiserId, advertiserId);
      Assert.AreEqual(newCreatives[1].name, "Image creative #1");
    }
    /// <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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201505.InventoryService);

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

      // Set the parent ad unit's ID for all ad units to be created under.
      String effectiveRootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

      // Create local ad unit object.
      AdUnit adUnit = new AdUnit();
      adUnit.name = "Mobile_Ad_Unit";
      adUnit.parentId = effectiveRootAdUnitId;
      adUnit.description = "Ad unit description.";
      adUnit.targetWindow = AdUnitTargetWindow.BLANK;
      adUnit.targetPlatform = TargetPlatform.MOBILE;

      // Create ad unit size.
      AdUnitSize adUnitSize = new AdUnitSize();
      Size size = new Size();
      size.width = 400;
      size.height = 300;
      size.isAspectRatio = false;
      adUnitSize.size = size;
      adUnitSize.environmentType = EnvironmentType.BROWSER;

      // Set the size of possible creatives that can match this ad unit.
      adUnit.adUnitSizes = new AdUnitSize[] {adUnitSize};

      try {
        // Create the ad unit on the server.
        AdUnit[] createdAdUnits = inventoryService.createAdUnits(new AdUnit[] {adUnit});

        foreach (AdUnit createdAdunit in createdAdUnits) {
          Console.WriteLine("An ad unit with ID \"{0}\" was created under parent with ID " +
              "\"{1}\".", createdAdunit.id, createdAdunit.parentId);
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create ad units. Exception says \"{0}\"", e.Message);
      }
    }
예제 #6
0
        public AdUnit CreateAdUnit(DfpUser user)
        {
            InventoryService inventoryService =
              (InventoryService) user.GetService(DfpService.v201505.InventoryService);

              AdUnit adUnit = new AdUnit();
              adUnit.name = string.Format("Ad_Unit_{0}", GetTimeStamp());
              adUnit.parentId = FindRootAdUnit(user).id;

              // Set the size of possible creatives that can match this ad unit.
              Size size = new Size();
              size.width = 300;
              size.height = 250;

              // Create ad unit size.
              AdUnitSize adUnitSize = new AdUnitSize();
              adUnitSize.size = size;
              adUnitSize.environmentType = EnvironmentType.BROWSER;

              adUnit.adUnitSizes = new AdUnitSize[] {adUnitSize};
              return inventoryService.createAdUnits(new AdUnit[] {adUnit})[0];
        }
    public void TestUpdateAdUnits() {
      List<AdUnitSize> adUnitSizes = null;
      Size size = null;

      // Modify ad unit 1.
      adUnitSizes = new List<AdUnitSize>(adUnit1.adUnitSizes);
      size = new Size();
      size.width = 728;
      size.height = 90;

      // Create ad unit size.
      AdUnitSize adUnitSize = new AdUnitSize();
      adUnitSize.size = size;
      adUnitSize.environmentType = EnvironmentType.BROWSER;

      adUnitSizes.Add(adUnitSize);
      adUnit1.adUnitSizes = adUnitSizes.ToArray();

      // Modify ad unit 2.
      adUnitSizes = new List<AdUnitSize>(adUnit2.adUnitSizes);
      size = new Size();
      size.width = 728;
      size.height = 90;

      // Create ad unit size.
      adUnitSize = new AdUnitSize();
      adUnitSize.size = size;
      adUnitSize.environmentType = EnvironmentType.BROWSER;

      adUnitSizes.Add(adUnitSize);
      adUnit2.adUnitSizes = adUnitSizes.ToArray();

      AdUnit[] newAdUnits = null;
      Assert.DoesNotThrow(delegate() {
        newAdUnits = inventoryService.updateAdUnits(new AdUnit[] {adUnit1, adUnit2});
      });

      Assert.NotNull(newAdUnits);
      Assert.AreEqual(newAdUnits.Length, 2);

      Assert.AreEqual(newAdUnits[0].name, adUnit1.name);
      Assert.AreEqual(newAdUnits[0].parentId, adUnit1.parentId);
      Assert.AreEqual(newAdUnits[0].id, adUnit1.id);
      Assert.AreEqual(newAdUnits[0].status, adUnit1.status);
      Assert.AreEqual(newAdUnits[0].targetWindow, adUnit1.targetWindow);
      Assert.AreEqual(newAdUnits[0].adUnitSizes.Length, adUnit1.adUnitSizes.Length);

      Assert.AreEqual(newAdUnits[1].name, adUnit2.name);
      Assert.AreEqual(newAdUnits[1].parentId, adUnit2.parentId);
      Assert.AreEqual(newAdUnits[1].id, adUnit2.id);
      Assert.AreEqual(newAdUnits[1].status, adUnit2.status);
      Assert.AreEqual(newAdUnits[1].targetWindow, adUnit2.targetWindow);
      Assert.AreEqual(newAdUnits[1].adUnitSizes.Length, adUnit2.adUnitSizes.Length);
    }
    /// <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.v201505.ForecastService);

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

      // 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;

      // Set the line item to run for one month.
      lineItem.endDateTime =
          DateTimeUtilities.FromDateTime(System.DateTime.Now.AddMonths(1), "America/New_York");

      // 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);
      }
    }
    /// <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.v201505.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 line item to run for one month.
      lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY;
      lineItem.endDateTime =
          DateTimeUtilities.FromDateTime(System.DateTime.Now.AddMonths(1), "America/New_York");

      // 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);
      }
    }
예제 #10
0
    /// <summary>
    /// Create a test company for running further tests.
    /// </summary>
    /// <returns>A creative for running further tests.</returns>
    public Creative CreateCreative(DfpUser user, long advertiserId) {
      CreativeService creativeService = (CreativeService)user.GetService(
          DfpService.v201505.CreativeService);

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

      // Create an image creative.
      ImageCreative imageCreative = new ImageCreative();
      imageCreative.name = string.Format("Image creative #{0}", GetTimeStamp());
      imageCreative.advertiserId = advertiserId;
      imageCreative.destinationUrl = "http://www.google.com";
      imageCreative.size = size;

      // Create image asset.
      CreativeAsset creativeAsset = new CreativeAsset();
      creativeAsset.fileName = "image.jpg";
      creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
          "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
      creativeAsset.size = size;
      imageCreative.primaryImageAsset = creativeAsset;

      return creativeService.createCreatives(new Creative[] {imageCreative})[0];
    }
예제 #11
0
    public LineItem CreateLineItem(DfpUser user, long orderId, string adUnitId) {
      LineItemService lineItemService =
          (LineItemService) user.GetService(DfpService.v201505.LineItemService);

      long placementId = CreatePlacement(user, new string[] {adUnitId}).id;

      // Create inventory targeting.
      InventoryTargeting inventoryTargeting = new InventoryTargeting();
      inventoryTargeting.targetedPlacementIds = new long[] {placementId};

      // Create geographical targeting.
      GeoTargeting geoTargeting = new GeoTargeting();

      // Include the US and Quebec, Canada.
      Location countryLocation = new Location();
      countryLocation.id = 2840L;

      Location regionLocation = new Location();
      regionLocation.id = 20123L;
      geoTargeting.targetedLocations = new Location[] {countryLocation, regionLocation};

      // Exclude Chicago and the New York metro area.
      Location cityLocation = new Location();
      cityLocation.id = 1016367L;

      Location metroLocation = new Location();
      metroLocation.id = 200501L;
      geoTargeting.excludedLocations = new Location[] {cityLocation, metroLocation};

      // Exclude domains that are not under the network's control.
      UserDomainTargeting userDomainTargeting = new UserDomainTargeting();
      userDomainTargeting.domains = new String[] {"usa.gov"};
      userDomainTargeting.targeted = false;

      // Create day-part targeting.
      DayPartTargeting dayPartTargeting = new DayPartTargeting();
      dayPartTargeting.timeZone = DeliveryTimeZone.BROWSER;

      // Target only the weekend in the browser's timezone.
      DayPart saturdayDayPart = new DayPart();
      saturdayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201505.DayOfWeek.SATURDAY;

      saturdayDayPart.startTime = new TimeOfDay();
      saturdayDayPart.startTime.hour = 0;
      saturdayDayPart.startTime.minute = MinuteOfHour.ZERO;

      saturdayDayPart.endTime = new TimeOfDay();
      saturdayDayPart.endTime.hour = 24;
      saturdayDayPart.endTime.minute = MinuteOfHour.ZERO;

      DayPart sundayDayPart = new DayPart();
      sundayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201505.DayOfWeek.SUNDAY;

      sundayDayPart.startTime = new TimeOfDay();
      sundayDayPart.startTime.hour = 0;
      sundayDayPart.startTime.minute = MinuteOfHour.ZERO;

      sundayDayPart.endTime = new TimeOfDay();
      sundayDayPart.endTime.hour = 24;
      sundayDayPart.endTime.minute = MinuteOfHour.ZERO;

      dayPartTargeting.dayParts = new DayPart[] {saturdayDayPart, sundayDayPart};


      // Create technology targeting.
      TechnologyTargeting technologyTargeting = new TechnologyTargeting();

      // Create browser targeting.
      BrowserTargeting browserTargeting = new BrowserTargeting();
      browserTargeting.isTargeted = true;

      // Target just the Chrome browser.
      Technology browserTechnology = new Technology();
      browserTechnology.id = 500072L;
      browserTargeting.browsers = new Technology[] {browserTechnology};
      technologyTargeting.browserTargeting = browserTargeting;

      LineItem lineItem = new LineItem();
      lineItem.name = "Line item #" + new TestUtils().GetTimeStamp();
      lineItem.orderId = orderId;
      lineItem.targeting = new Targeting();

      lineItem.targeting.inventoryTargeting = inventoryTargeting;
      lineItem.targeting.geoTargeting = geoTargeting;
      lineItem.targeting.userDomainTargeting = userDomainTargeting;
      lineItem.targeting.dayPartTargeting = dayPartTargeting;
      lineItem.targeting.technologyTargeting = technologyTargeting;

      lineItem.lineItemType = LineItemType.STANDARD;
      lineItem.allowOverbook = true;

      // Set the creative rotation type to even.
      lineItem.creativeRotationType = CreativeRotationType.EVEN;

      // Set the size of creatives that can be associated with this line item.
      Size size = new Size();
      size.width = 300;
      size.height = 250;
      size.isAspectRatio = false;

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

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

      // Set the line item to run for one month.
      lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY;
      lineItem.endDateTime =
          DateTimeUtilities.FromDateTime(System.DateTime.Today.AddMonths(1), "America/New_York");

      // Set the cost per unit to $2.
      lineItem.costType = CostType.CPM;
      lineItem.costPerUnit = new Money();
      lineItem.costPerUnit.currencyCode = "USD";
      lineItem.costPerUnit.microAmount = 2000000L;

      // Set the number of units bought to 500,000 so that the budget is
      // $1,000.
      Goal goal = new Goal();
      goal.units = 500000L;
      goal.unitType = UnitType.IMPRESSIONS;
      lineItem.primaryGoal = goal;

      return lineItemService.createLineItems(new LineItem[] {lineItem})[0];
    }
    public void TestGetAvailabilityForecast() {
      TestUtils utils = new TestUtils();

      LineItem lineItem = new LineItem();
      lineItem.name = string.Format("Line item #{0}", utils.GetTimeStamp());

      lineItem.orderId = orderId;

      lineItem.targeting = new Targeting();
      lineItem.targeting.inventoryTargeting = new InventoryTargeting();
      lineItem.targeting.inventoryTargeting.targetedPlacementIds = new long[] {placementId};

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

      Size size2 = new Size();
      size2.width = 120;
      size2.height = 600;

      // Create the creative placeholders.
      CreativePlaceholder creativePlaceholder1 = new CreativePlaceholder();
      creativePlaceholder1.size = size1;

      CreativePlaceholder creativePlaceholder2 = new CreativePlaceholder();
      creativePlaceholder1.size = size2;

      lineItem.creativePlaceholders =
          new CreativePlaceholder[] {creativePlaceholder1, creativePlaceholder2};

      lineItem.lineItemType = LineItemType.STANDARD;

      // Set start date time and end date time.
      lineItem.startDateTime =
          DateTimeUtilities.FromDateTime(System.DateTime.Today.AddDays(1), "America/New_York");
      lineItem.endDateTime =
          DateTimeUtilities.FromDateTime(System.DateTime.Today.AddMonths(1), "America/New_York");

      lineItem.costType = CostType.CPM;
      lineItem.costPerUnit = new Money();
      lineItem.costPerUnit.currencyCode = "USD";
      lineItem.costPerUnit.microAmount = 2000000;

      lineItem.creativeRotationType = CreativeRotationType.EVEN;
      lineItem.discountType = LineItemDiscountType.PERCENTAGE;

      Goal goal = new Goal();
      goal.units = 500000;
      goal.unitType = UnitType.IMPRESSIONS;
      lineItem.primaryGoal = goal;

      ProspectiveLineItem prospectiveLineItem = new ProspectiveLineItem();
      prospectiveLineItem.lineItem = lineItem;

      AvailabilityForecast forecast = null;
      Assert.DoesNotThrow(delegate() {
        forecast = forecastService.getAvailabilityForecast(prospectiveLineItem,
            new AvailabilityForecastOptions());
      });
      Assert.NotNull(forecast);
      Assert.AreEqual(forecast.orderId, orderId);
      Assert.AreEqual(forecast.unitType, lineItem.primaryGoal.unitType);
    }
    /// <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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201505.InventoryService);

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

      // Set the parent ad unit's ID for all ad units to be created under.
      String effectiveRootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

      // Create local ad unit object.
      AdUnit adUnit = new AdUnit();
      adUnit.name = "Video_Ad_Unit";
      adUnit.parentId = effectiveRootAdUnitId;
      adUnit.description = "Ad unit description.";
      adUnit.targetWindow = AdUnitTargetWindow.BLANK;
      adUnit.explicitlyTargeted = true;
      adUnit.targetPlatform = TargetPlatform.WEB;

      // Create master ad unit size.
      AdUnitSize masterAdUnitSize = new AdUnitSize();
      Size size1 = new Size();
      size1.width = 400;
      size1.height = 300;
      size1.isAspectRatio = false;
      masterAdUnitSize.size = size1;
      masterAdUnitSize.environmentType = EnvironmentType.VIDEO_PLAYER;

      // Create companion sizes.
      AdUnitSize companionAdUnitSize1 = new AdUnitSize();
      Size size2 = new Size();
      size2.width = 300;
      size2.height = 250;
      size2.isAspectRatio = false;
      companionAdUnitSize1.size = size2;
      companionAdUnitSize1.environmentType = EnvironmentType.BROWSER;

      AdUnitSize companionAdUnitSize2 = new AdUnitSize();
      Size size3 = new Size();
      size3.width = 728;
      size3.height = 90;
      size3.isAspectRatio = false;
      companionAdUnitSize2.size = size3;
      companionAdUnitSize2.environmentType = EnvironmentType.BROWSER;

      // Add companions to master ad unit size.
      masterAdUnitSize.companions = new AdUnitSize[] {companionAdUnitSize1, companionAdUnitSize2};

      // Set the size of possible creatives that can match this ad unit.
      adUnit.adUnitSizes = new AdUnitSize[] {masterAdUnitSize};

      try {
        // Create the ad unit on the server.
        AdUnit[] createdAdUnits = inventoryService.createAdUnits(new AdUnit[] {adUnit});

        foreach (AdUnit createdAdUnit in createdAdUnits) {
          Console.WriteLine("A video ad unit with ID \"{0}\" was created under parent with ID " +
              "\"{1}\".", createdAdUnit.id, createdAdUnit.parentId);
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create video ad units. 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 CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201505.CreativeService);

      // Set the ID of the advertiser (company) that all creative will be
      // assigned to.
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_COMPANY_ID_HERE"));

      // Use the image banner with optional third party tracking template.
      long creativeTemplateId = 10000680L;

      // Create the local custom creative object.
      TemplateCreative templateCreative = new TemplateCreative();
      templateCreative.name = "Template creative";
      templateCreative.advertiserId = advertiserId;
      templateCreative.creativeTemplateId = creativeTemplateId;

      // Set the creative size.
      Size size = new Size();
      size.width = 300;
      size.height = 250;
      size.isAspectRatio = false;

      templateCreative.size = size;

      // Create the asset variable value.
      AssetCreativeTemplateVariableValue assetVariableValue =
          new AssetCreativeTemplateVariableValue();
      assetVariableValue.uniqueName = "Imagefile";
      assetVariableValue.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
          "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
      assetVariableValue.fileName = String.Format("image{0}.jpg", this.GetTimeStamp());

      // Create the image width variable value.
      LongCreativeTemplateVariableValue imageWidthVariableValue =
          new LongCreativeTemplateVariableValue();
      imageWidthVariableValue.uniqueName = "Imagewidth";
      imageWidthVariableValue.value = 300;

      // Create the image height variable value.
      LongCreativeTemplateVariableValue imageHeightVariableValue =
          new LongCreativeTemplateVariableValue();
      imageHeightVariableValue.uniqueName = "Imageheight";
      imageHeightVariableValue.value = 250;

      // Create the URL variable value.
      UrlCreativeTemplateVariableValue urlVariableValue = new UrlCreativeTemplateVariableValue();
      urlVariableValue.uniqueName = "ClickthroughURL";
      urlVariableValue.value = "www.google.com";

      // Create the target window variable value.
      StringCreativeTemplateVariableValue targetWindowVariableValue =
          new StringCreativeTemplateVariableValue();
      targetWindowVariableValue.uniqueName = "Targetwindow";
      targetWindowVariableValue.value = "_blank";

      templateCreative.creativeTemplateVariableValues = new BaseCreativeTemplateVariableValue[] {
          assetVariableValue, imageWidthVariableValue, imageHeightVariableValue, urlVariableValue,
          targetWindowVariableValue};

      try {
        // Create the template creative on the server.
        Creative[] createdTemplateCreatives = creativeService.createCreatives(
            new Creative[] {templateCreative});

        foreach (Creative createdTemplateCreative in createdTemplateCreatives) {
          Console.WriteLine("A template creative with ID \"{0}\", name \"{1}\", and type " +
              "\"{2}\" was created and can be previewed at {3}", createdTemplateCreative.id,
              createdTemplateCreative.name, createdTemplateCreative.GetType().Name,
              createdTemplateCreative.previewUrl);
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create creatives. 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 CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201505.CreativeService);

      // Set the ID of the advertiser (company) that all creatives will be
      // assigned to.
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_COMPANY_ID_HERE"));

      // Create an array to store local image creative objects.
      Creative[] imageCreatives = new ImageCreative[5];

      for (int i = 0; i < 5; i++) {
        // Create creative size.
        Size size = new Size();
        size.width = 300;
        size.height = 250;

        // Create an image creative.
        ImageCreative imageCreative = new ImageCreative();
        imageCreative.name = string.Format("Image creative #{0}", i);
        imageCreative.advertiserId = advertiserId;
        imageCreative.destinationUrl = "http://www.google.com";
        imageCreative.size = size;

        // Create image asset.
        CreativeAsset creativeAsset = new CreativeAsset();
        creativeAsset.fileName = "image.jpg";
        creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
            "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
        creativeAsset.size = size;
        imageCreative.primaryImageAsset = creativeAsset;

        imageCreatives[i] = imageCreative;
      }

      try {
        // Create the image creatives on the server.
        imageCreatives = creativeService.createCreatives(imageCreatives);

        if (imageCreatives != null) {
          foreach (Creative creative in imageCreatives) {
            // Use "is" operator to determine what type of creative was
            // returned.
            if (creative is ImageCreative) {
              ImageCreative imageCreative = (ImageCreative) creative;
              Console.WriteLine("An image creative with ID ='{0}', name ='{1}' and size = " +
                  "({2},{3}) was created and can be previewed at: {4}", imageCreative.id,
                  imageCreative.name, imageCreative.size.width, imageCreative.size.height,
                  imageCreative.previewUrl);
            } else {
              Console.WriteLine("A creative with ID ='{0}', name='{1}' and type='{2}' was created.",
                  creative.id, creative.name, creative.GetType().Name);
            }
          }
        } else {
          Console.WriteLine("No creatives created.");
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create creatives. Exception says \"{0}\"", e.Message);
      }
    }
    /// <summary>
    /// Run the code examples.
    /// </summary>
    /// <param name="user">The DFP user object running the code examples.</param>
    public override void Run(DfpUser user) {
      // Get the LineItemService.
      LineItemService lineItemService =
          (LineItemService) user.GetService(DfpService.v201505.LineItemService);

      // Set the order that all created line items will belong to and the
      // placement ID to target.
      long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));
      long[] targetPlacementIds = new long[] {long.Parse(_T("INSERT_PLACEMENT_ID_HERE"))};

      // Create inventory targeting.
      InventoryTargeting inventoryTargeting = new InventoryTargeting();
      inventoryTargeting.targetedPlacementIds = targetPlacementIds;

      // Create geographical targeting.
      GeoTargeting geoTargeting = new GeoTargeting();

      // Include the US and Quebec, Canada.
      Location countryLocation = new Location();
      countryLocation.id = 2840L;

      Location regionLocation = new Location();
      regionLocation.id = 20123L;
      geoTargeting.targetedLocations = new Location[] {countryLocation, regionLocation};

      Location postalCodeLocation = new Location();
      postalCodeLocation.id = 9000093;

      // Exclude Chicago and the New York metro area.
      Location cityLocation = new Location();
      cityLocation.id = 1016367L;

      Location metroLocation = new Location();
      metroLocation.id = 200501L;
      geoTargeting.excludedLocations = new Location[] {cityLocation, metroLocation};

      // Exclude domains that are not under the network's control.
      UserDomainTargeting userDomainTargeting = new UserDomainTargeting();
      userDomainTargeting.domains = new String[] {"usa.gov"};
      userDomainTargeting.targeted = false;

      // Create day-part targeting.
      DayPartTargeting dayPartTargeting = new DayPartTargeting();
      dayPartTargeting.timeZone = DeliveryTimeZone.BROWSER;

      // Target only the weekend in the browser's timezone.
      DayPart saturdayDayPart = new DayPart();
      saturdayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201505.DayOfWeek.SATURDAY;

      saturdayDayPart.startTime = new TimeOfDay();
      saturdayDayPart.startTime.hour = 0;
      saturdayDayPart.startTime.minute = MinuteOfHour.ZERO;

      saturdayDayPart.endTime = new TimeOfDay();
      saturdayDayPart.endTime.hour = 24;
      saturdayDayPart.endTime.minute = MinuteOfHour.ZERO;

      DayPart sundayDayPart = new DayPart();
      sundayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201505.DayOfWeek.SUNDAY;

      sundayDayPart.startTime = new TimeOfDay();
      sundayDayPart.startTime.hour = 0;
      sundayDayPart.startTime.minute = MinuteOfHour.ZERO;

      sundayDayPart.endTime = new TimeOfDay();
      sundayDayPart.endTime.hour = 24;
      sundayDayPart.endTime.minute = MinuteOfHour.ZERO;

      dayPartTargeting.dayParts = new DayPart[] {saturdayDayPart, sundayDayPart};


      // Create technology targeting.
      TechnologyTargeting technologyTargeting = new TechnologyTargeting();

      // Create browser targeting.
      BrowserTargeting browserTargeting = new BrowserTargeting();
      browserTargeting.isTargeted = true;

      // Target just the Chrome browser.
      Technology browserTechnology = new Technology();
      browserTechnology.id = 500072L;
      browserTargeting.browsers = new Technology[] {browserTechnology};
      technologyTargeting.browserTargeting = browserTargeting;

      // Create an array to store local line item objects.
      LineItem[] lineItems = new LineItem[5];

      for (int i = 0; i < 5; i++) {
        LineItem lineItem = new LineItem();
        lineItem.name = "Line item #" + i;
        lineItem.orderId = orderId;
        lineItem.targeting = new Targeting();

        lineItem.targeting.inventoryTargeting = inventoryTargeting;
        lineItem.targeting.geoTargeting = geoTargeting;
        lineItem.targeting.userDomainTargeting = userDomainTargeting;
        lineItem.targeting.dayPartTargeting = dayPartTargeting;
        lineItem.targeting.technologyTargeting = technologyTargeting;

        lineItem.lineItemType = LineItemType.STANDARD;
        lineItem.allowOverbook = true;

        // Set the creative rotation type to even.
        lineItem.creativeRotationType = CreativeRotationType.EVEN;

        // Set the size of creatives that can be associated with this line item.
        Size size = new Size();
        size.width = 300;
        size.height = 250;
        size.isAspectRatio = false;

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

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

        // Set the line item to run for one month.
        lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY;
        lineItem.endDateTime =
            DateTimeUtilities.FromDateTime(System.DateTime.Today.AddMonths(1), "America/New_York");

        // Set the cost per unit to $2.
        lineItem.costType = CostType.CPM;
        lineItem.costPerUnit = new Money();
        lineItem.costPerUnit.currencyCode = "USD";
        lineItem.costPerUnit.microAmount = 2000000L;

        // Set the number of units bought to 500,000 so that the budget is
        // $1,000.
        Goal goal = new Goal();
        goal.goalType = GoalType.LIFETIME;
        goal.unitType = UnitType.IMPRESSIONS;
        goal.units = 500000L;
        lineItem.primaryGoal = goal;

        lineItems[i] = lineItem;
      }

      try {
        // Create the line items on the server.
        lineItems = lineItemService.createLineItems(lineItems);

        if (lineItems != null) {
          foreach (LineItem lineItem in lineItems) {
            Console.WriteLine("A line item with ID \"{0}\", belonging to order ID \"{1}\", and" +
                " named \"{2}\" was created.", lineItem.id, lineItem.orderId, lineItem.name);
          }
        } else {
          Console.WriteLine("No line items created.");
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create line items. Exception says \"{0}\"",
            e.Message);
      }
    }