Ejemplo n.º 1
0
        /// <summary>
        /// Create a SpecField from a 'Fields' entry in the tagged data from the 'spec' command.
        /// </summary>
        /// <param name="def"></param>
        /// <returns></returns>
        public static SpecField FromSpecCmdTaggedData(string def)
        {
            SpecField val = new SpecField();

            string[] parts = def.Split(' ');

            int v = -1;

            int.TryParse(parts[0], out v);
            val.Code = v;

            val.Name = parts[1];

            val._dataType = parts[2];

            v = -1;
            int.TryParse(parts[3], out v);
            val.Length = v;

            val._fieldType = parts[4];

            return(val);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a FormSpec from the tagged output of the 'spec' command
        /// </summary>
        /// <param name="obj">Tagged object returned by the 'spec' command</param>
        /// <returns></returns>
        public static FormSpec FromSpecCmdTaggedOutput(TaggedObject obj)
        {
            FormSpec val = new FormSpec();
            int      idx = 0;

            // Check for each property in the tagged data, and use it to set the
            // appropriate filed in the object

            string key = String.Format("Fields{0}", idx);

            while (obj.ContainsKey(key))
            {
                string fieldDef = obj[key];
                val.Fields.Add(SpecField.FromSpecCmdTaggedData(fieldDef));
                key = String.Format("Fields{0}", ++idx);
            }

            idx = 0;
            key = String.Format("Fields{0}", idx);
            while (obj.ContainsKey(key))
            {
                string   line  = obj[key];
                string[] parts = line.Split(new char[] { ' ' }, 3);
                val.FieldMap[parts[1]] = line;
                key = String.Format("Fields{0}", ++idx);
            }

            idx = 0;
            key = String.Format("Words{0}", idx);
            while (obj.ContainsKey(key))
            {
                string word = obj[key];
                val.Words.Add(word);
                key = String.Format("Words{0}", ++idx);
            }

            idx = 0;
            key = String.Format("Formats{0}", idx);
            while (obj.ContainsKey(key))
            {
                string word = obj[key];
                val.Formats.Add(word);
                key = String.Format("Formats{0}", ++idx);
            }

            idx = 0;
            key = String.Format("Values{0}", idx);
            while (obj.ContainsKey(key))
            {
                string   line  = obj[key];
                string[] parts = line.Split(new char[] { ' ' }, 2);
                val.Values[parts[0]] = parts[1];
                key = String.Format("Values{0}", ++idx);
            }

            idx = 0;
            key = String.Format("Presets{0}", idx);
            while (obj.ContainsKey(key))
            {
                string   line  = obj[key];
                string[] parts = line.Split(new char[] { ' ' }, 2);
                val.Presets[parts[0]] = parts[1];
                key = String.Format("Presets{0}", ++idx);
            }

            if (obj.ContainsKey("Comments"))
            {
                val.Comments = obj["Comments"];
            }

            return(val);
        }