Exemplo n.º 1
0
        /// <summary>
        /// Beendet alle Aktivitäten dieses Zugriffsmoduls.
        /// </summary>
        protected override void OnDispose()
        {
            // Forward - will stop the feed
            base.OnDispose();

            // Finished with the file
            using (m_Stream)
                m_Stream = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Erzeugt eine neue Zugriffsinstanz.
        /// </summary>
        /// <param name="stream">Die Verwaltung eines Datenstroms.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Datenstrom angegeben.</exception>
        public FileAccessor(IVirtualStream stream)
        {
            // Validate
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            // Remember
            m_Stream = stream;

            // Must be called periodically
            SetExternalFeed(false);
        }
        /// <summary>
        /// Überprüft den Inhalt der zusammengesetzten Datei.
        /// </summary>
        /// <param name="stream">Die zusammengesetzte Datei.</param>
        /// <param name="position">Optional eine neue Position in der Datei.</param>
        /// <param name="data">Die erwarteten Daten.</param>
        /// <param name="offset">Die erste Position in den erwarteten Daten.</param>
        /// <param name="count">Die Anzahl der zu überprüfenden Bytes.</param>
        private static void Validate(IVirtualStream stream, long?position, byte[] data, int offset, int count)
        {
            // Report
            Console.WriteLine("Validate({0}, {1}, {2})", position, offset, count);

            // Move position
            if (position.HasValue)
            {
                stream.Position = position.Value;
            }

            // Load position
            long initialPosition = stream.Position;

            // Validate
            if (position.HasValue)
            {
                Assert.AreEqual(position.Value, initialPosition, "Initital Position");
            }

            // Random shift
            byte[] shift = Enumerable.Range(0, Generator.Next(100)).Select(i => (byte)Generator.Next(256)).ToArray();

            // Allocate read buffer
            byte[] read = new byte[shift.Length + count];

            // Fill
            Array.Copy(shift, read, shift.Length);

            // Process the read
            Assert.AreEqual(count, stream.Read(read, shift.Length, count));

            // Validate
            Assert.AreEqual(initialPosition + count, stream.Position, "Final Position");

            // Validate random pattern
            for (int i = shift.Length; i-- > 0;)
            {
                Assert.AreEqual(shift[i], read[i], "Guard at {0}", i);
            }

            // Real data
            for (int i = count; i-- > 0;)
            {
                Assert.AreEqual(data[i + offset], read[i + shift.Length], "Data at {0}", i);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Ändert den abzuspielenden Datenstrom.
        /// </summary>
        /// <param name="stream">Der gewünschte neue Datenstrom.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Datenstrom angegeben.</exception>
        public void ChangeStream(IVirtualStream stream)
        {
            // Validate
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            // Change
            var oldStream = Interlocked.Exchange(ref m_Stream, stream);

            // Release
            if (oldStream != null)
            {
                lock (oldStream)
                    oldStream.Dispose();
            }
        }
        /// <summary>
        /// Überprüft den Inhalt der zusammengesetzten Datei.
        /// </summary>
        /// <param name="stream">Die zusammengesetzte Datei.</param>
        /// <param name="position">Optional eine neue Position in der Datei.</param>
        /// <param name="data">Die erwarteten Daten.</param>
        /// <param name="offset">Die erste Position in den erwarteten Daten.</param>
        /// <param name="count">Die Anzahl der zu überprüfenden Bytes.</param>
        private static void Validate( IVirtualStream stream, long? position, byte[] data, int offset, int count )
        {
            // Report 
            Console.WriteLine( "Validate({0}, {1}, {2})", position, offset, count );

            // Move position
            if (position.HasValue)
                stream.Position = position.Value;

            // Load position
            long initialPosition = stream.Position;

            // Validate
            if (position.HasValue)
                Assert.AreEqual( position.Value, initialPosition, "Initital Position" );

            // Random shift
            byte[] shift = Enumerable.Range( 0, Generator.Next( 100 ) ).Select( i => (byte) Generator.Next( 256 ) ).ToArray();

            // Allocate read buffer
            byte[] read = new byte[shift.Length + count];

            // Fill
            Array.Copy( shift, read, shift.Length );

            // Process the read
            Assert.AreEqual( count, stream.Read( read, shift.Length, count ) );

            // Validate
            Assert.AreEqual( initialPosition + count, stream.Position, "Final Position" );

            // Validate random pattern
            for (int i = shift.Length; i-- > 0; )
                Assert.AreEqual( shift[i], read[i], "Guard at {0}", i );

            // Real data
            for (int i = count; i-- > 0; )
                Assert.AreEqual( data[i + offset], read[i + shift.Length], "Data at {0}", i );
        }
Exemplo n.º 6
0
        /// <summary>
        /// Beendet alle Aktivitäten dieses Zugriffsmoduls.
        /// </summary>
        protected override void OnDispose()
        {
            // Forward - will stop the feed
            base.OnDispose();

            // Finished with the file
            using (m_Stream)
                m_Stream = null;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Ändert den abzuspielenden Datenstrom.
        /// </summary>
        /// <param name="stream">Der gewünschte neue Datenstrom.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Datenstrom angegeben.</exception>
        public void ChangeStream( IVirtualStream stream )
        {
            // Validate
            if (stream == null)
                throw new ArgumentNullException( "stream" );

            // Change
            var oldStream = Interlocked.Exchange( ref m_Stream, stream );

            // Release
            if (oldStream != null)
                lock (oldStream)
                    oldStream.Dispose();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Erzeugt eine neue Zugriffsinstanz.
        /// </summary>
        /// <param name="stream">Die Verwaltung eines Datenstroms.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Datenstrom angegeben.</exception>
        public FileAccessor( IVirtualStream stream )
        {
            // Validate
            if (stream == null)
                throw new ArgumentNullException( "stream" );

            // Remember
            m_Stream = stream;

            // Must be called periodically
            SetExternalFeed( false );
        }