/// <summary> /// Translates the information in the CollectionSyncEventArgs object into the IProcEventData object. /// </summary> /// <param name="args">CollectionSyncEventArgs containing Sync event information.</param> private void FromCollectionSyncEventArgs(CollectionSyncEventArgs args) { AddData(new IProcEventNameValue(CEA_NameTag, args.Name)); AddData(new IProcEventNameValue(CEA_IDTag, args.ID)); AddData(new IProcEventNameValue(CEA_ActionTag, args.Action.ToString())); AddData(new IProcEventNameValue(CEA_ConnectedTag, args.Connected.ToString())); AddData(new IProcEventNameValue(CEA_YieldedTag, args.Yielded.ToString())); }
/// <summary> /// Initializes an instance of the object. /// </summary> /// <param name="args">Information regarding the collection sync event.</param> public IProcEventData(CollectionSyncEventArgs args) { document = new XmlDocument(); XmlElement element = document.CreateElement(EventTag); element.SetAttribute(EventTypeTag, typeof(CollectionSyncEventArgs).Name); document.AppendChild(element); FromCollectionSyncEventArgs(args); }
/// <summary> /// Processes queued event data messages by calling the delegates registered for the respective events. /// </summary> /// <param name="eventData">Event message received from the server.</param> private void ProcessEventData(IProcEventData eventData) { switch (eventData.Type) { case "NodeEventArgs": { // Get the node arguments from the document. NodeEventArgs nodeArgs = eventData.ToNodeEventArgs(); // Determine the type of event that occurred. switch (( EventType )Enum.Parse(typeof(EventType), nodeArgs.EventData)) { case EventType.NodeChanged: { if (onChangedNodeEvent != null) { Delegate[] cbList = onChangedNodeEvent.GetInvocationList(); foreach (IProcEventHandler cb in cbList) { try { cb(nodeArgs); } catch (Exception ex) { ReportError(new ApplicationException("Removing subscriber because of exception", ex)); onChangedNodeEvent -= cb; } } } break; } case EventType.NodeCreated: { if (onCreatedNodeEvent != null) { Delegate[] cbList = onCreatedNodeEvent.GetInvocationList(); foreach (IProcEventHandler cb in cbList) { try { cb(nodeArgs); } catch (Exception ex) { ReportError(new ApplicationException("Removing subscriber because of exception", ex)); onCreatedNodeEvent -= cb; } } } break; } case EventType.NodeDeleted: { if (onDeletedNodeEvent != null) { Delegate[] cbList = onDeletedNodeEvent.GetInvocationList(); foreach (IProcEventHandler cb in cbList) { try { cb(nodeArgs); } catch (Exception ex) { ReportError(new ApplicationException("Removing subscriber because of exception", ex)); onDeletedNodeEvent -= cb; } } } break; } } break; } case "CollectionSyncEventArgs": { if (onCollectionSyncEvent != null) { // Get the collection sync arguments from the document. CollectionSyncEventArgs collectionArgs = eventData.ToCollectionSyncEventArgs(); Delegate[] cbList = onCollectionSyncEvent.GetInvocationList(); foreach (IProcEventHandler cb in cbList) { try { cb(collectionArgs); } catch (Exception ex) { ReportError(new ApplicationException("Removing subscriber because of exception", ex)); onCollectionSyncEvent -= cb; } } } break; } case "FileSyncEventArgs": { if (onFileSyncEvent != null) { // Get the file sync arguments from the document. FileSyncEventArgs fileArgs = eventData.ToFileSyncEventArgs(); Delegate[] cbList = onFileSyncEvent.GetInvocationList(); foreach (IProcEventHandler cb in cbList) { try { cb(fileArgs); } catch (Exception ex) { ReportError(new ApplicationException("Removing subscriber because of exception", ex)); onFileSyncEvent -= cb; } } } break; } case "NotifyEventArgs": { if (onNotifyEvent != null) { // Get the notify arguments from the document. NotifyEventArgs notifyArgs = eventData.ToNotifyEventArgs(); Delegate[] cbList = onNotifyEvent.GetInvocationList(); foreach (IProcEventHandler cb in cbList) { try { cb(notifyArgs); } catch (Exception ex) { ReportError(new ApplicationException("Removing subscriber because of exception", ex)); onNotifyEvent -= cb; } } } break; } } }