/** Links the assets to a campaign. */

        /// <summary>
        /// Links the sitelinks to campaign.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="campaignId">ID of the campaign to which sitelinks are added.
        /// </param>
        /// <param name="sitelinkAssetResourceNames">The sitelink asset resource names.</param>
        private void LinkSitelinksToCampaign(GoogleAdsClient client, long customerId,
                                             long campaignId, List <string> sitelinkAssetResourceNames)
        {
            CampaignAssetServiceClient campaignAssetService = client.GetService(
                Services.V10.CampaignAssetService);

            string campaignResourceName = ResourceNames.Campaign(customerId, campaignId);

            // Creates operations.
            List <CampaignAssetOperation> campaignAssetOperations =
                sitelinkAssetResourceNames.Select(resourceName =>
                                                  new CampaignAssetOperation()
            {
                // Creates CampaignAsset representing the association between sitelinks
                // and campaign.
                Create = new CampaignAsset()
                {
                    Asset     = resourceName,
                    Campaign  = campaignResourceName,
                    FieldType = AssetFieldType.Sitelink
                }
            }).ToList();

            // Sends the mutate request.
            MutateCampaignAssetsResponse response = campaignAssetService.MutateCampaignAssets(
                customerId.ToString(), campaignAssetOperations);

            // Prints some information about the result.
            foreach (MutateCampaignAssetResult result in response.Results)
            {
                Console.WriteLine($"Linked sitelink to campaign with resource " +
                                  $"name '{result.ResourceName}'.");
            }
        }
        /// <summary>
        /// Creates the lead form extension.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="campaignId">
        /// ID of the campaign to which lead form extensions are added.
        /// </param>
        /// <param name="leadFormAssetResourceName">The lead form asset resource name.</param>
        // [START add_lead_form_extension_1]
        private void CreateLeadFormExtension(GoogleAdsClient client, long customerId,
                                             long campaignId, string leadFormAssetResourceName)
        {
            CampaignAssetServiceClient campaignAssetService = client.GetService(
                Services.V10.CampaignAssetService);

            // Creates the campaign asset for the lead form.
            CampaignAsset campaignAsset = new CampaignAsset()
            {
                Asset     = leadFormAssetResourceName,
                FieldType = AssetFieldTypeEnum.Types.AssetFieldType.LeadForm,
                Campaign  = ResourceNames.Campaign(customerId, campaignId),
            };

            CampaignAssetOperation operation = new CampaignAssetOperation()
            {
                Create = campaignAsset
            };

            MutateCampaignAssetsResponse response = campaignAssetService.MutateCampaignAssets(
                customerId.ToString(), new[] { operation });

            foreach (MutateCampaignAssetResult result in response.Results)
            {
                Console.WriteLine("Created campaign asset with resource name =" +
                                  $" '{result.ResourceName}' for campaign ID {campaignId}.");
            }
        }
        public async stt::Task MutateCampaignAssetsAsync()
        {
            moq::Mock <CampaignAssetService.CampaignAssetServiceClient> mockGrpcClient = new moq::Mock <CampaignAssetService.CampaignAssetServiceClient>(moq::MockBehavior.Strict);
            MutateCampaignAssetsRequest request = new MutateCampaignAssetsRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new CampaignAssetOperation(),
                },
            };
            MutateCampaignAssetsResponse expectedResponse = new MutateCampaignAssetsResponse
            {
                PartialFailureError = new gr::Status(),
                Results             =
                {
                    new MutateCampaignAssetResult(),
                },
            };

            mockGrpcClient.Setup(x => x.MutateCampaignAssetsAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <MutateCampaignAssetsResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            CampaignAssetServiceClient   client = new CampaignAssetServiceClientImpl(mockGrpcClient.Object, null);
            MutateCampaignAssetsResponse responseCallSettings = await client.MutateCampaignAssetsAsync(request.CustomerId, request.Operations, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            MutateCampaignAssetsResponse responseCancellationToken = await client.MutateCampaignAssetsAsync(request.CustomerId, request.Operations, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public void MutateCampaignAssets()
        {
            moq::Mock <CampaignAssetService.CampaignAssetServiceClient> mockGrpcClient = new moq::Mock <CampaignAssetService.CampaignAssetServiceClient>(moq::MockBehavior.Strict);
            MutateCampaignAssetsRequest request = new MutateCampaignAssetsRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new CampaignAssetOperation(),
                },
            };
            MutateCampaignAssetsResponse expectedResponse = new MutateCampaignAssetsResponse
            {
                PartialFailureError = new gr::Status(),
                Results             =
                {
                    new MutateCampaignAssetResult(),
                },
            };

            mockGrpcClient.Setup(x => x.MutateCampaignAssets(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            CampaignAssetServiceClient   client   = new CampaignAssetServiceClientImpl(mockGrpcClient.Object, null);
            MutateCampaignAssetsResponse response = client.MutateCampaignAssets(request.CustomerId, request.Operations);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 5
0
        public void MutateCampaignAssetsRequestObject()
        {
            moq::Mock <CampaignAssetService.CampaignAssetServiceClient> mockGrpcClient = new moq::Mock <CampaignAssetService.CampaignAssetServiceClient>(moq::MockBehavior.Strict);
            MutateCampaignAssetsRequest request = new MutateCampaignAssetsRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new CampaignAssetOperation(),
                },
                PartialFailure      = false,
                ValidateOnly        = true,
                ResponseContentType = gagve::ResponseContentTypeEnum.Types.ResponseContentType.ResourceNameOnly,
            };
            MutateCampaignAssetsResponse expectedResponse = new MutateCampaignAssetsResponse
            {
                PartialFailureError = new gr::Status(),
                Results             =
                {
                    new MutateCampaignAssetResult(),
                },
            };

            mockGrpcClient.Setup(x => x.MutateCampaignAssets(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            CampaignAssetServiceClient   client   = new CampaignAssetServiceClientImpl(mockGrpcClient.Object, null);
            MutateCampaignAssetsResponse response = client.MutateCampaignAssets(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 6
0
 /// <summary>Snippet for MutateCampaignAssets</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCampaignAssets()
 {
     // Create client
     CampaignAssetServiceClient campaignAssetServiceClient = CampaignAssetServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <CampaignAssetOperation> operations = new CampaignAssetOperation[]
     {
         new CampaignAssetOperation(),
     };
     // Make the request
     MutateCampaignAssetsResponse response = campaignAssetServiceClient.MutateCampaignAssets(customerId, operations);
 }
 /// <summary>Snippet for MutateCampaignAssets</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCampaignAssetsRequestObject()
 {
     // Create client
     CampaignAssetServiceClient campaignAssetServiceClient = CampaignAssetServiceClient.Create();
     // Initialize request argument(s)
     MutateCampaignAssetsRequest request = new MutateCampaignAssetsRequest
     {
         CustomerId = "",
         Operations =
         {
             new CampaignAssetOperation(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     MutateCampaignAssetsResponse response = campaignAssetServiceClient.MutateCampaignAssets(request);
 }
        /// <summary>Snippet for MutateCampaignAssetsAsync</summary>
        public async Task MutateCampaignAssetsAsync()
        {
            // Snippet: MutateCampaignAssetsAsync(string, IEnumerable<CampaignAssetOperation>, CallSettings)
            // Additional: MutateCampaignAssetsAsync(string, IEnumerable<CampaignAssetOperation>, CancellationToken)
            // Create client
            CampaignAssetServiceClient campaignAssetServiceClient = await CampaignAssetServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <CampaignAssetOperation> operations = new CampaignAssetOperation[]
            {
                new CampaignAssetOperation(),
            };
            // Make the request
            MutateCampaignAssetsResponse response = await campaignAssetServiceClient.MutateCampaignAssetsAsync(customerId, operations);

            // End snippet
        }
        /// <summary>Snippet for MutateCampaignAssetsAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task MutateCampaignAssetsRequestObjectAsync()
        {
            // Create client
            CampaignAssetServiceClient campaignAssetServiceClient = await CampaignAssetServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateCampaignAssetsRequest request = new MutateCampaignAssetsRequest
            {
                CustomerId = "",
                Operations =
                {
                    new CampaignAssetOperation(),
                },
                PartialFailure      = false,
                ValidateOnly        = false,
                ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
            };
            // Make the request
            MutateCampaignAssetsResponse response = await campaignAssetServiceClient.MutateCampaignAssetsAsync(request);
        }
Exemplo n.º 10
0
 /// <summary>Snippet for MutateCampaignAssets</summary>
 public void MutateCampaignAssetsRequestObject()
 {
     // Snippet: MutateCampaignAssets(MutateCampaignAssetsRequest, CallSettings)
     // Create client
     CampaignAssetServiceClient campaignAssetServiceClient = CampaignAssetServiceClient.Create();
     // Initialize request argument(s)
     MutateCampaignAssetsRequest request = new MutateCampaignAssetsRequest
     {
         CustomerId = "",
         Operations =
         {
             new CampaignAssetOperation(),
         },
         PartialFailure      = false,
         ValidateOnly        = false,
         ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
     };
     // Make the request
     MutateCampaignAssetsResponse response = campaignAssetServiceClient.MutateCampaignAssets(request);
     // End snippet
 }
        /// <summary>Snippet for MutateCampaignAssetsAsync</summary>
        public async Task MutateCampaignAssetsRequestObjectAsync()
        {
            // Snippet: MutateCampaignAssetsAsync(MutateCampaignAssetsRequest, CallSettings)
            // Additional: MutateCampaignAssetsAsync(MutateCampaignAssetsRequest, CancellationToken)
            // Create client
            CampaignAssetServiceClient campaignAssetServiceClient = await CampaignAssetServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateCampaignAssetsRequest request = new MutateCampaignAssetsRequest
            {
                CustomerId = "",
                Operations =
                {
                    new CampaignAssetOperation(),
                },
                PartialFailure = false,
                ValidateOnly   = false,
            };
            // Make the request
            MutateCampaignAssetsResponse response = await campaignAssetServiceClient.MutateCampaignAssetsAsync(request);

            // End snippet
        }
Exemplo n.º 12
0
        // [END migrate_promotion_feed_to_asset]

        /// <summary>
        /// Associates the specified Promotion asset with the specified campaigns.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="promotionAssetResourceName">The string resource name of the Promotion
        /// Asset.</param>
        /// <param name="campaignIds">A list of campaign IDs with which the Asset should be
        /// associated.</param>
        // [START migrate_promotion_feed_to_asset_2]
        private void AssociateAssetWithCampaigns(GoogleAdsClient client, long customerId,
                                                 string promotionAssetResourceName, List <long> campaignIds)
        {
            if (campaignIds.Count == 0)
            {
                Console.WriteLine("Asset was not associated with any campaigns.");
                return;
            }

            CampaignAssetServiceClient campaignAssetServiceClient = client.GetService(Services.V10
                                                                                      .CampaignAssetService);

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

            foreach (long campaignId in campaignIds)
            {
                operations.Add(new CampaignAssetOperation
                {
                    Create = new CampaignAsset
                    {
                        Asset     = promotionAssetResourceName,
                        FieldType = AssetFieldTypeEnum.Types.AssetFieldType.Promotion,
                        Campaign  = ResourceNames.Campaign(customerId, campaignId),
                    }
                });
            }

            MutateCampaignAssetsResponse response = campaignAssetServiceClient.MutateCampaignAssets(
                customerId.ToString(), operations);

            foreach (MutateCampaignAssetResult result in response.Results)
            {
                Console.WriteLine($"Created campaign asset with resource name " +
                                  $"{result.ResourceName}.");
            }
        }