private async void ServerConsoleContextMenu_Click(object sender, RoutedEventArgs e) { lkcode.hetznercloudapi.Api.Server server = this.ServerDataGrid.SelectedItem as lkcode.hetznercloudapi.Api.Server; ServerActionResponse serverActionResponse = null; try { this.AddLogMessage(string.Format("get console for server '{0}'", server.Name)); serverActionResponse = await server.RequestConsole(); ServerConsoleData consoleData = (serverActionResponse.AdditionalActionContent as ServerConsoleData); string consoleUrl = consoleData.Url; string consolePassword = consoleData.Password; this.AddLogMessage(string.Format("success: get console for server '{0}'", server.Name)); this.AddLogMessage(string.Format("note: url is '{0}'", consoleUrl)); this.AddLogMessage(string.Format("note: password is '{0}'", consolePassword)); } catch (Exception err) { this.AddLogMessage(string.Format("error: {0}", err.Message)); } }
private async void CreateServerButton_Clicked(object sender, RoutedEventArgs e) { try { Server newServer = new Server(); Image createIsoImage = null; bool startAfterCreate = true; bool hasError = false; // required fields // server-name if (!string.IsNullOrEmpty(this.ServerNameTextBox.Text) && !string.IsNullOrWhiteSpace(this.ServerNameTextBox.Text)) { newServer.Name = this.ServerNameTextBox.Text; } else { hasError = true; await this.ShowMessageAsync("error at server.create", "server-name is empty or invalid"); return; } // server-type if (this.ServerTypesDataGrid.SelectedItem != null) { ServerType ServerType = (this.ServerTypesDataGrid.SelectedItem as ServerType); newServer.ServerType = ServerType; } else { hasError = true; await this.ShowMessageAsync("error at server.create", "server-type is empty or invalid"); return; } // server-type if (this.ImageDataGrid.SelectedItem != null) { createIsoImage = (this.ImageDataGrid.SelectedItem as Image); } else { hasError = true; await this.ShowMessageAsync("error at server.create", "iso-image is empty or invalid"); return; } // optional fields if (this.StartAfterCreateToggleSwitch.IsChecked.HasValue) { startAfterCreate = this.StartAfterCreateToggleSwitch.IsChecked.Value; } if (!hasError) { ServerActionResponse action = await newServer.SaveAsync(createIsoImage, startAfterCreate); if (action.Error != null) { // error await this.ShowMessageAsync("error at server.create api exception", action.Error.Message); } else { // success string password = (action.AdditionalActionContent as string); await this.ShowMessageAsync("success at server.create", string.Format("server created with id {0} and password '{1}'.", newServer.Id, password)); } } } catch (Exception err) { await this.ShowMessageAsync("error at server.create", err.Message); } }