Ejemplo n.º 1
0
 internal IAsyncResult BeginClose(AsyncCallback callback, object state)
 {
     var multiResult = new MultiAsyncResult(this, callback, state);
     Close(multiResult);
     multiResult.CompleteSequence();
     return multiResult;
 }
        internal static object End(IAsyncResult result)
        {
            MultiAsyncResult result2 = (MultiAsyncResult)result;

            result2.InternalWaitForCompletion();
            return(result2.Result);
        }
Ejemplo n.º 3
0
        internal static IAsyncResult BeginSend(SmtpConnection conn, AsyncCallback callback, object state)
        {
            MultiAsyncResult multiResult = new MultiAsyncResult(conn, callback, state);
            multiResult.Enter();
            IAsyncResult writeResult = conn.BeginFlush(s_onWrite, multiResult);
            if (writeResult.CompletedSynchronously)
            {
                conn.EndFlush(writeResult);
                multiResult.Leave();
            }
            SmtpReplyReader reader = conn.Reader.GetNextReplyReader();
            multiResult.Enter();

            //this actually does a read on the stream.
            IAsyncResult result = reader.BeginReadLine(s_onReadLine, multiResult);
            if (result.CompletedSynchronously)
            {
                LineInfo info = reader.EndReadLine(result);
                if (!(multiResult.Result is Exception))
                    multiResult.Result = info;
                multiResult.Leave();
            }
            multiResult.CompleteSequence();
            return multiResult;
        }
 internal static IAsyncResult BeginSend(SmtpConnection conn, AsyncCallback callback, object state)
 {
     MultiAsyncResult result = new MultiAsyncResult(conn, callback, state);
     result.Enter();
     IAsyncResult result2 = conn.BeginFlush(onWrite, result);
     if (result2.CompletedSynchronously)
     {
         conn.EndFlush(result2);
         result.Leave();
     }
     SmtpReplyReader nextReplyReader = conn.Reader.GetNextReplyReader();
     result.Enter();
     IAsyncResult result3 = nextReplyReader.BeginReadLines(onReadLines, result);
     if (result3.CompletedSynchronously)
     {
         LineInfo[] infoArray = conn.Reader.CurrentReader.EndReadLines(result3);
         if (!(result.Result is Exception))
         {
             result.Result = infoArray;
         }
         result.Leave();
     }
     result.CompleteSequence();
     return result;
 }
Ejemplo n.º 5
0
        internal IAsyncResult BeginClose(AsyncCallback callback, object state)
        {
            MultiAsyncResult multiResult = new MultiAsyncResult(this, callback, state);

            this.Close(multiResult);
            multiResult.CompleteSequence();
            return(multiResult);
        }
Ejemplo n.º 6
0
 private void Close(MultiAsyncResult multiResult)
 {
     _bufferBuilder.Append(s_crlf);
     _bufferBuilder.Append(s_DASHDASH);
     _bufferBuilder.Append(_boundaryBytes);
     _bufferBuilder.Append(s_DASHDASH);
     _bufferBuilder.Append(s_crlf);
     Flush(multiResult);
 }
Ejemplo n.º 7
0
 void Close(MultiAsyncResult multiResult)
 {
     this.bufferBuilder.Append(CRLF);
     this.bufferBuilder.Append(DASHDASH);
     this.bufferBuilder.Append(this.boundaryBytes);
     this.bufferBuilder.Append(DASHDASH);
     this.bufferBuilder.Append(CRLF);
     Flush(multiResult);
 }
Ejemplo n.º 8
0
 internal IAsyncResult BeginGetContentStream(AsyncCallback callback, object state)
 {
     var multiResult = new MultiAsyncResult(this, callback, state);
     var contentStream = GetContentStream(multiResult);
     if (!(multiResult.Result is Exception))
         multiResult.Result = contentStream;
     multiResult.CompleteSequence();
     return multiResult;
 }
Ejemplo n.º 9
0
 void Close(MultiAsyncResult multiResult)
 {
     this.bufferBuilder.Append(CRLF);
     this.bufferBuilder.Append(DASHDASH);
     this.bufferBuilder.Append(this.boundaryBytes);
     this.bufferBuilder.Append(DASHDASH);
     this.bufferBuilder.Append(CRLF);
     Flush(multiResult);
 }
