Beispiel #1
0
        public void TestPipeline()
        {
            stream = new PipelineStream(256);
            ThreadPool.QueueUserWorkItem(WriteThread);

            var readed = false;

            stream.OnRead += (_) =>
            {
                readed = true;
            };
            var data = new byte[100];
            int read;
            var actual = new StringBuilder();
            var rand   = new Random();

            while ((read = stream.Read(data, 0, data.Length)) != 0)
            {
                var str = Encoding.UTF8.GetString(data, 0, read);
                actual.Append(str);
                Thread.Sleep(rand.Next(1, 5));
            }
            stream.Dispose();

            var expected = new StringBuilder();

            for (var i = 0; i < 1000; i++)
            {
                expected.Append("0123456789");
            }

            Assert.AreEqual(expected.ToString(), actual.ToString());
            Assert.AreEqual(true, readed);
        }
        private void ReadThread()
        {
            OnRead(_input);

            _input.Dispose();

            // Write end of pipe
            ShutdownOutputs();
        }
Beispiel #3
0
        public void TestDisposeAndWrite()
        {
            var stream = new PipelineStream(256);

            Assert.AreEqual(true, stream.CanWrite);
            Assert.AreEqual(false, stream.CanRead);
            stream.Dispose();
            Assert.AreEqual(false, stream.CanWrite);
            Assert.AreEqual(false, stream.CanRead);
            stream.Write(Encoding.UTF8.GetBytes("0123456789"), 0, 10);
        }
        /// <summary>
        /// Overidden dispose method
        /// </summary>
        /// <param name="disposing">True if should dispose of managed and unmanaged data</param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (!_isDisposed)
            {
                _isDisposed = true;
                using (_cancel_source)
                {
                    _cancel_source?.Cancel();
                }

                try
                {
                    _input?.Dispose();
                }
                catch
                {
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Overidden dispose method
        /// </summary>
        /// <param name="disposing">True if should dispose of managed and unmanaged data</param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (!_isDisposed)
            {
                _isDisposed = true;

                GeneralUtils.AbortThread(_thread);
                _thread = null;

                try
                {
                    if (_input != null)
                    {
                        _input.Dispose();
                    }
                }
                catch
                {
                }
            }
        }