示例#1
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="baseCampaignId">Id of the campaign to use as base of the
        /// draft.</param>
        public void Run(AdWordsUser user, long baseCampaignId)
        {
            // Get the DraftService.
            DraftService draftService = (DraftService)user.GetService(
                AdWordsService.v201603.DraftService);
            Draft draft = new Draft()
            {
                baseCampaignId = baseCampaignId,
                draftName      = "Test Draft #" + ExampleUtilities.GetRandomString()
            };

            DraftOperation draftOperation = new DraftOperation()
            {
                @operator = Operator.ADD,
                operand   = draft
            };

            try {
                draft = draftService.mutate(new DraftOperation[] { draftOperation }).value[0];

                Console.WriteLine("Draft with ID {0}, base campaign ID {1} and draft campaign ID " +
                                  "{2} created.", draft.draftId, draft.baseCampaignId, draft.draftCampaignId);

                // Once the draft is created, you can modify the draft campaign as if it
                // were a real campaign. For example, you may add criteria, adjust bids,
                // or even include additional ads. Adding a criterion is shown here.
                CampaignCriterionService campaignCriterionService =
                    (CampaignCriterionService)user.GetService(
                        AdWordsService.v201603.CampaignCriterionService);

                Language language = new Language()
                {
                    id = 1003L // Spanish
                };

                // Make sure to use the draftCampaignId when modifying the virtual draft
                // campaign.
                CampaignCriterion campaignCriterion = new CampaignCriterion()
                {
                    campaignId = draft.draftCampaignId,
                    criterion  = language
                };

                CampaignCriterionOperation criterionOperation = new CampaignCriterionOperation()
                {
                    @operator = Operator.ADD,
                    operand   = campaignCriterion
                };

                campaignCriterion = campaignCriterionService.mutate(
                    new CampaignCriterionOperation[] { criterionOperation }).value[0];

                Console.WriteLine("Draft updated to include criteria in draft campaign ID {0}.",
                                  draft.draftCampaignId);
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to create draft campaign and add " +
                                                      "criteria.", e);
            }
        }
示例#2
0
        public async Task Daft([FromBody] DraftOperation operation)
        {
            await _repository.Decrement(operation.AccountNumber, operation.Amount);

            await _repository.Decrement(operation.AccountNumber, operation.Rate);

            await _operationRepository.Register(operation);

            Ok();
        }
示例#3
0
        /// <summary>
        /// Creates a test draft for running further tests.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="baseCampaignId">The base campaign ID for the draft.</param>
        /// <returns>The draft.</returns>
        /// <remarks>We are returning the Draft itself, since there's no way to get
        /// the draft campaign ID given a draft ID.</remarks>
        public Draft AddDraft(AdWordsUser user, long baseCampaignId)
        {
            // Get the DraftService.
            DraftService draftService = (DraftService)user.GetService(
                AdWordsService.v201607.DraftService);
            Draft draft = new Draft()
            {
                baseCampaignId = baseCampaignId,
                draftName      = "Test Draft #" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")
            };

            DraftOperation draftOperation = new DraftOperation()
            {
                @operator = Operator.ADD,
                operand   = draft
            };

            return(draftService.mutate(new DraftOperation[] { draftOperation }).value[0]);
        }