//public void Del /// <summary> /// Delete a once listener. /// </summary> /// <param name="proto">the proto name of the listener</param> public void DelOnceListener(ProtoName proto) { if (onceListeners.ContainsKey(proto)) { onceListeners.Remove(proto); } }
public static ProtocolBytes GetProtocolHead(ProtoName protoName) { ProtocolBytes proto = new ProtocolBytes(); proto.AddInt((int)protoName); return(proto); }
/// <summary> /// Add a listener to the list /// </summary> /// <param name="name"> the ProtoName</param> /// <param name="callBack">the feed back method</param> public void AddListenerEvent(ProtoName name, ProtocolProcessor callBack) { try { proDic[(int)name] += callBack; } catch (Exception e) { Console.WriteLine(e); } }
/// <summary> /// Add once listener /// </summary> /// <param name="name">name of the listener</param> /// <param name="callBack">the call back function</param> public void AddOnceListener(ProtoName _name, ProtocolProcessor callBack) { if (onceListeners.Keys.Contains(_name)) { onceListeners[_name] += callBack; } else { onceListeners.Add(_name, callBack); } }
/// <summary> /// To handle a protocol. /// First handle listener and if not handle once listener. /// (First patron and then new costomer) /// </summary> /// <param name="protocol">The protocol to handle</param> private void Handle(ProtocolBase protocol) { int number = protocol.GetNumber(); ProtoName pn = (ProtoName)number; Debug.Log("Accept" + pn.ToString()); //Debug.Log("Contain key" + pn.ToString() + " " + proDic.ContainsKey(number)); //Debug.Log("Contain listener" + pn.ToString() + " " + listeners.Contains(pn)); if (proDic.ContainsKey(number))//&& listeners.Contains(pn) { proDic[number](protocol); Debug.Log("Handle listener" + pn.ToString()); } //Debug.Log("Contain once listener" + pn.ToString() + " " + onceListeners.ContainsKey(pn)); if (onceListeners.ContainsKey(pn)) { onceListeners[pn](protocol); onceListeners.Remove(pn); Debug.Log("Handle once listener" + pn.ToString()); } }