Skip to content

Commit

Permalink
Merge pull request #6 from keimpema/feature/cleanup
Browse files Browse the repository at this point in the history
Feature/cleanup
  • Loading branch information
keimpema authored Nov 20, 2018
2 parents 2431abb + 2ed489f commit 0c0bfaa
Show file tree
Hide file tree
Showing 166 changed files with 205 additions and 2,642 deletions.
24 changes: 2 additions & 22 deletions Usenet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Usenet", "src\Usenet\Usenet.csproj", "{42FE8430-45CC-401A-AE90-6E3594543BA9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Usenet", "Usenet\Usenet.csproj", "{42FE8430-45CC-401A-AE90-6E3594543BA9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UsenetTests", "test\UsenetTests\UsenetTests.csproj", "{8A17385B-0B95-4CF3-93E1-8DF807F026E9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CC3B2071-7B50-44C1-B599-7A49FE367557}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{8E3D2D44-1804-49A7-9007-CF9E17B30CF3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib", "test\Lib\Lib.csproj", "{C1329F59-21B7-4C7C-814F-95201E54143C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C32CF571-3C3A-4E1A-8C21-E8F3BA4C6DE0}"
ProjectSection(SolutionItems) = preProject
readme.md = readme.md
EndProjectSection
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UsenetTests", "UsenetTests\UsenetTests.csproj", "{8A17385B-0B95-4CF3-93E1-8DF807F026E9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -32,19 +21,10 @@ Global
{8A17385B-0B95-4CF3-93E1-8DF807F026E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A17385B-0B95-4CF3-93E1-8DF807F026E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A17385B-0B95-4CF3-93E1-8DF807F026E9}.Release|Any CPU.Build.0 = Release|Any CPU
{C1329F59-21B7-4C7C-814F-95201E54143C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1329F59-21B7-4C7C-814F-95201E54143C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1329F59-21B7-4C7C-814F-95201E54143C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1329F59-21B7-4C7C-814F-95201E54143C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{42FE8430-45CC-401A-AE90-6E3594543BA9} = {CC3B2071-7B50-44C1-B599-7A49FE367557}
{8A17385B-0B95-4CF3-93E1-8DF807F026E9} = {8E3D2D44-1804-49A7-9007-CF9E17B30CF3}
{C1329F59-21B7-4C7C-814F-95201E54143C} = {8E3D2D44-1804-49A7-9007-CF9E17B30CF3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C065DFE8-4994-4995-9F95-E6AE6F196223}
EndGlobalSection
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using Microsoft.Extensions.Logging;
using Usenet.Exceptions;
using Usenet.Extensions;
using Usenet.Logging;
using Usenet.Nntp.Models;
using Usenet.Util;

Expand All @@ -16,7 +16,7 @@ namespace Usenet.Nntp.Builders
/// </summary>
public class NntpArticleBuilder
{
private static readonly ILogger log = LibraryLogging.Create<NntpArticleBuilder>();
private static readonly ILog log = LogProvider.For<NntpArticleBuilder>();

private const string dateFormat = "dd MMM yyyy HH:mm:ss";

Expand Down Expand Up @@ -78,7 +78,7 @@ public NntpArticleBuilder InitializeFrom(NntpArticle article)
}
else
{
log.LogWarning("Found more than 1 {messageId} header. Skipping it.", NntpHeaders.MessageId);
log.Warn("Found more than 1 {messageId} header. Skipping it.", NntpHeaders.MessageId);
}
break;

Expand All @@ -89,7 +89,7 @@ public NntpArticleBuilder InitializeFrom(NntpArticle article)
}
else
{
log.LogWarning("Found more than 1 {from} header. Skipping it.", NntpHeaders.From);
log.Warn("Found more than 1 {from} header. Skipping it.", NntpHeaders.From);
}
break;

Expand All @@ -100,7 +100,7 @@ public NntpArticleBuilder InitializeFrom(NntpArticle article)
}
else
{
log.LogWarning("Found more than 1 {subject} header. Skipping it.", NntpHeaders.Subject);
log.Warn("Found more than 1 {subject} header. Skipping it.", NntpHeaders.Subject);
}
break;

Expand All @@ -115,12 +115,12 @@ public NntpArticleBuilder InitializeFrom(NntpArticle article)
}
else
{
log.LogWarning("{date} header has invalid value {value}. Skipping it.", NntpHeaders.Date, value);
log.Warn("{date} header has invalid value {value}. Skipping it.", NntpHeaders.Date, value);
}
}
else
{
log.LogWarning("Found more than 1 {date} header. Skipping it.", NntpHeaders.Date);
log.Warn("Found more than 1 {date} header. Skipping it.", NntpHeaders.Date);
}
break;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
namespace Usenet.Nntp.Models
{
/// <summary>
/// Represents origin information about a <see cref="NntpGroup"/> like who
/// created the <see cref="NntpGroup"/> and when.
/// See https://tools.ietf.org/html/rfc3977#section-7.6.4 for more information.
/// See https://tools.ietf.org/html/rfc2980#section-2.1.3 for some older information.
/// Represents origin information about a <see cref="NntpGroup"/> like who created the
/// <see cref="NntpGroup"/> and when. Can be retrieved from the server with the
/// <a href="https://tools.ietf.org/html/rfc3977#section-7.6.4">LIST ACTIVE.TIMES</a> command.
/// (<a href="https://tools.ietf.org/html/rfc2980#section-2.1.3">Some older information</a>).
/// </summary>
public class NntpGroupOrigin : IEquatable<NntpGroupOrigin>
{
Expand All @@ -23,7 +23,7 @@ public class NntpGroupOrigin : IEquatable<NntpGroupOrigin>

/// <summary>
/// A description of the entity that created the <see cref="NntpGroup"/>;
/// it is often a mailbox as described in https://tools.ietf.org/html/rfc2822.
/// it is often a mailbox as described in <a href="https://tools.ietf.org/html/rfc2822">RFC 2822</a>.
/// </summary>
public string CreatedBy { get; }

Expand All @@ -33,7 +33,7 @@ public class NntpGroupOrigin : IEquatable<NntpGroupOrigin>
/// <param name="name">The name of the <see cref="NntpGroup"/>.</param>
/// <param name="createdAt">The date and time the <see cref="NntpGroup"/> was created.</param>
/// <param name="createdBy">A description of the entity that created the <see cref="NntpGroup"/>;
/// it is often a mailbox as described in https://tools.ietf.org/html/rfc2822. </param>
/// it is often a mailbox as described in <a href="https://tools.ietf.org/html/rfc2822">RFC 2822</a>. </param>
public NntpGroupOrigin(string name, DateTimeOffset createdAt, string createdBy)
{
Name = name ?? string.Empty;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Usenet.Extensions;

namespace Usenet.Nntp.Models
{
/// <summary>
/// Represents an NNTP message id.
/// See https://tools.ietf.org/html/rfc3977#appendix-A.2 for more information.
/// Also https://tools.ietf.org/html/rfc3977#section-3.6 contains some useful information.
/// Represents an NNTP <a href="https://tools.ietf.org/html/rfc3977#appendix-A.2">Message-ID</a>.
/// (<a href="https://tools.ietf.org/html/rfc3977#section-3.6">More information</a>).
/// </summary>
public class NntpMessageId : IEquatable<NntpMessageId>
{
Expand All @@ -24,7 +22,7 @@ public class NntpMessageId : IEquatable<NntpMessageId>
/// Wrapping characters "&lt;" and "&gt;" will be stripped.</param>
public NntpMessageId(string value)
{
Value = value?.TrimStart('<').TrimEnd('>').Pack();
Value = value == null ? string.Empty : value.TrimStart('<').TrimEnd('>').Pack();
}

/// <summary>
Expand All @@ -40,7 +38,7 @@ public NntpMessageId(string value)
/// Wraps the <see cref="NntpMessageId"/> in "&lt;" and "&gt;" according to the NNTP specifications.
/// </summary>
/// <returns></returns>
public override string ToString() => Value == null ? null : string.Concat("<", Value, ">");
public override string ToString() => string.IsNullOrEmpty(Value) ? string.Empty : string.Concat("<", Value, ">");

/// <summary>
/// Converts a <see cref="NntpMessageId"/> implicitly to a string.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Usenet.Nntp.Models
{
/// <summary>
/// Represents the status a <see cref="NntpGroup"/> can have on the server.
/// See https://tools.ietf.org/html/rfc3977#section-7.6.3
/// and https://tools.ietf.org/html/rfc6048#section-3.1 for more information.
/// Represents the status a <see cref="NntpGroup"/> can have on the server. Can be retrieved with
/// the <a href="https://tools.ietf.org/html/rfc3977#section-7.6.3">LIST ACTIVE</a> command.
/// (<a href="https://tools.ietf.org/html/rfc6048#section-3.1">More information</a>).
/// </summary>
public enum NntpPostingStatus
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public NntpArticleResponse Body(NntpMessageId messageId) =>
/// that, if the article exists, the response code is 222 instead of 220
/// and only the body is presented (the empty line separating the headers
/// and body MUST NOT be included).
/// See https://tools.ietf.org/html/rfc3977#section-6.2.3 for more information.
/// See <a href="https://tools.ietf.org/html/rfc3977#section-6.2.3">RFC 3977</a> for more information.
/// </summary>
/// <param name="number">The number of the article to receive from the server.</param>
/// <returns>An article response object.</returns>
Expand All @@ -221,7 +221,7 @@ public NntpArticleResponse Body(long number) =>
/// that, if the article exists, the response code is 222 instead of 220
/// and only the body is presented (the empty line separating the headers
/// and body MUST NOT be included).
/// See https://tools.ietf.org/html/rfc3977#section-6.2.3 for more information.
/// See <a href="https://tools.ietf.org/html/rfc3977#section-6.2.3">RFC 3977</a> for more information.
/// </summary>
/// <returns>An article response object.</returns>
public NntpArticleResponse Body() =>
Expand Down Expand Up @@ -262,7 +262,7 @@ public NntpStatResponse Stat(NntpMessageId messageId) =>

/// <summary>
/// Post an article.
/// https://tools.ietf.org/html/rfc3977#section-6.3.1
/// <a href="https://tools.ietf.org/html/rfc3977#section-6.3.1">POST</a> an article.
/// </summary>
public bool Post(NntpArticle article)
{
Expand All @@ -277,9 +277,8 @@ public bool Post(NntpArticle article)
}

/// <summary>
/// The IHAVE command informs the server that the client has an article
/// with the specified message-id.
/// https://tools.ietf.org/html/rfc3977#section-6.3.2
/// The <a href="https://tools.ietf.org/html/rfc3977#section-6.3.2">IHAVE</a> command
/// informs the server that the client has an article with the specified message-id.
/// </summary>
public bool Ihave(NntpArticle article)
{
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.Net.Security;
using System.Net.Sockets;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Usenet.Exceptions;
using Usenet.Logging;
using Usenet.Nntp.Parsers;
using Usenet.Nntp.Responses;
using Usenet.Util;
Expand All @@ -19,7 +19,7 @@ namespace Usenet.Nntp
/// does not support compressed multi-line results.</remarks>
public class NntpConnection : INntpConnection
{
private static readonly ILogger log = LibraryLogging.Create<NntpConnection>();
private static readonly ILog log = LogProvider.For<NntpConnection>();

private readonly TcpClient client = new TcpClient();
private StreamWriter writer;
Expand All @@ -31,7 +31,7 @@ public class NntpConnection : INntpConnection
/// <inheritdoc/>
public async Task<TResponse> ConnectAsync<TResponse>(string hostname, int port, bool useSsl, IResponseParser<TResponse> parser)
{
log.LogInformation("Connecting: {hostname} {port} (Use SSl = {useSsl})", hostname, port, useSsl);
log.Info("Connecting: {hostname} {port} (Use SSl = {useSsl})", hostname, port, useSsl);
await client.ConnectAsync(hostname, port);
Stream = await GetStreamAsync(hostname, useSsl);
writer = new StreamWriter(Stream, UsenetEncoding.Default) { AutoFlush = true };
Expand All @@ -43,8 +43,7 @@ public async Task<TResponse> ConnectAsync<TResponse>(string hostname, int port,
public TResponse Command<TResponse>(string command, IResponseParser<TResponse> parser)
{
ThrowIfNotConnected();
log.LogInformation("Sending command: {Command}",
command.StartsWith("AUTHINFO PASS", StringComparison.Ordinal) ? "AUTHINFO PASS [omitted]" : command);
log.Info("Sending command: {Command}",command.StartsWith("AUTHINFO PASS", StringComparison.Ordinal) ? "AUTHINFO PASS [omitted]" : command);
writer.WriteLine(command);
return GetResponse(parser);
}
Expand All @@ -65,7 +64,7 @@ public TResponse MultiLineCommand<TResponse>(string command, IMultiLineResponseP
public TResponse GetResponse<TResponse>(IResponseParser<TResponse> parser)
{
string responseText = reader.ReadLine();
log.LogInformation("Response received: {Response}", responseText);
log.Info("Response received: {Response}", responseText);

if (responseText == null)
{
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
using Usenet.Logging;
using Usenet.Nntp.Builders;
using Usenet.Nntp.Models;
using Usenet.Nntp.Responses;
Expand All @@ -19,7 +19,7 @@ internal enum ArticleRequestType

internal class ArticleResponseParser : IMultiLineResponseParser<NntpArticleResponse>
{
private static readonly ILogger log = LibraryLogging.Create<ArticleResponseParser>();
private static readonly ILog log = LogProvider.For<ArticleResponseParser>();

private readonly ArticleRequestType requestType;
private readonly int successCode;
Expand Down Expand Up @@ -58,7 +58,7 @@ public NntpArticleResponse Parse(int code, string message, IEnumerable<string> d
string[] responseSplit = message.Split(' ');
if (responseSplit.Length < 2)
{
log.LogError("Invalid response message: {Message} Expected: {{number}} {{messageid}}", message);
log.Error("Invalid response message: {Message} Expected: {{number}} {{messageid}}", message);
}

long.TryParse(responseSplit.Length > 0 ? responseSplit[0] : null, out long number);
Expand Down Expand Up @@ -107,7 +107,7 @@ private static MultiValueDictionary<string, string> GetHeaders(IEnumerator<strin
while (enumerator.MoveNext())
{
string line = enumerator.Current;
if (line.Length == 0)
if (string.IsNullOrEmpty(line))
{
// no more headers (skip empty line)
break;
Expand All @@ -121,7 +121,7 @@ private static MultiValueDictionary<string, string> GetHeaders(IEnumerator<strin
int splitPos = line.IndexOf(':');
if (splitPos < 0)
{
log.LogError("Invalid header line: {Line} Expected: {{key}}:{{value}}", line);
log.Error("Invalid header line: {Line} Expected: {{key}}:{{value}}", line);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Globalization;
using Microsoft.Extensions.Logging;
using Usenet.Logging;
using Usenet.Nntp.Responses;

namespace Usenet.Nntp.Parsers
{
internal class DateResponseParser : IResponseParser<NntpDateResponse>
{
private static readonly ILogger log = LibraryLogging.Create<DateResponseParser>();
private static readonly ILog log = LogProvider.For<DateResponseParser>();

public bool IsSuccessResponse(int code) => code == 111;

Expand All @@ -21,7 +21,7 @@ public NntpDateResponse Parse(int code, string message)
return new NntpDateResponse(code, message, true, dateTime);
}

log.LogError("Invalid response message: {Message} Expected: {{yyyymmddhhmmss}}", message);
log.Error("Invalid response message: {Message} Expected: {{yyyymmddhhmmss}}", message);
return new NntpDateResponse(code, message, false, DateTimeOffset.MinValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
using Usenet.Logging;
using Usenet.Nntp.Models;
using Usenet.Nntp.Responses;

namespace Usenet.Nntp.Parsers
{
internal class GroupOriginsResponseParser : IMultiLineResponseParser<NntpGroupOriginsResponse>
{
private static readonly ILogger log = LibraryLogging.Create<GroupOriginsResponseParser>();
private static readonly ILog log = LogProvider.For<GroupOriginsResponseParser>();

public bool IsSuccessResponse(int code) => code == 215;

Expand Down Expand Up @@ -43,7 +43,7 @@ private static IEnumerable<NntpGroupOrigin> EnumerateGroupOrigins(IEnumerable<st
string[] lineSplit = line.Split(' ');
if (lineSplit.Length < 3)
{
log.LogError("Invalid newsgroup origin line: {Line} Expected: {{group}} {{timestamp}} {{createdby}}", line);
log.Error("Invalid newsgroup origin line: {Line} Expected: {{group}} {{timestamp}} {{createdby}}", line);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Microsoft.Extensions.Logging;
using Usenet.Logging;
using Usenet.Nntp.Models;
using Usenet.Nntp.Responses;

namespace Usenet.Nntp.Parsers
{
internal class GroupResponseParser : IResponseParser<NntpGroupResponse>
{
private static readonly ILogger log = LibraryLogging.Create<GroupResponseParser>();
private static readonly ILog log = LogProvider.For<GroupResponseParser>();

public bool IsSuccessResponse(int code) => code == 211;

Expand All @@ -22,7 +22,7 @@ public NntpGroupResponse Parse(int code, string message)
string[] responseSplit = message.Split(' ');
if (responseSplit.Length < 4)
{
log.LogError("Invalid response message: {Message} Expected: {{count}} {{low}} {{high}} {{group}}", message);
log.Error("Invalid response message: {Message} Expected: {{count}} {{low}} {{high}} {{group}}", message);
}

long.TryParse(responseSplit.Length > 0 ? responseSplit[0] : null, out long articleCount);
Expand Down
File renamed without changes.
Loading

0 comments on commit 0c0bfaa

Please sign in to comment.