-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
426 additions
and
312 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
40 changes: 40 additions & 0 deletions
40
src/console/LibplanetConsole.Console/ConsoleContentBase.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,40 @@ | ||
namespace LibplanetConsole.Console; | ||
|
||
public abstract class ConsoleContentBase(string name) : IConsoleContent, IDisposable | ||
{ | ||
private readonly string _name = name; | ||
private bool _isDisposed; | ||
|
||
public string Name => _name != string.Empty ? _name : GetType().Name; | ||
|
||
public virtual IEnumerable<IConsoleContent> Dependencies => []; | ||
|
||
void IDisposable.Dispose() | ||
{ | ||
OnDispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
Task IConsoleContent.StartAsync(CancellationToken cancellationToken) | ||
=> OnStartAsync(cancellationToken); | ||
|
||
Task IConsoleContent.StopAsync(CancellationToken cancellationToken) | ||
=> OnStopAsync(cancellationToken); | ||
|
||
protected abstract Task OnStartAsync(CancellationToken cancellationToken); | ||
|
||
protected abstract Task OnStopAsync(CancellationToken cancellationToken); | ||
|
||
protected virtual void OnDispose(bool disposing) | ||
{ | ||
if (!_isDisposed) | ||
{ | ||
if (disposing) | ||
{ | ||
// do nothing | ||
} | ||
|
||
_isDisposed = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.