private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { //var copy_cell = senderGrid.Rows[e.RowIndex].Cells["CopyIP"] as DataGridViewButtonCell; var restart_cell = senderGrid.Rows[e.RowIndex].Cells["RestartSS"] as DataGridViewButtonCell; var server = servers[e.RowIndex]; var extension = extenstions[server.Id]; //if (senderGrid.Columns[e.ColumnIndex].Name == "CopyIP") //{ // if (!string.IsNullOrWhiteSpace(servers[e.RowIndex].IP)) // { // Clipboard.SetText(servers[e.RowIndex].IP); // extension.IpCopied = true; // copy_cell.Value = "Copied"; // } //} if (senderGrid.Columns[e.ColumnIndex].Name == "RestartSS") { if (!string.IsNullOrWhiteSpace(servers[e.RowIndex].IP)) { ShadowsocksUtility.Restart(server.IP); extension.ShadowsocksRestarted = true; restart_cell.Value = "Restarted"; } } if (senderGrid.Columns[e.ColumnIndex].Name == "Start") { string command = "ec2 start-instances --instance-ids " + servers[e.RowIndex].Id; string result = AwsCommandUtility.Call(command); resultTextBox.Text += "\r\n" + result; Refresh(); } if (senderGrid.Columns[e.ColumnIndex].Name == "Stop") { string command = "ec2 stop-instances --instance-ids " + servers[e.RowIndex].Id; string result = AwsCommandUtility.Call(command); resultTextBox.Text = result; extension.IpCopied = false; extension.ShadowsocksRestarted = false; Refresh(); } if (senderGrid.Columns[e.ColumnIndex].Name == "SSH") { string result = AwsCommandUtility.Ssh(servers[e.RowIndex].PublicDns); resultTextBox.Text = result; } } }
public async Task <IActionResult> Stop(string id) { if (id == null) { return(NotFound()); } AwsCommandUtility.Stop(id); return(RedirectToAction(nameof(Index))); }
private void Refresh() { servers = AwsCommandUtility.GetServers(); bindingSource1.DataSource = servers; lastRefreshToolStripLabel.Text = "Last Refreshed: " + DateTime.Now.ToString(); //Fix extensions foreach (Server ec2 in servers) { if (!extenstions.ContainsKey(ec2.Id)) { extenstions.Add(ec2.Id, new ServerExtension()); } } for (int i = 0; i < servers.Count; i++) { var id = servers[i].Id; //var copy_cell = dataGridView1.Rows[i].Cells["CopyIP"] as DataGridViewButtonCell; //copy_cell.Value = extenstions[id].IpCopied?"Copied":""; var restart_cell = dataGridView1.Rows[i].Cells["RestartSS"] as DataGridViewButtonCell; restart_cell.Value = extenstions[id].IpCopied ? "Restarted" : ""; } }
public IActionResult Ec2() { string ec2 = AwsCommandUtility.Call("aws", "ec2 describe-instances"); return(Json(ec2)); }
public IActionResult Whoami() { string whoami = AwsCommandUtility.Call("whoami", null); return(Json(whoami)); }
public async Task <IActionResult> Index() { return(View(AwsCommandUtility.GetServers())); }