// Process each found device in the event handler private async void deviceLocator_DeviceAvailable(object sender, DeviceAvailableEventArgs e) { if (DeviceFoundEvent == null) { return; } //Device data returned only contains basic device details and location of full device description. //Console.WriteLine("Found " + e.DiscoveredDevice.Usn + " at " + e.DiscoveredDevice.DescriptionLocation.ToString()); //Can retrieve the full device description easily though. try { SsdpDevice fullDevice = await e.DiscoveredDevice.GetDeviceInfo().ConfigureAwait(false); } catch (Exception ex) { // ToDo: Error Handling return; } DeviceFoundEventArgs eventArgs = new DeviceFoundEventArgs(); eventArgs.Usn = e.DiscoveredDevice.Usn; eventArgs.DescriptionLocation = e.DiscoveredDevice.DescriptionLocation.ToString(); //eventArgs.FriendlyName = fullDevice.FriendlyName; DeviceFoundEvent(this, eventArgs); }
private async void OnDeviceAvailable(object sender, DeviceAvailableEventArgs e) { var fullDevice = await e.DiscoveredDevice.GetDeviceInfo(); onDiscovered?.Invoke(e.DiscoveredDevice, fullDevice); updateCounter?.Invoke(); }
private void FoundDevice(object sender, DeviceAvailableEventArgs e) { if (e.DiscoveredDevice.Usn.Contains("6111f321-2cee-455e-b203-4abfaf14b516")) { status.Server = e.DiscoveredDevice.DescriptionLocation.Host; } }
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; } var dev = new DeviceInfo(info, usn); Log.Trace("Discovered " + dev.ModelName, tags: "camera." + dev.ModelName); if (usnToLumix.TryGetValue(usn, out var oldcamera)) { DeviceDiscovered2?.Invoke(dev, oldcamera); } else { DeviceDiscovered2?.Invoke(dev, null); } } catch (HttpRequestException e) { // var status = WebSocketError.GetStatus(ex.GetBaseException().HResult); Debug.WriteLine(e); // Ignore because GetDeviceInfo has problems } catch (Exception e) { Log.Error(e); } }
// Process each found device in the event handler void deviceLocator_DeviceAvailable(object sender, DeviceAvailableEventArgs e) { DeviceNames.Add(e.DiscoveredDevice.DescriptionLocation.ToString()); //Can retrieve the full device description easily though. /*var fullDevice = await e.DiscoveredDevice.GetDeviceInfo(); * try * { * if (fullDevice != null) * DeviceNames.Add(fullDevice.FriendlyName); * } * catch * { * Android.Util.Log.Debug("CommunicationController: searchFordevices method", "Null Error"); * }*/ DeviceCount++; }
// Process each found device in the event handler public async static void deviceLocator_DeviceAvailable(object sender, DeviceAvailableEventArgs e) { try { //Device data returned only contains basic device details and location of full device description. Console.WriteLine("Found " + e.DiscoveredDevice.Usn + " at " + e.DiscoveredDevice.DescriptionLocation.ToString()); //Can retrieve the full device description easily though. var fullDevice = await e.DiscoveredDevice.GetDeviceInfo(); Console.WriteLine(fullDevice.FriendlyName); Console.WriteLine(); } catch (Exception ex) { ConsoleLogger.Error(ex.Message); //continue; } }
// Process each found device in the event handler private void OnDeviceLocatorDeviceAvailable(object sender, DeviceAvailableEventArgs e) { var originalHeaders = e.DiscoveredDevice.ResponseHeaders; var headerDict = originalHeaders == null ? new Dictionary <string, KeyValuePair <string, IEnumerable <string> > >() : originalHeaders.ToDictionary(i => i.Key, StringComparer.OrdinalIgnoreCase); var headers = headerDict.ToDictionary(i => i.Key, i => i.Value.Value.FirstOrDefault(), StringComparer.OrdinalIgnoreCase); var args = new GenericEventArgs <UpnpDeviceInfo>( new UpnpDeviceInfo { Location = e.DiscoveredDevice.DescriptionLocation, Headers = headers, LocalIpAddress = e.LocalIpAddress }); DeviceDiscoveredInternal?.Invoke(this, args); }
private void DeviceLocator_DeviceAvailable(object sender, DeviceAvailableEventArgs e) { try { var info = e.DiscoveredDevice.GetDeviceInfo().GetAwaiter().GetResult(); var objects = new List <object> { e.DiscoveredDevice, info }; var device = Uow.BuildObject <FoundDevice, List <object> >(objects); Uow.Commit(device); } catch (TaskCanceledException) { } catch (HttpRequestException) { } }
// Process each found device in the event handler void deviceLocator_DeviceAvailable(object sender, DeviceAvailableEventArgs e) { var originalHeaders = e.DiscoveredDevice.ResponseHeaders; var headerDict = originalHeaders == null ? new Dictionary <string, KeyValuePair <string, IEnumerable <string> > >() : originalHeaders.ToDictionary(i => i.Key, StringComparer.OrdinalIgnoreCase); var headers = headerDict.ToDictionary(i => i.Key, i => i.Value.Value.FirstOrDefault(), StringComparer.OrdinalIgnoreCase); var args = new GenericEventArgs <UpnpDeviceInfo> { Argument = new UpnpDeviceInfo { Location = e.DiscoveredDevice.DescriptionLocation, Headers = headers } }; EventHelper.FireEventIfNotNull(DeviceDiscovered, this, args, _logger); }
private void DeviceLocator_DeviceAvailable(object sender, DeviceAvailableEventArgs e) { try { var device = e.DiscoveredDevice; var infoDevice = device.GetDeviceInfo().ConfigureAwait(false).GetAwaiter().GetResult(); var objs = new List <object> { device, infoDevice }; var foundDevice = auow.BuildObject <FoundDevice, List <object> >(objs); FoundDeviceCollection.Add(foundDevice); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Handles the DeviceAvailable event of the DeviceLocator control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DeviceAvailableEventArgs"/> instance containing the event data.</param> private async void DeviceLocator_DeviceAvailableAsync(object sender, DeviceAvailableEventArgs e) { if (!e.IsNewlyDiscovered) { Debug.WriteLine("AVAIL DEVICE EVENT --> " + e.DiscoveredDevice.NotificationType + ": " + e.DiscoveredDevice.DescriptionLocation); } else { var foundDevice = e.DiscoveredDevice; Debug.WriteLine("New DEVICE FOUND: " + foundDevice.Usn + " at " + foundDevice.DescriptionLocation.ToString()); // Can retrieve the full device description easily though. var fullDevice = await foundDevice.GetDeviceInfo().ConfigureAwait(false); Debug.WriteLine(fullDevice.FriendlyName); var result = await RenderDeviceAsync(foundDevice.DescriptionLocation.ToString()).ConfigureAwait(false); if (result != null && DeviceFound != null) { DeviceFound(this, result); } } }
static void _BroadcastListener_DeviceAvailable(object sender, DeviceAvailableEventArgs e) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Alive Broadcast: " + e.DiscoveredDevice.Usn + " @ " + e.DiscoveredDevice.DescriptionLocation); Console.ForegroundColor = ConsoleColor.Gray; }
async void DeviceLocator_DeviceAvailable(object sender, DeviceAvailableEventArgs e) { //Device data returned only contains basic device details and location of full device description. Debug.WriteLine("UPnP Found: " + e.DiscoveredDevice.Usn + " at " + e.DiscoveredDevice.DescriptionLocation.ToString()); try { //Can retrieve the full device description easily though. SsdpDevice fullDevice = await e.DiscoveredDevice.GetDeviceInfo(); Debug.WriteLine("\t Name=" + fullDevice.FriendlyName); Debug.WriteLine(""); // If we don't have a serial number for this device, we need to construct one. string serialNumber = fullDevice.Uuid + "|" + fullDevice.ModelDescription + "|" + fullDevice.ModelName + "|" + fullDevice.ModelNumber + "|" + fullDevice.ModelUrl + "|" + fullDevice.PresentationUrl; if (null != fullDevice.SerialNumber) { serialNumber = fullDevice.SerialNumber; } ISensorItem videoCameraSensorItem = null; IDeviceItem videoCameraDeviceItem = await App.DeviceCollection.BeginFindBySerialNumber(serialNumber); if (null == videoCameraDeviceItem) { // No device was found to contain this camera. Build the device and the sensor. videoCameraDeviceItem = await this.CreateVideoDevice(fullDevice, serialNumber); Debug.Assert(null != videoCameraDeviceItem); videoCameraSensorItem = await this.CreateVideoSensor(fullDevice, serialNumber, videoCameraDeviceItem); Debug.Assert(null != videoCameraSensorItem); } else if ((null != fullDevice.PresentationUrl) && (videoCameraDeviceItem.IPAddress != fullDevice.PresentationUrl.ToString())) { // The IP address of the camera changed. We need to refresh the device. await App.DeviceCollection.BeginDelete(videoCameraDeviceItem); videoCameraDeviceItem = await this.CreateVideoDevice(fullDevice, serialNumber); Debug.Assert(null != videoCameraDeviceItem); videoCameraSensorItem = await this.CreateVideoSensor(fullDevice, serialNumber, videoCameraDeviceItem); Debug.Assert(null != videoCameraSensorItem); } else if (videoCameraDeviceItem.Sensors.Count == 0) { // We have a device to hold the camera, but no camera sensor. We need to build the sensor. videoCameraSensorItem = await this.CreateVideoSensor(fullDevice, serialNumber, videoCameraDeviceItem); Debug.Assert(null != videoCameraSensorItem); } else { videoCameraDeviceItem.IsOnline = true; } } catch (Exception ex) { Debug.WriteLine("\t Unable to get device info. " + ex.Message); } }
public void DeviceAvailableEventArgs_Constructor_ThrowsOnNullDevice() { var args = new DeviceAvailableEventArgs(null, true); }