Beispiel #1
0
        /// <summary>
        /// Opens a connection to the given usenet server on the specified port, and whether or not to use ssl.
        /// </summary>
        /// <param name="hostname">Usenet hostname</param>
        /// <param name="port">Port to connect on</param>
        /// <param name="ssl">Uses a secure connection if true</param>
        public void Connect(string hostname, int port, bool ssl)
        {
            conn = new Connection(hostname, port, ssl);
            var reply = ServerReply.Parse(conn.ReadLine());

            Connected = reply.IsGood;
        }
Beispiel #2
0
        public ServerReply WriteLine(string line, params object[] args)
        {
            w.WriteLine(line, args);
            string result = ReadLine();
            var    reply  = ServerReply.Parse(result);

            return(reply);
        }
Beispiel #3
0
        private Article ProcessArticle(ServerReply result, bool bodyOnly)
        {
            IBinaryDecoder decoder;

            if (result.IsGood)
            {
                Dictionary <string, string> dict;
                if (bodyOnly)
                {
                    dict = new Dictionary <string, string>();
                    conn.ReadLine();
                }
                else
                {
                    dict = ReadHeader();
                }

                decoder = DecoderFactory.DetermineDecoder(conn);
                if (decoder == null)
                {
                    throw new Exception("Unable to determine binary post encoding.");
                }

                decoder.Decode(
                    d => DownloadedChunk(this, new DownloadProgressEventArgs(d.BytesRead, d.Size, d.Filename, d.Part, d.TotalParts))
                    );

                return(new Article
                {
                    Headers = dict,
                    Body = decoder.Result,
                    Filename = decoder.Filename,
                    Part = decoder.Part,
                    TotalParts = decoder.TotalParts,
                    ExpectedCrc32 = decoder.ExpectedCrc32,
                    ActualCrc32 = decoder.ActualCrc32,
                    Start = decoder.ByteOffset
                });
            }

            return(null);
        }
Beispiel #4
0
        private Article ProcessArticle(ServerReply result, bool bodyOnly)
        {
            IBinaryDecoder decoder;

            if(result.IsGood)
            {
                Dictionary<string, string> dict;
                if(bodyOnly)
                {
                    dict = new Dictionary<string, string>();
                    conn.ReadLine();
                }
                else
                {
                    dict = ReadHeader();
                }

                decoder = DecoderFactory.DetermineDecoder(conn);
                if(decoder == null)
                {
                    throw new Exception("Unable to determine binary post encoding.");
                }

                decoder.Decode(
                    d => DownloadedChunk(this, new DownloadProgressEventArgs(d.BytesRead, d.Size, d.Filename, d.Part, d.TotalParts))
                );

                return new Article
                {
                    Headers = dict,
                    Body = decoder.Result,
                    Filename = decoder.Filename,
                    Part = decoder.Part,
                    TotalParts = decoder.TotalParts,
                    ExpectedCrc32 = decoder.ExpectedCrc32,
                    ActualCrc32 = decoder.ActualCrc32,
                    Start = decoder.ByteOffset
                };
            }
            
            return null;
        }