コード例 #1
0
ファイル: ITextStream.cs プロジェクト: rajeshwarn/SmtpServer
        /// <summary>
        /// Reply to the client.
        /// </summary>
        /// <param name="stream">The text stream to perform the operation on.</param>
        /// <param name="response">The response.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A task which performs the operation.</returns>
        public static async Task ReplyAsync(this ITextStream stream, SmtpResponse response, CancellationToken cancellationToken)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            await stream.WriteLineAsync($"{(int)response.ReplyCode} {response.Message}", cancellationToken);

            await stream.FlushAsync(cancellationToken);
        }
コード例 #2
0
ファイル: ITextStream.cs プロジェクト: rajeshwarn/SmtpServer
        /// <summary>
        /// Writes a line of characters asynchronously to the current stream.
        /// </summary>
        /// <param name="stream">The stream to perform the operation on.</param>
        /// <param name="text">The text to write to the stream.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A task that represents the asynchronous write operation.</returns>
        public static async Task WriteLineAsync(this ITextStream stream, string text, CancellationToken cancellationToken)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            try
            {
                await stream.WriteLineAsync(text).WithCancellation(cancellationToken);
            }
            catch (OperationCanceledException) { }
        }