private void HandleOnEndpointDisconnected(object sender, EndpointEventArgs e)
        {
            var id = e.Endpoint;

            var wasRemoved = false;

            lock (m_Lock)
            {
                if (m_EndpointConnectionProgress.ContainsKey(id))
                {
                    m_EndpointConnectionProgress.Remove(id);
                    wasRemoved = true;
                }

                Uri matchingUri = null;
                if (m_EndpointMap.ContainsKey(id))
                {
                    matchingUri = m_EndpointMap[id];
                    m_EndpointMap.Remove(id);
                    wasRemoved = true;
                }

                if ((matchingUri != null) && m_UriMap.ContainsKey(matchingUri))
                {
                    m_UriMap.Remove(matchingUri);
                    wasRemoved = true;
                }
            }

            if (wasRemoved)
            {
                RaiseOnEndpointDisconnected(id);
            }
        }
        public void Create()
        {
            var id   = new EndpointId("a");
            var args = new EndpointEventArgs(id);

            Assert.AreSame(id, args.Endpoint);
        }
        private void HandleOnEndpointConnected(object sender, EndpointEventArgs e)
        {
            var hasEndpointBeenApproved = false;

            var id = e.Endpoint;

            lock (m_Lock)
            {
                if (!m_EndpointConnectionProgress.ContainsKey(id))
                {
                    m_EndpointConnectionProgress.Add(id, new EndpointConnectionCompletionMap());
                }

                var map = m_EndpointConnectionProgress[id];
                map.HasBeenApprovedForProtocol      = map.HasBeenApprovedForProtocol || ReferenceEquals(sender, m_EndpointStorage);
                map.HasBeenApprovedForCommands      = map.HasBeenApprovedForCommands || ReferenceEquals(sender, m_Commands);
                map.HasBeenApprovedForNotifications = map.HasBeenApprovedForNotifications || ReferenceEquals(sender, m_Notifications);

                if (map.HasBeenApprovedForProtocol && map.HasBeenApprovedForCommands && map.HasBeenApprovedForNotifications)
                {
                    EndpointInformation information;
                    if (!m_EndpointStorage.TryGetConnectionFor(id, out information))
                    {
                        return;
                    }

                    if (!m_EndpointMap.ContainsKey(id))
                    {
                        m_EndpointMap.Add(id, information.DiscoveryInformation.Address);
                    }

                    if (!m_UriMap.ContainsKey(information.DiscoveryInformation.Address))
                    {
                        m_UriMap.Add(information.DiscoveryInformation.Address, id);
                    }

                    m_EndpointConnectionProgress.Remove(id);
                    hasEndpointBeenApproved = true;
                }
            }

            if (hasEndpointBeenApproved)
            {
                RaiseOnEndpointConnected(id);
            }
        }