/// <summary> /// Initializes an instance of the object. /// </summary> /// <param name="args">Information regarding the file sync event.</param> public IProcEventData(FileSyncEventArgs args) { document = new XmlDocument(); XmlElement element = document.CreateElement(EventTag); element.SetAttribute(EventTypeTag, typeof(FileSyncEventArgs).Name); document.AppendChild(element); FromFileSyncEventArgs(args); }
/// <summary> /// Translates the information in the FileSyncEventArgs object into the IProcEventData object. /// </summary> /// <param name="args">FileSyncEventArgs containing Sync event information.</param> private void FromFileSyncEventArgs(FileSyncEventArgs args) { AddData(new IProcEventNameValue(FEA_CollectionIDTag, args.CollectionID)); AddData(new IProcEventNameValue(FEA_ObjectTypeTag, args.ObjectType.ToString())); AddData(new IProcEventNameValue(FEA_DeleteTag, args.Delete.ToString())); AddData(new IProcEventNameValue(FEA_NameTag, args.Name)); AddData(new IProcEventNameValue(FEA_SizeTag, args.Size.ToString())); AddData(new IProcEventNameValue(FEA_SizeToSyncTag, args.SizeToSync.ToString())); AddData(new IProcEventNameValue(FEA_SizeRemainingTag, args.SizeRemaining.ToString())); AddData(new IProcEventNameValue(FEA_DirectionTag, args.Direction.ToString())); AddData(new IProcEventNameValue(FEA_StatusTag, args.Status.ToString())); }
/// <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; } } }