-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shell for test FTP server can now list and close connections
Copied ReadLine into third-party and changed to allow async auto completion handlers.
- Loading branch information
1 parent
318fb3c
commit a45b452
Showing
26 changed files
with
926 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// <copyright file="FtpConnectionStatus.cs" company="Fubar Development Junker"> | ||
// Copyright (c) Fubar Development Junker. All rights reserved. | ||
// </copyright> | ||
|
||
namespace TestFtpServer.Api | ||
{ | ||
/// <summary> | ||
/// Information about a single FTP connection. | ||
/// </summary> | ||
public class FtpConnectionStatus | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FtpConnectionStatus"/> class. | ||
/// </summary> | ||
/// <param name="id">The ID of the connection.</param> | ||
public FtpConnectionStatus(string id) | ||
{ | ||
Id = id; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the ID of the connection. | ||
/// </summary> | ||
public string Id { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the connection is alive (read: not expired). | ||
/// </summary> | ||
public bool IsAlive { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
samples/TestFtpServer.Shell/Commands/CloseConnectionCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// <copyright file="CloseConnectionCommandHandler.cs" company="Fubar Development Junker"> | ||
// Copyright (c) Fubar Development Junker. All rights reserved. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using JKang.IpcServiceFramework; | ||
|
||
using TestFtpServer.Api; | ||
|
||
namespace TestFtpServer.Shell.Commands | ||
{ | ||
/// <summary> | ||
/// Command handler for closing a client FTP connection. | ||
/// </summary> | ||
public class CloseConnectionCommandHandler : ICommandInfo | ||
{ | ||
private readonly IpcServiceClient<IFtpServerHost> _client; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CloseConnectionCommandHandler"/> class. | ||
/// </summary> | ||
/// <param name="client">The IPC client.</param> | ||
public CloseConnectionCommandHandler(IpcServiceClient<IFtpServerHost> client) | ||
{ | ||
_client = client; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public string Name { get; } = "connection"; | ||
|
||
/// <inheritdoc /> | ||
public IReadOnlyCollection<string> AlternativeNames { get; } = Array.Empty<string>(); | ||
|
||
/// <inheritdoc /> | ||
public async IAsyncEnumerable<ICommandInfo> GetSubCommandsAsync( | ||
[EnumeratorCancellation] CancellationToken cancellationToken) | ||
{ | ||
var connections = await _client | ||
.InvokeAsync(host => host.GetConnections(), cancellationToken) | ||
.ConfigureAwait(false); | ||
foreach (var connection in connections) | ||
{ | ||
yield return new CloseConnectionFinalCommandHandler(_client, connection.Id); | ||
} | ||
} | ||
|
||
private class CloseConnectionFinalCommandHandler : IExecutableCommandInfo | ||
{ | ||
private readonly IpcServiceClient<IFtpServerHost> _client; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CloseConnectionFinalCommandHandler"/> class. | ||
/// </summary> | ||
/// <param name="client">The IPC client.</param> | ||
/// <param name="connectionId">The FTP connection ID.</param> | ||
public CloseConnectionFinalCommandHandler( | ||
IpcServiceClient<IFtpServerHost> client, | ||
string connectionId) | ||
{ | ||
_client = client; | ||
Name = connectionId; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public string Name { get; } | ||
|
||
/// <inheritdoc /> | ||
public IReadOnlyCollection<string> AlternativeNames { get; } = Array.Empty<string>(); | ||
|
||
/// <inheritdoc /> | ||
public IAsyncEnumerable<ICommandInfo> GetSubCommandsAsync(CancellationToken cancellationToken) | ||
=> AsyncEnumerable.Empty<ICommandInfo>(); | ||
|
||
/// <inheritdoc /> | ||
public Task ExecuteAsync(CancellationToken cancellationToken) | ||
{ | ||
return _client.InvokeAsync(host => host.CloseConnectionAsync(Name), cancellationToken); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.