internal void RunCalls() { AdClients adClients = GetAllAdClients(); // Get a host ad client ID, so we can run the rest of the samples. // Make sure it's a host ad client. AdClient exampleAdClient = FindAdClientForHost(adClients.Items); if (exampleAdClient != null) { // Custom Channels: List, Add, Update, Delete CustomChannels hostCustomChannels = GetAllCustomChannels(exampleAdClient.Id); CustomChannel newCustomChannel = AddCustomChannel(exampleAdClient.Id); newCustomChannel = UpdateCustomChannel(exampleAdClient.Id, newCustomChannel.Id); DeleteCustomChannel(exampleAdClient.Id, newCustomChannel.Id); // URL Channels: List, Add, Delete GetAllUrlChannels(exampleAdClient.Id); UrlChannel newUrlChannel = AddUrlChannel(exampleAdClient.Id); DeleteUrlChannel(exampleAdClient.Id, newUrlChannel.Id); GenerateReport(service, exampleAdClient.Id); } else { Console.WriteLine("No host ad clients found, unable to run remaining host samples."); } }
public void OverWrite(CustomChannels newObj) { using (var session = Store.OpenSession()) { session.Store(newObj, $"{newObj.GuildId}-Channels"); session.SaveChanges(); } }
/// <summary>Displays all custom channels an ad unit has been added to.</summary> /// <param name="adClientId">The ID for the ad client to be used.</param> /// <param name="adUnitId">The ID for the ad unit to be used.</param> private void DisplayAllCustomChannelsForAdUnit(string adClientId, string adUnitId) { Console.WriteLine("================================================================="); Console.WriteLine("Listing all custom channels for ad unit {0}", adUnitId); Console.WriteLine("================================================================="); // Retrieve custom channel list in pages and display data as we receive it. string pageToken = null; CustomChannels customChannelResponse = null; do { var customChannelRequest = service.Accounts.Adunits.Customchannels.List( adSenseAccount.Id, adClientId, adUnitId); customChannelRequest.MaxResults = maxListPageSize; customChannelRequest.PageToken = pageToken; customChannelResponse = customChannelRequest.Execute(); if (!customChannelResponse.Items.IsNullOrEmpty()) { foreach (var customChannel in customChannelResponse.Items) { Console.WriteLine( "Custom channel with code \"{0}\" and name \"{1}\" was found.", customChannel.Code, customChannel.Name); } } else { Console.WriteLine("No custom channels found."); } pageToken = customChannelResponse.NextPageToken; }while (pageToken != null); Console.WriteLine(); }
/// <summary> /// Gets and prints all custom channels in an ad client. /// </summary> /// <param name="adClientId">The ID for the ad client to be used.</param> /// <returns>The last page of custom channels.</returns> private CustomChannels GetAllCustomChannels(string adClientId) { Console.WriteLine("================================================================="); Console.WriteLine("Listing all custom channels for ad client {0}", adClientId); Console.WriteLine("================================================================="); // Retrieve custom channel list in pages and display data as we receive it. string pageToken = null; CustomChannels customChannelResponse = null; do { var customChannelRequest = service.Accounts.Customchannels.List(adSenseAccount.Id, adClientId); customChannelRequest.MaxResults = maxListPageSize; customChannelRequest.PageToken = pageToken; customChannelResponse = customChannelRequest.Execute(); if (!customChannelResponse.Items.IsNullOrEmpty()) { foreach (var customChannel in customChannelResponse.Items) { Console.WriteLine( "Custom channel with code \"{0}\" and name \"{1}\" was found.", customChannel.Code, customChannel.Name); } } else { Console.WriteLine("No custom channels found."); } pageToken = customChannelResponse.NextPageToken; }while (pageToken != null); Console.WriteLine(); // Return the last page of custom channels, so that the main sample has something to run. return(customChannelResponse); }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="adClientId">The ID for the ad client to be used.</param> /// <param name="maxPageSize">The maximum page size to retrieve.</param> /// <returns>The last page of custom channels.</returns> public static CustomChannels Run(AdsenseService adsense, string adClientId, int maxPageSize) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Listing all custom channels for ad client {0}", adClientId); CommandLine.WriteLine("================================================================="); // Retrieve custom channel list in pages and display data as we receive it. string pageToken = null; CustomChannels customChannelResponse = null; do { var customChannelRequest = adsense.Customchannels.List(adClientId); customChannelRequest.MaxResults = maxPageSize; customChannelRequest.PageToken = pageToken; customChannelResponse = customChannelRequest.Fetch(); if (customChannelResponse.Items != null && customChannelResponse.Items.Count > 0) { foreach (var customChannel in customChannelResponse.Items) { CommandLine.WriteLine("Custom channel with code \"{0}\" and name \"{1}\" was found.", customChannel.Code, customChannel.Name); } } else { CommandLine.WriteLine("No custom channels found."); } pageToken = customChannelResponse.NextPageToken; } while (pageToken != null); CommandLine.WriteLine(); // Return the last page of custom channels, so that the main sample has something to run. return(customChannelResponse); }