/// <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.v201306.OrderService);

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

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

          // Get orders by Statement.
          page = orderService.getOrdersByStatement(statement);

          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++;
            }
          }

          offset += 500;
        } while (page.results != null && page.results.Length == 500);

        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 UserService.
              UserService userService = (UserService) user.GetService(DfpService.v201306.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 InventoryService.
              InventoryService inventoryService =
              (InventoryService) user.GetService(DfpService.v201306.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) {
      // Get the UserService.
      UserService userService = (UserService) user.GetService(DfpService.v201306.UserService);

      // Create a Statement to get all users sorted by name.
      Statement statement = new Statement();
      statement.query = "ORDER BY name LIMIT 500";

      try {
        // Get users by Statement.
        UserPage 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);
          }
        }
        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 SuggestedAdUnitService.
      SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService) user.GetService(
          DfpService.v201306.SuggestedAdUnitService);

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

      try {
        do {
          // Create a statement to get all suggested ad units.
          filterStatement.query = "LIMIT 500 OFFSET " + offset;

          // Get suggested ad units by statement.
          page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(filterStatement);

          if (page.results != null) {
            int i = page.startIndex;
            foreach (SuggestedAdUnit suggestedAdUnit in page.results) {
              Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and number of requests " +
                  "\"{2}\" was found.", i, suggestedAdUnit.id, suggestedAdUnit.numRequests);
              i++;
            }
          }
          offset += 500;
        } while (offset < page.totalResultSetSize);

        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get suggested 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 ActivityGroupService.
              ActivityGroupService activityGroupService =
              (ActivityGroupService) user.GetService(DfpService.v201306.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);
              }
        }
    /// <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.v201306.CompanyService);

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

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

          // Get companies by Statement.
          page = companyService.getCompaniesByStatement(statement);

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

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get companies. Exception says \"{0}\"", ex.Message);
      }
    }
Ejemplo n.º 8
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 ContentService.
      ContentService contentService =
          (ContentService) user.GetService(DfpService.v201306.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.v201306.TeamService);

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

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

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

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

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

              // Get the InventoryService.
              InventoryService inventoryService =
              (InventoryService) user.GetService(DfpService.v201306.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 CustomFieldService.
              CustomFieldService customFieldService = (CustomFieldService) user.GetService(
              DfpService.v201306.CustomFieldService);

              // Sets defaults for page and filter.
              CustomFieldPage page = new CustomFieldPage();
              Statement filterStatement = new Statement();
              int offset = 0;

              try {
            do {
              // Create a statement to get all custom fields.
              filterStatement.query = "LIMIT 500 OFFSET " + offset;

              // Get custom fields by statement.
              page = customFieldService.getCustomFieldsByStatement(filterStatement);

              if (page.results != null) {
            int i = page.startIndex;
            foreach (CustomField customField in page.results) {
              if (customField is DropDownCustomField) {
                List<String> dropDownCustomFieldStrings = new List<String>();
                DropDownCustomField dropDownCustomField = (DropDownCustomField) customField;
                if (dropDownCustomField.options != null) {
                  foreach (CustomFieldOption customFieldOption in dropDownCustomField.options) {
                    dropDownCustomFieldStrings.Add(customFieldOption.displayName);
                  }
                }
                Console.WriteLine("{0}) Drop-down custom field with ID \"{1}\", name \"{2}\", " +
                    "and options {{{3}}} was found.", i, customField.id, customField.name,
                    string.Join(", ", dropDownCustomFieldStrings.ToArray()));
              } else {
                Console.WriteLine("{0}) Custom field with ID \"{1}\" and  name \"{2}\" was found.",
                    i, customField.id, customField.name);
              }
              i++;
            }
              }

              offset += 500;
            } while (page.results != null && page.results.Length == 500);

            Console.WriteLine("Number of results found: " + page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get all custom fields. Exception says \"{0}\"", ex.Message);
              }
        }
