예제 #1
0
 public Task Open(Action onClose)
 {
     this.closeCallback = onClose;
     this.tcs = new TaskCompletionSource<bool>();
     this.responseWriter = new AsyncWriter(this.responseStream, Close);
     if(this.openCallback != null) {
         this.openCallback.Invoke();
     }
     return this.tcs.Task;
 }
예제 #2
0
 public void TestSingleWrite()
 {
     Func<Exception, bool> error = e => false;
     var ms = new MemoryStream();
     var aw = new AsyncWriter(ms, error);
     var aMessage = "A message";
     var expected = Encoding.UTF8.GetBytes(aMessage);
     aw.WriteAndFlushAsync(aMessage);
     aw.Flush().Wait();
     var result = Encoding.UTF8.GetString(ms.ToArray());
     Assert.AreEqual(aMessage, result);
 }
예제 #3
0
 public void TestFailures()
 {
     bool errorThrown = false;
     Func<Exception, bool> error = e => {
         return errorThrown = true;
     };
     var buffer = new byte[30];
     var ms = new MemoryStream(buffer, true);
     var aw = new AsyncWriter(ms, error);
     var message1 = "0123456789ABCDEF";
     var message2 = "01234567890123456789";
     var expected = Encoding.UTF8.GetBytes(message1);
     aw.WriteAndFlushAsync(message1);
     aw.WriteAndFlushAsync(message2);
     Assert.AreEqual(true, errorThrown);
 }
예제 #4
0
        public void TestLotsOfWrites()
        {
            Func<Exception, bool> error = e => {
                Assert.Fail("Should not reach this.");
                return false;
            };
            File.Delete("./BigFile.txt");
            var ms = new FileStream("./BigFile.txt", FileMode.Append);
            var aw = new AsyncWriter(ms, error);
            var message1 = "A message";
            var message2 = "Another message";
            var expected = Encoding.UTF8.GetBytes(message1);
            string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            for (int i = 5000; i > 0; i -= 1) {
                string repeating = new string(chars[i % chars.Length], i) + "\n";
                aw.WriteAsync(repeating);
            }

        }
예제 #5
0
 public BatchAsyncWriter(Stream dest, Func<Exception, bool> errorHandler, int batchSize = 100)
 {
     this.writer = new AsyncWriter(dest, errorHandler);
     this.batchSize = batchSize;
     this.buffer = null;
 }