/// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            ReportService reportService = (ReportService) user.GetService(
              DfpService.v201403.ReportService);

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

              // Get the root ad unit ID to filter on.
              String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

              // Create statement to filter on an ancestor ad unit with the root ad unit ID to include all
              // ad units in the network.
              StatementBuilder statementBuilder = new StatementBuilder(
              "where AD_UNIT_ANCESTOR_AD_UNIT_ID = :ancestorAdUnitId").
              AddValue("ancestorAdUnitId", long.Parse(rootAdUnitId));

              // Create report query.
              ReportQuery reportQuery = new ReportQuery();
              reportQuery.dimensions =
              new Dimension[] { Dimension.AD_UNIT_ID, Dimension.AD_UNIT_NAME };
              reportQuery.columns = new Column[] {Column.AD_SERVER_IMPRESSIONS,
            Column.AD_SERVER_CLICKS, Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_IMPRESSIONS,
            Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_CLICKS,
            Column.TOTAL_INVENTORY_LEVEL_IMPRESSIONS,
            Column.TOTAL_INVENTORY_LEVEL_CPM_AND_CPC_REVENUE};

              // Set the filter statement.
              reportQuery.statement = statementBuilder.ToStatement();

              reportQuery.adUnitView = ReportQueryAdUnitView.HIERARCHICAL;
              reportQuery.dateRangeType = DateRangeType.LAST_WEEK;

              // Create report job.
              ReportJob reportJob = new ReportJob();
              reportJob.reportQuery = reportQuery;

              try {
            // Run report.
            reportJob = reportService.runReportJob(reportJob);
            // Wait for report to complete.
            while (reportJob.reportJobStatus == ReportJobStatus.IN_PROGRESS) {
              Console.WriteLine("Report job with id = '{0}' is still running.", reportJob.id);
              Thread.Sleep(30000);
              // Get report job.
              reportJob = reportService.getReportJob(reportJob.id);
            }

            if (reportJob.reportJobStatus == ReportJobStatus.COMPLETED) {
              Console.WriteLine("Report job with id = '{0}' completed successfully.", reportJob.id);
            } else if (reportJob.reportJobStatus == ReportJobStatus.FAILED) {
              Console.WriteLine("Report job with id = '{0}' failed to complete successfully.",
              reportJob.id);
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to run inventory report. 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 InventoryService.
              InventoryService inventoryService =
              (InventoryService) user.GetService(DfpService.v201302.InventoryService);

              // Get the NetworkService.
              NetworkService networkService =
              (NetworkService) user.GetService(DfpService.v201302.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 ex) {
            Console.WriteLine("Failed to create ad units. 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 PlacementService.
              PlacementService placementService =
              (PlacementService) user.GetService(DfpService.v201208.PlacementService);

              // Get the InventoryService.
              InventoryService inventoryService =
              (InventoryService) user.GetService(DfpService.v201208.InventoryService);

              // Create a statement to select first 500 placements.
              Statement filterStatement = new Statement();
              filterStatement.query = "LIMIT 500";

              try {
            // Get placements by statement.
            PlacementPage page = placementService.getPlacementsByStatement(filterStatement);

            if (page.results != null) {
              Placement[] placements = page.results;

              // Update each local placement object by enabling AdSense targeting.
              foreach (Placement placement in placements) {
            placement.targetingDescription = (string.IsNullOrEmpty(placement.description))?
                "Generic description" : placement.description;
            placement.targetingAdLocation = "All images on sports pages.";
            placement.targetingSiteName = "http://code.google.com";
            placement.isAdSenseTargetingEnabled = true;
              }

              // Update the placements on the server.
              placements = placementService.updatePlacements(placements);

              // Display results.
              if (placements != null) {
            foreach (Placement placement in placements) {
              Console.WriteLine("A placement with ID \"{0}\", name \"{1}\", and AdSense targeting" +
                  " enabled \"{2}\" was updated.", placement.id, placement.name,
                  placement.isAdSenseTargetingEnabled);
            }
              } else {
            Console.WriteLine("No placements updated.");
              }
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update placements. 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 UserService.
              UserService userService = (UserService) user.GetService(DfpService.v201211.UserService);

              // Sets defaults for page and Statement.
              UserPage page = new UserPage();
              Statement statement = new Statement();
              int offset = 0;

              try {
            do {
              // Create a Statement to get all users.
              statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);

              // Get users by Statement.
              page = userService.getUsersByStatement(statement);

              if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (User usr in page.results) {
              Console.WriteLine("{0}) User with ID = '{1}', email = '{2}', and role = '{3}'" +
                  " was found.", i, usr.id, usr.email, usr.roleName);
              i++;
            }
              }
              offset += 500;
            } while (offset < page.totalResultSetSize);

            Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get all users. 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 PlacementService.
      PlacementService placementService =
          (PlacementService) user.GetService(DfpService.v201211.PlacementService);

      // Create a Statement to only select active placements.
      Statement statement = new StatementBuilder("WHERE status = :status LIMIT 500").AddValue(
          "status", InventoryStatus.ACTIVE.ToString()).ToStatement();

      try {
        // Get placements by Statement.
        PlacementPage page = placementService.getPlacementsByStatement(statement);

        // Display results.
        if (page.results != null && page.results.Length > 0) {
          int i = page.startIndex;
          foreach (Placement placement in page.results) {
            Console.WriteLine("{0}) Placement with ID = '{1}', name ='{2}', and status = '{3}' " +
              "was found.", i, placement.id, placement.name, placement.status);
            i++;
          }
        }

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get placement by Statement. 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 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);
      }
    }
    /// <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 ContactService.
      ContactService contactService =
          (ContactService) user.GetService(DfpService.v201505.ContactService);

      // Set the ID of the contact to update.
      long contactId = long.Parse(_T("INSERT_CONTACT_ID_HERE"));

      try {
        StatementBuilder statementBuilder = new StatementBuilder()
            .Where("id = :id")
            .OrderBy("id ASC")
            .Limit(1)
            .AddValue("id", contactId);

        // Get the contact.
        ContactPage page = contactService.getContactsByStatement(statementBuilder.ToStatement());
        Contact contact = page.results[0];

        // Update the address of the contact.
        contact.address = "123 New Street, New York, NY, 10011";

        // Update the contact on the server.
        Contact[] contacts = contactService.updateContacts(new Contact[] {contact});

        // Display results.
        foreach (Contact updatedContact in contacts) {
          Console.WriteLine("Contact with ID \"{0}\", name \"{1}\", and comment \"{2}\" was " +
              "updated.", updatedContact.id, updatedContact.name, updatedContact.comment);
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to update contacts. 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 NetworkService.
      NetworkService networkService =
          (NetworkService) user.GetService(DfpService.v201308.NetworkService);
      // Set the networkCode field to null to retrieve all networks you have
      // access to.
      networkService.RequestHeader.networkCode = null;

      try {
        // Get all networks that you have access to with the current login
        // credentials.
        Network[] networks = networkService.getAllNetworks();

        int i = 0;
        foreach (Network network in networks) {
         Console.WriteLine("{0} ) Network with network code \"{1}\" and display name \"{2}\" " +
            "was found.", i + 1, network.networkCode, network.displayName);
          i++;
        }
        Console.WriteLine("Number of networks found: {0}", i);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get all networks. 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 LabelService.
              LabelService labelService =
              (LabelService) user.GetService(DfpService.v201208.LabelService);

              // Create a statement to only select labels that are competitive
              // sorted by name.
              Statement filterStatement = new StatementBuilder("WHERE type = :type ORDER BY name LIMIT 500")
              .AddValue("type", LabelType.COMPETITIVE_EXCLUSION.ToString()).ToStatement();

              try {
            // Get labels by statement.
            LabelPage page = labelService.getLabelsByStatement(filterStatement);

            if (page.results != null) {
              int i = page.startIndex;
              foreach (Label label in page.results) {
            StringBuilder builder = new StringBuilder();
            foreach (LabelType labelType in label.types) {
              builder.AppendFormat("{0} | ", labelType);
            }

            Console.WriteLine("{0}) Label with ID '{1}', name '{2}'and type '{3}' was found.",
                i, label.id, label.name, builder.ToString().TrimEnd(' ', '|'));
            i++;
              }
            }
            Console.WriteLine("Number of results found: " + page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get labels. 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 ContentService.
              ContentService contentService =
              (ContentService) user.GetService(DfpService.v201403.ContentService);

              // Set defaults for page and filterStatement.
              ContentPage page = new ContentPage();
              Statement filterStatement = new Statement();
              int offset = 0;

              try {
            do {
              // Create a statement to get all content.
              filterStatement.query = "LIMIT 500 OFFSET " + offset.ToString();

              // Get content by statement.
              page = contentService.getContentByStatement(filterStatement);

              if (page.results != null) {
            int i = page.startIndex;
            foreach (Content content in page.results) {
              Console.WriteLine("{0}) Content with ID \"{1}\", name \"{2}\", and status \"{3}\" " +
                  "was found.", i, content.id, content.name, content.status);
              i++;
            }
              }
              offset += 500;
            } while (offset < page.totalResultSetSize);

            Console.WriteLine("Number of results found: " + page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get all content. 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 TeamService.
      TeamService teamService = (TeamService) user.GetService(DfpService.v201208.TeamService);

      // Create a statement to order teams by name.
      Statement filterStatement = new StatementBuilder("ORDER BY name LIMIT 500").ToStatement();

      try {
      // Get teams by statement.
      TeamPage page = teamService.getTeamsByStatement(filterStatement);

      // Display results.
      if (page.results != null) {
        int i = page.startIndex;
        foreach (Team team in page.results) {
          Console.WriteLine("{0}) Team with ID \"{1}\" and name \"{2}\" was found.",
              i, team.id, team.name);
          i++;
        }
      }

      Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get teams by statement. 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) {
      // Create the CreativeWrapperService.
      CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService(
          DfpService.v201502.CreativeWrapperService);

      long creativeWrapperId = long.Parse(_T("INSERT_CREATIVE_WRAPPER_ID_HERE"));

      try {
        StatementBuilder statementBuilder = new StatementBuilder()
            .Where("id = :id")
            .OrderBy("id ASC")
            .Limit(1)
            .AddValue("id", creativeWrapperId);
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(
            statementBuilder.ToStatement());
        CreativeWrapper wrapper = page.results[0];

        wrapper.ordering = CreativeWrapperOrdering.OUTER;
        // Update the creative wrappers on the server.
        CreativeWrapper[] creativeWrappers = creativeWrapperService.updateCreativeWrappers(
            new CreativeWrapper[] {wrapper});

        // Display results.
        foreach (CreativeWrapper createdCreativeWrapper in creativeWrappers) {
          Console.WriteLine("Creative wrapper with ID '{0}' and wrapping order '{1}' was " +
              "updated.", createdCreativeWrapper.id, createdCreativeWrapper.ordering);
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to update creative wrappers. 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 AudienceSegmentService.
      AudienceSegmentService audienceSegmentService =
          (AudienceSegmentService) user.GetService(DfpService.v201306.AudienceSegmentService);

      // Set defaults for page and Statement.
      AudienceSegmentPage page = new AudienceSegmentPage();
      Statement statement = new Statement();
      int offset = 0;

      try {
        do {
          // Create a Statement to get all creatives.
          statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);

          // Get audience segment by Statement.
          page = audienceSegmentService.getAudienceSegmentsByStatement(statement);

          // Display results.
          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (AudienceSegment segment in page.results) {
              Console.WriteLine("{0}) 'Audience segment with id \"{1}\" and name \"{2}\" was " +
                  "found.", i, segment.id, segment.name);
              i++;
            }
          }

          offset += 500;
        } while (offset < page.totalResultSetSize);
        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get audience segment. 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 UserService.
      UserService userService = (UserService) user.GetService(DfpService.v201403.UserService);

      // Create a Statement to get all active users sorted by name.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("status = :status")
          .OrderBy("name ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("status", "ACTIVE");

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

      try {
        do {
          // Get users by Statement.
          page = userService.getUsersByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (User usr in page.results) {
              Console.WriteLine("{0}) User with ID = '{1}', email = '{2}', and role = '{3}'" +
                " was found.", i, usr.id, usr.email, usr.roleName);
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);
        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get user by ID. 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.v201311.LineItemService);

      // Set the ID of the order to get line items from.
      long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

      // Create a statement to only select line items that need creatives from a
      // given order.
      Statement filterStatement =
          new StatementBuilder("WHERE orderId = :orderId AND status = :status LIMIT 500")
              .AddValue("orderId", orderId)
              .AddValue("status", ComputedStatus.NEEDS_CREATIVES.ToString())
              .ToStatement();

      try {
        // Get line items by Statement.
        LineItemPage page = lineItemService.getLineItemsByStatement(filterStatement);

        if (page.results != null && page.results.Length > 0) {
          int i = page.startIndex;
          foreach (LineItem lineItem in page.results) {
            Console.WriteLine("{0}) Line item with ID ='{1}', belonging to order ID = '{2}' and " +
                 "named '{3}' was found.", i, lineItem.id, lineItem.orderId, lineItem.name);
            i++;
          }
        }
        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get line item by Statement. 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 PlacementService.
              PlacementService placementService =
              (PlacementService) user.GetService(DfpService.v201308.PlacementService);

              // Set the ID of the placement to get.
              long placementId = long.Parse(_T("INSERT_PLACEMENT_ID_HERE"));

              try {
            // Get the placement.
            Placement placement = placementService.getPlacement(placementId);

            if (placement != null) {
              Console.WriteLine("Placement with ID = '{0}', name = '{1}', and status = '{2}' " +
              "was found.", placement.id, placement.name, placement.status);
            } else {
              Console.WriteLine("No placement found for this ID.");
            }

              } catch (Exception ex) {
            Console.WriteLine("Failed to get placement by ID. 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 CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201211.CreativeService);

      // Set defaults for page and Statement.
      CreativePage page = new CreativePage();
      Statement statement = new Statement();
      int offset = 0;

      try {
        do {
          // Create a Statement to get all creatives.
          statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);

          // Get creatives by Statement.
          page = creativeService.getCreativesByStatement(statement);

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Creative creative in page.results) {
              Console.WriteLine("{0}) Creative with ID ='{1}', name ='{2}' and type ='{3}' " +
                  "was found.", i, creative.id, creative.name, creative.CreativeType);
              i++;
            }
          }

          offset += 500;
        } while (offset < page.totalResultSetSize);

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get all creatives. Exception says \"{0}\"", ex.Message);
      }
    }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="dfpUser">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the UserTeamAssociationService.
              UserTeamAssociationService userTeamAssociationService =
              (UserTeamAssociationService) user.GetService(
              DfpService.v201302.UserTeamAssociationService);

              // Set the IDs of the user and team to get the association for.
              long userId = long.Parse(_T("INSERT_USER_ID_HERE"));
              long teamId = long.Parse(_T("INSERT_TEAM_ID_HERE"));

              try {
            // Get the user team association.
            UserTeamAssociation userTeamAssociation = userTeamAssociationService.getUserTeamAssociation(
            teamId, userId);

            if (userTeamAssociation != null) {
              Console.WriteLine("User team association between user with ID \"{0}\" and team with " +
              "ID \"{1}\" was found.", userTeamAssociation.userId, userTeamAssociation.teamId);
            } else {
              Console.WriteLine("No user team association found.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to get user team associations. 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 ActivityService.
      ActivityService activityService =
          (ActivityService) user.GetService(DfpService.v201502.ActivityService);

      int totalResultsCounter = 0;

      try {
        StatementBuilder statementBuilder = new StatementBuilder()
            .OrderBy("id ASC")
            .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

        ActivityPage page = new ActivityPage();

        do {
          // Get activities by statement.
          page = activityService.getActivitiesByStatement(statementBuilder.ToStatement());

          // Display results.
          if (page.results != null) {
            foreach (Activity activity in page.results) {
              Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\" and type \"{3}\" " +
                  "was found.\n", totalResultsCounter, activity.id, activity.name,
                  activity.type);
              totalResultsCounter++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);
        Console.WriteLine("Number of results found: {0}.", totalResultsCounter);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get contacts. 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 TeamService.
      TeamService teamService = (TeamService) user.GetService(DfpService.v201508.TeamService);

      // Create a statement to order teams by name.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("name ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

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

      try {
        do {
          // Get teams by statement.
          page = teamService.getTeamsByStatement(statementBuilder.ToStatement());

          // Display results.
          if (page.results != null) {
            int i = page.startIndex;
            foreach (Team team in page.results) {
              Console.WriteLine("{0}) Team with ID \"{1}\" and name \"{2}\" was found.",
                  i, team.id, team.name);
              i++;
            }
          }

          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while(statementBuilder.GetOffset() < page.totalResultSetSize);
      Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception e) {
        Console.WriteLine("Failed to get teams 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 override void Run(DfpUser user) {
      // Get the InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201408.InventoryService);

      // Create a Statement to get all ad units.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

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

      try {
        do {
          // Get ad units by Statement.
          page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (AdUnit adUnit in page.results) {
              Console.WriteLine("{0}) Ad unit with ID = '{1}', name = '{2}' and status = '{3}' " +
                  "was found.", i, adUnit.id, adUnit.name, adUnit.status);
              i++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get ad unit. 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 ActivityGroupService.
      ActivityGroupService activityGroupService =
          (ActivityGroupService) user.GetService(DfpService.v201505.ActivityGroupService);

      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("status = :status")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("status", ActivityGroupStatus.ACTIVE.ToString());

      // Set default for page.
      ActivityGroupPage page;

      try {
        do {
          // Get contacts by statement.
          page = activityGroupService.getActivityGroupsByStatement(statementBuilder.ToStatement());

          if (page.results != null) {
            int i = page.startIndex;
            foreach (ActivityGroup activityGroup in page.results) {
              Console.WriteLine("{0}) Activity group with ID \"{1}\" and name \"{2}\" was found.",
                  i, activityGroup.id, activityGroup.name);
              i++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception e) {
        Console.WriteLine("Failed to get activity groups. Exception says \"{0}\"", e.Message);
      }
    }
Пример #23
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 TeamService.
      TeamService teamService = (TeamService) user.GetService(DfpService.v201405.TeamService);

      try {
        // Create an array to store local team objects.
        Team[] teams = new Team[5];

        for (int i = 0; i < 5; i++) {
          Team team = new Team();
          team.name = "Team #" + i;
          team.hasAllCompanies = false;
          team.hasAllInventory = false;
          teams[i] = team;
        }

        // Create the teams on the server.
        teams = teamService.createTeams(teams);

        if (teams != null && teams.Length > 0) {
          foreach (Team newTeam in teams) {
            Console.WriteLine("A team with ID \"{0}\", and name \"{1}\" was created.",
                newTeam.id, newTeam.name);
          }
        } else {
          Console.WriteLine("No teams created.");
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to create teams. Exception says \"{0}\"", ex.Message);
      }
    }
Пример #24
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 InventoryService.
              InventoryService inventoryService =
              (InventoryService) user.GetService(DfpService.v201308.InventoryService);

              // Sets defaults for page and statement.
              AdUnitPage page = new AdUnitPage();
              Statement statement = new Statement();
              int offset = 0;

              try {
            do {
              // Create a Statement to get all ad units.
              statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);

              // Get ad units by Statement.
              page = inventoryService.getAdUnitsByStatement(statement);

              if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (AdUnit adUnit in page.results) {
              Console.WriteLine("{0}) Ad unit with ID = '{1}', name = '{2}' and status = '{3}' " +
                  "was found.", i, adUnit.id, adUnit.name, adUnit.status);
              i++;
            }
              }
              offset += 500;
            } while (offset < page.totalResultSetSize);

            Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get ad unit. 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) {
      // Create the CreativeWrapperService.
      CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService(
          DfpService.v201306.CreativeWrapperService);

      long creativeWrapperId = long.Parse(_T("INSERT_CREATIVE_WRAPPER_ID_HERE"));

      try {
        CreativeWrapper wrapper = creativeWrapperService.getCreativeWrapper(creativeWrapperId);
        if (wrapper != null) {
          wrapper.ordering = CreativeWrapperOrdering.OUTER;
          // Update the creative wrappers on the server.
          CreativeWrapper[] creativeWrappers = creativeWrapperService.updateCreativeWrappers(
              new CreativeWrapper[] {wrapper});

          // Display results.
          Console.WriteLine("Creative wrapper with ID '{0}' and wrapping order '{1}' was " +
              "updated.", creativeWrappers[0].id, creativeWrappers[0].ordering);
        } else {
          Console.WriteLine("No creative wrappers found to update.");
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to update creative wrappers. Exception says \"{0}\"",
            ex.Message);
      }
    }
Пример #26
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 OrderService.
      OrderService orderService = (OrderService) user.GetService(DfpService.v201505.OrderService);

      // Create a statement to get all orders.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

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

      try {
        do {
          // Get orders by statement.
          page = orderService.getOrdersByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Order order in page.results) {
              Console.WriteLine("{0}) Order with ID = '{1}', name = '{2}', and advertiser " +
                  "ID = '{3}' was found.", i, order.id, order.name, order.advertiserId);
              i++;
            }
          }

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

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get all orders. 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 CompanyService.
      CompanyService companyService =
          (CompanyService) user.GetService(DfpService.v201508.CompanyService);

      // Create an array to store local company objects.
      Company[] companies = new Company[5];

      for (int i = 0; i < 5; i++) {
        Company company = new Company();
        company.name = string.Format("Advertiser #{0}", i);
        company.type = CompanyType.ADVERTISER;
        companies[i] = company;
      }

      try {
        // Create the companies on the server.
        companies = companyService.createCompanies(companies);

        if (companies != null && companies.Length > 0) {
          foreach (Company company in companies) {
            Console.WriteLine("A company with ID = '{0}', name = '{1}' and type = '{2}' was" +
                " created.", company.id, company.name, company.type);
          }
        } else {
          Console.WriteLine("No companies created.");
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create company. 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 ActivityGroupService.
              ActivityGroupService activityGroupService =
              (ActivityGroupService) user.GetService(DfpService.v201308.ActivityGroupService);

              ActivityGroupPage page;
              Statement filterStatement = new Statement();
              int offset = 0;

              try {
            do {
              filterStatement.query = "ORDER BY id LIMIT 500 OFFSET " + offset.ToString();
              // Get activity groups by statement.
              page = activityGroupService.getActivityGroupsByStatement(filterStatement);

              // Display results.
              if (page.results != null) {
            int i = page.startIndex;

            foreach (ActivityGroup activityGroup in page.results) {
              Console.WriteLine("{0}) Activity group with ID \"{1}\" and name \"{2}\" was " +
                  "found.", i, activityGroup.id, activityGroup.name);
              i++;
            }
              }

              offset += 500;
            } while (offset < page.totalResultSetSize);

            Console.WriteLine("Number of results found: " + page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get activity groups. Exception says \"{0}\"", ex.Message);
              }
        }
Пример #29
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)
        {
            ReportService reportService = (ReportService) user.GetService(
              DfpService.v201308.ReportService);

              // Set the id of the completed report.
              long reportJobId = long.Parse(_T("INSERT_REPORT_JOB_ID_HERE"));
              ExportFormat exportFormat = (ExportFormat) Enum.Parse(typeof(ExportFormat),
              _T("INSERT_EXPORT_FORMAT_HERE"));

              // Set the format of the report (e.g., CSV_DUMP) and download without
              // compression so we can print it.
              ReportDownloadOptions reportDownloadOptions = new ReportDownloadOptions();
              reportDownloadOptions.exportFormat = exportFormat;
              reportDownloadOptions.useGzipCompression = false;

              try {
            // Download report data.
            string downloadUrl = reportService.getReportDownloadUrlWithOptions(reportJobId,
            reportDownloadOptions);
            byte[] rawReport = MediaUtilities.GetAssetDataFromUrl(downloadUrl);
            string reportContents = Encoding.UTF8.GetString(rawReport);

            // Display results.
            Console.WriteLine("Data for report job with id '{0}\':\n{1}", reportJobId, reportContents);
              } catch (Exception ex) {
            Console.WriteLine("Failed to download report. 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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201508.InventoryService);

      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("targetPlatform = :targetPlatform")
          .AddValue("targetPlatform", "WEB");

      try {
        // Get all ad unit sizes.
        AdUnitSize[] adUnitSizes = inventoryService.getAdUnitSizesByStatement(
            statementBuilder.ToStatement());

        // Display results.
        if (adUnitSizes != null) {
          for (int i = 0; i < adUnitSizes.Length; i++) {
            AdUnitSize adUnitSize = adUnitSizes[i];
            Console.WriteLine("{0}) Ad unit size ({1}x{2}) was found.\n", i,
                adUnitSize.size.width, adUnitSize.size.height);
          }
        } else {
          Console.WriteLine("No ad unit sizes found.");
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to get ad unit sizes. Exception says \"{0}\"", e.Message);
      }
    }