/// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the ExpressBusinessService.
              ExpressBusinessService businessService = (ExpressBusinessService)
              user.GetService(AdWordsService.v201502.ExpressBusinessService);

              ExpressBusiness business1 = new ExpressBusiness();
              business1.status = ExpressBusinessStatus.ENABLED;
              business1.name = "Express Interplanetary Cruise #" + ExampleUtilities.GetShortRandomString();

              Address address1 = new Address();
              address1.streetAddress = "1600 Amphitheatre Pkwy";
              address1.cityName = "Mountain View";
              address1.provinceCode = "CA";
              address1.countryCode = "US";

              business1.address = address1;
              business1.website = "http://www.example.com/cruise1";

              ExpressBusinessOperation operation1 = new ExpressBusinessOperation();
              operation1.@operator = Operator.ADD;
              operation1.operand = business1;

              ExpressBusiness business2 = new ExpressBusiness();
              business2.status = (ExpressBusinessStatus.ENABLED);
              business2.name = "Express Interplanetary Cruise #" + ExampleUtilities.GetShortRandomString();

              Address address2 = new Address();
              address2.streetAddress = "111 8th Ave";
              address2.cityName = "New York";
              address2.provinceCode = "NY";
              address2.countryCode = "US";

              business2.address = address2;
              business2.website = "http://www.example.com/cruise2";

              ExpressBusinessOperation operation2 = new ExpressBusinessOperation();
              operation2.@operator = Operator.ADD;
              operation2.operand = business2;

              try {
            ExpressBusiness[] addedBusinesses = businessService.mutate(
            new ExpressBusinessOperation[] {operation1, operation2});

            Console.WriteLine("Added {0} express businesses", addedBusinesses.Length);
            foreach (ExpressBusiness addedBusiness in addedBusinesses) {
              Console.WriteLine("Added express business with ID = {0} and name '{1}'.",
              addedBusiness.id, addedBusiness.name);
            }
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to add express business.", e);
              }
        }
Пример #2
0
    /// <summary>
    /// Gets the geo location for a given address.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="address">The address for which geolocation should be
    /// fetched.</param>
    /// <returns>Geo location for the address.</returns>
    public GeoLocation GetLocationForAddress(AdWordsUser user, Address address) {
      GeoLocationService geoService =
          (GeoLocationService) user.GetService(AdWordsService.v201502.GeoLocationService);

      GeoLocationSelector selector = new GeoLocationSelector();
      selector.addresses = new Address[] {address};
      return geoService.get(selector)[0];
    }
        /// <summary>
        /// Formats the address as a printable text.
        /// </summary>
        /// <param name="address">The address object.</param>
        /// <returns>The formatted text.</returns>
        private static string FormatAddress(Address address)
        {
            if (address == null) {
            return "Not available.";
              }
              StringBuilder addressBuilder = new StringBuilder();

              addressBuilder.AppendFormat("Line 1: {0}\n", address.streetAddress ?? "");
              addressBuilder.AppendFormat("Line 2: {0}\n", address.streetAddress2 ?? "");
              addressBuilder.AppendFormat("Province Name: {0}\n", address.provinceName ?? "");
              addressBuilder.AppendFormat("Province Code: {0}\n", address.provinceCode ?? "");
              addressBuilder.AppendFormat("City name: {0}\n", address.cityName ?? "");
              addressBuilder.AppendFormat("Postal code: {0}\n", address.postalCode ?? "");
              addressBuilder.AppendFormat("Country name: {0}\n", address.countryCode ?? "");

              return addressBuilder.ToString();
        }