예제 #1
0
        /// <summary>
        /// Adds the binding.
        /// </summary>
        /// <param name="endpoint">The endpoint.</param>
        public void AddBinding(IPEndPoint endpoint)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            if (Active)
            {
                throw new InvalidOperationException("Must be called when Active == false");
            }

            if (Bindings.Any(existed => existed.Endpoint.Equals(endpoint)))
            {
                return;
            }

            var binding = new ListenerBinding(Users, endpoint);

            binding.ExceptionRaised += (o, args) =>
            {
                ExceptionRaised?.Invoke(o, args);
            };
            binding.MessageReceived += (o, args) =>
            {
                MessageReceived?.Invoke(o, args);
            };
            Bindings.Add(binding);
        }
        /// <summary>
        /// Processes the message.
        /// </summary>
        /// <param name="message">Message.</param>
        /// <param name="sender">Sender.</param>
        /// <param name="binding">The binding.</param>
        public void Process(ISnmpMessage message, System.Net.IPEndPoint sender, ListenerBinding binding)
        {
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }
            
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            
            if (message.Version != VersionCode.V2)
            {
                return;
            }
            
            switch (message.Pdu.TypeCode)
            {
                case SnmpType.TrapV2Pdu:
                    {
                        EventHandler<MessageReceivedEventArgs<TrapV2Message>> handler = TrapV2Received;
                        if (handler != null)
                        {
                            handler(this, new MessageReceivedEventArgs<TrapV2Message>(sender, (TrapV2Message)message, binding));
                        }

                        break;
                    }

                case SnmpType.InformRequestPdu:
                    {
                        InformRequestMessage inform = (InformRequestMessage)message;
                        binding.SendResponse(inform.GenerateResponse(), sender);

                        EventHandler<MessageReceivedEventArgs<InformRequestMessage>> handler = InformRequestReceived;
                        if (handler != null)
                        {
                            handler(this, new MessageReceivedEventArgs<InformRequestMessage>(sender, inform, binding));
                        }

                        break;
                    }

                default:
                    break;
            }
        }
        /// <summary>
        /// Processes the message.
        /// </summary>
        /// <param name="message">Message.</param>
        /// <param name="sender">Sender.</param>
        /// <param name="binding">The binding.</param>
        public void Process(ISnmpMessage message, System.Net.IPEndPoint sender, ListenerBinding binding)
        {
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }

            if (message.Version != VersionCode.V3)
            {
                return;
            }

            switch (message.Pdu.TypeCode)
            {
            case SnmpType.TrapV2Pdu:
            {
                EventHandler <MessageReceivedEventArgs <TrapV2Message> > handler = TrapV2Received;
                if (handler != null)
                {
                    handler(this, new MessageReceivedEventArgs <TrapV2Message>(sender, (TrapV2Message)message, binding));
                }

                break;
            }

            case SnmpType.InformRequestPdu:
            {
                InformRequestMessage inform = (InformRequestMessage)message;
                binding.SendResponse(inform.GenerateResponse(), sender);

                EventHandler <MessageReceivedEventArgs <InformRequestMessage> > handler = InformRequestReceived;
                if (handler != null)
                {
                    handler(this, new MessageReceivedEventArgs <InformRequestMessage>(sender, inform, binding));
                }

                break;
            }

            default:
                break;
            }
        }
예제 #4
0
        /// <summary>
        /// Adds the binding.
        /// </summary>
        /// <param name="endpoint">The endpoint.</param>
        public void AddBinding(IPEndPoint endpoint)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            if (Active)
            {
                throw new InvalidOperationException("Must be called when Active == false");
            }

            foreach (ListenerBinding existed in Bindings)
            {
                if (existed.Endpoint.Equals(endpoint))
                {
                    return;
                }
            }

            var binding = new ListenerBinding(Users, Adapters, endpoint);

            binding.ExceptionRaised += (o, args) =>
            {
                var handler = ExceptionRaised;
                if (handler != null)
                {
                    handler(o, args);
                }
            };
            binding.MessageReceived += (o, args) =>
            {
                var handler = MessageReceived;
                if (handler != null)
                {
                    handler(o, args);
                }
            };
            Bindings.Add(binding);
        }
        /// <summary>
        /// Processes the message.
        /// </summary>
        /// <param name="message">Message.</param>
        /// <param name="sender">Sender.</param>
        /// <param name="binding">The binding.</param>
        public void Process(ISnmpMessage message, System.Net.IPEndPoint sender, ListenerBinding binding)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }

            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            if (message.Version != VersionCode.V1)
            {
                return;
            }
            
            switch (message.Pdu.TypeCode)
            {
                case SnmpType.TrapV1Pdu:
                    {
                        EventHandler<MessageReceivedEventArgs<TrapV1Message>> handler = TrapV1Received;
                        if (handler != null)
                        {
                            handler(this, new MessageReceivedEventArgs<TrapV1Message>(sender, (TrapV1Message)message, binding));
                        }

                        break;
                    }

                default:
                    break;
            }
        }
예제 #6
0
        /// <summary>
        /// Processes the message.
        /// </summary>
        /// <param name="message">Message.</param>
        /// <param name="sender">Sender.</param>
        /// <param name="binding">The binding.</param>
        public void Process(ISnmpMessage message, System.Net.IPEndPoint sender, ListenerBinding binding)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }

            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            if (message.Version != VersionCode.V1)
            {
                return;
            }

            switch (message.Pdu.TypeCode)
            {
            case SnmpType.TrapV1Pdu:
            {
                EventHandler <MessageReceivedEventArgs <TrapV1Message> > handler = TrapV1Received;
                if (handler != null)
                {
                    handler(this, new MessageReceivedEventArgs <TrapV1Message>(sender, (TrapV1Message)message, binding));
                }

                break;
            }

            default:
                break;
            }
        }
예제 #7
0
 /// <summary>
 /// Adds the binding.
 /// </summary>
 /// <param name="endpoint">The endpoint.</param>
 public void AddBinding(IPEndPoint endpoint)
 {
     if (_disposed)
     {
         throw new ObjectDisposedException(GetType().FullName);
     }            
     
     if (Active)
     {
         throw new InvalidOperationException("Must be called when Active == false");
     }
     
     if (Bindings.Any(existed => existed.Endpoint.Equals(endpoint)))
     {
         return;
     }
     
     var binding = new ListenerBinding(Users, endpoint);
     binding.ExceptionRaised += (o, args) =>
     {
         var handler = ExceptionRaised;
         if (handler != null)
         {
             handler(o, args);
         }
     };
     binding.MessageReceived += (o, args) =>
     {
         var handler = MessageReceived;
         if (handler != null)
         {
             handler(o, args);
         }
     };
     Bindings.Add(binding);
 }