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); } }
IEnumerable <DiscoveryDevice> ProcessResponses(IEnumerable <UdpReceiveResult> responses) { foreach (var response in responses) { if (response.Buffer != null) { string strResponse = Encoding.UTF8.GetString(response.Buffer); XmlProbeReponse xmlResponse = DeserializeResponse(strResponse); foreach (var device in CreateDevices(xmlResponse, response.RemoteEndPoint)) { yield return(device); } } } }
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); }
DiscoveryDevice ProcessResponse(UdpReceiveResult response, Guid messageId) { if (response.Buffer != null) { string strResponse = Encoding.UTF8.GetString(response.Buffer); XmlProbeReponse xmlResponse = DeserializeResponse(strResponse); if (IsFromProbeMessage(messageId, xmlResponse) && xmlResponse.Body.ProbeMatches.Any() && !string.IsNullOrEmpty(xmlResponse.Body.ProbeMatches[0].Scopes)) { return(CreateDevice(xmlResponse.Body.ProbeMatches[0], response.RemoteEndPoint)); } } return(null); }
List <DiscoveryDevice> ProcessResponses(IEnumerable <UdpReceiveResult> responses) { var processedResponse = new List <DiscoveryDevice> (); foreach (var response in responses) { if (response.Buffer != null) { string strResponse = Encoding.UTF8.GetString(response.Buffer); XmlProbeReponse xmlResponse = DeserializeResponse(strResponse); if (!String.IsNullOrEmpty(xmlResponse.Body.ProbeMatches[0].Scopes)) { processedResponse.Add(CreateDevice(xmlResponse, response.RemoteEndPoint)); } } } return(processedResponse); }
IEnumerable <DiscoveryDevice> ProcessResponses(IEnumerable <UdpReceiveResult> responses, Guid messageId) { var processedResponse = new List <DiscoveryDevice> (); foreach (var response in responses) { if (response.Buffer != null) { string strResponse = Encoding.UTF8.GetString(response.Buffer); XmlProbeReponse xmlResponse = DeserializeResponse(strResponse); if (IsFromProbeMessage(messageId, xmlResponse) && xmlResponse.Body.ProbeMatches.Any() && !string.IsNullOrEmpty(xmlResponse.Body.ProbeMatches[0].Scopes)) { var device = CreateDevice(xmlResponse.Body.ProbeMatches[0], response.RemoteEndPoint); processedResponse.Add(device); } } } return(processedResponse); }
bool IsFromProbeMessage(Guid messageId, XmlProbeReponse response) { return(response.Header.RelatesTo.Contains(messageId.ToString())); }