private static async Task<NntpClient> ConnectAsync(Server server) { // connect to nntp server var client = new NntpClient(new NntpConnection()); //var client = new NntpClient(new Usenet.Nntp.Experimental.NntpConnection()); if (!await client.ConnectAsync(server.Hostname, server.Port, server.UseSsl)) { Console.WriteLine("Failed to connect."); return null; } // authenticate if (!server.NeedsAuthentication || Authenticate(client, server.Username, server.Password)) { return client; } Console.WriteLine("Login failed, bye."); client.Quit(); return null; }
private static async Task MainAsync(string[] args) { // init logging LibraryLogging.Factory = ApplicationLogging.Factory; log.LogInformation("Program started with {Arguments}.", (object)args); // init config IConfigurationBuilder configBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); config = configBuilder.Build(); // setup DI IServiceProvider serviceProvider = new ServiceCollection() .AddOptions() .Configure<Nntp>(config.GetSection(nameof(Nntp))) .AddSingleton(ApplicationLogging.Factory) .BuildServiceProvider(); // read config Nntp nntpOptions = serviceProvider.GetService<IOptions<Nntp>>().Value; Server server; bool streaming = args.Length > 0 && args[0] == "stream"; log.LogInformation("Decode streaming: {streaming}", streaming); while ((server = ChooseServer(nntpOptions.Servers)) != null) { try { NntpClient client = await ConnectAsync(server); if (client == null) { continue; } TestDownloadNzb(client, @"Testfile.nzb"); //TestDownloadNzbStreaming(client, @"Testfile.nzb"); //TestDate(client); //TestCapabilities(client); //TestHelp(client); //TestListActiveTimes(client); //NntpGroup group = client.Group("alt.test.clienttest").Group; //ShowGroup(group); //TestArticle(client, @group); //TestPost(client); //TestListCounts(client); //TestListOverviewFormat(client); //TestListNewsGroups(client); //TestListDistribPats(client); //TestListHeaders(client); //TestXover(client, group); //TestXhdr(client, group); //TestListDistributions(client); //sw.Restart(); //TestListActive(client); //Console.WriteLine(sw.Elapsed); //TestNewGroups(client); //TestDecompression(client, @group); // quit - close connection client.Quit(); } catch (Exception exception) { log.LogError("Exception: {exception}", exception); } } }