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

      // Create account.
      ManagedCustomer customer = new ManagedCustomer();
      customer.name = "Customer created with ManagedCustomerService on " +
          new DateTime().ToString();
      customer.currencyCode = "EUR";
      customer.dateTimeZone = "Europe/London";

      // Create operations.
      ManagedCustomerOperation operation = new ManagedCustomerOperation();
      operation.operand = customer;
      operation.@operator = Operator.ADD;
      try {
        ManagedCustomerOperation[] operations = new ManagedCustomerOperation[] {operation};
        // Add account.
        ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);

        // Display accounts.
        if (result.value != null && result.value.Length > 0) {
          ManagedCustomer customerResult = result.value[0];
          Console.WriteLine("Account with customer ID \"{0}\" was created.",
              customerResult.customerId);
        } else {
          Console.WriteLine("No accounts were created.");
        }
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to create accounts.", e);
      }
    }
Esempio n. 2
0
        public void TestGetCustomer()
        {
            var ms = new MarketplaceService();

            Action f1 = () => ms.GetCustomer(null);

            f1.ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: email");

            Action f2 = () => ms.GetCustomer("invalidemail.address");

            f2.ShouldThrow <ArgumentException>().WithMessage("The email address is not correctly structured.");

            var c = ms.GetCustomer("*****@*****.**");

            c.Should().BeNull();

            var mc = new ManagedCustomer
            {
                Name      = "Alan Elbow",
                FirstName = "Alan",
                LastName  = "Elbow",
                Email     = "*****@*****.**"
            };

            mc.Save();

            var r = ms.GetCustomer("*****@*****.**");

            r.Should().NotBeNull();
            r.Name.Should().Be(mc.Name);
            r.FirstName.Should().Be(mc.FirstName);
            r.LastName.Should().Be(mc.LastName);
        }
Esempio n. 3
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            using (ManagedCustomerService managedCustomerService =
                       (ManagedCustomerService)user.GetService(AdWordsService.v201806
                                                               .ManagedCustomerService))
            {
                // Create account.
                ManagedCustomer customer = new ManagedCustomer
                {
                    name = "Customer created with ManagedCustomerService on " +
                           new DateTime().ToString(),
                    currencyCode = "EUR",
                    dateTimeZone = "Europe/London"
                };

                // Create operations.
                ManagedCustomerOperation operation = new ManagedCustomerOperation
                {
                    operand   = customer,
                    @operator = Operator.ADD
                };

                // For whitelisted users only, uncomment two commands below as part of the
                // ADD operation to invite a user to have access to an account. An email
                // will be sent to that user inviting them to have access to the newly
                // created account.
                // operation.inviteeEmail = "*****@*****.**";
                // operation.inviteeRole = AccessRole.ADMINISTRATIVE;

                try
                {
                    ManagedCustomerOperation[] operations = new ManagedCustomerOperation[]
                    {
                        operation
                    };
                    // Add account.
                    ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);

                    // Display accounts.
                    if (result.value != null && result.value.Length > 0)
                    {
                        ManagedCustomer customerResult = result.value[0];
                        Console.WriteLine("Account with customer ID \"{0}\" was created.",
                                          customerResult.customerId);
                    }
                    else
                    {
                        Console.WriteLine("No accounts were created.");
                    }
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to create accounts.", e);
                }
            }
        }