Ejemplo n.º 13
0
    public User GetUserByEmail(DfpUser user, string email) {
      UserService userService = (UserService) user.GetService(DfpService.v201306.UserService);

      // Create a Statement to get all users sorted by name.
      Statement statement = new Statement();
      statement.query = string.Format("where email = '{0}' LIMIT 1", email);

      UserPage page = userService.getUsersByStatement(statement);

      if (page.results != null && page.results.Length > 0) {
        return page.results[0];
      } else {
        return null;
      }
    }
        /// <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.
              CustomTargetingService customTargetingService =
              (CustomTargetingService) user.GetService(DfpService.v201306.CustomTargetingService);

              // Create a statement to get all custom targeting keys.
              Statement filterStatement = new Statement();
              filterStatement.query = "LIMIT 500";

              try {
            // Get custom targeting keys by statement.
            CustomTargetingKeyPage page =
            customTargetingService.getCustomTargetingKeysByStatement(filterStatement);

            if (page.results != null) {
              CustomTargetingKey[] customTargetingKeys = page.results;

              // Update each local custom targeting key object by changing its display
              // name.
              foreach (CustomTargetingKey customTargetingKey in customTargetingKeys) {
            if (customTargetingKey.displayName == null) {
              customTargetingKey.displayName = customTargetingKey.name;
            }
            customTargetingKey.displayName = customTargetingKey.displayName + " (Deprecated)";
              }

              // Update the custom targeting keys on the server.
              customTargetingKeys =
              customTargetingService.updateCustomTargetingKeys(customTargetingKeys);

              if (customTargetingKeys != null) {
            foreach (CustomTargetingKey customTargetingKey in customTargetingKeys) {
              Console.WriteLine("Custom targeting key with ID \"{0}\", name \"{1}\", and " +
                  "display name \"{2}\" was updated.", customTargetingKey.id,
                  customTargetingKey.name, customTargetingKey.displayName);
            }
              } else {
            Console.WriteLine("No custom targeting keys updated.");
              }
            } else {
              Console.WriteLine("No custom targeting keys found to update.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update display name of custom targeting keys. Exception " +
            "says \"{0}\"", ex.Message);
              }
        }
 private static bool StatementsAreEqual(Statement s1, Statement s2) {
   // Assumes both Statements are non-null and have non-null properties
   if (String.Compare(s1.query, s2.query, true) != 0) {
     return false;
   }
   if (s1.values.Length != s2.values.Length) {
     return false;
   }
   // Assumes Statement values are in the same order
   for (int i = 0; i < s1.values.Length; i++) {
     if (!StringValueMapEntriesAreEqual(s1.values[i], s2.values[i])) {
       return false;
     }
   }
   return true;
 }
        /// <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.v201306.OrderService);

              // Create a Statement to get all orders.
              Statement statement = new Statement();
              statement.query = "LIMIT 500";

              try {
            // Get orders by Statement.
            OrderPage page = orderService.getOrdersByStatement(statement);

            if (page.results != null && page.results.Length > 0) {
              Order[] orders = page.results;
              List<Order> ordersToUpdate = new List<Order>();

              // Update each local order object by changing its notes.
              foreach (Order order in orders) {
            if (!order.isArchived) {
              order.notes = "Spoke to advertiser. All is well.";
              ordersToUpdate.Add(order);
            }
              }

              // Update the orders on the server.
              orders = orderService.updateOrders(ordersToUpdate.ToArray());

              if (orders != null) {
            foreach (Order order in orders) {
              Console.WriteLine("Order with ID = '{0}', name = '{1}', advertiser ID = '{2}', " +
                  "and notes = '{3}' was updated.", order.id, order.name, order.advertiserId,
                  order.notes);
            }
              } else {
            Console.WriteLine("No orders updated.");
              }
            } else {
              Console.WriteLine("No orders found to update.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update orders. Exception says \"{0}\"",
            ex.Message);
              }
        }
