Example #1
0
        private async Task GetLocations(
            JObject template,
            JObject returnObj,
            string token,
            SubscriptionInfo[] subscriptions)
        {
            IEnumerable<string> locations = null;
            IEnumerable<string> dbServerLocations = null;

            using (var client = GetRMClient(token, subscriptions.FirstOrDefault().subscriptionId))
            {
                var websites = (await client.Providers.GetAsync("Microsoft.Web")).Provider;
                locations = websites.ResourceTypes.FirstOrDefault(rt => rt.Name == "sites").Locations
                       .Where(location => location.IndexOf("MSFT", StringComparison.OrdinalIgnoreCase) < 0);

                var parameters = template["parameters"];
                if (parameters != null)
                {
                    var dbServerLocation = parameters["sqlServerLocation"];
                    if (dbServerLocation != null)
                    {
                        var sql = (await client.Providers.GetAsync("Microsoft.Sql")).Provider;
                        dbServerLocations = sql.ResourceTypes.FirstOrDefault(rt => rt.Name == "servers").Locations;
                    }
                }
            }

            returnObj["siteLocations"] = JArray.FromObject(locations);
            returnObj["sqlServerLocations"] = dbServerLocations == null ? null : JArray.FromObject(dbServerLocations);
            return;
        }
Example #2
0
        private async Task<string> GenerateResourceGroupName(string token, Repository repo, SubscriptionInfo[] subscriptions)
        {
            if (!string.IsNullOrEmpty(repo.RepositoryName))
            {
                bool isAvailable = false;
                var creds = new TokenCloudCredentials(subscriptions.First().subscriptionId, token);
                var rdfeBaseUri = new Uri(Utils.GetRDFEUrl(Request.RequestUri.Host));

                using (var webSiteMgmtClient = CloudContext.Clients.CreateWebSiteManagementClient(creds, rdfeBaseUri))
                {
                    // Make 3 attempts to get a random name (based on the repo name)
                    for (int i = 0; i < 3; i++)
                    {
                        string resourceGroupName = GenerateRandomResourceGroupName(repo.RepositoryName);
                        isAvailable = await IsSiteNameAvailable(webSiteMgmtClient, resourceGroupName);

                        if (isAvailable)
                        {
                            return resourceGroupName;
                        }
                    }
                }
            }

            return null;
        }