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


C# IConnection.ReadLineAsync方法代码示例

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


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

示例1: ProcessAsync

        public async virtual Task ProcessAsync(IConnection connection, SmtpCommand command)
        {
            if (connection.CurrentMessage == null)
            {
                await connection.WriteResponseAsync(new SmtpResponse(StandardSmtpResponseCode.BadSequenceOfCommands,
                                                                   "Bad sequence of commands"));
                return;
            }

            connection.CurrentMessage.SecureConnection = connection.Session.SecureConnection;
            await connection.WriteResponseAsync(new SmtpResponse(StandardSmtpResponseCode.StartMailInputEndWithDot,
                                                               "End message with period"));

            using (StreamWriter writer = new StreamWriter(connection.CurrentMessage.WriteData(), connection.ReaderEncoding))
            {
                bool firstLine = true;

                do
                {
                    string line = await connection.ReadLineAsync();

                    if (line != ".")
                    {
                        line = ProcessLine(line);

                        if (!firstLine)
                            writer.Write(Environment.NewLine);

                        writer.Write(line);
                    }
                    else
                    {
                        break;
                    }

                    firstLine = false;
                } while (true);

                writer.Flush();
                long? maxMessageSize =
                    connection.Server.Behaviour.GetMaximumMessageSize(connection);

                if (maxMessageSize.HasValue && writer.BaseStream.Length > maxMessageSize.Value)
                {
                    await connection.WriteResponseAsync(
                        new SmtpResponse(StandardSmtpResponseCode.ExceededStorageAllocation,
                                         "Message exceeds fixed size limit"));
                }
                else
                {
                    writer.Dispose();
                    connection.Server.Behaviour.OnMessageCompleted(connection);
                    await connection.WriteResponseAsync(new SmtpResponse(StandardSmtpResponseCode.OK, "Mail accepted"));
                    connection.CommitMessage();
                }
            }
        }
开发者ID:rnwood,项目名称:smtp4dev,代码行数:57,代码来源:DataVerb.cs

示例2: ProcessAsync

        public async Task ProcessAsync(IConnection connection, SmtpCommand command)
        {
            ArgumentsParser argumentsParser = new ArgumentsParser(command.ArgumentsText);

            if (argumentsParser.Arguments.Length > 0)
            {
                if (connection.Session.Authenticated)
                {
                    throw new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.BadSequenceOfCommands,
                                                                   "Already authenticated"));
                }

                string mechanismId = argumentsParser.Arguments[0];
                IAuthMechanism mechanism = AuthExtensionProcessor.MechanismMap.Get(mechanismId);

                if (mechanism == null)
                {
                    throw new SmtpServerException(
                        new SmtpResponse(StandardSmtpResponseCode.CommandParameterNotImplemented,
                                         "Specified AUTH mechanism not supported"));
                }

                if (!AuthExtensionProcessor.IsMechanismEnabled(mechanism))
                {
                    throw new SmtpServerException(
                        new SmtpResponse(StandardSmtpResponseCode.AuthenticationFailure,
                                         "Specified AUTH mechanism not allowed right now (might require secure connection etc)"));
                }

                IAuthMechanismProcessor authMechanismProcessor =
                    mechanism.CreateAuthMechanismProcessor(connection);

                string initialData = null;
                if (argumentsParser.Arguments.Length > 1)
                {
                    initialData = string.Join(" ", argumentsParser.Arguments.Skip(1).ToArray());
                }

                AuthMechanismProcessorStatus status =
                    await authMechanismProcessor.ProcessResponseAsync(initialData);
                while (status == AuthMechanismProcessorStatus.Continue)
                {
                    string response = await connection.ReadLineAsync();

                    if (response == "*")
                    {
                        await connection.WriteResponseAsync(new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments, "Authentication aborted"));
                        return;
                    }

                    status = await authMechanismProcessor.ProcessResponseAsync(response);
                }

                if (status == AuthMechanismProcessorStatus.Success)
                {
                    await connection.WriteResponseAsync(new SmtpResponse(StandardSmtpResponseCode.AuthenticationOK,
                                                              "Authenticated OK"));
                    connection.Session.Authenticated = true;
                    connection.Session.AuthenticationCredentials = authMechanismProcessor.Credentials;
                }
                else
                {
                    await connection.WriteResponseAsync(new SmtpResponse(StandardSmtpResponseCode.AuthenticationFailure,
                                                              "Authentication failure"));
                }
            }
            else
            {
                throw new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments,
                                                               "Must specify AUTH mechanism as a parameter"));
            }
        }
开发者ID:rnwood,项目名称:smtp4dev,代码行数:72,代码来源:AuthVerb.cs


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