Ejemplo n.º 17
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 LineItemCreativeAssociationService.
              LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService)
              user.GetService(DfpService.v201306.LineItemCreativeAssociationService);

              // Create a Statement to get all LICAs.
              Statement statement = new Statement();
              statement.query = "LIMIT 500";

              try {
            // Get LICAs by Statement.
            LineItemCreativeAssociationPage page =
            licaService.getLineItemCreativeAssociationsByStatement(statement);

            if (page.results != null && page.results.Length > 0) {
              LineItemCreativeAssociation[] licas = page.results;

              // Update each local LICA object by changing its destination URL.
              foreach (LineItemCreativeAssociation lica in licas) {
            lica.destinationUrl = "http://news.google.com";
              }

              // Update the LICAs on the server.
              licas = licaService.updateLineItemCreativeAssociations(licas);

              if (licas != null) {
            foreach (LineItemCreativeAssociation lica in licas) {
              Console.WriteLine("LICA with line item ID = '{0}, creative ID ='{1}' and " +
                  "destination URL '{2}' was updated.", lica.lineItemId, lica.creativeId,
                  lica.destinationUrl);
            }
              } else {
            Console.WriteLine("No LICAs updated.");
              }
            } else {
              Console.WriteLine("No LICAs found to update.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update LICAs. Exception says \"{0}\"", ex.Message);
              }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="dfpUser">The DFP user object running the code example.</param>
        public override void Run(DfpUser dfpUser)
        {
            // Get the UserService.
              UserService userService = (UserService) dfpUser.GetService(DfpService.v201306.UserService);

              // Create a Statement to get all users.
              Statement statement = new Statement();
              statement.query = "LIMIT 500";

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

            if (page.results != null && page.results.Length > 0) {
              User[] users = page.results;

              // Update each local users object by changing its name.
              foreach (User user in users) {
            user.name = user.name + " Sr.";
              }

              // Update the users on the server.
              users = userService.updateUsers(users);

              if (users != null) {
            foreach (User user in users) {
              Console.WriteLine("A user with ID = '{0}', name ='{1}', and role = '{2}'" +
                  " was updated.", user.id, user.name, user.roleName);
            }
              } else {
            Console.WriteLine("No users updated.");
              }
            } else {
              Console.WriteLine("No users found to update.");
            }
              } 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 LabelService.
              LabelService labelService =
              (LabelService) user.GetService(DfpService.v201306.LabelService);

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

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

              // Get labels by statement.
              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++;
            }
              }
              offset += 500;
            } while (offset < page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get labels. 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 dfpUser)
        {
            // Get the UserTeamAssociationService.
              UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService)
              dfpUser.GetService(DfpService.v201306.UserTeamAssociationService);

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

              try {
            do {
              // Create a statement to get all user team associations.
              filterStatement.query = "LIMIT 500 OFFSET " + offset;

              // Get user team associations by statement.
              page = userTeamAssociationService.getUserTeamAssociationsByStatement(filterStatement);

              if (page.results != null) {
            int i = page.startIndex;
            foreach (UserTeamAssociation userTeamAssociation in page.results) {
              Console.WriteLine("{0}) User team association between user with ID \"{1}\" and " +
                  "team with ID \"{2}\" was found.", i, userTeamAssociation.userId,
                  userTeamAssociation.teamId);
              i++;
            }
              }

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

            Console.WriteLine("Number of results found: {0}." + page.totalResultSetSize);
              } 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 PlacementService.
              PlacementService placementService =
              (PlacementService) user.GetService(DfpService.v201306.PlacementService);

              // Sets defaults for page and Statement.
              PlacementPage page = new PlacementPage();
              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 = placementService.getPlacementsByStatement(statement);

              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}' and name = '{2}' was found.",
                  i, placement.id, placement.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 all 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)
        {
            // Create the CreativeWrapperService.
              CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService(
              DfpService.v201306.CreativeWrapperService);

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

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

              // Get creative wrappers by Statement.
              page = creativeWrapperService.getCreativeWrappersByStatement(statement);

              if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (CreativeWrapper wrapper in page.results) {
              Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " +
                "status \'{2}\' was found.", wrapper.id, wrapper.labelId, wrapper.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 active creative wrappers. Exception says \"{0}\"",
            ex.Message);
              }
        }
