protected void OnRaiseUserEvent(UserEventArgs args) { // Make a temporary copy of the event to avoid the possibility of // a race condition if the last subscriber unsubscribes immediately // after the null check and before the event is raised. // This is modeled after: http://msdn.microsoft.com/en-us/library/w369ty8x.aspx // TODO: It might be nice to understand the details of what race condition this is preventing. EventHandler<UserEventArgs> handler = RaiseUserEvent; // Event will be null if there are no subscribers if (handler != null) { handler(this, args); } }
public void HandleUserEvent(object sender, UserEventArgs args) { switch (args.EventType) { case "LineReady": // For now, ignore lines sent by the user. break; case "Disconnect": // Break the listening relationship with the disconnected sender. // We remain connected to the world, and recieve ResponseEvents from it. RemoveSource(sender as IResponseConsumer); break; default: throw new NotImplementedException(String.Format("Unsupported EventType: {0}", args.EventType)); } }
public override void HandleUserEvent(object sender, UserEventArgs args) { switch (args.EventType) { case "LineReady": var lineArgs = args as LineReadyEventArgs; string line = lineArgs.Line.Trim(); HandleLineReadyEvent(sender, line); break; case "Disconnect": // Break the listening relationship with the disconnected sender. RemoveSource(sender as IResponseConsumer); break; default: throw new NotImplementedException(String.Format("Unsupported EventType: {0}", args.EventType)); } }
// Just pass the event through. // TODO: Annotate the event with the account. public void HandleUserEvent(object sender, UserEventArgs args) { if (args.EventType == "Disconnect") { // Break the listening relationship with the disconnected sender. RemoveSource(sender as IResponseConsumer); } // Reraise the event, whether or not it's a disconnection. OnRaiseUserEvent(args); }