Skip to content

Commit

Permalink
refactor: Use inheritdoc for PipeServer.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Dec 8, 2023
1 parent bd85946 commit 598067f
Showing 1 changed file with 13 additions and 41 deletions.
54 changes: 13 additions & 41 deletions src/libs/H.Pipes/PipeServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,21 @@ public sealed class PipeServer<T> : IPipeServer<T>
{
#region Properties

/// <summary>
/// Name of pipe
/// </summary>
/// <inheritdoc />
public string PipeName { get; }

/// <summary>
/// CreatePipeStreamFunc
/// </summary>
/// <inheritdoc />
public Func<string, NamedPipeServerStream>? CreatePipeStreamFunc { get; set; }

/// <summary>
/// If set, used instead of CreatePipeStreamFunc for connections
/// </summary>
public Func<string, NamedPipeServerStream>? CreatePipeStreamForConnectionFunc { get; set; }

/// <summary>
/// PipeStreamInitializeAction
/// </summary>
/// <inheritdoc />
public Action<NamedPipeServerStream>? PipeStreamInitializeAction { get; set; }

/// <summary>
/// Used formatter
/// </summary>
/// <inheritdoc />
public IFormatter Formatter { get; set; }

/// <summary>
Expand All @@ -58,11 +50,8 @@ public sealed class PipeServer<T> : IPipeServer<T>
.Where(connection => connection.IsConnected)
.ToList();

/// <summary>
/// IsStarted
/// </summary>
public bool IsStarted => ListenWorker != null && !ListenWorker.Task.IsCompleted && !ListenWorker.Task.IsCanceled && !ListenWorker.Task.IsFaulted;

/// <inheritdoc />
public bool IsStarted => ListenWorker is { Task: { IsCompleted: false, IsCanceled: false, IsFaulted: false } };

private TaskWorker? ListenWorker { get; set; }

Expand All @@ -72,24 +61,16 @@ public sealed class PipeServer<T> : IPipeServer<T>

#region Events

/// <summary>
/// Invoked whenever a client connects to the server.
/// </summary>
/// <inheritdoc />
public event EventHandler<ConnectionEventArgs<T>>? ClientConnected;

/// <summary>
/// Invoked whenever a client disconnects from the server.
/// </summary>
/// <inheritdoc />
public event EventHandler<ConnectionEventArgs<T>>? ClientDisconnected;

/// <summary>
/// Invoked whenever a client sends a message to the server.
/// </summary>
/// <inheritdoc />
public event EventHandler<ConnectionMessageEventArgs<T?>>? MessageReceived;

/// <summary>
/// Invoked whenever an exception is thrown during a read or write operation.
/// </summary>
/// <inheritdoc />
public event EventHandler<ExceptionEventArgs>? ExceptionOccurred;

private void OnClientConnected(ConnectionEventArgs<T> args)
Expand Down Expand Up @@ -131,12 +112,7 @@ public PipeServer(string pipeName, IFormatter? formatter = default)

#region Public methods

/// <summary>
/// Begins listening for client connections in a separate background thread.
/// This method waits when pipe will be created(or throws exception).
/// </summary>
/// <exception cref="InvalidOperationException"></exception>
/// <exception cref="IOException"></exception>
/// <inheritdoc />
public async Task StartAsync(CancellationToken cancellationToken = default)
{
if (IsStarted)
Expand Down Expand Up @@ -300,9 +276,7 @@ public async Task WriteAsync(T value, string pipeName, CancellationToken cancell
await WriteAsync(value, connection => connection.PipeName == pipeName, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Closes all open client connections and stops listening for new ones.
/// </summary>
/// <inheritdoc />
public async Task StopAsync(CancellationToken _ = default)
{
if (ListenWorker != null)
Expand All @@ -325,9 +299,7 @@ public async Task StopAsync(CancellationToken _ = default)

#region IDisposable

/// <summary>
/// Dispose internal resources
/// </summary>
/// <inheritdoc />
public async ValueTask DisposeAsync()
{
if (_isDisposed)
Expand Down

0 comments on commit 598067f

Please sign in to comment.