/// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to be deleted.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignService.
              CampaignService campaignService = (CampaignService) user.GetService(
              AdWordsService.v201306.CampaignService);

              // Create campaign with DELETED status.
              Campaign campaign = new Campaign();
              campaign.id = campaignId;

              // When deleting a campaign, rename it to avoid name collisions with new
              // campaigns.
              campaign.name = "Deleted Campaign - " + ExampleUtilities.GetRandomString();
              campaign.status = CampaignStatus.DELETED;

              // Create the operation.
              CampaignOperation operation = new CampaignOperation();
              operation.operand = campaign;
              operation.@operator = Operator.SET;

              try {
            // Delete the campaign.
            CampaignReturnValue retVal = campaignService.mutate(new CampaignOperation[] {operation});

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              Campaign deletedCampaign = retVal.value[0];
              Console.WriteLine("Campaign with id = \"{0}\" was renamed to \"{1}\" and deleted.",
              deletedCampaign.id, deletedCampaign.name);
            } else {
              Console.WriteLine("No campaigns were deleted.");
            }
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to delete campaign.", ex);
              }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the CampaignService.
              BudgetService budgetService =
              (BudgetService) user.GetService(AdWordsService.v201306.BudgetService);

              // Get the CampaignService.
              CampaignService campaignService =
              (CampaignService) user.GetService(AdWordsService.v201306.CampaignService);

              // Create the campaign budget.
              Budget budget = new Budget();
              budget.name = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString();
              budget.period = BudgetBudgetPeriod.DAILY;
              budget.deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD;
              budget.amount = new Money();
              budget.amount.microAmount = 500000;

              BudgetOperation budgetOperation = new BudgetOperation();
              budgetOperation.@operator = Operator.ADD;
              budgetOperation.operand = budget;

              try {
            BudgetReturnValue budgetRetval = budgetService.mutate(new BudgetOperation[] {budgetOperation});
            budget = budgetRetval.value[0];
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to add shared budget.", ex);
              }

              List<CampaignOperation> operations = new List<CampaignOperation>();

              for (int i = 0; i < NUM_ITEMS; i++) {
            // Create the campaign.
            Campaign campaign = new Campaign();
            campaign.name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString();
            campaign.status = CampaignStatus.PAUSED;

            BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
            biddingConfig.biddingStrategyType = BiddingStrategyType.MANUAL_CPM;

            // Optional: also provide matching bidding scheme.
            biddingConfig.biddingScheme = new ManualCpmBiddingScheme();

            campaign.biddingStrategyConfiguration = biddingConfig;

            // Set the campaign budget.
            campaign.budget = new Budget();
            campaign.budget.budgetId = budget.budgetId;

            // Set targetContentNetwork true. Other network targeting is not available
            // for Ad Exchange Buyers.
            campaign.networkSetting = new NetworkSetting();
            campaign.networkSetting.targetGoogleSearch = false;
            campaign.networkSetting.targetSearchNetwork = false;
            campaign.networkSetting.targetContentNetwork = true;
            campaign.networkSetting.targetPartnerSearchNetwork = false;

            // Enable campaign for Real-time bidding.
            RealTimeBiddingSetting rtbSetting = new RealTimeBiddingSetting();
            rtbSetting.optIn = true;

            campaign.settings = new Setting[] {rtbSetting};

            // Optional: Set the start date.
            campaign.startDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd");

            // Optional: Set the end date.
            campaign.endDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd");

            // Optional: Set the campaign ad serving optimization status.
            campaign.adServingOptimizationStatus = AdServingOptimizationStatus.ROTATE;

            // Optional: Set the frequency cap.
            FrequencyCap frequencyCap = new FrequencyCap();
            frequencyCap.impressions = 5;
            frequencyCap.level = Level.ADGROUP;
            frequencyCap.timeUnit = TimeUnit.DAY;
            campaign.frequencyCap = frequencyCap;

            // Create the operation.
            CampaignOperation operation = new CampaignOperation();
            operation.@operator = Operator.ADD;
            operation.operand = campaign;

            operations.Add(operation);
              }

              try {
            // Add the campaign.
            CampaignReturnValue retVal = campaignService.mutate(operations.ToArray());

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              foreach (Campaign newCampaign in retVal.value) {
            Console.WriteLine("Campaign with name = '{0}' and id = '{1}' was added.",
                newCampaign.name, newCampaign.id);
              }
            } else {
              Console.WriteLine("No campaigns were added.");
            }
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to add campaigns.", ex);
              }
        }
        /// <summary>
        /// Creates a test campaign for running further tests.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="biddingStrategy">The bidding strategy to be used.</param>
        /// <returns>The campaign id.</returns>
        public long CreateCampaign(AdWordsUser user, BiddingStrategyType strategyType)
        {
            CampaignService campaignService =
              (CampaignService) user.GetService(AdWordsService.v201306.CampaignService);

              BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
              biddingConfig.biddingStrategyType = strategyType;

              CampaignOperation campaignOperation = new CampaignOperation();
              campaignOperation.@operator = Operator.ADD;
              campaignOperation.operand = new Campaign();
              campaignOperation.operand.name =
              string.Format("Campaign {0}", DateTime.Now.ToString("yyyy-M-d H:m:s.ffffff"));
              campaignOperation.operand.status = CampaignStatus.PAUSED;
              campaignOperation.operand.biddingStrategyConfiguration = biddingConfig;
              campaignOperation.operand.budget = new Budget();
              campaignOperation.operand.budget.period = BudgetBudgetPeriod.DAILY;
              campaignOperation.operand.budget.amount = new Money();
              campaignOperation.operand.budget.amount.microAmount = 100000000;
              campaignOperation.operand.budget.deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD;
              KeywordMatchSetting matchSetting = new KeywordMatchSetting();
              matchSetting.optIn = true;
              campaignOperation.operand.settings = new Setting[] {matchSetting};

              CampaignReturnValue retVal =
              campaignService.mutate(new CampaignOperation[] {campaignOperation});
              return retVal.value[0].id;
        }
        /// <summary>
        /// Converts a campaign into enhanced campaign using forward compatibility
        /// map.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="campaignId">The campaign id.</param>
        public void EnhanceCampaign(AdWordsUser user, long campaignId)
        {
            CampaignService campaignService = (CampaignService) user.GetService(
              AdWordsService.v201306.CampaignService);

              // Campaign to be updated with the enhanced value.
              // Note: After setting the enhanced value to true, setting it back to false
              // will generate an ApiError.
              Campaign campaign = new Campaign();
              campaign.id = campaignId;
              campaign.enhanced = true;

              // Create operation.
              CampaignOperation operation = new CampaignOperation();
              operation.@operator = Operator.SET;
              operation.operand = campaign;

              campaignService.mutate(new CampaignOperation[] {operation});
              return;
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to be updated.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignService.
              CampaignService campaignService =
              (CampaignService)user.GetService(AdWordsService.v201306.CampaignService);

              // Create the campaign.
              Campaign campaign = new Campaign();
              campaign.id = campaignId;
              campaign.status = CampaignStatus.PAUSED;

              // Create the operation.
              CampaignOperation operation = new CampaignOperation();
              operation.@operator = Operator.SET;
              operation.operand = campaign;

              try {
            // Update the campaign.
            CampaignReturnValue retVal = campaignService.mutate((new CampaignOperation[] {operation}));

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              Campaign updatedCampaign = retVal.value[0];
              Console.WriteLine("Campaign with name = '{0}' and id = '{1}' was updated.",
              updatedCampaign.name, updatedCampaign.id);
            } else {
              Console.WriteLine("No campaigns were updated.");
            }
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to update campaign.", ex);
              }
        }