Skip to content

Commit f71b6d3

Browse files
committed
Janitory work
- Moved lots of stuff into FD.FS.Abstractions - Reactivated StyleCop.Analyzers - Added more documentation - Added more option classes - ConfigureAwait(false) - API cleanup (leaner) - Replaced rda.SocketsForPCL with .NET Core socket API
1 parent e192f56 commit f71b6d3

File tree

128 files changed

+1175
-910
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+1175
-910
lines changed

.editorconfig

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = CRLF
5+
indent_style = space
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.sql]
10+
insert_final_newline = false
11+
12+
[*.cs]
13+
indent_size = 4
14+
charset = utf-8
15+
csharp_style_var_for_built_in_types = true:suggestion
16+
csharp_style_var_when_type_is_apparent = true:suggestion
17+
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
18+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
19+
csharp_prefer_braces = true:suggestion
20+
dotnet_sort_system_directives_first = true
21+
dotnet_separate_import_directive_groups = true
22+
csharp_new_line_before_open_brace = all
23+
24+
# name all constant fields using PascalCase
25+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
26+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
27+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = constant_fields_style
28+
29+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
30+
dotnet_naming_symbols.constant_fields.required_modifiers = const
31+
32+
dotnet_naming_style.constant_fields_style.capitalization = pascal_case
33+
34+
# static fields should have s_ prefix
35+
dotnet_naming_rule.static_fields_fields_should_be_pascal_case.severity = suggestion
36+
dotnet_naming_rule.static_fields_fields_should_be_pascal_case.symbols = static_fields
37+
dotnet_naming_rule.static_fields_fields_should_be_pascal_case.style = static_fields_style
38+
39+
dotnet_naming_symbols.static_fields.applicable_kinds = field
40+
dotnet_naming_symbols.static_fields.required_modifiers = static
41+
42+
dotnet_naming_style.static_fields_style.capitalization = pascal_case
43+
44+
# internal and private fields should be _camelCase
45+
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
46+
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
47+
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
48+
49+
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
50+
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
51+
52+
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
53+
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
54+
55+
[*.{csproj,proj,targets}]
56+
indent_size = 2

FtpServer.ruleset

Lines changed: 0 additions & 19 deletions
This file was deleted.

FubarDev.FtpServer.AccountManagement/AnonymousFtpUser.cs renamed to FubarDev.FtpServer.Abstractions/AccountManagement/AnonymousFtpUser.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="AnonymousFtpUser.cs" company="Fubar Development Junker">
1+
// <copyright file="AnonymousFtpUser.cs" company="Fubar Development Junker">
22
// Copyright (c) Fubar Development Junker. All rights reserved.
33
// </copyright>
44

