async void ModifyPassword(object sender, RoutedEventArgs e) { string instanceId = GetSelectedInstance(); if (instanceId != "Not found") { var url = ECSAPI.ModifyPassword(instanceId); using (var httpClient = new HttpClient()) { try { var response = await httpClient.GetAsync(url); response.EnsureSuccessStatusCode(); MessageBox.Show("Action succeeded."); GetInstanceList(this, new RoutedEventArgs()); } catch (Exception exc) { MessageBox.Show(exc.ToString()); return; } } } else { MessageBox.Show("Please select an instance."); } }
async void CreateInstance(object sender, RoutedEventArgs e) { Window instanceTypeWnd = new SpecifyInstanceType(); instanceTypeWnd.Owner = this; Hide(); instanceTypeWnd.ShowDialog(); var url = ECSAPI.CreateInstance(imageType); using (var httpClient = new HttpClient()) { try { var response = await httpClient.GetAsync(url); response.EnsureSuccessStatusCode(); MessageBox.Show("Action succeeded."); GetInstanceList(this, new RoutedEventArgs()); } catch (Exception exc) { MessageBox.Show(exc.ToString()); return; } } }
async void DeleteInstance(object sender, RoutedEventArgs e) { string instanceId = GetSelectedInstance(); if (instanceId != "Not found") { var url = ECSAPI.DeleteInstance(instanceId); var radios = InstanceList.Children.OfType <RadioButton>(); string instanceAlias = ""; foreach (var ctrl in radios) { if (ctrl.IsChecked == true) { instanceAlias = ctrl.Content.ToString(); break; } } MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to delete instance " + instanceAlias + "?", "Confirm your operation", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.No) { return; } using (var httpClient = new HttpClient()) { try { var response = await httpClient.GetAsync(url); response.EnsureSuccessStatusCode(); MessageBox.Show("Action succeeded."); GetInstanceList(this, new RoutedEventArgs()); } catch (Exception exc) { MessageBox.Show(exc.ToString()); return; } } } else { MessageBox.Show("Please select an instance."); } }
async void GetInstanceList(object sender, RoutedEventArgs e) { var url = ECSAPI.GetInstanceList(); string content; //Clipboard.SetText(url); return; using (var httpClient = new HttpClient()) { try { var response = await httpClient.GetAsync(url); response.EnsureSuccessStatusCode(); content = await response.Content.ReadAsStringAsync(); RefreshInstanceList(content); } catch (Exception exc) { MessageBox.Show(exc.ToString()); return; } } }