本文整理汇总了C#中Lib.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# Lib.GetService方法的具体用法?C# Lib.GetService怎么用?C# Lib.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lib
的用法示例。
在下文中一共展示了Lib.GetService方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(Lib.DfpUser user) {
// Get the ContentMetadataKeyHierarchy service.
ContentMetadataKeyHierarchyService contentMetadataKeyHierarchyService =
(ContentMetadataKeyHierarchyService) user.GetService(
DfpService.v201405.ContentMetadataKeyHierarchyService);
// Set the ID of the content metadata key hierarchy to update.
long contentMetadataKeyHierarchyId =
long.Parse(_T("INSERT_CONTENT_METADATA_KEY_HIERARCHY_ID_HERE"));
// Set the ID of the custom targeting key to be added as a hierarchy level
long customTargetingKeyId = long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE"));
// Create a statement to get content metadata key hierarchies.
StatementBuilder statementBuilder = new StatementBuilder()
.Where("WHERE id = :id")
.OrderBy("id ASC")
.Limit(1)
.AddValue("id", contentMetadataKeyHierarchyId);
try {
ContentMetadataKeyHierarchyPage page = contentMetadataKeyHierarchyService
.getContentMetadataKeyHierarchiesByStatement(statementBuilder.ToStatement());
ContentMetadataKeyHierarchy contentMetadataKeyHierarchy = page.results[0];
// Update the content metadata key hierarchy by adding a hierarchy level.
ContentMetadataKeyHierarchyLevel[] hierarchyLevels = contentMetadataKeyHierarchy
.hierarchyLevels;
ContentMetadataKeyHierarchyLevel hierarchyLevel = new ContentMetadataKeyHierarchyLevel();
hierarchyLevel.customTargetingKeyId = customTargetingKeyId;
hierarchyLevel.hierarchyLevel = hierarchyLevels.Length + 1;
List<ContentMetadataKeyHierarchyLevel> updatedHieratchyLevels =
new List<ContentMetadataKeyHierarchyLevel>();
updatedHieratchyLevels.AddRange(hierarchyLevels);
updatedHieratchyLevels.Add(hierarchyLevel);
contentMetadataKeyHierarchy.hierarchyLevels = updatedHieratchyLevels.ToArray();
// Update the content hierarchy on the server.
ContentMetadataKeyHierarchy[] contentMetadataKeyHierarchies =
contentMetadataKeyHierarchyService.updateContentMetadataKeyHierarchies(
new ContentMetadataKeyHierarchy[] {contentMetadataKeyHierarchy});
foreach (ContentMetadataKeyHierarchy updatedContentMetadataKeyHierarchy in
contentMetadataKeyHierarchies) {
Console.WriteLine("Content metadata key hierarchy with ID \"{0}\", name " +
"\"{1}\" was updated.", updatedContentMetadataKeyHierarchy.id,
updatedContentMetadataKeyHierarchy.name);
}
} catch (Exception ex) {
Console.WriteLine("Failed to update content metadata key hierarchies. Exception " +
"says \"{0}\"", ex.Message);
}
}
示例2: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(Lib.DfpUser user) {
// Get the ContentMetadataKeyHierarchy service.
ContentMetadataKeyHierarchyService contentMetadataKeyHierarchyService =
(ContentMetadataKeyHierarchyService) user.GetService(
DfpService.v201403.ContentMetadataKeyHierarchyService);
// Set the IDs of the custom targeting keys for the hierarchy.
long customTargetingKeyId1 = long.Parse(_T("INSERT_LEVEL_ONE_CUSTOM_TARGETING_KEY_ID_HERE"));
long customTargetingKeyId2 = long.Parse(_T("INSERT_LEVEL_TWO_CUSTOM_TARGETING_KEY_ID_HERE"));
List<ContentMetadataKeyHierarchyLevel> hierarchyLevels =
new List<ContentMetadataKeyHierarchyLevel>();
ContentMetadataKeyHierarchyLevel hierarchyLevel1 = new ContentMetadataKeyHierarchyLevel();
hierarchyLevel1.customTargetingKeyId = customTargetingKeyId1;
hierarchyLevel1.hierarchyLevel = 1;
hierarchyLevels.Add(hierarchyLevel1);
ContentMetadataKeyHierarchyLevel hierarchyLevel2 = new ContentMetadataKeyHierarchyLevel();
hierarchyLevel2.customTargetingKeyId = customTargetingKeyId2;
hierarchyLevel2.hierarchyLevel = 2;
hierarchyLevels.Add(hierarchyLevel2);
ContentMetadataKeyHierarchy contentMetadataKeyHierarchy = new ContentMetadataKeyHierarchy();
contentMetadataKeyHierarchy.name = "Content hierarchy #" + new Random().Next(int.MaxValue);
contentMetadataKeyHierarchy.hierarchyLevels = hierarchyLevels.ToArray();
try {
// Create the content metadata key hierarchy on the server.
ContentMetadataKeyHierarchy[] contentMetadataKeyHierarchies =
contentMetadataKeyHierarchyService.createContentMetadataKeyHierarchies(
new ContentMetadataKeyHierarchy[] {contentMetadataKeyHierarchy});
foreach (ContentMetadataKeyHierarchy createdContentMetadataKeyHierarchy in
contentMetadataKeyHierarchies) {
Console.WriteLine("A content metadata key hierarchy with ID \"{0}\", name " +
"\"{1}\" and {2} levels was created.", createdContentMetadataKeyHierarchy.id,
createdContentMetadataKeyHierarchy.name,
createdContentMetadataKeyHierarchy.hierarchyLevels.Length);
}
} catch (Exception ex) {
Console.WriteLine("Failed to create content metadata key hierarchies. Exception says " +
"\"{0}\"", ex.Message);
}
}
示例3: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(Lib.DfpUser user) {
// Get the ContentMetadataKeyHierarchy service.
ContentMetadataKeyHierarchyService contentMetadataKeyHierarchyService =
(ContentMetadataKeyHierarchyService) user.GetService(
DfpService.v201408.ContentMetadataKeyHierarchyService);
// Set the ID of the content metadata key hierarchy to delete.
long contentMetadataKeyHierarchyId =
long.Parse(_T("INSERT_CONTENT_METADATA_KEY_HIERARCHY_ID_HERE"));
// Create a statement to select a content metadata key hierarchy.
StatementBuilder statementBuilder = new StatementBuilder()
.Where("WHERE id = :id")
.OrderBy("id ASC")
.Limit(1)
.AddValue("id", contentMetadataKeyHierarchyId);
try {
// Get content metadata key hierarchies by statement.
ContentMetadataKeyHierarchyPage page = contentMetadataKeyHierarchyService
.getContentMetadataKeyHierarchiesByStatement(statementBuilder.ToStatement());
ContentMetadataKeyHierarchy contentMetadataKeyHierarchy = page.results[0];
Console.WriteLine("Content metadata key hierarchy with ID \"{0}\" will be deleted.",
contentMetadataKeyHierarchy.id);
statementBuilder.RemoveLimitAndOffset();
// Create action.
Google.Api.Ads.Dfp.v201408.DeleteContentMetadataKeyHierarchies action =
new Google.Api.Ads.Dfp.v201408.DeleteContentMetadataKeyHierarchies();
// Perform action.
UpdateResult result = contentMetadataKeyHierarchyService
.performContentMetadataKeyHierarchyAction(action, statementBuilder.ToStatement());
Console.WriteLine("Number of content metadata key hierarchies deleted: {0}",
result.numChanges);
} catch (Exception ex) {
Console.WriteLine("Failed to delete content metadata key hierarchies. " +
"Exception says \"{0}\"", ex.Message);
}
}
示例4: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(Lib.DfpUser user) {
// Get the ContentMetadataKeyHierarchy service.
ContentMetadataKeyHierarchyService contentMetadataKeyHierarchyService =
(ContentMetadataKeyHierarchyService) user.GetService(
DfpService.v201408.ContentMetadataKeyHierarchyService);
// Create a statement to get all content metadata key hierarchies
StatementBuilder statementBuilder = new StatementBuilder()
.OrderBy("id ASC")
.Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
try {
int totalResultSetSize = 0;
do {
// Get content metadata key hierarchies by statement.
ContentMetadataKeyHierarchyPage page = contentMetadataKeyHierarchyService
.getContentMetadataKeyHierarchiesByStatement(statementBuilder.ToStatement());
if (page.results != null) {
totalResultSetSize = page.totalResultSetSize;
int i = page.startIndex;
foreach (ContentMetadataKeyHierarchy contentMetadataKeyHierarchy in page.results) {
Console.WriteLine("{0}) Content metadata key hierarchy with ID \"{1}\", " +
"and name \"{2}\" was found.", i++, contentMetadataKeyHierarchy.id,
contentMetadataKeyHierarchy.name);
}
}
statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.GetOffset() < totalResultSetSize);
Console.WriteLine("Number of results found: {0}", totalResultSetSize);
} catch (Exception ex) {
Console.WriteLine("Failed to get content metadata key hierarchies. Exception " +
"says \"{0}\"", ex.Message);
}
}