Ejemplo n.º 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 LineItemCreativeAssociationService.
              LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService)
              user.GetService(DfpService.v201306.LineItemCreativeAssociationService);

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

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

              // Get LICAs by Statement.
              page = licaService.getLineItemCreativeAssociationsByStatement(statement);

              if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (LineItemCreativeAssociation lica in page.results) {
              Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " +
                  "status ='{3}' was found.", i, lica.lineItemId, lica.creativeId,
                  lica.status);
              i++;
            }
              }

              offset += 500;
            } while (page.results != null && page.results.Length == 500);

            Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get all LICAs. Exception says \"{0}\"", ex.Message);
              }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Run the sample code.
        /// </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.v201306.InventoryService);

              // Create a statement to get all ad units.
              Statement statement = new Statement();
              statement.query = "LIMIT 500";

              try {
            // Get ad units by statement.
            AdUnitPage page = inventoryService.getAdUnitsByStatement(statement);

            if (page.results != null) {
              // Update each local ad unit object by enabling AdSense.
              foreach (AdUnit adUnit in page.results) {
            adUnit.inheritedAdSenseSettings.value.adSenseEnabled = true;
              }

              // Update the ad units on the server.
              AdUnit[] updatedAdUnits = inventoryService.updateAdUnits(page.results);

              if (updatedAdUnits != null) {
            foreach (AdUnit adUnit in updatedAdUnits) {
              Console.WriteLine("Ad unit with ID \"{0}\", name \"{1}\", and is AdSense enabled " +
                  "\"{2}\" was updated.", adUnit.id, adUnit.name,
                  adUnit.inheritedAdSenseSettings.value.adSenseEnabled);
            }
              } else {
            Console.WriteLine("No ad units updated.");
              }
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to update 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 LineItemService.
              LineItemService lineItemService =
              (LineItemService) user.GetService(DfpService.v201306.LineItemService);

              // Sets defaults for page and Statement.
              LineItemPage page = new LineItemPage();
              Statement statement = new Statement();
              int offset = 0;
              try {
            do {
              // Create a Statement to get all line items.
              statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);

              // Get line items by Statement.
              page = lineItemService.getLineItemsByStatement(statement);

              if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (LineItemSummary 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++;
            }
              }

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

            Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get line items. Exception says \"{0}\"",
            ex.Message);
              }
        }