Ejemplo n.º 10
0
 private void Close(MultiAsyncResult multiResult)
 {
     base._bufferBuilder.Append(BaseWriter.CRLF);
     base._bufferBuilder.Append(DASHDASH);
     base._bufferBuilder.Append(_boundaryBytes);
     base._bufferBuilder.Append(DASHDASH);
     base._bufferBuilder.Append(BaseWriter.CRLF);
     base.Flush(multiResult);
 }
Ejemplo n.º 11
0
 private void Close(MultiAsyncResult multiResult)
 {
     _bufferBuilder.Append(s_crlf);
     _bufferBuilder.Append(s_DASHDASH);
     _bufferBuilder.Append(_boundaryBytes);
     _bufferBuilder.Append(s_DASHDASH);
     _bufferBuilder.Append(s_crlf);
     Flush(multiResult);
 }
Ejemplo n.º 12
0
        internal Stream EndGetContentStream(IAsyncResult result)
        {
            object o = MultiAsyncResult.End(result);

            if (o is Exception)
            {
                throw (Exception)o;
            }
            return((Stream)o);
        }
Ejemplo n.º 13
0
        internal Stream EndGetContentStream(IAsyncResult result)
        {
            object o = MultiAsyncResult.End(result);

            if (o is Exception e)
            {
                ExceptionDispatchInfo.Throw(e);
            }
            return((Stream)o);
        }
Ejemplo n.º 14
0
        internal override Stream EndGetContentStream(IAsyncResult result)
        {
            object obj2 = MultiAsyncResult.End(result);

            if (obj2 is Exception)
            {
                throw ((Exception)obj2);
            }
            return((Stream)obj2);
        }
 internal IAsyncResult BeginGetContentStream(ContentTransferEncoding contentTransferEncoding, AsyncCallback callback, object state)
 {
     MultiAsyncResult multiResult = new MultiAsyncResult(this, callback, state);
     Stream contentStream = this.GetContentStream(contentTransferEncoding, multiResult);
     if (!(multiResult.Result is Exception))
     {
         multiResult.Result = contentStream;
     }
     multiResult.CompleteSequence();
     return multiResult;
 }
Ejemplo n.º 16
0
        internal IAsyncResult BeginGetContentStream(ContentTransferEncoding contentTransferEncoding, AsyncCallback callback, object state)
        {
            MultiAsyncResult multiResult   = new MultiAsyncResult(this, callback, state);
            Stream           contentStream = this.GetContentStream(contentTransferEncoding, multiResult);

            if (!(multiResult.Result is Exception))
            {
                multiResult.Result = contentStream;
            }
            multiResult.CompleteSequence();
            return(multiResult);
        }
Ejemplo n.º 17
0
 private Stream GetContentStream(MultiAsyncResult multiResult)
 {
     if (_isInContent)
         throw new InvalidOperationException(SR.GetString("MailWriterIsInContent"));
     _isInContent = true;
     CheckBoundary();
     _bufferBuilder.Append(CRLF);
     Flush(multiResult);
     var stream = new EightBitStream(_stream, _shouldEncodeLeadingDots);
     var stream2 = new ClosableStream(stream, _onCloseHandler);
     _contentStream = stream2;
     return stream2;
 }
Ejemplo n.º 18
0
        internal IAsyncResult BeginGetContentStream(AsyncCallback callback, object state)
        {
            MultiAsyncResult multiResult = new MultiAsyncResult(this, callback, state);

            Stream s = GetContentStream(multiResult);

            if (!(multiResult.Result is Exception))
            {
                multiResult.Result = s;
            }

            multiResult.CompleteSequence();

            return(multiResult);
        }
Ejemplo n.º 19
0
 private static void OnWrite(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult asyncState = (MultiAsyncResult)result.AsyncState;
         MimeWriter       context    = (MimeWriter)asyncState.Context;
         try
         {
             context.stream.EndWrite(result);
             asyncState.Leave();
         }
         catch (Exception exception)
         {
             asyncState.Leave(exception);
         }
     }
 }
Ejemplo n.º 20
0
 protected static void OnWrite(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult multiResult = (MultiAsyncResult)result.AsyncState;
         BaseWriter       thisPtr     = (BaseWriter)multiResult.Context;
         try
         {
             thisPtr._stream.EndWrite(result);
             multiResult.Leave();
         }
         catch (Exception e)
         {
             multiResult.Leave(e);
         }
     }
 }
