/// <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.v201311.UserTeamAssociationService); // Set the user to set to read only access within its teams. long userId = long.Parse(_T("INSERT_USER_ID_HERE")); // Create filter text to select user team associations by the user ID. String statementText = "WHERE userId = :userId LIMIT 500"; Statement filterStatement = new StatementBuilder(statementText). AddValue("userId", userId).ToStatement(); try { // Get user team associations by statement. UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement(filterStatement); if (page.results != null) { UserTeamAssociation[] userTeamAssociations = page.results; // Update each local user team association to read only access. foreach (UserTeamAssociation userTeamAssociation in userTeamAssociations) { userTeamAssociation.overriddenTeamAccessType = TeamAccessType.READ_ONLY; } // Update the user team associations on the server. userTeamAssociations = userTeamAssociationService.updateUserTeamAssociations(userTeamAssociations); if (userTeamAssociations != null) { foreach (UserTeamAssociation userTeamAssociation in userTeamAssociations) { Console.WriteLine("User team association between user with ID \"{0}\" and team " + "with ID \"{1}\" was updated to access type \"{2}\".", userTeamAssociation.userId, userTeamAssociation.teamId, userTeamAssociation.overriddenTeamAccessType); } } else { Console.WriteLine("No user team associations updated."); } } else { Console.WriteLine("No user team associations found to update."); } } catch (Exception ex) { Console.WriteLine("Failed to update 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 UserTeamAssociationService. UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService)user.GetService( DfpService.v201408.UserTeamAssociationService); // Set the user id of the user team association to update. long userId = long.Parse(_T("INSERT_USER_ID_HERE")); // Set the team id of the user team association to update. long teamId = long.Parse(_T("INSERT_TEAM_ID_HERE")); // Create a statement to select the user team association. StatementBuilder statementBuilder = new StatementBuilder() .Where("userId = :userId and teamId = :teamId") .OrderBy("userId ASC, teamId ASC") .Limit(1) .AddValue("userId", userId) .AddValue("teamId", teamId); try { // Get user team associations by statement. UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); UserTeamAssociation userTeamAssociation = page.results[0]; userTeamAssociation.overriddenTeamAccessType = TeamAccessType.READ_ONLY; // Update the user team associations on the server. UserTeamAssociation[] userTeamAssociations = userTeamAssociationService.updateUserTeamAssociations( new UserTeamAssociation[] { userTeamAssociation }); if (userTeamAssociations != null) { foreach (UserTeamAssociation updatedUserTeamAssociation in userTeamAssociations) { Console.WriteLine("User team association between user with ID \"{0}\" and team " + "with ID \"{1}\" was updated to access type \"{2}\".", updatedUserTeamAssociation.userId, updatedUserTeamAssociation.teamId, updatedUserTeamAssociation.overriddenTeamAccessType); } } else { Console.WriteLine("No user team associations updated."); } } catch (Exception ex) { Console.WriteLine("Failed to update 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 UserTeamAssociationService. UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService)user.GetService( DfpService.v201411.UserTeamAssociationService); // Set the ID of the user to fetch all user team associations for. long userId = long.Parse(_T("INSERT_USER_ID_HERE")); // Create statement to select user team associations by the user ID. StatementBuilder statementBuilder = new StatementBuilder() .Where("userId = :userId") .OrderBy("userId ASC, teamId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("userId", userId); // Set default for page. UserTeamAssociationPage page = new UserTeamAssociationPage(); try { do { // Get user team associations by statement. page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); // Display results. 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++; } } 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 user team associations. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> public void Run(DfpUser user, long userId) { UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService)user.GetService( DfpService.v201605.UserTeamAssociationService); // Create a statement to select user team associations. StatementBuilder statementBuilder = new StatementBuilder() .Where("userId = :userId") .OrderBy("userId ASC, teamId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("userId", userId); // Retrieve a small amount of user team associations at a time, paging through // until all user team associations have been retrieved. UserTeamAssociationPage page = new UserTeamAssociationPage(); try { do { page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); if (page.results != null) { // Print out some information for each user team association. int i = page.startIndex; foreach (UserTeamAssociation userTeamAssociation in page.results) { Console.WriteLine("{0}) User team association with user ID \"{1}\" " + "and team ID \"{2}\" was found.", i++, userTeamAssociation.userId, userTeamAssociation.teamId); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of results found: {0}", page.totalResultSetSize); } catch (Exception e) { Console.WriteLine("Failed to get user team associations. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> public void Run(DfpUser dfpUser, long userId) { using (UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService)dfpUser.GetService( DfpService.v201705.UserTeamAssociationService)) { // Create a statement to select user team associations. int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT; StatementBuilder statementBuilder = new StatementBuilder() .Where("userId = :userId") .OrderBy("userId ASC, teamId ASC") .Limit(pageSize) .AddValue("userId", userId); // Retrieve a small amount of user team associations at a time, paging through until all // user team associations have been retrieved. int totalResultSetSize = 0; do { UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); // Print out some information for each user team association. if (page.results != null) { totalResultSetSize = page.totalResultSetSize; int i = page.startIndex; foreach (UserTeamAssociation userTeamAssociation in page.results) { Console.WriteLine( "{0}) User team association with user ID {1} and team ID {2} was found.", i++, userTeamAssociation.userId, userTeamAssociation.teamId ); } } statementBuilder.IncreaseOffsetBy(pageSize); } while (statementBuilder.GetOffset() < totalResultSetSize); Console.WriteLine("Number of results found: {0}", totalResultSetSize); } }
/// <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 UserTeamAssociationService. UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService) user.GetService( DfpService.v201508.UserTeamAssociationService); // Set the ID of the user to fetch all user team associations for. long userId = long.Parse(_T("INSERT_USER_ID_HERE")); // Create statement to select user team associations by the user ID. StatementBuilder statementBuilder = new StatementBuilder() .Where("userId = :userId") .OrderBy("userId ASC, teamId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("userId", userId); // Set default for page. UserTeamAssociationPage page = new UserTeamAssociationPage(); try { do { // Get user team associations by statement. page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); // Display results. 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++; } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while(statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of results found: {0}", page.totalResultSetSize); } catch (Exception e) { Console.WriteLine("Failed to get user team associations. Exception says \"{0}\"", e.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.v201311.UserTeamAssociationService); // Get the UserService. UserService userService = (UserService)user.GetService(DfpService.v201311.UserService); try { // Get the current user. long currentUserId = userService.getCurrentUser().id; // Create filter text to select user team associations by the user ID. String statementText = "WHERE userId = :userId LIMIT 500"; Statement filterStatement = new StatementBuilder(statementText). AddValue("userId", currentUserId).ToStatement(); // Get user team associations by statement. UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement(filterStatement); // Display results. 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++; } } Console.WriteLine("Number of results found: " + 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="dfpUser">The DFP user object running the code example.</param> public void Run(DfpUser dfpUser) { // Get the UserTeamAssociationService. UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService) dfpUser.GetService(DfpService.v201602.UserTeamAssociationService); // Set default for page. UserTeamAssociationPage page = new UserTeamAssociationPage(); // Create a statement to get all user team associations. StatementBuilder statementBuilder = new StatementBuilder() .OrderBy("teamId ASC, userId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT); try { do { // Get user team associations by statement. page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); 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); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of results found: {0}", page.totalResultSetSize); } catch (Exception e) { Console.WriteLine("Failed to get user team associations. Exception says \"{0}\"", e.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.v201405.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> public void Run(AdManagerUser user) { using (UserTeamAssociationService userTeamAssociationService = user.GetService <UserTeamAssociationService>()) { // Create a statement to select user team associations. int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT; StatementBuilder statementBuilder = new StatementBuilder().OrderBy("id ASC").Limit(pageSize); // Retrieve a small amount of user team associations at a time, paging through until // all user team associations have been retrieved. int totalResultSetSize = 0; do { UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); // Print out some information for each user team association. if (page.results != null) { totalResultSetSize = page.totalResultSetSize; int i = page.startIndex; foreach (UserTeamAssociation userTeamAssociation in page.results) { Console.WriteLine( "{0}) User team association with team id {1} and user id {2} " + "was found.", i++, userTeamAssociation.teamId, userTeamAssociation.userId); } } statementBuilder.IncreaseOffsetBy(pageSize); } while (statementBuilder.GetOffset() < totalResultSetSize); Console.WriteLine("Number of results found: {0}", totalResultSetSize); } }
/// <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.v201508.UserTeamAssociationService); // Set default for page. UserTeamAssociationPage page = new UserTeamAssociationPage(); // Create a statement to get all user team associations. StatementBuilder statementBuilder = new StatementBuilder() .OrderBy("teamId ASC, userId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT); try { do { // Get user team associations by statement. page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); 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); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of results found: {0}", page.totalResultSetSize); } catch (Exception e) { Console.WriteLine("Failed to get user team associations. Exception says \"{0}\"", e.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.v201502.UserTeamAssociationService); // Set the user to remove from its teams. long userId = long.Parse(_T("INSERT_USER_ID_HERE")); // Create filter text to select user team associations by the user ID. StatementBuilder statementBuilder = new StatementBuilder() .Where("userId = :userId") .OrderBy("userId ASC, teamId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("userId", userId); // Set default for page. UserTeamAssociationPage page = new UserTeamAssociationPage(); try { do { // Get user team associations by statement. page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); 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}\" will be deleted.", i, userTeamAssociation.userId, userTeamAssociation.teamId); i++; } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of teams that the user will be removed from: " + page.totalResultSetSize); if (page.totalResultSetSize > 0) { // Modify statement for action. statementBuilder.RemoveLimitAndOffset(); // Create action. DeleteUserTeamAssociations action = new DeleteUserTeamAssociations(); // Perform action. UpdateResult result = userTeamAssociationService.performUserTeamAssociationAction(action, statementBuilder.ToStatement()); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of teams that the user was removed from: " + result.numChanges); } else { Console.WriteLine("No user team associations were deleted."); } } } catch (Exception ex) { Console.WriteLine("Failed to delete user team associations. 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.v201508.UserTeamAssociationService); // Set the user to remove from its teams. long userId = long.Parse(_T("INSERT_USER_ID_HERE")); // Create filter text to select user team associations by the user ID. StatementBuilder statementBuilder = new StatementBuilder() .Where("userId = :userId") .OrderBy("userId ASC, teamId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("userId", userId); // Set default for page. UserTeamAssociationPage page = new UserTeamAssociationPage(); try { do { // Get user team associations by statement. page = userTeamAssociationService.getUserTeamAssociationsByStatement( statementBuilder.ToStatement()); 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}\" will be deleted.", i, userTeamAssociation.userId, userTeamAssociation.teamId); i++; } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of teams that the user will be removed from: " + page.totalResultSetSize); if (page.totalResultSetSize > 0) { // Modify statement for action. statementBuilder.RemoveLimitAndOffset(); // Create action. DeleteUserTeamAssociations action = new DeleteUserTeamAssociations(); // Perform action. UpdateResult result = userTeamAssociationService.performUserTeamAssociationAction(action, statementBuilder.ToStatement()); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of teams that the user was removed from: " + result.numChanges); } else { Console.WriteLine("No user team associations were deleted."); } } } catch (Exception e) { Console.WriteLine("Failed to delete user team associations. Exception says \"{0}\"", e.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.v201311.UserTeamAssociationService); // Set the user to remove from its teams. long userId = long.Parse(_T("INSERT_USER_ID_HERE")); // Create filter text to select user team associations by the user ID. String statementText = "WHERE userId = :userId LIMIT 500"; Statement filterStatement = new StatementBuilder("").AddValue("userId", userId). ToStatement(); // Set defaults for page and offset. UserTeamAssociationPage page = new UserTeamAssociationPage(); int offset = 0; try { do { // Create a statement to page through user team associations. filterStatement.query = statementText + " 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}\" will be deleted.", i, userTeamAssociation.userId, userTeamAssociation.teamId); i++; } } offset += 500; } while (offset < page.totalResultSetSize); Console.WriteLine("Number of teams that the user will be removed from: " + page.totalResultSetSize); if (page.totalResultSetSize > 0) { // Modify statement for action. filterStatement.query = "WHERE userId = :userId"; // Create action. DeleteUserTeamAssociations action = new DeleteUserTeamAssociations(); // Perform action. UpdateResult result = userTeamAssociationService.performUserTeamAssociationAction(action, filterStatement); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of teams that the user was removed from: " + result.numChanges); } else { Console.WriteLine("No user team associations were deleted."); } } } catch (Exception ex) { Console.WriteLine("Failed to delete user team associations. Exception says \"{0}\"", ex.Message); } }