コード例 #1
0
        /// <summary>
        /// Does the basic command. In the NNTP protocol, a command is sent and the server
        /// possibly returns some text and finally is returns a response code. If a server
        /// returned line equal a single "." we are done and nothing more is returned. If
        /// the server returns a ".." (double period) the leading period is removed and the
        /// remaining string is returned.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="expectedResponseCode">The expected response code.</param>
        /// <returns></returns>
        protected IEnumerable <string> DoBasicCommand(string command, int expectedResponseCode)
        {
            ValidateConnectionState();
            NntpReaderWriter.WriteCommand(command);
            NntpReaderWriter.ReadResponse();

            if (NntpReaderWriter.LastResponseCode != expectedResponseCode)
            {
                throw new NntpResponseException(Resource.ErrorMessage12, NntpReaderWriter.LastResponse);
            }

            do
            {
                string line = NntpReaderWriter.ReadLine();
                if (line.Equals("."))
                {
                    break;
                }
                else if (line.StartsWith(".."))
                {
                    line = line.Substring(1);
                }
                yield return(line);
            } while (true);
        }
コード例 #2
0
        /// <summary>
        /// Does the basic command. In the NNTP protocol, a command is sent and the server
        /// possibly returns some text and finally is returns a response code. If a server
        /// returned line equal a single "." we are done and nothing more is returned. If
        /// the server returns a ".." (double period) the leading period is removed and the
        /// remaining string is returned.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="expectedResponseCode">The expected response code.</param>
        /// <returns></returns>
        protected IEnumerable <string> DoBasicCommand(string command, int expectedResponseCode)
        {
            ValidateConnectionState();
            NntpReaderWriter.WriteCommand(command);
            NntpReaderWriter.ReadResponse();

            if (NntpReaderWriter.LastResponseCode != expectedResponseCode)
            {
                throw new NntpResponseException(NntpErrorMessages.ERROR_12, NntpReaderWriter.LastResponse);
            }

            do
            {
                string line = NntpReaderWriter.ReadLine();
                if (line.Equals("."))
                {
                    break;
                }
                else if (line.Length > 1)
                {
                    if (line[0].Equals('.') && line[1].Equals('.'))
                    {
                        line = line.Substring(1);
                    }
                }

                yield return(line);
            } while (true);
        }