Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("################################");
                    Console.WriteLine("Help");
                    Console.WriteLine("Extract activation information to CSV: " + System.AppDomain.CurrentDomain.FriendlyName + " activationCSV");
                    Console.WriteLine("Extract customer usage information to CSV: " + System.AppDomain.CurrentDomain.FriendlyName + " customerUsageCSV");
                    Console.WriteLine("Extract activation information to Database: " + System.AppDomain.CurrentDomain.FriendlyName + " activationBD");
                    Console.WriteLine("################################");
                    return;
                }

                _stopwatch.Start();

                _logger.Info("#### Start date: " + DateTime.Now);

                #region Initialize APIs & Tokens

                _azureADGraphApiHelper  = new AzureADGraphApiHelper();
                _partnerCenterSdkHelper = new PartnerCenterSdkHelper(isTokenForUserPlusApplication: true);
                _partnerOperations      = _partnerCenterSdkHelper.GetPartnerCenterSdkClientAsync().ConfigureAwait(false).GetAwaiter().GetResult();

                #endregion

                #region Parse command parameter

                if (args[0] == "activationCSV")
                {
                    _reportProcessor = new ActivationReportProcessor(OutputChannel.CSV);
                }
                if (args[0] == "customerUsageCSV")
                {
                    _reportProcessor = new CustomerUsageReportProcessor(OutputChannel.CSV);
                }
                if (args[0] == "activationBD")
                {
                    _reportProcessor = new ActivationReportProcessor(OutputChannel.DATABASE);
                }

                ExtractReportInformationWithProcessor().ConfigureAwait(false).GetAwaiter().GetResult();

                #endregion
            }
            catch (Exception ex)
            {
                _logger.Error("Error: " + ex.ToString());
            }
            finally
            {
                _stopwatch.Stop();

                _logger.Info("#### End date: " + DateTime.Now + ". Duration: " + FormatStopwatch());

                //Console.WriteLine("Press any key to end.");
                //Console.ReadLine();
            }
        }
Пример #2
0
        public static List <Domain> GetCustomerDomains(PartnerSdkModels.Customers.Customer customer)
        {
            List <Domain> result = new List <Domain>();

            // Initialize the Azure AD Graph API helper with the customer tenant
            _azureADGraphApiHelper = new AzureADGraphApiHelper(customer.Id);
            // Get request client
            HttpWebRequest request = _azureADGraphApiHelper.BuildGetCustomerDomainsRequest();
            // Execute request
            dynamic requestResult = request.TryCatchRequest();

            foreach (dynamic domain in requestResult.value)
            {
                result.Add(DomainMapper.MapFromJson(customer.Id, domain));
            }

            return(result);
        }
