Ejemplo n.º 1
0
        /// <summary>
        /// Parses a UnitInfoMessage for any zone data.
        /// </summary>
        /// <param name="message"></param>
        private void ProcessUnitInfoMessage(UnitInfoMessage message)
        {
            SortedList <string, string> variables = message.Variables;
            Regex  regexParse;
            string match;
            int    zoneId;
            Zone   zone;

            // Check if we need get zone names
            if (_isInitialUnitInfoMessage && variables != null)
            {
                _isInitialUnitInfoMessage = false;

                // Check if this message pertains to security
                if (variables.ContainsKey("name") && variables["name"] == "Security")
                {
                    regexParse = new Regex(@"T\.(?<Zone>(?:[2-9]|1[0-6]|1))");

                    // Loop for all zone names
                    foreach (string key in variables.Keys)
                    {
                        match = regexParse.Match(key).Groups["Zone"].Value;

                        if (int.TryParse(match, out zoneId))
                        {
                            zone      = _zones[zoneId - 1];
                            zone.Name = variables[key];
                        }
                    } // for each
                }     // if name == Security
            }         // if(variables != null)
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Raises the UnitInfoMessageReceived event.
 /// </summary>
 /// <param name="message">Message data object.</param>
 protected void OnUnitInfoMessageReceived(UnitInfoMessage message)
 {
     if (UnitInfoMessageReceived != null)
     {
         UnitInfoMessageReceived(this, new UnitInfoMessageReceivedEventArgs(message));
     }  // if(UnitInfoMessageReceived != null)
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the UnitInfoMessageReceivedEventArgs class.
        /// </summary>
        /// <param name="message">The value for the Message property.</param>
        /// <exception cref="ArgumentNullException">message cannot be null.</exception>
        public UnitInfoMessageReceivedEventArgs(UnitInfoMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            this.Message = message;
        }
Ejemplo n.º 4
0
        private void ProcessUnitInfoPacket(byte[] data)
        {
            UnitInfoMessage message;
            Int32           ipTemp;
            IPAddress       ipAddress;
            PhysicalAddress macAddress;
            int             length;
            string          dataString;

            string[] rawVariables;
            string   key;
            string   value;
            SortedList <string, string> variables = new SortedList <string, string>();

            // Check for minimum valid data length
            if (data.Length >= 48)
            {
                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);

                        // Split into an array
                        rawVariables = dataString.Split((char)0x0A);

                        foreach (string item in rawVariables)
                        {
                            if (item.Contains("="))
                            {
                                key   = item.Substring(0, item.IndexOf("=", StringComparison.Ordinal));
                                value = item.Substring(item.IndexOf("=", StringComparison.Ordinal) + 1);
                                variables.Add(key, value);
                            } // if(dataString.Contains("="))
                        }     // foreach item

                        message = new UnitInfoMessage
                        {
                            IPAddress  = ipAddress,
                            MacAddress = macAddress,
                            Checksum   = ToUInt16(data, 8),
                            Variables  = variables
                        };

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

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