Ejemplo n.º 21
0
        private Stream GetContentStream(MultiAsyncResult multiResult)
        {
            if (_isInContent)
            {
                throw new InvalidOperationException(SR.MailWriterIsInContent);
            }

            _isInContent = true;

            CheckBoundary();

            _bufferBuilder.Append(s_crlf);
            Flush(multiResult);

            ClosableStream cs = new ClosableStream(new EightBitStream(_stream, _shouldEncodeLeadingDots), _onCloseHandler);

            _contentStream = cs;
            return(cs);
        }
Ejemplo n.º 22
0
 protected void Flush(MultiAsyncResult multiResult)
 {
     if (_bufferBuilder.Length > 0)
     {
         if (multiResult != null)
         {
             multiResult.Enter();
             var asyncResult = _stream.BeginWrite(_bufferBuilder.GetBuffer(), 0, _bufferBuilder.Length, _onWrite, multiResult);
             if (asyncResult.CompletedSynchronously)
             {
                 _stream.EndWrite(asyncResult);
                 multiResult.Leave();
             }
         }
         else
             _stream.Write(_bufferBuilder.GetBuffer(), 0, _bufferBuilder.Length);
         _bufferBuilder.Reset();
     }
 }
Ejemplo n.º 23
0
        private Stream GetContentStream(MultiAsyncResult multiResult)
        {
            if (this.isInContent)
            {
                throw new InvalidOperationException(SR.GetString(SR.MailWriterIsInContent));
            }

            this.isInContent = true;

            CheckBoundary();

            this.bufferBuilder.Append(CRLF);
            Flush(multiResult);

            Stream         tempStream = new EightBitStream(this.stream, shouldEncodeLeadingDots);
            ClosableStream cs         = new ClosableStream(tempStream, this.onCloseHandler);

            this.contentStream = cs;
            return(cs);
        }
 private void Flush(MultiAsyncResult multiResult)
 {
     if (this.bufferBuilder.Length > 0)
     {
         if (multiResult != null)
         {
             multiResult.Enter();
             IAsyncResult asyncResult = this.stream.BeginWrite(this.bufferBuilder.GetBuffer(), 0, this.bufferBuilder.Length, onWrite, multiResult);
             if (asyncResult.CompletedSynchronously)
             {
                 this.stream.EndWrite(asyncResult);
                 multiResult.Leave();
             }
         }
         else
         {
             this.stream.Write(this.bufferBuilder.GetBuffer(), 0, this.bufferBuilder.Length);
         }
         this.bufferBuilder.Reset();
     }
 }
Ejemplo n.º 25
0
 private void Flush(MultiAsyncResult multiResult)
 {
     if (this.bufferBuilder.Length > 0)
     {
         if (multiResult != null)
         {
             multiResult.Enter();
             IAsyncResult asyncResult = this.stream.BeginWrite(this.bufferBuilder.GetBuffer(), 0, this.bufferBuilder.Length, onWrite, multiResult);
             if (asyncResult.CompletedSynchronously)
             {
                 this.stream.EndWrite(asyncResult);
                 multiResult.Leave();
             }
         }
         else
         {
             this.stream.Write(this.bufferBuilder.GetBuffer(), 0, this.bufferBuilder.Length);
         }
         this.bufferBuilder.Reset();
     }
 }
Ejemplo n.º 26
0
 protected void Flush(MultiAsyncResult multiResult)
 {
     if (_bufferBuilder.Length > 0)
     {
         if (multiResult != null)
         {
             multiResult.Enter();
             IAsyncResult result = _stream.BeginWrite(_bufferBuilder.GetBuffer(), 0,
                                                      _bufferBuilder.Length, s_onWrite, multiResult);
             if (result.CompletedSynchronously)
             {
                 _stream.EndWrite(result);
                 multiResult.Leave();
             }
         }
         else
         {
             _stream.Write(_bufferBuilder.GetBuffer(), 0, _bufferBuilder.Length);
         }
         _bufferBuilder.Reset();
     }
 }
 private Stream GetContentStream(ContentTransferEncoding contentTransferEncoding, MultiAsyncResult multiResult)
 {
     if (this.isInContent)
     {
         throw new InvalidOperationException(SR.GetString("MailWriterIsInContent"));
     }
     this.isInContent = true;
     this.bufferBuilder.Append(CRLF);
     this.Flush(multiResult);
     Stream stream = this.stream;
     if (contentTransferEncoding == ContentTransferEncoding.SevenBit)
     {
         stream = new SevenBitStream(stream);
     }
     else if (contentTransferEncoding == ContentTransferEncoding.QuotedPrintable)
     {
         stream = new QuotedPrintableStream(stream, this.lineLength);
     }
     else if (contentTransferEncoding == ContentTransferEncoding.Base64)
     {
         stream = new Base64Stream(stream, this.lineLength);
     }
     ClosableStream stream2 = new ClosableStream(stream, this.onCloseHandler);
     this.contentStream = stream2;
     return stream2;
 }
