当前位置: 首页>>代码示例>>C#>>正文


C# Pipe.WriteText方法代码示例

本文整理汇总了C#中Pipe.WriteText方法的典型用法代码示例。如果您正苦于以下问题:C# Pipe.WriteText方法的具体用法?C# Pipe.WriteText怎么用?C# Pipe.WriteText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pipe的用法示例。


在下文中一共展示了Pipe.WriteText方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TimeoutTest

        public void TimeoutTest()
        {
            var pipe = new Pipe {OutputStream = {ReadTimeout = 0}};
            Assert.Throws<TimeoutException>(() => pipe.OutputStream.ReadByte());

            pipe.WriteText(new string('a', 2048));
            Assert.AreEqual(new string('a', 2048), pipe.ReadTextAsync(2048).Result);
        }
开发者ID:narkhedegs,项目名称:Pipe,代码行数:8,代码来源:PipeTest.cs

示例2: TestWriteTimeout

 public void TestWriteTimeout()
 {
     var pipe = new Pipe {InputStream = {WriteTimeout = 0}};
     pipe.SetFixedLength();
     pipe.WriteText(new string('a', 2*Pipe.ByteBufferSize));
     var asyncWrite = pipe.InputStream.WriteAsync(new byte[1], 0, 1);
     Assert.AreEqual(true, asyncWrite.ContinueWith(_ => { }).Wait(TimeSpan.FromSeconds(.01)));
     Assert.AreEqual(true, asyncWrite.IsFaulted);
     Assert.IsInstanceOf<TimeoutException>(asyncWrite.Exception.InnerException);
 }
开发者ID:narkhedegs,项目名称:Pipe,代码行数:10,代码来源:PipeTest.cs

示例3: SimpleTest

        public void SimpleTest()
        {
            var pipe = new Pipe();

            pipe.WriteText("abc");
            Assert.AreEqual("abc", pipe.ReadTextAsync(3).Result);

            pipe.WriteText("1");
            pipe.WriteText("2");
            pipe.WriteText("3");
            Assert.AreEqual("123", pipe.ReadTextAsync(3).Result);

            var asyncRead = pipe.ReadTextAsync(100);
            Assert.AreEqual(false, asyncRead.Wait(TimeSpan.FromSeconds(.01)),
                asyncRead.IsCompleted ? "Found: " + (asyncRead.Result ?? "null") : "not complete");
            pipe.WriteText("x");
            Assert.AreEqual(false, asyncRead.Wait(TimeSpan.FromSeconds(.01)),
                asyncRead.IsCompleted ? "Found: " + (asyncRead.Result ?? "null") : "not complete");
            pipe.WriteText(new string('y', 100));
            Assert.AreEqual(true, asyncRead.Wait(TimeSpan.FromSeconds(5)),
                asyncRead.IsCompleted ? "Found: " + (asyncRead.Result ?? "null") : "not complete");
            Assert.AreEqual("x" + new string('y', 99), asyncRead.Result);
        }
开发者ID:narkhedegs,项目名称:Pipe,代码行数:23,代码来源:PipeTest.cs

示例4: TestCancel

        public void TestCancel()
        {
            var pipe = new Pipe();
            var cancellationTokenSource = new CancellationTokenSource();

            var asyncRead = pipe.ReadTextAsync(1, cancellationTokenSource.Token);
            Assert.AreEqual(false, asyncRead.Wait(TimeSpan.FromSeconds(.01)));
            cancellationTokenSource.Cancel();
            Assert.AreEqual(true, asyncRead.ContinueWith(_ => { }).Wait(TimeSpan.FromSeconds(5)));
            Assert.AreEqual(true, asyncRead.IsCanceled);

            pipe.WriteText("aaa");
            Assert.AreEqual("aa", pipe.ReadTextAsync(2).Result);

            asyncRead = pipe.ReadTextAsync(1, cancellationTokenSource.Token);
            Assert.AreEqual(true, asyncRead.ContinueWith(_ => { }).Wait(TimeSpan.FromSeconds(5)));
            Assert.AreEqual(true, asyncRead.IsCanceled);
        }
开发者ID:narkhedegs,项目名称:Pipe,代码行数:18,代码来源:PipeTest.cs

