コード例 #1
0
ファイル: SecurityModule.cs プロジェクト: docBliny/VistaICM
 /// <summary>
 /// Raises the VariableMessageReceived event.
 /// </summary>
 /// <param name="message">Message data object.</param>
 protected void OnVariableMessageReceived(VariableMessage message)
 {
     if (VariableMessageReceived != null)
     {
         VariableMessageReceived(this, new VariableMessageReceivedEventArgs(message));
     }  // if(VariableMessageReceived != null)
 }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the VariableMessageReceivedEventArgs class.
        /// </summary>
        /// <param name="message">The value for the Message property.</param>
        /// <exception cref="ArgumentNullException">message cannot be null.</exception>
        public VariableMessageReceivedEventArgs(VariableMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            this.Message = message;
        }
コード例 #3
0
ファイル: SecurityModule.cs プロジェクト: docBliny/VistaICM
        /// <summary>
        /// Processes a received data packet that contains a variable.
        /// </summary>
        /// <param name="data"></param>
        private void ProcessVariablePacket(byte[] data)
        {
            VariableMessage message;
            int             length;
            string          dataString;
            string          node;
            string          unit;
            string          key;
            string          value;
            Regex           regexParse;

            // Check for minimum valid data length
            if (data.Length >= 8)
            {
                // Check the data length
                length = ToUInt16(data, 6);

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

                    // Parse out the data and create a new message object
                    try
                    {
                        regexParse = new Regex(@"(?<Node>\d+)\.(?<Unit>\d+)\.(?<Key>[.\w]+)=(?<Value>[^\x00]*)");

                        node  = regexParse.Match(dataString).Groups["Node"].Value;
                        unit  = regexParse.Match(dataString).Groups["Unit"].Value;
                        key   = regexParse.Match(dataString).Groups["Key"].Value;
                        value = regexParse.Match(dataString).Groups["Value"].Value;
                        if (string.IsNullOrEmpty(node) == false && string.IsNullOrEmpty(unit) == false)
                        {
                            message = new VariableMessage
                            {
                                Node  = int.Parse(node, CultureInfo.InvariantCulture),
                                Unit  = int.Parse(unit, CultureInfo.InvariantCulture),
                                Key   = key,
                                Value = value ?? String.Empty
                            };

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

                            // Raise an event
                            OnVariableMessageReceived(message);
                        } // if (string.IsNullOrEmpty(node) == false && string.IsNullOrEmpty(unit) == false)
                    }     // try
                    catch (ArgumentException)
                    {
                        // Syntax error in the regular expression
                    } // catch
                }     // if(data.Length == length + 8)
            }         // if(data.Length >= 10)
        }
コード例 #4
0
ファイル: SecurityModule.cs プロジェクト: docBliny/VistaICM
        /// <summary>
        /// Parses a VariableMessage for any data we wish to expose as properties or use as state data.
        /// </summary>
        /// <param name="message">The message to process.</param>
        private void ProcessVariableMessage(VariableMessage message)
        {
            // Check for Zone Status variable
            if (message.Key.StartsWith("ZS", StringComparison.Ordinal))
            {
                SetZoneStatus(message.Key, message.Value);
            }  // if(message.Key.StartsWith("ZS"))
            else
            {
                switch (message.Key)
                {
                case "AlarmEvent":
                    SetAlarmEvent(message.Value);
                    break;

                case "ArmStatus":
                    SetArmStatus(message.Value);
                    break;

                case "display":
                    this.Display = message.Value;
                    break;

                case "FireEvent":
                    SetFireEvent(message.Value);
                    break;

                case "ID":
                    if (message.Value != null)
                    {
                        Id = int.Parse(message.Value, CultureInfo.InvariantCulture);
                    }      // if(message.Value != null)
                    break;

                case "Ready":
                    SetReady(message.Value);
                    break;
                } // switch
            }     // else
        }