Exemplo n.º 1
0
 /// <summary>
 /// Translates the information in the NodeEventArgs object into the IProcEventData object.
 /// </summary>
 /// <param name="args">NodeEventArgs containing Node event information.</param>
 private void FromNodeEventArgs(NodeEventArgs args)
 {
     AddData(new IProcEventNameValue(NEA_ActionTag, args.EventData));
     AddData(new IProcEventNameValue(NEA_TimeTag, args.TimeStamp.Ticks.ToString()));
     AddData(new IProcEventNameValue(NEA_SourceTag, args.Source));
     AddData(new IProcEventNameValue(NEA_CollectionTag, args.Collection));
     AddData(new IProcEventNameValue(NEA_TypeTag, args.Type));
     AddData(new IProcEventNameValue(NEA_EventIDTag, args.EventId.ToString()));
     AddData(new IProcEventNameValue(NEA_NodeTag, args.Node));
     AddData(new IProcEventNameValue(NEA_FlagsTag, args.Flags.ToString()));
     AddData(new IProcEventNameValue(NEA_MasterRevTag, args.MasterRev.ToString()));
     AddData(new IProcEventNameValue(NEA_SlaveRevTag, args.SlaveRev.ToString()));
     AddData(new IProcEventNameValue(NEA_FileSizeTag, args.FileSize.ToString()));
     AddData(new IProcEventNameValue(NEA_ModifierTag, args.Modifier));
 }
Exemplo n.º 2
0
        /// <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;
            }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts the IProcEventData object into a NodeEventArgs object.
        /// </summary>
        /// <returns>A NodeEventArgs object.</returns>
        public NodeEventArgs ToNodeEventArgs()
        {
            // Preinitialize all of the node event arguments.
            EventType changeType = EventType.NodeChanged;
            DateTime  time       = DateTime.MinValue;
            string    source     = string.Empty;
            string    node       = string.Empty;
            string    collection = string.Empty;
            string    modifier   = string.Empty;
            string    type       = string.Empty;
            int       eventID    = 0;
            ushort    flags      = 0;
            ulong     masterRev  = 0;
            ulong     slaveRev   = 0;
            long      fileSize   = 0;

            // Walk through each named/value pair and convert the xml data back into NodeEventArgs data.
            foreach (XmlNode xn in document.DocumentElement)
            {
                switch (xn.Name)
                {
                case NEA_ActionTag:
                {
                    changeType = ( EventType )Enum.Parse(typeof(EventType), xn.InnerText);
                    break;
                }

                case NEA_TimeTag:
                {
                    time = new DateTime(Convert.ToInt64(xn.InnerText));
                    break;
                }

                case NEA_SourceTag:
                {
                    source = xn.InnerText;
                    break;
                }

                case NEA_CollectionTag:
                {
                    collection = xn.InnerText;
                    break;
                }

                case NEA_ModifierTag:
                {
                    modifier = xn.InnerText;
                    break;
                }

                case NEA_TypeTag:
                {
                    type = xn.InnerText;
                    break;
                }

                case NEA_EventIDTag:
                {
                    eventID = Convert.ToInt32(xn.InnerText);
                    break;
                }

                case NEA_NodeTag:
                {
                    node = xn.InnerText;
                    break;
                }

                case NEA_FlagsTag:
                {
                    flags = Convert.ToUInt16(xn.InnerText);
                    break;
                }

                case NEA_MasterRevTag:
                {
                    masterRev = Convert.ToUInt64(xn.InnerText);
                    break;
                }

                case NEA_SlaveRevTag:
                {
                    slaveRev = Convert.ToUInt64(xn.InnerText);
                    break;
                }

                case NEA_FileSizeTag:
                {
                    fileSize = Convert.ToInt64(xn.InnerText);
                    break;
                }
                }
            }

            // Create the object and set the flags.
            NodeEventArgs args = new NodeEventArgs(source, node, collection, modifier, type, changeType, eventID, time, masterRev, slaveRev, fileSize);

            args.Flags = flags;
            return(args);
        }