Exemple #1
0
        private static void TestArticle(NntpClient client, NntpGroup @group)
        {
            // get article by message id
            ShowArticle(client.Article("<*****@*****.**>").Article);

            // select group alt.test.clienttest with article numbers            
            ShowGroup(client.ListGroup("alt.test.clienttest").Group);

            // get first article in group
            ShowArticle(client.Article().Article);

            // get last article in group
            ShowArticle(client.Article(@group.HighWaterMark).Article);
        }
Exemple #2
0
        private static void TestDownloadNzbStreaming(NntpClient client, string nzbFileName)
        {
            string fullPath = Path.Combine(nzbFileName);
            string nzbData = File.ReadAllText(fullPath, UsenetEncoding.Default);
            NzbDocument nzbDocument = NzbParser.Parse(nzbData);

            string downloadDir = Path.Combine("downloads", nzbFileName);
            Directory.CreateDirectory(downloadDir);

            var sw = new Stopwatch();
            sw.Restart();

            log.LogInformation("Downloading nzb {nzbFileName}", nzbFileName);
            foreach (NzbFile file in nzbDocument.Files)
            {
                log.LogInformation("Downloading file {subject}", file.Subject);
                foreach (NzbSegment segment in file.Segments)
                {
                    log.LogInformation("Downloading article {messageId}", segment.MessageId);
                    NntpArticleResponse response = client.Article(segment.MessageId);
                    using (YencStream yencStream = YencStreamDecoder.Decode(response.Article.Body))
                    {
                        YencHeader header = yencStream.Header;

                        string fileName = Path.Combine(downloadDir, header.FileName);
                        if (!File.Exists(fileName))
                        {
                            log.LogInformation("Creating file {fileName}", fileName);
                            // create file and pre-allocate disk space for it
                            using (FileStream stream = File.Create(fileName))
                            {
                                stream.SetLength(header.FileSize);
                            }
                        }

                        log.LogInformation("Writing {size} bytes to file {fileName} at offset {offset}",
                            header.PartSize, fileName, header.PartOffset);

                        using (FileStream stream = File.Open(
                            fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
                        {
                            stream.Seek(header.PartOffset, SeekOrigin.Begin);
                            yencStream.CopyTo(stream);
                        }
                    }
                }
            }
            log.LogInformation("Nzb downloaded in {elapsed}", sw.Elapsed);
        }
Exemple #3
0
        private static string TestPost(NntpClient client)
        {
            string messageId = $"cucumber_{Guid.NewGuid()}@hhh.net";

            NntpArticle newArticle = new NntpArticleBuilder()
                .SetMessageId(messageId)
                .SetFrom("Superuser <*****@*****.**>")
                .SetSubject(messageId)
                .AddGroup("alt.test.clienttest")
                .AddGroup("alt.test")
                .AddLine("This is a message with id " + messageId)
                .AddLine("bla bla bla")
                .Build();

            // post
            client.Post(newArticle);

            // read back and show
            ShowArticle(client.Article(messageId).Article);

            return messageId;
        }