Ejemplo n.º 26
0
    public AdUnit FindRootAdUnit(DfpUser user) {
      // Get InventoryService.
      InventoryService inventoryService =
          (InventoryService)user.GetService(DfpService.v201306.InventoryService);

      // Create a Statement to only select the root ad unit.
      Statement statement = new Statement();
      statement.query = "WHERE parentId IS NULL LIMIT 500";

      // Get ad units by Statement.
      AdUnitPage page = inventoryService.getAdUnitsByStatement(statement);
      return page.results[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.v201306.InventoryService);

      // Get the PlacementService.
      PlacementService placementService =
          (PlacementService) user.GetService(DfpService.v201306.PlacementService);

      // Create local placement object to store skyscraper ad units.
      Placement skyscraperAdUnitPlacement = new Placement();
      skyscraperAdUnitPlacement.name = string.Format("Skyscraper AdUnit Placement #{0}",
          this.GetTimeStamp());
      skyscraperAdUnitPlacement.description = "Contains ad units that can hold creatives " +
          "of size 120x600";

      // Create local placement object to store medium square ad units.
      Placement mediumSquareAdUnitPlacement = new Placement();
      mediumSquareAdUnitPlacement.name = string.Format("Medium Square AdUnit Placement #{0}",
          this.GetTimeStamp());
      mediumSquareAdUnitPlacement.description = "Contains ad units that can hold creatives " +
          "of size 300x250";

      // Create local placement object to store banner ad units.
      Placement bannerAdUnitPlacement = new Placement();
      bannerAdUnitPlacement.name = string.Format("Banner AdUnit Placement #{0}",
          this.GetTimeStamp());
      bannerAdUnitPlacement.description = "Contains ad units that can hold creatives " +
          "of size 468x60";

      List<Placement> placementList = new List<Placement>();

      // Get the first 500 ad units.
      Statement statement = new Statement();
      statement.query = "LIMIT 500";

      List<string> mediumSquareTargetedUnitIds = new List<string>();
      List<string> skyscraperTargetedUnitIds = new List<string>();
      List<string> bannerTargetedUnitIds = new List<string>();

      try {
        AdUnitPage page = inventoryService.getAdUnitsByStatement(statement);

        // Separate the ad units by size.
        if (page.results != null) {
          foreach (AdUnit adUnit in page.results) {
            if (adUnit.parentId != null && adUnit.adUnitSizes != null) {
              foreach (AdUnitSize adUnitSize in adUnit.adUnitSizes) {
                Size size = adUnitSize.size;
                if (size.width == 300 && size.height == 250) {
                  if (!mediumSquareTargetedUnitIds.Contains(adUnit.id)) {
                    mediumSquareTargetedUnitIds.Add(adUnit.id);
                  }
                } else if (size.width == 120 && size.height == 600) {
                  if (!skyscraperTargetedUnitIds.Contains(adUnit.id)) {
                    skyscraperTargetedUnitIds.Add(adUnit.id);
                  }
                } else if (size.width == 468 && size.height == 60) {
                  if (!bannerTargetedUnitIds.Contains(adUnit.id)) {
                    bannerTargetedUnitIds.Add(adUnit.id);
                  }
                }
              }
            }
          }
        }
        mediumSquareAdUnitPlacement.targetedAdUnitIds = mediumSquareTargetedUnitIds.ToArray();
        skyscraperAdUnitPlacement.targetedAdUnitIds = skyscraperTargetedUnitIds.ToArray();
        bannerAdUnitPlacement.targetedAdUnitIds = bannerTargetedUnitIds.ToArray();


        // Only create placements with one or more ad unit.
        if (mediumSquareAdUnitPlacement.targetedAdUnitIds.Length != 0) {
          placementList.Add(mediumSquareAdUnitPlacement);
        }

        if (skyscraperAdUnitPlacement.targetedAdUnitIds.Length != 0) {
          placementList.Add(skyscraperAdUnitPlacement);
        }

        if (bannerAdUnitPlacement.targetedAdUnitIds.Length != 0) {
          placementList.Add(bannerAdUnitPlacement);
        }

        Placement[] placements =
          placementService.createPlacements(placementList.ToArray());

        // Display results.
        if (placements != null) {
          foreach (Placement placement in placements) {
            Console.Write("A placement with ID = '{0}', name ='{1}', and containing " +
                "ad units {{", placement.id, placement.name);

            foreach (string adUnitId in placement.targetedAdUnitIds) {
              Console.Write("{0}, ", adUnitId);
            }
            Console.WriteLine("} was created.");
          }
        } else {
          Console.WriteLine("No placements created.");
        }

      } catch (Exception ex) {
        Console.WriteLine("Failed to create placements. Exception says \"{0}\"",
            ex.Message);
      }
    }
    /// <summary>
    /// Get the list of all activity group ids.
    /// </summary>
    /// <param name="user">The DfpUser.</param>
    /// <returns>A list of ids for all the activity groups.</returns>
    private long[] getAllActivityGroupIds(DfpUser user) {
      List<long> activityGroupIds = new List<long>();

      // Get the ActivityGroupService.
      ActivityGroupService activityGroupService =
          (ActivityGroupService) user.GetService(DfpService.v201306.ActivityGroupService);

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

      do {
        // Create a statement to get all activity groups.
        filterStatement.query = "ORDER BY id LIMIT 500 OFFSET " + offset.ToString();

        // Get activity groups by statement.
        page = activityGroupService.getActivityGroupsByStatement(filterStatement);
        if (page.results != null) {
          foreach (ActivityGroup activityGroup in page.results) {
            activityGroupIds.Add(activityGroup.id);
          }
        }

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

      return activityGroupIds.ToArray();
    }
Ejemplo n.º 29
0
 public virtual ContactPage getContactsByStatement(Statement statement)
 {
     object[] results = this.Invoke("getContactsByStatement", new object[] { statement });
       return ((ContactPage) (results[0]));
 }
Ejemplo n.º 30
0
 public virtual CompanyPage getCompaniesByStatement(Statement filterStatement)
 {
     object[] results = this.Invoke("getCompaniesByStatement", new object[] { filterStatement });
       return ((CompanyPage) (results[0]));
 }