private async void create_new_connection_button_Click(object sender, EventArgs e) { if (!IsValidTimeoutValue()) { MessageBox.Show("Please provide a valid number for the timeout value", "Invalid Timeout Value", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } PhantomInfo pi = new PhantomInfo(); pi.server_name = create_new_connection_host_textbox.Text; pi.server_address = create_new_connection_host_textbox.Text; pi.server_port = create_new_connection_port_textbox.Text; pi.worker_threads = create_new_connection_workers_textbox.Text; pi.timeout = create_new_connection_timeout_textbox.Text; pi.ipv6 = create_new_connection_ipv6_checkbox.Checked; pi.remove_ports = create_new_connection_remove_ports_checkbox.Checked; pi.debug = create_new_connection_debug_checkbox.Checked; pi.bind = create_new_connection_binding_textbox.Text; pi.bind_port = create_new_connection_binding_port_textbox.Text; await db.SavePhantomInfoAsync(pi); await UpdateConnectionsList(); create_new_connection_panel.Visible = false; }
public bool TryKillProcess(PhantomInfo phantomInfo) { if (_phantomProcessIds.TryGetValue(phantomInfo, out int processId) == false) { return(false); } var process = Process.GetProcessById(processId); process.Kill(); return(true); }
public Task <int> SavePhantomInfoAsync(PhantomInfo phantom_info) { PhantomInfo existing_phantom_info = GetPhantomInfoAsync(phantom_info.id).Result; if (existing_phantom_info == null) { return(Database.InsertAsync(phantom_info)); } else { return(Database.UpdateAsync(phantom_info)); } }
private async void create_new_connection_button_Click(object sender, EventArgs e) { PhantomInfo pi = new PhantomInfo(); pi.server_name = create_new_connection_host_textbox.Text; pi.server_address = create_new_connection_host_textbox.Text; pi.server_port = create_new_connection_port_textbox.Text; pi.worker_threads = create_new_connection_workers_textbox.Text; await db.SavePhantomInfoAsync(pi); await UpdateConnectionsList(); create_new_connection_panel.Visible = false; }
private PhantomInfoConnectPanel CreateNewPhantonInfoConnectionButton(PhantomInfo phantom_info) { PhantomInfoConnectPanel phantom_info_connection = new PhantomInfoConnectPanel(); phantom_info_connection.phantom_info = phantom_info; phantom_info_connection.Size = new Size(194, 70); phantom_info_connection.Parent = phantom_connections_panel; phantom_info_connection.Location = new Point(3, (phantom_info_control_panels_list.Count * phantom_info_connection.Height) + (3 * phantom_info_control_panels_list.Count)); phantom_info_control_panels_list.Add(phantom_info_connection); phantom_connections_panel.Controls.Add(phantom_info_connection); return(phantom_info_connection); }
public static string CreateParametersString(PhantomInfo pi) { string result; string phantomParameters = string.Format($"--server {pi.server_address}:{pi.server_port} --workers {pi.worker_threads}"); StringBuilder phantomOptions = new StringBuilder(); if (!string.IsNullOrEmpty(pi.timeout) && pi.timeout != "60") { phantomOptions.AppendFormat($" --timeout {pi.timeout}"); } if (pi.ipv6) { phantomOptions.AppendFormat($" --6={pi.ipv6.ToString().ToLower()}"); } if (pi.debug) { phantomOptions.AppendFormat($" --debug={pi.debug.ToString().ToLower()}"); } if (pi.remove_ports) { phantomOptions.AppendFormat($" --remove_ports={pi.remove_ports.ToString().ToLower()}"); } if (!string.IsNullOrEmpty(pi.bind)) { phantomOptions.AppendFormat($" --bind \"{pi.bind}\""); } if (!string.IsNullOrEmpty(pi.bind_port)) { phantomOptions.AppendFormat($" --bind_port {pi.bind_port}"); } if (phantomOptions.Length > 0) { result = string.Format($"{phantomOptions} {phantomParameters}"); } else { result = phantomParameters; } return(result); }
public bool TryStartProcess(PhantomInfo phantomInfo, string fileName) { var psi = new ProcessStartInfo(fileName, phantomInfo.AsParametersString()) { WindowStyle = ProcessWindowStyle.Hidden }; var process = new Process { StartInfo = psi }; if (process.Start() == false) { return(false); } _phantomProcessIds.Add(phantomInfo, process.Id); return(true); }
public bool TryCreatePhantomExecutable(PhantomInfo phantomInfo, out string exePath, string serverFolderPath = "./Servers/") { if (Directory.Exists(serverFolderPath) == false) { Directory.CreateDirectory(serverFolderPath); } exePath = serverFolderPath + phantomInfo.ServerName + "_phantom.exe"; try { using (var stream = new FileStream(exePath, FileMode.Create, FileAccess.Write)) { stream.Write(_baseExeBytes, 0, _baseExeBytes.Length); } return(true); } catch (Exception exception) { _onException?.Invoke(exception); return(false); } }
public static string CreateParametersString(PhantomInfo pi) { string parameters = "--server " + pi.server_address + ":" + pi.server_port + " --workers " + pi.worker_threads; return(parameters); }