Esempio n. 1
0
        private MotionRecord makeRecord(string line)
        {
            string[] tokens = line.Split(new char[] { ' ' });
            // There must be room for at least a name and two positions.
            if (tokens.Length < 3)
            {
                throw new MalformedException("Need at least three tokens per line.");
            }
            // The first token should be the name. If this is not the correct, throw exception.
            string name = tokens[0].Trim();

            if (!name.EndsWith("="))
            {
                throw new MalformedException("Name was not specified with = operator.");
            }
            // Finally create the returnvalue.
            MotionRecord rv = new MotionRecord(name.Trim(new char[] { '=', ' ', '\t' }));

            // And fill it up!
            for (int i = 1; i < tokens.Length; i++)
            {
                rv.Add(SequenceItem.FromToken(tokens[i]));
            }

            // We still need to enable the modifiers.
            rv.InitModifiers();
            return(rv);
        }
Esempio n. 2
0
        /// <summary>
        /// Parses the input file.
        /// </summary>
        public void Parse()
        {
            // If the file does not exist, throw an exception.
            if (!File.Exists(Path))
            {
                throw new FileNotFoundException("The input file does not exist.", Path);
            }
            // name and csv strings, for file input.
            string       line;
            StreamReader reader     = new StreamReader(Path);
            int          lineNumber = -1; // For potential error messages.

            try
            {
                while (reader.Peek() != -1)
                {
                    // Read line per line. Each line is one record.
                    line = read(reader, ref lineNumber);
                    if (line == null)
                    {
                        return;
                    }
                    MotionRecord record = makeRecord(line);
                    AddRecord(record);
                }
            }
            catch (MalformedException e)
            {
                // Add linenumber and path to the exception.
                throw new MalformedException(e.Message, Path, lineNumber);
            }
            catch (KeyNotFoundException e)
            {
                throw new MalformedException(e.Message, Path, lineNumber);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                reader.Close();
                reader.Dispose();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Adds a record to the list of known records.
 /// </summary>
 /// <param name="record">The new record.</param>
 public static void AddRecord(MotionRecord record)
 {
     records.Add(record.Name, record);
 }