Ejemplo n.º 28
0
        internal void EndClose(IAsyncResult result)
        {
            MultiAsyncResult.End(result);

            this.stream.Close();
        }
Ejemplo n.º 29
0
        private Stream GetContentStream(MultiAsyncResult multiResult)
        {
            if (_isInContent)
            {
                throw new InvalidOperationException(SR.MailWriterIsInContent);
            }

            _isInContent = true;

            CheckBoundary();

            _bufferBuilder.Append(s_crlf);
            Flush(multiResult);

            ClosableStream cs = new ClosableStream(new EightBitStream(_stream, _shouldEncodeLeadingDots), _onCloseHandler);
            _contentStream = cs;
            return cs;
        }
 private Stream GetContentStream(ContentTransferEncoding contentTransferEncoding, MultiAsyncResult multiResult)
 {
     this.CheckBoundary();
     this.bufferBuilder.Append(CRLF);
     this.Flush(multiResult);
     Stream stream = this.stream;
     if (contentTransferEncoding == ContentTransferEncoding.SevenBit)
     {
         stream = new SevenBitStream(stream);
     }
     else if (contentTransferEncoding == ContentTransferEncoding.QuotedPrintable)
     {
         stream = new QuotedPrintableStream(stream, this.lineLength);
     }
     else if (contentTransferEncoding == ContentTransferEncoding.Base64)
     {
         stream = new Base64Stream(stream, this.lineLength);
     }
     ClosableStream stream2 = new ClosableStream(stream, this.onCloseHandler);
     this.contentStream = stream2;
     return stream2;
 }
Ejemplo n.º 31
0
        private Stream GetContentStream(MultiAsyncResult multiResult)
        {
            if (this.isInContent)
                throw new InvalidOperationException(SR.GetString(SR.MailWriterIsInContent));

            this.isInContent = true;

            CheckBoundary();

            this.bufferBuilder.Append(CRLF);
            Flush(multiResult);

            Stream tempStream = new EightBitStream(this.stream, shouldEncodeLeadingDots);
            ClosableStream cs = new ClosableStream(tempStream, this.onCloseHandler);
            this.contentStream = cs;
            return cs;
        }
Ejemplo n.º 32
0
        private Stream GetContentStream(ContentTransferEncoding contentTransferEncoding, MultiAsyncResult multiResult)
        {
            this.CheckBoundary();
            this.bufferBuilder.Append(CRLF);
            this.Flush(multiResult);
            Stream stream = this.stream;

            if (contentTransferEncoding == ContentTransferEncoding.SevenBit)
            {
                stream = new SevenBitStream(stream);
            }
            else if (contentTransferEncoding == ContentTransferEncoding.QuotedPrintable)
            {
                stream = new QuotedPrintableStream(stream, this.lineLength);
            }
            else if (contentTransferEncoding == ContentTransferEncoding.Base64)
            {
                stream = new Base64Stream(stream, this.lineLength);
            }
            ClosableStream stream2 = new ClosableStream(stream, this.onCloseHandler);

            this.contentStream = stream2;
            return(stream2);
        }
Ejemplo n.º 33
0
 internal static IAsyncResult BeginSend(SmtpConnection conn, AsyncCallback callback, object state)
 {
     MultiAsyncResult multiResult = new MultiAsyncResult(conn, callback, state);
     multiResult.Enter();
     IAsyncResult writeResult = conn.BeginFlush(s_onWrite, multiResult);
     if (writeResult.CompletedSynchronously)
     {
         conn.EndFlush(writeResult);
         multiResult.Leave();
     }
     SmtpReplyReader reader = conn.Reader.GetNextReplyReader();
     multiResult.Enter();
     IAsyncResult readLinesResult = reader.BeginReadLines(s_onReadLines, multiResult);
     if (readLinesResult.CompletedSynchronously)
     {
         LineInfo[] lines = conn.Reader.CurrentReader.EndReadLines(readLinesResult);
         if (!(multiResult.Result is Exception))
             multiResult.Result = lines;
         multiResult.Leave();
     }
     multiResult.CompleteSequence();
     return multiResult;
 }