using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Tango.PMR.Discovery; using Tango.Transport.Discovery; namespace Tango.BuildExtensions { public partial class RemoteDebugForm : Form { private bool closed; public class RemoteRunnerService { public String Address { get; set; } public String HostName { get; set; } public int Port { get; set; } public override string ToString() { return String.Format("[{0}] - [{1}:{2}]", HostName, Address, Port); } } private UdpDiscoveryClient _discoveryClient; public RemoteRunnerService SelectedRemoteRunner { get; set; } public RemoteDebugForm(String projectName) { InitializeComponent(); txtProjectName.Text = projectName; btnOK.Click += BtnOK_Click; btnCancel.Click += BtnCancel_Click; btnOK.Enabled = false; _discoveryClient = new UdpDiscoveryClient(2018); _discoveryClient.ServiceDiscovered += _discoveryClient_ServiceDiscovered; listServices.SelectedIndexChanged += ListServices_SelectedIndexChanged; } private void ListServices_SelectedIndexChanged(object sender, EventArgs e) { btnOK.Enabled = listServices.SelectedItem != null; } private void _discoveryClient_ServiceDiscovered(object sender, DiscoveredService e) { if (!closed) { BeginInvoke(new Action(() => { if (e.Message.ServiceName == "Tango Remote Runner") { if (!listServices.Items.OfType().ToList().Exists(x => x.Address == e.Address)) { listServices.Items.Add(new RemoteRunnerService() { Address = e.Address, HostName = e.HostName, Port = e.Message.Port, }); } } })); } } private void BtnCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } private void BtnOK_Click(object sender, EventArgs e) { if (listServices.SelectedItem != null) { SelectedRemoteRunner = listServices.SelectedItem as RemoteRunnerService; DialogResult = DialogResult.OK; Close(); } } protected override void OnShown(EventArgs e) { base.OnShown(e); _discoveryClient.Start(); } protected override void OnClosed(EventArgs e) { closed = true; _discoveryClient.Stop(); } } }