@@ -12,7 +12,7 @@ namespace FubarDev.FtpServer.AccountManagement
1212
/// <summary>
1313
/// An anonymous FTP user
1414
/// </summary>
15-
public class AnonymousFtpUser : FtpUser
15+
public class AnonymousFtpUser : IFtpUser
1616
{
1717
private readonly HashSet<string> _guestGroups = new HashSet<string>(new[] { "anonymous", "guest" }, StringComparer.OrdinalIgnoreCase);
1818

@@ -21,19 +21,21 @@ public class AnonymousFtpUser : FtpUser
2121
/// </summary>
2222
/// <param name="email">The anonymous users email address</param>
2323
public AnonymousFtpUser([CanBeNull] string email)
24-
: base("anonymous")
2524
{
2625
Email = email;
2726
}
2827

28+
/// <inheritdoc />
29+
public string Name { get; } = "anonymous";
30+
2931
/// <summary>
3032
/// Gets the anonymous users email address
3133
/// </summary>
3234
[CanBeNull]
3335
public string Email { get; }
3436

3537
/// <inheritdoc/>
36-
public override bool IsInGroup(string groupName)
38+
public bool IsInGroup(string groupName)
3739
{
3840
return _guestGroups.Contains(groupName);
3941
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// <copyright file="IFtpUser.cs" company="Fubar Development Junker">
2+
// Copyright (c) Fubar Development Junker. All rights reserved.
3+
// </copyright>
4+
5+
using JetBrains.Annotations;
6+
7+
namespace FubarDev.FtpServer.AccountManagement
8+
{
9+
/// <summary>
10+
/// A basic FTP user interface
11+
/// </summary>
12+
public interface IFtpUser
13+
{
14+
/// <summary>
15+
/// Gets the name of the user
16+
/// </summary>
17+
[NotNull]
18+
string Name { get; }
19+
20+
/// <summary>
21+
/// Returns <code>true</code> when the user is in the given group.
22+
/// </summary>
23+
/// <param name="groupName">The name of the group</param>
24+
/// <returns><c>true</c> when the user is in the queries <paramref name="groupName"/></returns>
25+
bool IsInGroup([NotNull] string groupName);
26+
}
27+
}

FubarDev.FtpServer.AccountManagement/MemberValidationResult.cs renamed to FubarDev.FtpServer.Abstractions/AccountManagement/MemberValidationResult.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="MemberValidationResult.cs" company="Fubar Development Junker">
1+
// <copyright file="MemberValidationResult.cs" company="Fubar Development Junker">
22
// Copyright (c) Fubar Development Junker. All rights reserved.
33
// </copyright>
44

@@ -11,7 +11,7 @@ namespace FubarDev.FtpServer.AccountManagement
1111
/// </summary>
1212
public class MemberValidationResult
1313
{
14-
private readonly FtpUser _user;
14+
private readonly IFtpUser _user;
1515

1616
/// <summary>
1717
/// Initializes a new instance of the <see cref="MemberValidationResult"/> class.
@@ -29,14 +29,12 @@ public MemberValidationResult(MemberValidationStatus status)
2929
/// </summary>
3030
/// <param name="status">The success status for the validation</param>
3131
/// <param name="user">The validated user</param>
32-
public MemberValidationResult(MemberValidationStatus status, FtpUser user)
32+
public MemberValidationResult(MemberValidationStatus status, IFtpUser user)
3333
{
34-
if (user == null)
35-
throw new ArgumentNullException(nameof(user));
3634
if (status != MemberValidationStatus.Anonymous && status != MemberValidationStatus.AuthenticatedUser)
3735
throw new ArgumentOutOfRangeException(nameof(status), "User object must only be specified when validation was successful.");
3836
Status = status;
39-
_user = user;
37+
_user = user ?? throw new ArgumentNullException(nameof(user));
4038
}
4139

4240
/// <summary>
@@ -53,7 +51,7 @@ public MemberValidationStatus Status
5351
/// <summary>
5452
/// Gets the authenticated user.
5553
/// </summary>
56-
public FtpUser User
54+
public IFtpUser User
5755
{
5856
get
5957
{

FubarDev.FtpServer/Address.cs renamed to FubarDev.FtpServer.Abstractions/Address.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
//-----------------------------------------------------------------------
77

88
using System;
9+
using System.Net.Sockets;
910
using System.Text;
1011

1112
using JetBrains.Annotations;
1213

14+
using AF = System.Net.Sockets.AddressFamily;
15+
1316
namespace FubarDev.FtpServer
1417
{
1518
/// <summary>
@@ -41,7 +44,7 @@ public Address(AddressFamily addressFamily, string address, int port)
4144
public Address(string address, int port)
4245
{
4346
_isEnhanced = false;
44-
AddressFamily = address.IndexOf(':') == -1 ? FubarDev.FtpServer.AddressFamily.IPv4 : FubarDev.FtpServer.AddressFamily.IPv6;
47+
AddressFamily = address.IndexOf(':') == -1 ? AF.InterNetwork : AF.InterNetworkV6;
4548
IpAddress = address;
4649
IpPort = port;
4750
}
@@ -97,7 +100,7 @@ public static Address Parse(string address)
97100
/// <returns>The newly created URI</returns>
98101
public Uri ToUri()
99102
{
100-
if (AddressFamily != null && AddressFamily == FubarDev.FtpServer.AddressFamily.IPv6)
103+
if (AddressFamily != null && AddressFamily == AF.InterNetworkV6)
101104
{
102105
return new Uri($"port://[{IpAddress}]:{IpPort}/");
103106
}
@@ -113,7 +116,7 @@ public string ToString(bool logFormat)
113116
{
114117
if (logFormat)
115118
{
116-
if (AddressFamily != null && AddressFamily == FubarDev.FtpServer.AddressFamily.IPv6)
119+
if (AddressFamily != null && AddressFamily == AF.InterNetworkV6)
117120
{
118121
return $"[{IpAddress}]:{IpPort}";
119122
}
@@ -136,10 +139,10 @@ public override string ToString()
136139
{
137140
switch (AddressFamily)
138141
{
139-
case FubarDev.FtpServer.AddressFamily.IPv4:
142+
case AF.InterNetwork:
140143
result.Append("1");
141144
break;
142-
case FubarDev.FtpServer.AddressFamily.IPv6:
145+
case AF.InterNetworkV6:
143146
result.Append("2");
144147
break;
145148
default:
@@ -203,9 +206,9 @@ private static Address ParseEnhanced(string address)
203206
switch (addressType)
204207
{
205208
case 1:
206-
return new Address(FubarDev.FtpServer.AddressFamily.IPv4, ipAddress, port);
209+
return new Address(AF.InterNetwork, ipAddress, port);
207210
case 2:
208-
return new Address(FubarDev.FtpServer.AddressFamily.IPv6, ipAddress, port);
211+
return new Address(AF.InterNetworkV6, ipAddress, port);
209212
default:
210213
throw new NotSupportedException($"Unknown network protocol {addressType}");
211214
}

FubarDev.FtpServer.FileSystem/FileSystemExtensions.cs renamed to FubarDev.FtpServer.Abstractions/FileSystem/FileSystemExtensions.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-----------------------------------------------------------------------
1+
//-----------------------------------------------------------------------
22
// <copyright file="FileSystemExtensions.cs" company="Fubar Development Junker">
33
// Copyright (c) Fubar Development Junker. All rights reserved.
44
// </copyright>
@@ -97,9 +97,8 @@ public static async Task<IUnixDirectoryEntry> GetDirectoryAsync([NotNull] this I
9797
continue;
9898
}
9999

100-
var foundEntry = await fileSystem.GetEntryByNameAsync(currentDir, pathElement, cancellationToken);
101-
var foundDirEntry = foundEntry as IUnixDirectoryEntry;
102-
if (foundDirEntry == null)
100+
var foundEntry = await fileSystem.GetEntryByNameAsync(currentDir, pathElement, cancellationToken).ConfigureAwait(false);
101+
if (!(foundEntry is IUnixDirectoryEntry foundDirEntry))
103102
return null;
104103

105104
currentPath.Push(foundDirEntry);
@@ -136,11 +135,11 @@ public static Task<SearchResult<IUnixDirectoryEntry>> SearchDirectoryAsync([NotN
136135
[ItemCanBeNull]
137136
public static async Task<SearchResult<IUnixDirectoryEntry>> SearchDirectoryAsync([NotNull] this IUnixFileSystem fileSystem, [NotNull, ItemNotNull] Stack<IUnixDirectoryEntry> currentPath, [NotNull, ItemNotNull] IReadOnlyList<string> pathElements, CancellationToken cancellationToken)
138137
{
139-
var sourceDir = await GetDirectoryAsync(fileSystem, currentPath, new ListSegment<string>(pathElements, 0, pathElements.Count - 1), cancellationToken);
138+
var sourceDir = await GetDirectoryAsync(fileSystem, currentPath, new ListSegment<string>(pathElements, 0, pathElements.Count - 1), cancellationToken).ConfigureAwait(false);
140139
if (sourceDir == null)
141140
return null;
142141
var fileName = pathElements[pathElements.Count - 1];
143-
var foundEntry = await fileSystem.GetEntryByNameAsync(sourceDir, fileName, cancellationToken);
142+
var foundEntry = await fileSystem.GetEntryByNameAsync(sourceDir, fileName, cancellationToken).ConfigureAwait(false);
144143
var foundDirEntry = foundEntry as IUnixDirectoryEntry;
145144
if (foundDirEntry == null && foundEntry != null)
146145
return null;
@@ -175,11 +174,11 @@ public static Task<SearchResult<IUnixFileEntry>> SearchFileAsync([NotNull] this
175174
[ItemCanBeNull]
176175
public static async Task<SearchResult<IUnixFileEntry>> SearchFileAsync(this IUnixFileSystem fileSystem, [NotNull, ItemNotNull] Stack<IUnixDirectoryEntry> currentPath, [NotNull, ItemNotNull] IReadOnlyList<string> pathElements, CancellationToken cancellationToken)
177176
{
178-
var sourceDir = await GetDirectoryAsync(fileSystem, currentPath, new ListSegment<string>(pathElements, 0, pathElements.Count - 1), cancellationToken);
177+
var sourceDir = await GetDirectoryAsync(fileSystem, currentPath, new ListSegment<string>(pathElements, 0, pathElements.Count - 1), cancellationToken).ConfigureAwait(false);
179178
if (sourceDir == null)
180179
return null;
181180
var fileName = pathElements[pathElements.Count - 1];
182-
var foundEntry = await fileSystem.GetEntryByNameAsync(sourceDir, fileName, cancellationToken);
181+
var foundEntry = await fileSystem.GetEntryByNameAsync(sourceDir, fileName, cancellationToken).ConfigureAwait(false);
183182
var foundFileEntry = foundEntry as IUnixFileEntry;
184183
if (foundEntry != null && foundFileEntry == null)
185184
return null;
@@ -214,7 +213,7 @@ public static Task<SearchResult<IUnixFileSystemEntry>> SearchEntryAsync([NotNull
214213
[ItemCanBeNull]
215214
public static async Task<SearchResult<IUnixFileSystemEntry>> SearchEntryAsync(this IUnixFileSystem fileSystem, [NotNull, ItemNotNull] Stack<IUnixDirectoryEntry> currentPath, [NotNull, ItemNotNull] IReadOnlyList<string> pathElements, CancellationToken cancellationToken)
216215
{
217-
var sourceDir = await GetDirectoryAsync(fileSystem, currentPath, new ListSegment<string>(pathElements, 0, pathElements.Count - 1), cancellationToken);
216+
var sourceDir = await GetDirectoryAsync(fileSystem, currentPath, new ListSegment<string>(pathElements, 0, pathElements.Count - 1), cancellationToken).ConfigureAwait(false);
218217
if (sourceDir == null)
219218
return null;
220219
IUnixFileSystemEntry foundEntry;
@@ -253,7 +252,7 @@ public static async Task<SearchResult<IUnixFileSystemEntry>> SearchEntryAsync(th
253252
}
254253
break;
255254
default:
256-
foundEntry = await fileSystem.GetEntryByNameAsync(sourceDir, fileName, cancellationToken);
255+
foundEntry = await fileSystem.GetEntryByNameAsync(sourceDir, fileName, cancellationToken).ConfigureAwait(false);
257256
break;
258257
}
259258
return new SearchResult<IUnixFileSystemEntry>(sourceDir, foundEntry, fileName);
@@ -373,7 +372,7 @@ public static IReadOnlyList<string> SplitPath([CanBeNull] string path)
373372
return parts;
374373
var isEscaped = false;
375374
var partCollector = new StringBuilder();
376-
foreach (var ch in path.ToCharArray())
375+
foreach (var ch in path)
377376
{
378377
if (!isEscaped)
379378
{

FubarDev.FtpServer.FileSystem/MemoryTemporaryData.cs renamed to FubarDev.FtpServer.Abstractions/FileSystem/MemoryTemporaryData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-----------------------------------------------------------------------
1+
//-----------------------------------------------------------------------
22
// <copyright file="MemoryTemporaryData.cs" company="Fubar Development Junker">
33
// Copyright (c) Fubar Development Junker. All rights reserved.
44
// </copyright>
@@ -31,7 +31,7 @@ public async Task FillAsync(Stream stream, CancellationToken cancellationToken)
3131
{
3232
_data?.Dispose();
3333
_data = new MemoryStream();
34-
await stream.CopyToAsync(_data, 4096, cancellationToken);
34+
await stream.CopyToAsync(_data, 4096, cancellationToken).ConfigureAwait(false);
3535
}
3636

3737
/// <inheritdoc/>

0 commit comments

Comments
 (0)