public virtual void AddEdgeListener(EdgeListener el) { /* The EdgeFactory needs to be made aware of all EdgeListeners */ _edge_factory.AddListener(el); _edgelistener_list.Add(el); /** * It is ESSENTIAL that the EdgeEvent of EdgeListener objects * be connected to the EdgeHandler method of ConnectionPacketHandler */ el.EdgeEvent += this.EdgeHandler; el.EdgeCloseRequestEvent += delegate(object elsender, EventArgs args) { EdgeCloseRequestArgs ecra = (EdgeCloseRequestArgs)args; Close(ecra.Edge); }; }
///<summary>This handles the RequestClose of the underlying edge.</summary> ///<remarks> /// The convoluted model for handling edge closes is this... /// I) UEL calls RequestClose /// 1) Triggers HandleEdgeCloseRequestEvent /// 2) If there is a wrapper edge, call RequestClose on it /// 3) If there isn't a wrapper edge, we are forced to simply close the edge and send a failed ecw /// II) A wrapper edge is responsible for calling edge close on the wrapped edge on edge close /// III) if an wrapped edge calls close, we are notified via an event, that will send a failed ecw or close the wrapper edge /// </remarks> protected void HandleEdgeCloseRequestEvent(object el, EventArgs ea) { EdgeCloseRequestArgs ecra = ea as EdgeCloseRequestArgs; if (ecra == null) { throw new Exception("Not an EdgeCloseRequestArgs!"); } EdgeCreationWrapper ecw = null; Edge e = null; lock (_sync) { if (_edge_to_ecw.ContainsKey(ecra.Edge)) { ecw = _edge_to_ecw[ecra.Edge]; _edge_to_ecw.Remove(ecra.Edge); } else if (_edge_to_wrapper_edge.ContainsKey(ecra.Edge)) { e = _edge_to_wrapper_edge[ecra.Edge]; _edge_to_wrapper_edge.Remove(ecra.Edge); } } if (e != null) { RequestClose(e); } else { ecra.Edge.Close(); if (ecw != null) { ecw.CreationCallback(false, null, new EdgeException("Requested close on an unwrapped edge.")); } } }