private async void ListBtn_ClickAsync(object sender, EventArgs e) { string token = await AuthenticationHelper.GetTokenForUserAsync(); if (token != null) { HTTPResponse.AppendText("\r\nGetting Policies.\r\n"); HttpResponseMessage response = null; response = await UserMode.HttpGetAsync(Constants.TrustFrameworkPolicesUri); string content = await response.Content.ReadAsStringAsync(); //HTTPResponse.AppendText(JToken.Parse(content).ToString(Formatting.Indented)); //HTTPResponse.AppendText(await response.Content.ReadAsStringAsync()); if (response.IsSuccessStatusCode == true) { HTTPResponse.AppendText("\r\nSuccessfully updated policy list.\r\n"); } else { HTTPResponse.AppendText(content); } PolicyList pL = JsonConvert.DeserializeObject <PolicyList>(content); UpdatePolicyList(pL); } }
private async void LoginBtn_Click(object sender, EventArgs e) { if (loginBtn.Text == "Login") { //Task<string> token = AuthenticationHelper.GetTokenForUserAsync(); string token = await AuthenticationHelper.GetTokenForUserAsync(); if (token != null) { loginBtn.Text = "Logout"; DateTime thisDayLogin = DateTime.Now; HTTPResponse.AppendText("\r\n" + thisDayLogin.ToString() + " - Logged in, getting policies.\r\n"); HttpResponseMessage response = null; response = await UserMode.HttpGetAsync(Constants.TrustFrameworkPolicesUri); string content = await response.Content.ReadAsStringAsync(); //HTTPResponse.AppendText(await response.Content.ReadAsStringAsync()); PolicyList pL = JsonConvert.DeserializeObject <PolicyList>(content); UpdatePolicyList(pL); } } else { loginBtn.Text = "Login"; AuthenticationHelper.ClearCache(); policyList.Items.Clear(); } }
private async void DeleteSelectedBtn_Click(object sender, EventArgs e) { if (policyList.SelectedItem != null) { string token = await AuthenticationHelper.GetTokenForUserAsync(); if (token != null) { DateTime thisDay = DateTime.Now; HTTPResponse.AppendText("\r\n" + thisDay.ToString() + " - Deleting " + policyList.SelectedItem.ToString() + "\r\n"); HttpResponseMessage response = null; response = await UserMode.HttpDeleteIDAsync(Constants.TrustFrameworkPolicesUri, Constants.TrustFrameworkPolicyByIDUri, policyList.SelectedItem.ToString()); string content = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode == true) { DateTime thisDayItem = DateTime.Now; HTTPResponse.AppendText("\r\n" + thisDayItem.ToString() + " - Successfully deleted " + policyList.SelectedItem.ToString() + "\r\n"); } else { HTTPResponse.AppendText(content); } //HTTPResponse.AppendText(await response.Content.ReadAsStringAsync()); response = await UserMode.HttpGetAsync(Constants.TrustFrameworkPolicesUri); content = await response.Content.ReadAsStringAsync(); //HTTPResponse.AppendText(await response.Content.ReadAsStringAsync()); if (response.IsSuccessStatusCode == true) { DateTime thisDayUpdate = DateTime.Now; HTTPResponse.AppendText("\r\n" + thisDayUpdate.ToString() + " - Successfully updated policy list.\r\n"); } else { HTTPResponse.AppendText(content); } PolicyList pL = JsonConvert.DeserializeObject <PolicyList>(content); UpdatePolicyList(pL); } } }
private async void DeleteAllBtn_Click(object sender, EventArgs e) { string token = await AuthenticationHelper.GetTokenForUserAsync(); if (token != null) { DateTime thisDay = DateTime.Now; HTTPResponse.AppendText("\r\n" + thisDay.ToString() + " - Deleting all custom polices from B2C.\r\n"); HttpResponseMessage response = null; response = await UserMode.HttpGetAsync(Constants.TrustFrameworkPolicesUri); HTTPResponse.AppendText(await response.Content.ReadAsStringAsync()); string content = await response.Content.ReadAsStringAsync(); PolicyList pL = JsonConvert.DeserializeObject <PolicyList>(content); foreach (Value policyValue in pL.Value) { response = await UserMode.HttpDeleteIDAsync(Constants.TrustFrameworkPolicesUri, Constants.TrustFrameworkPolicyByIDUri, policyValue.Id); string log = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode == true) { DateTime thisDayDeleted = DateTime.Now; HTTPResponse.AppendText("\r\n" + thisDayDeleted.ToString() + " - Successfully deleted " + policyValue.ToString() + "\r\n"); } else { HTTPResponse.AppendText(log); } } response = null; response = await UserMode.HttpGetAsync(Constants.TrustFrameworkPolicesUri); //HTTPResponse.AppendText(await response.Content.ReadAsStringAsync()); content = await response.Content.ReadAsStringAsync(); pL = JsonConvert.DeserializeObject <PolicyList>(content); UpdatePolicyList(pL); } }
private async void LoginBtn_Click(object sender, EventArgs e) { //Task<string> token = AuthenticationHelper.GetTokenForUserAsync(); string token = await AuthenticationHelper.GetTokenForUserAsync(); if (token != null) { HTTPResponse.AppendText("\r\nLogged in, getting Policies.\r\n"); HttpResponseMessage response = null; response = await UserMode.HttpGetAsync(Constants.TrustFrameworkPolicesUri); string content = await response.Content.ReadAsStringAsync(); HTTPResponse.AppendText(await response.Content.ReadAsStringAsync()); PolicyList pL = JsonConvert.DeserializeObject <PolicyList>(content); UpdatePolicyList(pL); } }
private async void UpdateAllPolicesBtn_Click(object sender, EventArgs e) { if (policyFolderLbl.Text != "No Folder selected.") { HTTPResponse.AppendText("\r\nUpdating selected policies.\r\n"); string token = await AuthenticationHelper.GetTokenForUserAsync(); if (token != null) { HttpResponseMessage response = null; string[] fileEntries = checkedPolicyList.CheckedItems.OfType <string>().ToArray(); List <string> fileList = new List <string>(fileEntries); //if we found ext file, move to top var regexExtensions = @"\w*Extensions\w*"; var indexExtensions = -1; indexExtensions = fileList.FindIndex(d => regexExtensions.Any(s => Regex.IsMatch(d.ToString(), regexExtensions))); if (indexExtensions > -1) { fileList.Insert(0, fileList[indexExtensions]); fileList.RemoveAt(indexExtensions + 1); } //if we found base file, move to top var regexBase = @"\w*Base\w*"; var indexBase = -1; indexBase = fileList.FindIndex(d => regexBase.Any(s => Regex.IsMatch(d.ToString(), regexBase))); if (indexBase > -1) { fileList.Insert(0, fileList[indexBase]); fileList.RemoveAt(indexBase + 1); } foreach (string file in fileList) { string xml = File.ReadAllText(policyFolderLbl.Text + @"\" + file); string fileName = file.Split('.')[0]; response = await UserMode.HttpPutIDAsync(Constants.TrustFrameworkPolicyByIDUriPUT, @"B2C_1A_" + fileName, xml); if (response.IsSuccessStatusCode == false) { HTTPResponse.AppendText(await response.Content.ReadAsStringAsync()); } else { HTTPResponse.AppendText("\r\nSuccefully updated " + file + "\r\n"); } } response = await UserMode.HttpGetAsync(Constants.TrustFrameworkPolicesUri); string content = await response.Content.ReadAsStringAsync(); //HTTPResponse.AppendText(await response.Content.ReadAsStringAsync()); if (response.IsSuccessStatusCode == true) { HTTPResponse.AppendText("\r\nSuccessfully updated policy list.\r\n"); } else { HTTPResponse.AppendText(content); } PolicyList pL = JsonConvert.DeserializeObject <PolicyList>(content); UpdatePolicyList(pL); } } }