示例5: TestCloseReadSide

        public void TestCloseReadSide()
        {
            var pipe = new Pipe();
            pipe.WriteText("abc");
            Assert.AreEqual("ab", pipe.ReadTextAsync(2).Result);
            pipe.OutputStream.Close();
            Assert.Throws<ObjectDisposedException>(() => pipe.OutputStream.ReadByte());

            var largeBytes = new byte[10*1024];
            var initialMemory = GC.GetTotalMemory(forceFullCollection: true);
            for (var i = 0; i < int.MaxValue/1024; ++i)
            {
                pipe.InputStream.Write(largeBytes, 0, largeBytes.Length);
            }
            var finalMemory = GC.GetTotalMemory(forceFullCollection: true);

            Assert.IsTrue(finalMemory - initialMemory < 10*largeBytes.Length,
                "final = " + finalMemory + " initial = " + initialMemory);

            Assert.Throws<ObjectDisposedException>(() => pipe.OutputStream.ReadByte());

            pipe.InputStream.Close();
        }
开发者ID:narkhedegs,项目名称:Pipe,代码行数:23,代码来源:PipeTest.cs

示例6: TestCloseWriteSide

        public void TestCloseWriteSide()
        {
            var pipe = new Pipe();
            pipe.WriteText("123456");
            pipe.InputStream.Close();
            Assert.Throws<ObjectDisposedException>(() => pipe.InputStream.WriteByte(1));

            Assert.AreEqual("12345", pipe.ReadTextAsync(5).Result);
            Assert.AreEqual(null, pipe.ReadTextAsync(2).Result);

            pipe = new Pipe();
            var asyncRead = pipe.ReadTextAsync(1);
            Assert.AreEqual(false, asyncRead.Wait(TimeSpan.FromSeconds(.01)));
            pipe.InputStream.Close();
            Assert.AreEqual(true, asyncRead.Wait(TimeSpan.FromSeconds(5)));
        }
开发者ID:narkhedegs,项目名称:Pipe,代码行数:16,代码来源:PipeTest.cs

示例7: TestPartialWriteDoesNotCancel

        public void TestPartialWriteDoesNotCancel()
        {
            var pipe = new Pipe();
            var cancellationTokenSource = new CancellationTokenSource();

            pipe.WriteText(new string('a', 2*Pipe.ByteBufferSize));

            var asyncRead = pipe.ReadTextAsync(1);
            Assert.AreEqual(true, asyncRead.Wait(TimeSpan.FromSeconds(5)));
            Assert.AreEqual("a", asyncRead.Result);

            pipe.SetFixedLength();

            var bytes = Enumerable.Repeat((byte) 'b', Pipe.ByteBufferSize).ToArray();
            var asyncWrite = pipe.InputStream.WriteAsync(bytes, 0, bytes.Length, cancellationTokenSource.Token);
            Assert.AreEqual(false, asyncWrite.Wait(TimeSpan.FromSeconds(.01)));
            cancellationTokenSource.Cancel();
            Assert.AreEqual(false, asyncWrite.Wait(TimeSpan.FromSeconds(.01)));

            asyncRead = pipe.ReadTextAsync((3*Pipe.ByteBufferSize) - 1);
            Assert.AreEqual(true, asyncRead.Wait(TimeSpan.FromSeconds(5)));
            Assert.AreEqual(
                new string('a', (2*Pipe.ByteBufferSize) - 1) + new string('b', Pipe.ByteBufferSize),
                asyncRead.Result);
        }
开发者ID:narkhedegs,项目名称:Pipe,代码行数:25,代码来源:PipeTest.cs

示例8: TestCancelWrite

        public void TestCancelWrite()
        {
            var pipe = new Pipe();
            var cancellationTokenSource = new CancellationTokenSource();

            pipe.WriteText(new string('a', 2*Pipe.ByteBufferSize));

            pipe.SetFixedLength();

            var bytes = Enumerable.Repeat((byte) 'b', Pipe.ByteBufferSize).ToArray();
            var asyncWrite = pipe.InputStream.WriteAsync(bytes, 0, bytes.Length, cancellationTokenSource.Token);
            Assert.AreEqual(false, asyncWrite.Wait(TimeSpan.FromSeconds(.01)));
            cancellationTokenSource.Cancel();
            Assert.AreEqual(true, asyncWrite.ContinueWith(_ => { }).Wait(TimeSpan.FromSeconds(5)));
            Assert.AreEqual(true, asyncWrite.IsCanceled);
        }
开发者ID:narkhedegs,项目名称:Pipe,代码行数:16,代码来源:PipeTest.cs


注:本文中的Pipe.WriteText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。