Beispiel #1
0
 /// <summary>
 /// Raises the DiscoveryMessageReceived event.
 /// </summary>
 /// <param name="message">Message data object.</param>
 protected void OnDiscoveryMessageReceived(DiscoveryMessage message)
 {
     if (DiscoveryMessageReceived != null)
     {
         DiscoveryMessageReceived(this, new DiscoveryMessageReceivedEventArgs(message));
     }  // if(DiscoveryMessageReceived != null)
 }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the DiscoveryMessageReceivedEventArgs class.
        /// </summary>
        /// <param name="message">The value for the Message property.</param>
        /// <exception cref="ArgumentNullException">message cannot be null.</exception>
        public DiscoveryMessageReceivedEventArgs(DiscoveryMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            this.Message = message;
        }
Beispiel #3
0
        /// <summary>
        /// Check if we've already got an IP address, and if not, parse a DiscoveryMessage IP-address.
        /// </summary>
        /// <param name="message"></param>
        private void ProcessDiscoveryMessage(DiscoveryMessage message)
        {
            if (IPAddress == null)
            {
                // Set the IP address
                this.IPAddress  = message.IPAddress;
                this.MacAddress = message.MacAddress;

                if (IPAddress != null)
                {
                    // Request ICM status update
                    Refresh();

                    OnDiscoveryCompleted();

                    // Start updating
                    _tmrRefresh.Start();
                } // if(_ipAddress != null)
            }     // if(_ipAddress == null)
        }
Beispiel #4
0
        /// <summary>
        /// Processes a received data packet that contains the ICM network information.
        /// </summary>
        /// <param name="data"></param>
        private void ProcessDiscoveryPacket(byte[] data)
        {
            DiscoveryMessage message;
            Int32            ipTemp;
            IPAddress        ipAddress;
            PhysicalAddress  macAddress;
            int    length;
            string dataString;
            string key   = String.Empty;
            string value = null;

            // Check for minimum valid data length
            if (data.Length >= 34)
            {
                try
                {
                    ipTemp    = BitConverter.ToInt32(data, 20);
                    ipAddress = new IPAddress(ipTemp);
                    byte[] mac = { data[28], data[29], data[30], data[31], data[32] };
                    macAddress = new PhysicalAddress(mac);

                    // Get the data length
                    length = ToUInt16(data, 12);

                    // Make sure the data packet actually has this amount of data
                    if (data.Length == length + 52)
                    {
                        // Get the contained text
                        dataString = Encoding.ASCII.GetString(data, 52, length);

                        if (dataString.Contains("="))
                        {
                            key   = dataString.Substring(0, dataString.IndexOf("=", StringComparison.Ordinal));
                            value = dataString.Substring(dataString.IndexOf("=", StringComparison.Ordinal) + 1);
                            if (value.Contains("\n"))
                            {
                                value = value.Remove(value.IndexOf("\n", StringComparison.Ordinal));
                            }
                        }  // if(dataString.Contains("="))

                        message = new DiscoveryMessage
                        {
                            IPAddress  = ipAddress,
                            MacAddress = macAddress,
                            Checksum   = ToUInt16(data, 8),
                            Key        = key,
                            Value      = value
                        };

                        // Process the message internally for data we need
                        ProcessDiscoveryMessage(message);

                        // Raise an event
                        OnDiscoveryMessageReceived(message);
                    } // if (data.Length == length + 52)
                }     // try
                catch (Exception ex)
                {
                    Debug.WriteLine("ProcessDiscoveryPacket(): " + ex, "SecurityModule");
                } // catch
            }     // if (data.Length >= 34)
        }