private void btnFind_Click(object sender, EventArgs e) { try { btnStartStop.Text = StartText; lstNodes.Items.Clear(); var projectName = txtProjectName.Text; var host = txtHost.Text; var textPort = txtPort.Text; var user = txtUserName.Text; var password = txtPassword.Text; if (string.IsNullOrEmpty(projectName.Trim())) { MessageBox.Show("Project name field cannot be empty!"); return; } if (!ushort.TryParse(textPort, out ushort port)) { MessageBox.Show("Port must be numeric and in range [0; 65535]!"); return; } GNS3sharp.SetCredentials(user, password); var projectId = ServerProjects.GetProjectIDByName(projectName, host, port); if (string.IsNullOrEmpty(projectId)) { MessageBox.Show($"Project with name {projectName} isn't found!"); return; } bwoGNS.SetGns3Data(projectName, projectId, host, port); bwGNS3_API.RunWorkerAsync(sender); } catch (Exception ex) { MessageBox.Show("Internal error occur! Check log file."); LoggingHelper.LogEntry(SystemCategories.GeneralError, $"{ex.Message} {ex.StackTrace}"); } }
public void DoWork(object obj) { if (obj is Button btn) { switch (btn.Name) { case "btnFind": Handler = new GNS3sharp(projectId, SetTextLabel1, host, port); UpdateNodesTable(); break; case "btnReloadStatus": Handler.UpdateProject(); UpdateNodesTable(); break; case "btnStartStop": string text = btn.Text; if (text == StartText) { Handler.StartProject(); StartProject(btn); bwListener.RunWorkerAsync(); } else if (text == StopText) { var res = ShowMessageWithResult("Are you want to stop all nodes?"); if (res) { Handler.StopProject(); } StopProject(btn); bwListener.CancelAsync(); } UpdateNodesTable(); break; } } else if (obj is ToolStripItem tsi) { string item = GetSelectedNodeName(); var selectedNode = Handler.GetNodeByName(item); switch (tsi.Name) { case "tsStart": Handler.StartNode(selectedNode); break; case "tsStop": Handler.StopNode(selectedNode); break; case "tsReload": Handler.ReloadNode(selectedNode); break; case "tsSuspend" when selectedNode is Router || selectedNode is Switch: Handler.SuspendNode(selectedNode); break; default: MessageBox.Show("Incorrect menu item selected!"); break; } SetNodeStatus(selectedNode.GetStatus); } }