private static async Task <bool> CreateSkillSet() { Console.WriteLine("Creating Skill Set..."); try { Skillset skillset = SearchResources.GetSkillset(SkillsetName, await KeyHelper.GetAzureFunctionHostKey(_httpClient), BlobContainerNameForImageStore); await _searchClient.Skillsets.CreateAsync(skillset); } catch (Exception ex) { if (DebugMode) { Console.WriteLine("Error creating skillset: {0}", ex.Message); } return(false); } return(true); }
private static async Task <bool> CreateSkillSet() { Console.WriteLine("Creating Skill Set..."); try { if (_azureFunctionHostKey == null) { _azureFunctionHostKey = await KeyHelper.GetAzureFunctionHostKey(_httpClient); } using (StreamReader r = new StreamReader("skillset.json")) { string json = r.ReadToEnd(); json = json.Replace("[AzureFunctionEndpointUrl]", String.Format("https://{0}.azurewebsites.net", ConfigurationManager.AppSettings["AzureFunctionSiteName"])); json = json.Replace("[AzureFunctionDefaultHostKey]", _azureFunctionHostKey); json = json.Replace("[BlobContainerName]", BlobContainerNameForImageStore); json = json.Replace("[CognitiveServicesKey]", ConfigurationManager.AppSettings["CognitiveServicesAccountKey"]); string uri = String.Format("{0}/skillsets/{1}?api-version=2017-11-11-Preview", _searchServiceEndpoint, SkillsetName); HttpContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _httpClient.PutAsync(uri, content); if (DebugMode) { string responseText = await response.Content.ReadAsStringAsync(); Console.WriteLine("Create Skill Set response: \n{0}", responseText); } if (!response.IsSuccessStatusCode) { return(false); } } } catch (Exception ex) { if (DebugMode) { Console.WriteLine("Error creating skillset: {0}", ex.Message); } return(false); } return(true); }
private static async Task <bool> DeployWebsite() { try { Console.WriteLine("Setting Website Keys..."); string searchQueryKey = ConfigurationManager.AppSettings["SearchServiceQueryKey"]; string envText = File.ReadAllText("../../../../frontend/.env"); envText = envText.Replace("[SearchServiceName]", ConfigurationManager.AppSettings["SearchServiceName"]); envText = envText.Replace("[SearchServiceDomain]", _searchClient.SearchDnsSuffix); envText = envText.Replace("[IndexName]", IndexName); envText = envText.Replace("[SearchServiceApiKey]", searchQueryKey); envText = envText.Replace("[SearchServiceApiVersion]", _searchClient.ApiVersion); envText = envText.Replace("[AzureFunctionName]", ConfigurationManager.AppSettings["AzureFunctionSiteName"]); envText = envText.Replace("[AzureFunctionDefaultHostKey]", await KeyHelper.GetAzureFunctionHostKey(_httpClient)); File.WriteAllText("../../../../frontend/.env", envText); Console.WriteLine("Website keys have been set. Please build the website and then return here and press any key to continue."); Console.ReadKey(); Console.WriteLine("Deploying Website..."); if (File.Exists("website.zip")) { File.Delete("website.zip"); } ZipFile.CreateFromDirectory("../../../../frontend/dist", "website.zip"); byte[] websiteZip = File.ReadAllBytes("website.zip"); HttpContent content = new ByteArrayContent(websiteZip); string uri = String.Format("https://{0}.scm.azurewebsites.net/api/zipdeploy?isAsync=true", ConfigurationManager.AppSettings["AzureWebAppSiteName"]); byte[] credentials = Encoding.ASCII.GetBytes(String.Format("{0}:{1}", ConfigurationManager.AppSettings["AzureWebAppUsername"], ConfigurationManager.AppSettings["AzureWebAppPassword"])); _httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials)); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); if (DebugMode) { string responseText = await response.Content.ReadAsStringAsync(); Console.WriteLine("Deploy website response: \n{0}", responseText); } if (!response.IsSuccessStatusCode) { return(false); } Console.WriteLine("Website deployment accepted. Waiting for deployment to complete..."); IEnumerable <string> values; if (response.Headers.TryGetValues("Location", out values)) { string pollingUri = values.First(); bool complete = false; while (!complete) { Thread.Sleep(3000); HttpResponseMessage pollingResponse = await _httpClient.GetAsync(pollingUri); string responseText = await pollingResponse.Content.ReadAsStringAsync(); JObject json = JObject.Parse(responseText); complete = json.SelectToken("complete") == null ? false : json.SelectToken("complete").ToObject <bool>(); if (DebugMode) { Console.WriteLine("Current website deployment status: {0}", json.SelectToken("progress")?.ToString()); } } Console.WriteLine("Website deployment completed."); } else { Console.WriteLine("Could not find polling url from response."); } Console.WriteLine("Website url: https://{0}.azurewebsites.net/", ConfigurationManager.AppSettings["AzureWebAppSiteName"]); } catch (Exception ex) { if (DebugMode) { Console.WriteLine("Error deploying website: {0}", ex.Message); } return(false); } return(true); }