Esempio n. 4
0
        public IEnumerable <GetAdAccountsResponse> GetAllAccounts(AdWordsUser user)
        {
            ManagedCustomer customer = new ManagedCustomer();
            var             result   = new List <GetAdAccountsResponse>();

            using (ManagedCustomerService managedCustomerService = (ManagedCustomerService)user.GetService(AdWordsService.v201802.ManagedCustomerService))
            {
                try
                {
                    // Create selector.
                    Selector selector = new Selector();
                    selector.fields = new String[]
                    {
                        ManagedCustomer.Fields.CustomerId, ManagedCustomer.Fields.Name
                    };
                    selector.paging = Paging.Default;
                    ManagedCustomerPage accounts = null;
                    accounts = managedCustomerService.get(selector);

                    if (accounts.entries != null)
                    {
                        foreach (var account in accounts.entries)
                        {
                            result.Add(new GetAdAccountsResponse
                            {
                                CustomerId   = account.customerId,
                                CustomerName = account.name
                            });
                        }
                    }
                    else
                    {
                        //Test Account
                        result.Add(new GetAdAccountsResponse
                        {
                            CustomerId   = 3,
                            CustomerName = "Test account 3"
                        });
                        result.Add(new GetAdAccountsResponse
                        {
                            CustomerId   = 4,
                            CustomerName = "Test account 4"
                        });
                    }
                }
                catch (Exception x)
                {
                    throw new Exception(x.Message);
                }
                return(result);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            using (ManagedCustomerService managedCustomerService =
                       (ManagedCustomerService)user.GetService(AdWordsService.v201806
                                                               .ManagedCustomerService))
            {
                // Create account.
                ManagedCustomer customer = new ManagedCustomer
                {
                    name = "Customer created with ManagedCustomerService on " +
                           new DateTime().ToString(),
                    currencyCode = "EUR",
                    dateTimeZone = "Europe/London"
                };

                // Create operations.
                ManagedCustomerOperation operation = new ManagedCustomerOperation
                {
                    operand   = customer,
                    @operator = Operator.ADD
                };

                try
                {
                    ManagedCustomerOperation[] operations = new ManagedCustomerOperation[]
                    {
                        operation
                    };
                    // Add account.
                    ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);

                    // Display accounts.
                    if (result.value != null && result.value.Length > 0)
                    {
                        ManagedCustomer customerResult = result.value[0];
                        Console.WriteLine("Account with customer ID \"{0}\" was created.",
                                          customerResult.customerId);
                    }
                    else
                    {
                        Console.WriteLine("No accounts were created.");
                    }
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to create accounts.", e);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the platform that a customer should have its tenant(s) and subsequent applications
        /// deployed to.
        /// </summary>
        /// <param name="customer">The customer.</param>
        /// <param name="tenant">The specific tenant owned by the customer. (Optional.)</param>
        /// <returns>The managed platform that has been selected.</returns>
        public ManagedPlatform GetPlatform(ManagedCustomer customer, ManagedTenant tenant = null)
        {
            return(default(ManagedPlatform));
            //         ManagedPlatform platform = null;

            //         // TODO: Maybe compare timezones first, then round-trip time or entity load?

            //         var platforms = Entity.GetInstancesOfType<ManagedPlatform>().ToList();
            //if ( platforms.Count > 0 )
            //         {
            //             platform = platforms.Where(p => p.LastContact != null)
            //                                 .OrderByDescending(p => p.LastContact)
            //                                 .FirstOrDefault() ?? platforms.First();
            //         }

            //         // writeable? bah.
            //         return platform != null ? platform.AsWritable<ManagedPlatform>() : null;
        }
Esempio n. 7
0
        public void TestCreateTenant()
        {
            // Arrange
            var ms = new MarketplaceService();
            var c  = new ManagedCustomer
            {
                Email     = "*****@*****.**",
                FirstName = "Foo",
                LastName  = "Bar"
            };

            c.Save();

            Action f1 = () => ms.CreateTenant(null);

            f1.ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: customer");

            // Act
            var t = ms.CreateTenant(c);

            // Assert
            t.Should().NotBeNull();
            t.Customer.Should().NotBeNull();
            t.Customer.Id.Should().Be(c.Id);
            t.IsTemporaryId.Should().BeTrue();
            t.Name.Should().Be("FOOBARCOM");

            // The means for determining the tenant name... not 100% solid yet.
            c.Name = "Foo Bar";
            t      = ms.CreateTenant(c);
            t.Name.Should().Be("FOOBAR");

            c.Company = "Elbow Inc.";
            t         = ms.CreateTenant(c);
            t.Name.Should().Be("ELBOWINC");

            // If the tenant name already exists?... not 100% solid yet.
            t.Save();
            t = ms.CreateTenant(c);
            t.Name.Should().NotBe("ELBOWINC");
            t.Name.Should().StartWith("ELBOWINC_");
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a new tenant object (unsaved) for the customer with the name of the tenant derived from
        /// the details given by the customer.
        /// </summary>
        /// <param name="customer">The customer to create the tenant for.</param>
        /// <returns>The newly created tenant object.</returns>
        public ManagedTenant CreateTenant(ManagedCustomer customer)
        {
            return(default(ManagedTenant));
            //if (customer == null)
            //{
            //    throw new ArgumentNullException("customer");
            //}

            //var managedTenant = EntityRepository.Create<ManagedTenant>();
            //managedTenant.Customer = customer;

            //// I don't know if this is even necessary and it will most likely change.
            //// Whatever logic should be applied... stick it here.
            //var rgx = new Regex("[^A-Za-z0-9]");

            //var baseName = rgx.Replace(customer.Name, "").ToUpper();

            //// Use company if given.
            //if (!string.IsNullOrEmpty(customer.Company))
            //{
            //    var cleanCompany = rgx.Replace(customer.Company, "").ToUpper();
            //    if (!string.IsNullOrEmpty(cleanCompany))
            //    {
            //        baseName = cleanCompany;
            //    }
            //}

            //var tenantName = baseName;
            //var rnd = new Random();
            //while (EntityModel.GetByName<ManagedTenant>(tenantName).Any())
            //{
            //    tenantName = baseName + "_" + rnd.Next(100, 1000);
            //}

            //managedTenant.Name = tenantName;

            //return managedTenant;
        }