Пример #3
0
        public static async Task <List <SubscribedSku> > GetCustomerSubscribedSkus(
            PartnerSdkModels.Customers.Customer customer)
        {
            AzureADGraphApiHelper azureADGraphApiHelper = new AzureADGraphApiHelper(customer.Id);

            GraphClient.ActiveDirectoryClient activeDirectoryClient = azureADGraphApiHelper.GetActiveDirectoryClient();

            GraphClient.Extensions.IPagedCollection <GraphClient.ISubscribedSku> subscribedSkus = await activeDirectoryClient.SubscribedSkus.ExecuteAsync();

            List <SubscribedSku> result = new List <SubscribedSku>();

            do
            {
                foreach (GraphClient.ISubscribedSku subscribedSku in subscribedSkus.CurrentPage.ToList())
                {
                    result.Add(SubscribedSkuMapper.MapFromSource(subscribedSku));
                }

                subscribedSkus = await subscribedSkus.GetNextPageAsync();
            }while (subscribedSkus != null && subscribedSkus.MorePagesAvailable);

            return(result);
        }
        /// This is a sample console application that shows a End to End Provisioning scenario:
        ///  1. Create a Customer with the CREST API.
        ///  2. Add an Exchange Subscription with the CREST API.
        ///  3. Associate a custom domain with the Azure AD Graph API.
        ///  4. Get new domain TXT record for verification with the Azure AD Graph API.
        ///  5. Verify domain TXT record configuration with the Azure AD Graph API. 
        ///  6. Create a new user with the Azure AD Graph API.
        ///  7. Assign the new user a Exchange license with the Azure AD Graph API.
        static void Main(string[] args)
        {
            try
            {
                #region Initialize APIs & Tokens

                crestApiHelper = new CrestApiHelper();
                azureADGraphApiHelper = new AzureADGraphApiHelper();

                #endregion

                #region 1. Create a Customer with the CREST API

                // New customer information
                dynamic newCustomer = new
                {
                    domain_prefix = "createit" + new Random().Next(9999),
                    user_name = "admin",
                    password = "******",
                    profile = new
                    {
                        first_name = "Create",
                        last_name = "It",
                        email = "*****@*****.**",
                        company_name = "Create It",
                        culture = "en-US",
                        language = "en",
                        type = "organization",

                        // Note: This data/location depends on your CSP tenant location
                        // It will be validated by Microsoft and will fail if not valid
                        default_address = new
                        {
                            first_name = "Create",
                            last_name = "It",
                            address_line1 = "One Microsoft Way",
                            city = "Redmond",
                            region = "WA",
                            postal_code = "98052-6399",
                            country = "US",
                            phone_number = "19165767760",
                        }
                    }
                };

                // Create customer
                Guid customerId = CreateCustomer(newCustomer);

                // Created customer base information
                var customer = new Customer()
                {
                    CustomerId = customerId,
                    TenantDomainName = newCustomer.domain_prefix + ".onmicrosoft.com"
                };

                #endregion

                #region 2. Add an Exchange Subscription with the CREST API.

                // New order information
                dynamic newOrder = new
                {
                    recipient_customer_id = customer.CustomerId,
                    line_items = new[]
                    {
                        new 
                        {
                            line_item_number = 0,
                            offer_uri = "/3c95518e-8c37-41e3-9627-0ca339200f53/offers/195416c1-3447-423a-b37b-ee59a99a19c4",
                            quantity = 20,
                            friendly_name = "Exchange Online (Plan 1)",
                        }
                    }
                };

                // Place order
                dynamic placedOrder = PlaceOrder(newOrder);

                #endregion

                #region 3. Associate a custom domain with the Azure AD Graph API.

                // NOTE: From here we initialize the Azure AD Graph API helper with the new customer tenant domain
                // Azure AD Graph API operations will be against the customer tenant, using the Pre-Consent delegated access
                azureADGraphApiHelper = new AzureADGraphApiHelper(customer.TenantDomainName);

                // New domain information
                var tenantDomainName = customer.TenantDomainName;
                //string domainName = new Random().Next(9999) + "." + tenantDomainName;
                string domainName = "create.pt";

                // Add domain
                dynamic newDomain = AddCustomerDomain(domainName);

                #endregion

                #region 4. Get new domain TXT record for verification with the Azure AD Graph API.

                dynamic newDomainVerificationRecords = GetCustomerDomainVerificationRecords(domainName);

                // Note: You now need to go to your DNS service provider and place the TXT record

                #endregion

                #region 5. Verify domain TXT record configuration with the Azure AD Graph API.

                // Note: Will only have success if the TXT record is present in the DNS
                VerifyCustomerDomain(domainName);

                #endregion

                #region 6. Create a new user with the Azure AD Graph API.

                // New user information
                GraphClient.IUser newUser = new GraphClient.User()
                {

                    DisplayName = "createitUser" + new Random().Next(9999),
                    AccountEnabled = true,
                    UsageLocation = "US",
                    PasswordProfile = new GraphClient.PasswordProfile()
                    {
                        ForceChangePasswordNextLogin = true,
                        Password = "******",
                    },
                };
                newUser.MailNickname = newUser.DisplayName;
                newUser.UserPrincipalName = newUser.DisplayName + "@" + tenantDomainName;

                GraphClient.IUser addedUser = AddCustomerUser(newUser);

                #endregion

                #region 7. Assign the new user a Exchange license with the Azure AD Graph API.

                // Get the customer subscribed Skus to determine the Sku id to use in the license assignment
                IReadOnlyList<GraphClient.ISubscribedSku> subscribedSkus = GetSubscribedSkus();

                if (subscribedSkus != null && subscribedSkus.Count > 0)
                {
                    // Filter the license to assign
                    GraphClient.ISubscribedSku subscribeSkuToUser = subscribedSkus
                        .FirstOrDefault(x => x.SkuPartNumber == "EXCHANGESTANDARD");

                    // License to assign information
                    GraphClient.AssignedLicense addLicense = new GraphClient.AssignedLicense()
                    {
                        SkuId = subscribeSkuToUser.SkuId
                    };

                    // Assign license
                    GraphClient.IUser newUserWithLicenseAssigned =
                        AssignOrRemoveLicensesToUser(newUser.UserPrincipalName, addLicense);

                    // Check proper license assignment
                    if (newUserWithLicenseAssigned != null && newUserWithLicenseAssigned.AssignedLicenses != null
                        && newUserWithLicenseAssigned.AssignedLicenses.Count > 0)
                    {
                        GraphClient.AssignedLicense checkAssignedLicense = newUserWithLicenseAssigned.AssignedLicenses
                            .SingleOrDefault(x => x.SkuId == subscribeSkuToUser.SkuId);

                        Debug.Assert(checkAssignedLicense != null, "User assigned license not validated");
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                Console.Write("Error: " + ex.ToString());
            }

            Console.Write("\n\n\nHit enter to exit the app...");
            Console.ReadLine();
        }