private MTConnectDevices.Document GetProbe(Data.AgentInfo config) { MTConnectDevices.Document result = null; string address = config.Address; int port = config.Port; string deviceName = config.DeviceName; //// Set Proxy Settings //var proxy = new HTTP.ProxySettings(); //proxy.Address = config.ProxyAddress; //proxy.Port = config.ProxyPort; DateTime requestTimestamp = DateTime.Now; // Create Agent Url var protocol = "http://"; var adr = address; if (adr.IndexOf(protocol) >= 0) { adr = adr.Substring(protocol.Length); } else { adr = protocol + adr; } var url = adr; if (port > 0 && port != 80) { url += ":" + port; } // Send Probe Request var probe = new MTConnect.Clients.Probe(url, deviceName); result = probe.Execute(); if (result != null) { if (verbose) { logger.Info("Probe Successful : " + url + " @ " + requestTimestamp.ToString("o")); } } else { logger.Warn("Probe Error : " + url + " @ " + requestTimestamp.ToString("o") + " : Retrying in " + (config.Heartbeat / 1000) + " sec.."); } return(result); }
private void AddDevice_Worker(object o) { var info = (AddDeviceInfo)o; bool success = false; DeviceConfiguration config = null; if (info != null) { // Create Agent Url var protocol = "http://"; var adr = info.Address; if (adr.IndexOf(protocol) >= 0) { adr = adr.Substring(protocol.Length); } else { adr = protocol + adr; } var url = adr; if (info.Port > 0 && info.Port != 80) { url += ":" + info.Port; } // Send Probe Request var probe = new MTConnect.Clients.Probe(url, info.DeviceName); var document = probe.Execute(); if (document != null) { var probeData = new Configuration.ProbeData(); probeData.Address = info.Address; probeData.Port = info.Port.ToString(); probeData.Device = document.Devices[0]; config = Configuration.Create(probeData); // Add Device to user (or save to disk if local) if (info.CurrentUser != null) { success = TrakHound.API.Devices.Update(info.CurrentUser, config); } else { success = DeviceConfiguration.Save(config); } } } Dispatcher.BeginInvoke(new Action(() => { Loading = false; if (success) { // Send message that device was added var data = new EventData(this); data.Id = "DEVICE_ADDED"; data.Data01 = new DeviceDescription(config); SendData?.Invoke(data); TrakHound_UI.MessageBox.Show("Device added successfully!", "Add Device Successful", TrakHound_UI.MessageBoxButtons.Ok); } else { TrakHound_UI.MessageBox.Show("Error during Add Device. Please Try Again.", "Add Device Error", TrakHound_UI.MessageBoxButtons.Ok); } }), System.Windows.Threading.DispatcherPriority.Background, new object[] { }); }