private void Sniffer_DeviceFound(TrakHound.MTConnectSniffer.MTConnectDevice device)
        {
            if (device != null && device.IpAddress != null && !string.IsNullOrEmpty(device.DeviceName))
            {
                // Create Agent Url
                var protocol = "http://";
                var adr      = device.IpAddress.ToString();
                if (adr.IndexOf(protocol) >= 0)
                {
                    adr = adr.Substring(protocol.Length);
                }
                else
                {
                    adr = protocol + adr;
                }
                var url = adr;
                if (device.Port > 0 && device.Port != 80)
                {
                    url += ":" + device.Port;
                }

                // Run Probe Request
                var probe = new MTConnect.Clients.Probe(url, device.DeviceName);
                probe.Successful += Probe_Successful;
                probe.UserObject  = device;
                probe.ExecuteAsync();
            }
        }
        //class Probe_Info
        //{
        //    public string address;
        //    public int port;
        //    public string deviceName;
        //    //public MTConnect.HTTP.ProxySettings proxy;
        //}

        void RunProbe(string address, int port, string deviceName)
        {
            // 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;
            }

            // Run Probe Request
            var probe = new MTConnect.Clients.Probe(url, deviceName);

            probe.Successful += Probe_Successful;
            probe.ExecuteAsync();
        }
Exemplo n.º 3
0
        private void TestConnection()
        {
            var info = new TestConnectionInfo();

            info.Address = Address;
            int port = 0;

            if (int.TryParse(Port, out port))
            {
            }
            else
            {
                port = 80;
            }
            info.Port       = port;
            info.DeviceName = DeviceName;

            if (!string.IsNullOrEmpty(info.Address) && port > 0 && !string.IsNullOrEmpty(info.DeviceName))
            {
                ConnectionTestLoading    = true;
                ConnectionTestResult     = 0;
                ConnectionTestResultText = 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 (port > 0 && port != 80)
                {
                    url += ":" + port;
                }

                // Send Probe Request
                var probe = new MTConnect.Clients.Probe(url, info.DeviceName);
                probe.Successful      += Probe_Successful;
                probe.Error           += Probe_Error;
                probe.ConnectionError += Probe_ConnectionError;
                probe.ExecuteAsync();
            }
            else
            {
                ConnectionTestResult     = -1;
                ConnectionTestResultText = "Incorrect Information. Be sure to enter in the IP Address, Port, and Device Name and Try Again.";
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        private void SendProbe(IPAddress address, int port)
        {
            var uri = new UriBuilder("http", address.ToString(), port);

            var probe = new MTConnect.Clients.Probe(uri.ToString());

            probe.UserObject       = new ProbeSender(address, port);
            probe.Successful      += Probe_Successful;
            probe.Error           += Probe_Error;
            probe.ConnectionError += Probe_ConnectionError;
            sentProbeRequests++;
            probe.ExecuteAsync();
        }
Exemplo n.º 6
0
        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[] { });
        }