private void OnChannelClosed(object sender, EventArgs e) { IMasterServerCallback hCb = sender as IMasterServerCallback; NodeReference hRef = HandleDisconnection(hCb); ChannelFaulted?.Invoke(hRef); }
public void Register(int iPort) { IMasterServerCallback hCb = OperationContext.Current.GetCallbackChannel <IMasterServerCallback>(); RemoteEndpointMessageProperty hEndPointProp = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; NodeReference hNewNode = new NodeReference(hCb, new IPEndPoint(IPAddress.Parse(hEndPointProp.Address), iPort)); (hNewNode as ICommunicationObject).Faulted += OnChannelFaulted; (hNewNode as ICommunicationObject).Closed += OnChannelClosed; m_hKnownPeers.TryAdd(hNewNode.RemoteEndPoint, hNewNode); }
private NodeReference HandleDisconnection(IMasterServerCallback hCb) { KeyValuePair <IPEndPoint, NodeReference> hRef = (from c in m_hKnownPeers where c.Value.Node == hCb select c).FirstOrDefault(); NodeReference hRes; if (hRef.Key != null && m_hKnownPeers.TryRemove(hRef.Key, out hRes)) { (hRef.Value as ICommunicationObject).Faulted -= OnChannelFaulted; (hRef.Value as ICommunicationObject).Closed -= OnChannelClosed; return(hRes); } else { return(null); } }
public NodeReference(IMasterServerCallback hCb, IPEndPoint hEp) { Node = hCb; RemoteEndPoint = hEp; }