/// <summary> /// Adds the specified event to the registration. /// </summary> /// <param name="type">IProcEventAction to add.</param> public void AddEvent(IProcEventAction type) { XmlElement element = document.CreateElement(EventTag); element.SetAttribute(EventActionTag, type.ToString()); document.DocumentElement.AppendChild(element); }
/// <summary> /// Starts subscribing to or unsubscribing from the specified event. /// </summary> /// <param name="action">Action to take regarding the event.</param> /// <param name="handler">Delegate that gets called when specified event happens or is /// to be removed.</param> public void SetEvent(IProcEventAction action, IProcEventHandler handler) { lock ( subscribeLock ) { // Queue the event so that if the client is not connected to the server, the event // can be registered after the connection is made. eventActionQueue.Enqueue(new EventActionQueueItem(action, handler)); // Only let through if connected. if (state == ClientState.Running) { SubscribeEvent(action, handler); } } }
/// <summary> /// Starts subscribing to or unsubscribing from the specified event. /// </summary> /// <param name="action">Action to take regarding the event.</param> /// <param name="handler">Delegate that gets called when specified event happens or is /// to be removed.</param> private void SubscribeEvent(IProcEventAction action, IProcEventHandler handler) { bool duplicateSubscriber = false; // Build the listener message. IProcEventListener message = new IProcEventListener(); message.AddEvent(action); // Set the handler for the proper event type. switch (action) { case IProcEventAction.AddNodeCreated: { duplicateSubscriber = (onCreatedNodeEvent != null) ? true : false; onCreatedNodeEvent += handler; break; } case IProcEventAction.AddNodeDeleted: { duplicateSubscriber = (onDeletedNodeEvent != null) ? true : false; onDeletedNodeEvent += handler; break; } case IProcEventAction.AddNodeChanged: { duplicateSubscriber = (onChangedNodeEvent != null) ? true : false; onChangedNodeEvent += handler; break; } case IProcEventAction.AddCollectionSync: { duplicateSubscriber = (onCollectionSyncEvent != null) ? true : false; onCollectionSyncEvent += handler; break; } case IProcEventAction.AddFileSync: { duplicateSubscriber = (onFileSyncEvent != null) ? true : false; onFileSyncEvent += handler; break; } case IProcEventAction.AddNotifyMessage: { duplicateSubscriber = (onNotifyEvent != null) ? true : false; onNotifyEvent += handler; break; } case IProcEventAction.RemoveNodeCreated: { onCreatedNodeEvent -= handler; duplicateSubscriber = (onCreatedNodeEvent != null) ? true : false; break; } case IProcEventAction.RemoveNodeDeleted: { onDeletedNodeEvent -= handler; duplicateSubscriber = (onDeletedNodeEvent != null) ? true : false; break; } case IProcEventAction.RemoveNodeChanged: { onChangedNodeEvent -= handler; duplicateSubscriber = (onChangedNodeEvent != null) ? true : false; break; } case IProcEventAction.RemoveCollectionSync: { onCollectionSyncEvent -= handler; duplicateSubscriber = (onCollectionSyncEvent != null) ? true : false; break; } case IProcEventAction.RemoveFileSync: { onFileSyncEvent -= handler; duplicateSubscriber = (onFileSyncEvent != null) ? true : false; break; } case IProcEventAction.RemoveNotifyMessage: { onNotifyEvent -= handler; duplicateSubscriber = (onNotifyEvent != null) ? true : false; break; } } // Send the message if necessary. if (!duplicateSubscriber) { SendMessage(message.ToBuffer()); } }
/// <summary> /// Initializes a new instance of the structure. /// </summary> /// <param name="action">Action to take regarding the event.</param> /// <param name="handler">Delegate that gets called when specified event happens or is /// to be removed.</param> public EventActionQueueItem(IProcEventAction action, IProcEventHandler handler) { this.action = action; this.handler = handler; }