Exemplo n.º 1
0
        public void MergeFrom(ExtensionFeedItem other)
        {
            if (other == null)
            {
                return;
            }
            if (other.ResourceName.Length != 0)
            {
                ResourceName = other.ResourceName;
            }
            if (other.ExtensionType != 0)
            {
                ExtensionType = other.ExtensionType;
            }
            if (other.startDateTime_ != null)
            {
                if (startDateTime_ == null || other.StartDateTime != "")
                {
                    StartDateTime = other.StartDateTime;
                }
            }
            if (other.endDateTime_ != null)
            {
                if (endDateTime_ == null || other.EndDateTime != "")
                {
                    EndDateTime = other.EndDateTime;
                }
            }
            adSchedules_.Add(other.adSchedules_);
            if (other.Device != 0)
            {
                Device = other.Device;
            }
            if (other.Status != 0)
            {
                Status = other.Status;
            }
            switch (other.ExtensionCase)
            {
            case ExtensionOneofCase.SitelinkFeedItem:
                if (SitelinkFeedItem == null)
                {
                    SitelinkFeedItem = new global::Google.Ads.GoogleAds.V1.Common.SitelinkFeedItem();
                }
                SitelinkFeedItem.MergeFrom(other.SitelinkFeedItem);
                break;

            case ExtensionOneofCase.StructuredSnippetFeedItem:
                if (StructuredSnippetFeedItem == null)
                {
                    StructuredSnippetFeedItem = new global::Google.Ads.GoogleAds.V1.Common.StructuredSnippetFeedItem();
                }
                StructuredSnippetFeedItem.MergeFrom(other.StructuredSnippetFeedItem);
                break;

            case ExtensionOneofCase.AppFeedItem:
                if (AppFeedItem == null)
                {
                    AppFeedItem = new global::Google.Ads.GoogleAds.V1.Common.AppFeedItem();
                }
                AppFeedItem.MergeFrom(other.AppFeedItem);
                break;

            case ExtensionOneofCase.CallFeedItem:
                if (CallFeedItem == null)
                {
                    CallFeedItem = new global::Google.Ads.GoogleAds.V1.Common.CallFeedItem();
                }
                CallFeedItem.MergeFrom(other.CallFeedItem);
                break;

            case ExtensionOneofCase.CalloutFeedItem:
                if (CalloutFeedItem == null)
                {
                    CalloutFeedItem = new global::Google.Ads.GoogleAds.V1.Common.CalloutFeedItem();
                }
                CalloutFeedItem.MergeFrom(other.CalloutFeedItem);
                break;

            case ExtensionOneofCase.TextMessageFeedItem:
                if (TextMessageFeedItem == null)
                {
                    TextMessageFeedItem = new global::Google.Ads.GoogleAds.V1.Common.TextMessageFeedItem();
                }
                TextMessageFeedItem.MergeFrom(other.TextMessageFeedItem);
                break;

            case ExtensionOneofCase.PriceFeedItem:
                if (PriceFeedItem == null)
                {
                    PriceFeedItem = new global::Google.Ads.GoogleAds.V1.Common.PriceFeedItem();
                }
                PriceFeedItem.MergeFrom(other.PriceFeedItem);
                break;

            case ExtensionOneofCase.PromotionFeedItem:
                if (PromotionFeedItem == null)
                {
                    PromotionFeedItem = new global::Google.Ads.GoogleAds.V1.Common.PromotionFeedItem();
                }
                PromotionFeedItem.MergeFrom(other.PromotionFeedItem);
                break;

            case ExtensionOneofCase.LocationFeedItem:
                if (LocationFeedItem == null)
                {
                    LocationFeedItem = new global::Google.Ads.GoogleAds.V1.Common.LocationFeedItem();
                }
                LocationFeedItem.MergeFrom(other.LocationFeedItem);
                break;

            case ExtensionOneofCase.AffiliateLocationFeedItem:
                if (AffiliateLocationFeedItem == null)
                {
                    AffiliateLocationFeedItem = new global::Google.Ads.GoogleAds.V1.Common.AffiliateLocationFeedItem();
                }
                AffiliateLocationFeedItem.MergeFrom(other.AffiliateLocationFeedItem);
                break;
            }

            _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a Promotion asset that copies values from the specified extension feed item.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="extensionFeedItem">The extension feed item to be migrated.</param>
        /// <returns>The resource name of the newly created Promotion asset.</returns>
        // [START migrate_promotion_feed_to_asset]
        private string CreatePromotionAssetFromFeed(GoogleAdsClient client, long customerId,
                                                    ExtensionFeedItem extensionFeedItem)
        {
            // Get the Asset Service client.
            AssetServiceClient assetServiceClient = client.GetService(Services.V10.AssetService);

            PromotionFeedItem promotionFeedItem = extensionFeedItem.PromotionFeedItem;

            // Create the Promotion asset.
            Asset asset = new Asset
            {
                // Name field is optional.
                Name           = $"Migrated from feed item #{extensionFeedItem.Id}",
                PromotionAsset = new PromotionAsset
                {
                    PromotionTarget     = promotionFeedItem.PromotionTarget,
                    DiscountModifier    = promotionFeedItem.DiscountModifier,
                    RedemptionStartDate = promotionFeedItem.PromotionStartDate,
                    RedemptionEndDate   = promotionFeedItem.PromotionEndDate,
                    Occasion            = promotionFeedItem.Occasion,
                    LanguageCode        = promotionFeedItem.LanguageCode,
                },
                TrackingUrlTemplate = promotionFeedItem.TrackingUrlTemplate,
                FinalUrlSuffix      = promotionFeedItem.FinalUrlSuffix
            };

            // Either PercentOff or MoneyAmountOff must be set.
            if (promotionFeedItem.PercentOff > 0)
            {
                // Adjust the percent off scale when copying.
                asset.PromotionAsset.PercentOff = promotionFeedItem.PercentOff / 100;
            }
            else
            {
                asset.PromotionAsset.MoneyAmountOff = new Money
                {
                    AmountMicros = promotionFeedItem.MoneyAmountOff.AmountMicros,
                    CurrencyCode = promotionFeedItem.MoneyAmountOff.CurrencyCode
                };
            }

            // Either PromotionCode or OrdersOverAmount must be set.
            if (!string.IsNullOrEmpty(promotionFeedItem.PromotionCode))
            {
                asset.PromotionAsset.PromotionCode = promotionFeedItem.PromotionCode;
            }
            else
            {
                asset.PromotionAsset.OrdersOverAmount = new Money
                {
                    AmountMicros = promotionFeedItem.OrdersOverAmount.AmountMicros,
                    CurrencyCode = promotionFeedItem.OrdersOverAmount.CurrencyCode
                };
            }

            // Set the start and end dates if set in the existing extension.
            if (extensionFeedItem.HasStartDateTime)
            {
                asset.PromotionAsset.StartDate = DateTime.Parse(extensionFeedItem.StartDateTime)
                                                 .ToString("yyyy-MM-dd");
            }

            if (extensionFeedItem.HasEndDateTime)
            {
                asset.PromotionAsset.EndDate = DateTime.Parse(extensionFeedItem.EndDateTime)
                                               .ToString("yyyy-MM-dd");
            }

            asset.PromotionAsset.AdScheduleTargets.Add(extensionFeedItem.AdSchedules);
            asset.FinalUrls.Add(promotionFeedItem.FinalUrls);
            asset.FinalMobileUrls.Add(promotionFeedItem.FinalMobileUrls);
            asset.UrlCustomParameters.Add(promotionFeedItem.UrlCustomParameters);

            // Build an operation to create the Promotion asset.
            AssetOperation operation = new AssetOperation
            {
                Create = asset
            };

            // Issue the request and return the resource name of the new Promotion asset.
            MutateAssetsResponse response = assetServiceClient.MutateAssets(
                customerId.ToString(), new[] { operation });

            Console.WriteLine("Created Promotion asset with resource name " +
                              $"{response.Results.First().ResourceName}");
            return(response.Results.First().ResourceName);
        }
Exemplo n.º 3
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ResourceName.Length != 0)
            {
                hash ^= ResourceName.GetHashCode();
            }
            if (ExtensionType != 0)
            {
                hash ^= ExtensionType.GetHashCode();
            }
            if (startDateTime_ != null)
            {
                hash ^= StartDateTime.GetHashCode();
            }
            if (endDateTime_ != null)
            {
                hash ^= EndDateTime.GetHashCode();
            }
            hash ^= adSchedules_.GetHashCode();
            if (Device != 0)
            {
                hash ^= Device.GetHashCode();
            }
            if (Status != 0)
            {
                hash ^= Status.GetHashCode();
            }
            if (extensionCase_ == ExtensionOneofCase.SitelinkFeedItem)
            {
                hash ^= SitelinkFeedItem.GetHashCode();
            }
            if (extensionCase_ == ExtensionOneofCase.StructuredSnippetFeedItem)
            {
                hash ^= StructuredSnippetFeedItem.GetHashCode();
            }
            if (extensionCase_ == ExtensionOneofCase.AppFeedItem)
            {
                hash ^= AppFeedItem.GetHashCode();
            }
            if (extensionCase_ == ExtensionOneofCase.CallFeedItem)
            {
                hash ^= CallFeedItem.GetHashCode();
            }
            if (extensionCase_ == ExtensionOneofCase.CalloutFeedItem)
            {
                hash ^= CalloutFeedItem.GetHashCode();
            }
            if (extensionCase_ == ExtensionOneofCase.TextMessageFeedItem)
            {
                hash ^= TextMessageFeedItem.GetHashCode();
            }
            if (extensionCase_ == ExtensionOneofCase.PriceFeedItem)
            {
                hash ^= PriceFeedItem.GetHashCode();
            }
            if (extensionCase_ == ExtensionOneofCase.PromotionFeedItem)
            {
                hash ^= PromotionFeedItem.GetHashCode();
            }
            if (extensionCase_ == ExtensionOneofCase.LocationFeedItem)
            {
                hash ^= LocationFeedItem.GetHashCode();
            }
            if (extensionCase_ == ExtensionOneofCase.AffiliateLocationFeedItem)
            {
                hash ^= AffiliateLocationFeedItem.GetHashCode();
            }
            hash ^= (int)extensionCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }