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

Run() public method

Runs the code example.
public Run ( Google.Api.Ads.AdWords.Lib.AdWordsUser user, long experimentId ) : void
user Google.Api.Ads.AdWords.Lib.AdWordsUser The AdWords user.
experimentId long Id of the experiment to be promoted.
return void
        public void Run(AdWordsUser user, long experimentId)
        {
            // Get the ExperimentService.
              ExperimentService experimentService =
              (ExperimentService) user.GetService(AdWordsService.v201306.ExperimentService);

              // Set experiment's status to PROMOTED.
              Experiment experiment = new Experiment();
              experiment.id = experimentId;
              experiment.status = ExperimentStatus.PROMOTED;

              // Create the operation.
              ExperimentOperation operation = new ExperimentOperation();
              operation.@operator = Operator.SET;
              operation.operand = experiment;

              try {
            // Update the experiment.
            ExperimentReturnValue retVal = experimentService.mutate(
            new ExperimentOperation[] {operation});

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              Experiment promotedExperiment = retVal.value[0];
              Console.WriteLine("Experiment with name = \"{0}\" and id = \"{1}\" was promoted.\n",
              promotedExperiment.name, promotedExperiment.id);
            } else {
              Console.WriteLine("No experiments were promoted.");
            }
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to promote experiment.", 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)
 {
     PromoteExperiment codeExample = new PromoteExperiment();
       Console.WriteLine(codeExample.Description);
       try {
     long experimentId = long.Parse("INSERT_EXPERIMENT_ID_HERE");
     codeExample.Run(new AdWordsUser(), experimentId);
       } catch (Exception ex) {
     Console.WriteLine("An exception occurred while running this code example. {0}",
     ExampleUtilities.FormatException(ex));
       }
 }
PromoteExperiment