Beispiel #1
0
        private async void DeviceLocator_DeviceAvailable(object sender, DeviceAvailableEventArgs arg)
        {
            try
            {
                var usn  = arg.DiscoveredDevice.Usn;
                var host = arg.DiscoveredDevice.DescriptionLocation.Host;
                lock (foundDevices)
                {
                    if (foundDevices.Contains(usn + host))
                    {
                        Debug.WriteLine("Discovered but already found: " + usn, "Discovery");
                        return;
                    }

                    Debug.WriteLine("Discovered new: " + usn, "Discovery");

                    foundDevices.Add(usn + host);
                }

                if (!arg.DiscoveredDevice.ResponseHeaders.TryGetValues("SERVER", out var values) || !values.Any(s => s.Contains("Panasonic")))
                {
                    return;
                }

                var info = await arg.DiscoveredDevice.GetDeviceInfo() as SsdpRootDevice;

                if (info == null)
                {
                    return;
                }

                if (info.ModelName != "LUMIX")
                {
                    return;
                }

                if (usnToLumix.TryGetValue(usn, out var oldcamera))
                {
                    await oldcamera.Disconnect(false);

                    lock (foundDevices)
                    {
                        foundDevices.Add(usn + host);
                    }
                }

                var dev = new DeviceInfo(info, usn);
                Log.Trace("Discovered " + dev.ModelName, tags: "camera." + dev.ModelName);
                OnDeviceDiscovered(dev);
            }
            catch (HttpRequestException e)
            {
                // var status = WebSocketError.GetStatus(ex.GetBaseException().HResult);
                Debug.WriteLine(e);

                // Ignore because GetDeviceInfo has problems
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Beispiel #2
0
 protected void OnDeviceDiscovered(DeviceInfo obj)
 {
     DeviceDiscovered?.Invoke(obj);
 }