예제 #1
0
 static void EnsureWriter(StdfFileWriter writer)
 {
     if (writer == null)
     {
         throw new InvalidOperationException(Resources.WriteOutsideSOSEOS);
     }
 }
예제 #2
0
        /// <summary>
        /// Consumes a stream of records to write to the output directory.
        /// Files cannot span calls to this method.
        /// </summary>
        /// <param name="records">The records to write.</param>
        public void WriteRecords(IEnumerable <StdfRecord> records)
        {
            StdfFileWriter writer = null;

            foreach (var r in records)
            {
                if (r.GetType() == typeof(StartOfStreamRecord))
                {
                    var sos = (StartOfStreamRecord)r;
                    if (writer != null)
                    {
                        throw new InvalidOperationException(Resources.SOFBeforeEOF);
                    }
                    writer = new StdfFileWriter(Path.Combine(_Path, sos.FileName), sos.Endian);
                }
                else if (r.GetType() == typeof(EndOfStreamException))
                {
                    EnsureWriter(writer);
                    writer.Dispose();
                    writer = null;
                }
                else
                {
                    EnsureWriter(writer);
                    writer.WriteRecord(r);
                }
            }
            if (writer != null)
            {
                throw new InvalidOperationException(Resources.EndWithoutEOS);
            }
        }