public async Task <List <DiscoveredSsdpDevice> > Search() { deviceLocator = new SsdpDeviceLocator(); try { var foundDevices = deviceLocator.SearchAsync().Result.ToList(); if (foundDevices.Count > 0) { foreach (var device in foundDevices) { SsdpDevice info = await device.GetDeviceInfo().ConfigureAwait(false); var objs = new List <object> { device, info }; var foundDevice = auow.BuildObject <FoundDevice, List <object> >(objs); auow.Commit(foundDevice); } } return(foundDevices.ToList()); } catch (SocketException ex) { Console.WriteLine(ex.Message); throw; } }
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) { } }
private void ParseMessage(Message message) { foreach (var record in message.Answers) { if (message?.AdditionalRecords.Count > 0) { AddressRecord ARecord = (AddressRecord)message.AdditionalRecords.Find(x => x.Type.Equals(DnsType.A)); TXTRecord TRecord = (TXTRecord)message.AdditionalRecords.Find(x => x.Type.Equals(DnsType.TXT)); var services = Utils.LoadMdnsServices(); var name = record.Name.ToString(); if (services.Contains(name) && ARecord != null) { var foundDevice = BuildResponse(ARecord, TRecord); Uow.Commit(foundDevice); } } } }