Google.Api.Ads.AdWords.Examples.CSharp.v201306.GetAccountAlerts.Run C# (CSharp) Method

Run() public method

Runs the code example.
public Run ( Google.Api.Ads.AdWords.Lib.AdWordsUser user ) : void
user Google.Api.Ads.AdWords.Lib.AdWordsUser The AdWords user.
return void
        public void Run(AdWordsUser user)
        {
            // Get the AlertService.
              AlertService alertService = (AlertService) user.GetService(
              AdWordsService.v201306.AlertService);

              // Create the selector.
              AlertSelector selector = new AlertSelector();

              // Create the alert query.
              AlertQuery query = new AlertQuery();
              query.filterSpec = FilterSpec.ALL;
              query.clientSpec = ClientSpec.ALL;
              query.triggerTimeSpec = TriggerTimeSpec.ALL_TIME;
              query.severities = new AlertSeverity[] {AlertSeverity.GREEN, AlertSeverity.YELLOW,
              AlertSeverity.RED};

              // Enter all possible values of AlertType to get all alerts. If you are
              // interested only in specific alert types, then you may also do it as
              // follows:
              // query.types = new AlertType[] {AlertType.CAMPAIGN_ENDING,
              //     AlertType.CAMPAIGN_ENDED};
              query.types = (AlertType[]) Enum.GetValues(typeof(AlertType));
              selector.query = query;

              // Set paging for selector.
              selector.paging = new Paging();

              int offset = 0;
              int pageSize = 500;

              AlertPage page = new AlertPage();

              try {
            do {
              // Get account alerts.
              selector.paging.startIndex = offset;
              selector.paging.numberResults = pageSize;

              page = alertService.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = offset;
            foreach (Alert alert in page.entries) {
              Console.WriteLine("{0}) Customer Id is {1:###-###-####}, Alert type is '{2}', " +
                  "Severity is {3}", i + 1, alert.clientCustomerId, alert.alertType,
                  alert.alertSeverity);
              for (int j = 0; j < alert.details.Length; j++) {
                Console.WriteLine("  - Triggered at {0}", alert.details[j].triggerTime);
              }
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of alerts found: {0}", page.totalNumEntries);
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to retrieve alerts.", ex);
              }
        }

Usage Example

 /// <summary>
 /// Main method, to run this code example as a standalone application.
 /// </summary>
 /// <param name="args">The command line arguments.</param>
 public static void Main(string[] args)
 {
     GetAccountAlerts codeExample = new GetAccountAlerts();
       Console.WriteLine(codeExample.Description);
       try {
     codeExample.Run(new AdWordsUser());
       } catch (Exception ex) {
     Console.WriteLine("An exception occurred while running this code example. {0}",
     ExampleUtilities.FormatException(ex));
       }
 }
GetAccountAlerts