Exemple #1
0
        /// <summary>
        /// Removes an event from the list of monitored events.
        /// </summary>
        /// <param name="evt">The event which should be removed.</param>
        private void RemoveEvent(Enumerators.Event evt)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("this");
            }

            lock (synchronize)
            {
                int counter = 0;

                if (!events.ContainsKey(evt))
                {
                    return;
                }

                events.TryGetValue(evt, out counter);
                counter--;

                if (counter == 0)
                {
                    events.Remove(evt);
                    SetEvents();
                }
                else
                {
                    events[evt] = counter;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds an event to the list of monitored events.
        /// </summary>
        /// <param name="evt">The event which should be monitored for.</param>
        private void AddEvent(Enumerators.Event evt)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("this");
            }

            lock (synchronize)
            {
                int counter = 0;

                events.TryGetValue(evt, out counter);
                events[evt] = ++counter;

                if (enabled && counter == 1)
                {
                    SetEvents();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Raises the <see cref="E:LogReceived" /> event.
        /// </summary>
        /// <param name="e">The <see cref="LogEventArgs"/> instance containing the event data.</param>
        /// <param name="evt">The event which was processed.</param>
        internal void OnLogReceived(LogEventArgs e, Enumerators.Event evt)
        {
            switch (evt)
            {
            case Enumerators.Event.LogDebug:
                if (debugReceivedHandlers != null)
                {
                    debugReceivedHandlers(client, e);
                }
                break;

            case Enumerators.Event.LogError:
                if (errorReceivedHandlers != null)
                {
                    errorReceivedHandlers(client, e);
                }
                break;

            case Enumerators.Event.LogInfo:
                if (infoReceivedHandlers != null)
                {
                    infoReceivedHandlers(client, e);
                }
                break;

            case Enumerators.Event.LogNotice:
                if (noticeReceivedHandlers != null)
                {
                    noticeReceivedHandlers(client, e);
                }
                break;

            case Enumerators.Event.LogWarn:
                if (warnReceivedHandlers != null)
                {
                    warnReceivedHandlers(client, e);
                }
                break;
            }
        }
Exemple #4
0
        /// <summary>
        /// Dispatches an event by parsing the content of the line and raising the relevant event.
        /// </summary>
        /// <param name="line">The line received from the control connection.</param>
        private void Dispatch(string line)
        {
            if (line == null)
            {
                throw new ArgumentNullException("line");
            }

            string trimmed = line.Trim();

            if (trimmed.Length < 3)
            {
                return;
            }

            string[] parts = null;

            if (trimmed.Length > 3 && trimmed[3] == '-')
            {
                string[] intermediate = trimmed.Split(new[] { '-' }, 2); // [650, EVENT....]

                if (intermediate.Length < 2)
                {
                    return;
                }

                string status  = intermediate[0].Trim();
                string content = intermediate[1].Trim();

                string[] data = content.Split(new string[] { EOL }, 2, StringSplitOptions.None); // [EVENT, ...]

                if (data.Length < 2)
                {
                    return;
                }

                parts = new string[] { status, data[0], data[1] };
            }
            else
            {
                parts = trimmed.Split(new[] { ' ' }, 3);
            }

            if (parts.Length < 2)
            {
                return;
            }

            if (parts[0].Equals("650"))
            {
                Enumerators.Event evt = ReflectionHelper.GetEnumerator <Enumerators.Event, DescriptionAttribute>(attr => parts[1].Equals(attr.Description, StringComparison.CurrentCultureIgnoreCase));

                if (evt == Enumerators.Event.Unknown)
                {
                    return;
                }

                Type type;

                if (!dispatchers.TryGetValue(evt, out type))
                {
                    return;
                }

                Dispatcher dispatcher = Activator.CreateInstance(type) as Dispatcher;
                dispatcher.Client       = client;
                dispatcher.CurrentEvent = evt;
                dispatcher.Events       = this;

                if (dispatcher == null)
                {
                    return;
                }

                dispatcher.Dispatch(parts[2]);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventAssocAttribute"/> class.
 /// </summary>
 /// <param name="evt">The event the class is associated with.</param>
 public EventAssocAttribute(Enumerators.Event evt)
 {
     this.evt = evt;
 }