public void DiscoveryCallback(IAsyncResult ar) { UdpClient u = (UdpClient)((ShepherdUdpState)(ar.AsyncState)).client; IPEndPoint ip = (IPEndPoint)((ShepherdUdpState)(ar.AsyncState)).ip; XMLStream inputXMLStream = new XMLStream(); //IPEndPoint ip= new IPEndPoint(); XElement xmlDescription; string herdAgentXMLDescription; try { Byte[] receiveBytes = u.EndReceive(ar, ref ip); //if (!IsLocalIpAddress(ip.Address.ToString())) { herdAgentXMLDescription = Encoding.ASCII.GetString(receiveBytes); xmlDescription = XElement.Parse(herdAgentXMLDescription); HerdAgentInfo herdAgentInfo = new HerdAgentInfo(); herdAgentInfo.parse(xmlDescription); //we copy the ip address into the properties herdAgentInfo.ipAddress = ip; //we update the ack time DateTime now = DateTime.Now; herdAgentInfo.lastACK = now; lock (m_listLock) { if (!m_herdAgentList.ContainsKey(ip)) { m_herdAgentList.Add(ip, herdAgentInfo); } else { m_herdAgentList[ip] = herdAgentInfo; } } //check how much time ago the agent list was updated double lastUpdateElapsedTime = (now - m_lastHerdAgentListUpdate).TotalSeconds; //notify, if we have to, that the agent list has probably changed if (lastUpdateElapsedTime > m_herdAgentListUpdateTime) { m_lastHerdAgentListUpdate = now; if (m_notifyAgentListChanged != null) { m_notifyAgentListChanged(); } } } u.BeginReceive(new AsyncCallback(DiscoveryCallback), ar.AsyncState); } catch (TaskCanceledException ex) { logMessage("Task canceled exception in Shepherd"); logMessage(ex.ToString()); } catch (Exception ex) { logMessage("Exception in discovery callback function"); logMessage(ex.StackTrace); } }
public void DiscoveryCallback(IAsyncResult ar) { UdpClient u = (UdpClient)((ShepherdUdpState)(ar.AsyncState)).client; IPEndPoint ip = (IPEndPoint)((ShepherdUdpState)(ar.AsyncState)).ip; XMLStream inputXMLStream = new XMLStream(); //IPEndPoint ip= new IPEndPoint(); XElement xmlDescription; string herdAgentXMLDescription; try { Byte[] receiveBytes = u.EndReceive(ar, ref ip); //if (!IsLocalIpAddress(ip.Address.ToString())) { herdAgentXMLDescription = Encoding.ASCII.GetString(receiveBytes); xmlDescription = XElement.Parse(herdAgentXMLDescription); HerdAgentInfo herdAgentInfo = new HerdAgentInfo(); herdAgentInfo.parse(xmlDescription); //we copy the ip address into the properties herdAgentInfo.ipAddress = ip; //we update the ack time DateTime now = DateTime.Now; herdAgentInfo.lastACK = now; lock (m_listLock) { if (!m_herdAgentList.ContainsKey(ip)) m_herdAgentList.Add(ip, herdAgentInfo); else m_herdAgentList[ip] = herdAgentInfo; } //check how much time ago the agent list was updated double lastUpdateElapsedTime = (now - m_lastHerdAgentListUpdate).TotalSeconds; //notify, if we have to, that the agent list has probably changed if (lastUpdateElapsedTime > m_herdAgentListUpdateTime) { m_lastHerdAgentListUpdate = now; if (m_notifyAgentListChanged != null) m_notifyAgentListChanged(); } } u.BeginReceive(new AsyncCallback(DiscoveryCallback), ar.AsyncState); } catch(TaskCanceledException ex) { logMessage("Task canceled exception in Shepherd"); logMessage(ex.ToString()); } catch (Exception ex) { logMessage("Exception in discovery callback function"); logMessage(ex.StackTrace); } }
public HerdAgentViewModel(HerdAgentInfo info) { m_herdAgentInfo = info; }