public SatIpDevice FindByUDN(string uuid)
        {
            SatIpDevice device = null;

            if (_devices.ContainsKey(uuid))
            {
                _devices.TryGetValue(uuid, out device);
            }
            return(device);
        }
 /// <summary>
 /// The UnicastReceiveCallback receives Http Responses
 /// and Fired the SatIpDeviceFound Event for adding the SatIpDevice
 /// </summary>
 /// <param name="ar"></param>
 private void UnicastReceiveCallback(IAsyncResult ar)
 {
     if (_running)
     {
         var u = ((UdpState)(ar.AsyncState)).U;
         var e = ((UdpState)(ar.AsyncState)).E;
         if (u.Client != null)
         {
             var responseBytes  = u.EndReceive(ar, ref e);
             var responseString = Encoding.UTF8.GetString(responseBytes);
             var httpMatch      = HttpResponseRegex.Match(responseString);
             if (httpMatch.Success)
             {
                 responseString = httpMatch.Groups[5].Captures[0].Value;
                 var    headerDictionary = ProcessSsdpResponse(responseString);
                 string location;
                 headerDictionary.TryGetValue("location", out location);
                 string st;
                 headerDictionary.TryGetValue("st", out st);
                 string usn;
                 headerDictionary.TryGetValue("usn", out usn);
                 string bootId;
                 headerDictionary.TryGetValue("bootid.upnp.org", out bootId);
                 string configId;
                 headerDictionary.TryGetValue("configid.upnp.org", out configId);
                 string deviceId;
                 headerDictionary.TryGetValue("deviceid.ses.com", out deviceId);
                 var m = UuidRegex.Match(usn);
                 if (!m.Success)
                 {
                     return;
                 }
                 var uuid = m.Value;
                 if ((!string.IsNullOrEmpty(location)) && (!string.IsNullOrEmpty(st)) && (st.Equals("urn:ses-com:device:SatIPServer:1")))
                 {
                     if (!_devices.ContainsKey(uuid))
                     {
                         var device = new SatIpDevice(location);
                         _devices.Add(uuid, device);
                         OnDeviceFound(new SatIpDeviceFoundArgs(device));
                     }
                 }
             }
             UnicastSetBeginReceive();
         }
     }
 }
 /// <summary>
 /// The MulticastReceiveCallback receives M-Search and Notify Responses
 /// M-Search Responses are ignored
 /// Notify Responses fires SatIpDeviceLost Event if nts.Equals(ssdp:byebye) for removing the Device
 /// or SatIpDeviceNotify Event if nts.Equals(ssdp:alive) for inform that the SatIp device is alive
 /// it can be used for initialize a new M-Seach Request too
 /// </summary>
 /// <param name="ar"></param>
 private void MulticastReceiveCallback(IAsyncResult ar)
 {
     if (_running)
     {
         var u = ((UdpState)(ar.AsyncState)).U;
         var e = ((UdpState)(ar.AsyncState)).E;
         if (u.Client != null)
         {
             var responseBytes  = u.EndReceive(ar, ref e);
             var responseString = Encoding.UTF8.GetString(responseBytes);
             var msearchMatch   = MSearchResponseRegex.Match(responseString);
             if (msearchMatch.Success)
             {
                 responseString = msearchMatch.Groups[3].Captures[0].Value;
                 var    headerDictionary = ProcessSsdpResponse(responseString);
                 string host;
                 headerDictionary.TryGetValue("host", out host);
                 string man;
                 headerDictionary.TryGetValue("man", out man);
                 string mx;
                 headerDictionary.TryGetValue("mx", out mx);
                 string st;
                 headerDictionary.TryGetValue("st", out st);
             }
             var notifyMatch = NotifyResponseRegex.Match(responseString);
             if (notifyMatch.Success)
             {
                 responseString = notifyMatch.Groups[3].Captures[0].Value;
                 var    headerDictionary = ProcessSsdpResponse(responseString);
                 string location;
                 headerDictionary.TryGetValue("location", out location);
                 string host;
                 headerDictionary.TryGetValue("host", out host);
                 string nt;
                 headerDictionary.TryGetValue("nt", out nt);
                 string nts;
                 headerDictionary.TryGetValue("nts", out nts);
                 string usn;
                 headerDictionary.TryGetValue("usn", out usn);
                 string bootId;
                 headerDictionary.TryGetValue("bootid.upnp.org", out bootId);
                 string configId;
                 headerDictionary.TryGetValue("configid.upnp.org", out configId);
                 var m = UuidRegex.Match(usn);
                 if (!m.Success)
                 {
                     return;
                 }
                 var uuid = m.Value;
                 if (nts != null &&
                     (nt != null && (nt.Equals("urn:ses-com:device:SatIPServer:1") && nts.Equals("ssdp:byebye"))))
                 {
                     if (usn != null)
                     {
                         if (_devices.ContainsKey(uuid))
                         {
                             _devices.Remove(uuid);
                         }
                         OnDeviceLost(new SatIpDeviceLostArgs(uuid));
                     }
                 }
                 if (nts != null &&
                     (nt != null && (nt.Equals("urn:ses-com:device:SatIPServer:1") && nts.Equals("ssdp:alive"))))
                 {
                     if (!string.IsNullOrEmpty(location))
                     {
                         if (!_devices.ContainsKey(uuid))
                         {
                             var device = new SatIpDevice(location);
                             _devices.Add(uuid, device);
                             OnDeviceFound(new SatIpDeviceFoundArgs(device));
                         }
                     }
                 }
             }
         }
         MulticastSetBeginReceive();
     }
 }
 public SatIpDeviceFoundArgs(SatIpDevice device)
 {
     Device = device;
 }