/// <summary>
        /// Read XAML formatted text into message types.
        /// </summary>
        /// <param name="contents"></param>
        public void ReadConfig(string contents)
        {
            Regex typeDetails = new Regex(@"(\w+)\s*=\s*""([\w\s]+)"""),
                  fieldReg = new Regex(@"<\s*Field\s+(.*?)\\\s*(Field\s*)?>", RegexOptions.Singleline);
            MatchCollection   detailMatches, fieldMatches;
            MessageFieldModel messageFieldModel;

            // Return if invalid
            if (null == contents)
            {
                return;
            }

            // Set general Type details
            if (typeDetails.IsMatch(contents))
            {
                detailMatches = typeDetails.Matches(contents);
                ReadProperties(detailMatches);
            }

            // Define fields for each field found
            if (fieldReg.IsMatch(contents))
            {
                fieldMatches = fieldReg.Matches(contents);
                foreach (Match fieldMatch in fieldMatches)
                {
                    messageFieldModel = new MessageFieldModel();
                    messageFieldModel.ReadConfig(fieldMatch.Groups[1].Value);

                    MessageFields.Add(messageFieldModel);
                }
            }
        }
Beispiel #2
0
        //public void OnAddWord(string a = "")
        //{
        //    if (NumWords >= maxWords) return;

        //    // Create a new field to fill in the spaces of the new word
        //    for (int i = 0; i < 16; ++i)
        //    {
        //        MessageFieldModel newField = new MessageFieldModel();
        //        newField.MessageFieldDetails.WordNum = NumWords;
        //        newField.MessageFieldDetails.BitStart = i;
        //        newField.MessageFieldDetails.BitLength = 1;

        //        MessageFields.Add(newField);
        //    }

        //    // Add to WordNumbers collection
        //    WordNumbers.Add(NumWords.ToString());

        //    // Increment field last
        //    ++NumWords;
        //}

        //public void OnSubtractWord(string a = "")
        //{
        //    if (NumWords <= 1) return;

        //    // Decrement field first
        //    --NumWords;

        //    // Remove from WordNumbers collection
        //    WordNumbers.Remove(NumWords.ToString());

        //    // Modify the collection by removing unwanted elements
        //    for (int i = 0; i < MessageFields.Count; ++i)
        //    {
        //        if (NumWords == MessageFields[i].MessageFieldDetails.WordNum)
        //        {
        //            MessageFields.Remove(MessageFields[i]);
        //            --i;
        //        }
        //    }
        //}

        public void AddWordFields()
        {
            // Create a new field to fill in the spaces of the new word
            for (int i = 0; i < 16; ++i)
            {
                MessageFieldModel newField = new MessageFieldModel();
                newField.MessageFieldDetails.WordNum   = NumWords;
                newField.MessageFieldDetails.BitStart  = i;
                newField.MessageFieldDetails.BitLength = 1;

                MessageFields.Add(newField);
            }
            NumWords++;
            UpdateMessageFields();
        }