Пример #1
0
 private void OnNewDevice(DiscoveryDevice device)
 {
     // New device discovered
     if (OnOnvifDeviceDiscovered != null)
     {
         OnOnvifDeviceDiscovered(device);
     }
 }
Пример #2
0
        private void NotifyListener(DiscoveryDevice serviceDevice)
        {
            var listener = _discoveryListeners.FirstOrDefault(s => s.ServiceName == serviceDevice.Service);

            if (listener != null)
            {
                var listenerService = _neonManager.Resolve(listener.TypeName) as IDiscoveryDevice;

                listenerService?.OnDeviceDiscovered(serviceDevice);
            }
        }
Пример #3
0
        DiscoveryDevice CreateDevice(ProbeMatch probeMatch, IPEndPoint remoteEndpoint)
        {
            var    discoveryDevice = new DiscoveryDevice();
            string scopes          = probeMatch.Scopes;

            discoveryDevice.Address   = remoteEndpoint.Address.ToString();
            discoveryDevice.Model     = Regex.Match(scopes, "(?<=hardware/).*?(?= )")?.Value;
            discoveryDevice.Mfr       = ParseMfrFromScopes(scopes);
            discoveryDevice.XAdresses = ConvertToList(probeMatch.XAddrs);
            discoveryDevice.Types     = ConvertToList(probeMatch.Types);
            return(discoveryDevice);
        }
Пример #4
0
 IEnumerable <DiscoveryDevice> CreateDevices(XmlProbeReponse response, IPEndPoint remoteEndpoint)
 {
     foreach (var probeMatch in response.Body.ProbeMatches)
     {
         var discoveryDevice = new DiscoveryDevice();
         discoveryDevice.Address   = remoteEndpoint.Address;
         discoveryDevice.XAdresses = ConvertToList(probeMatch.XAddrs);
         discoveryDevice.Types     = ConvertToList(probeMatch.Types);
         discoveryDevice.Model     = ParseModelFromScopes(probeMatch.Scopes);
         discoveryDevice.Name      = ParseNameFromScopes(probeMatch.Scopes);
         yield return(discoveryDevice);
     }
 }
Пример #5
0
        DiscoveryDevice CreateDevice(XmlProbeReponse response, IPEndPoint remoteEndpoint)
        {
            var    discoveryDevice = new DiscoveryDevice();
            string scopes          = response.Body.ProbeMatches[0].Scopes;

            discoveryDevice.Address = remoteEndpoint.Address.ToString();
            discoveryDevice.Model   = Regex.Match(scopes, "(?<=hardware/).*?(?= )").Value;
            discoveryDevice.Mac     = GetMacAddress(discoveryDevice.Address);
            discoveryDevice.Mfr     = ParseMfrFromScopes(scopes);
            string xaddr = response.Body.ProbeMatches[0].XAddrs;
            Uri    uri   = new Uri(xaddr);

            discoveryDevice.Port = uri.Port;
            return(discoveryDevice);
        }
Пример #6
0
        private static void OnNewDevice(DiscoveryDevice device)
        {
            // Multiple events could be received at the same time.
            // The lock is here to avoid messing the console.
            lock (Console.Out)
            {
                Console.WriteLine(
                    $"Device model {device.Model} from manufacturer {device.Mfr} has address {device.Address}");
                Console.Write($"Urls to device: ");
                foreach (var address in device.XAdresses)
                {
                    Console.Write($"{address}, ");
                }

                Console.WriteLine("\n");
            }
        }
Пример #7
0
        private async void StartDiscovery()
        {
            var domains = await ZeroconfResolver.BrowseDomainsAsync();

            var responses = await ZeroconfResolver.ResolveAsync(domains.Select(g => g.Key));

            responses.ToList().ForEach(r =>
            {
                r.Services.ToList().ForEach(s =>
                {
                    var service = new DiscoveryDevice()
                    {
                        IpAddress = r.IPAddress,
                        Service   = s.Key.Split('.')[0],
                        Name      = s.Key,
                        Port      = s.Value.Port,
                        Ttl       = s.Value.Ttl
                    };

                    s.Value.Properties.ToList().ForEach(k =>
                    {
                        foreach (var(key, value) in k.ToList())
                        {
                            if (!service.Properties.ContainsKey(key))
                            {
                                service.Properties.Add(key, value);
                            }
                        }
                    });

                    var existService = DiscoveredDevices.FirstOrDefault(srvc =>
                                                                        srvc.IpAddress == service.IpAddress && srvc.Name == service.Name);

                    if (existService == null)
                    {
                        DiscoveredDevices.Add(service);
                    }
                });
            });


            _logger.LogInformation($"Found {DiscoveredDevices.Count} services on network");
        }
Пример #8
0
 public void OnDeviceDiscovered(DiscoveryDevice device)
 {
     AddDevice(device.Properties["id"], $"{device.IpAddress}:{device.Port}", device.Properties["fn"]);
 }