-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FileStream and NetworkStream Receiver Abstractions (#103)
* Support NetworkStreamNmeaReceiver and FileStreamNmeaReceiver for online / offline demos. * Remove unused reference * Switch back to networkstream
- Loading branch information
1 parent
9f2e873
commit eacca73
Showing
6 changed files
with
72 additions
and
14 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
43 changes: 43 additions & 0 deletions
43
Solutions/Ais.Net.Receiver/Ais/Net/Receiver/Receiver/FileStreamNmeaReceiver.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,43 @@ | ||
// <copyright file="NmeaReceiver.cs" company="Endjin Limited"> | ||
// Copyright (c) Endjin Limited. All rights reserved. | ||
// </copyright> | ||
|
||
namespace Ais.Net.Receiver.Receiver | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
|
||
public class FileStreamNmeaReceiver : INmeaReceiver | ||
{ | ||
private readonly string path; | ||
|
||
public FileStreamNmeaReceiver(string path) | ||
{ | ||
this.path = path; | ||
} | ||
|
||
public int RetryAttemptLimit { get; } | ||
|
||
public TimeSpan RetryPeriodicity { get; } | ||
|
||
public async IAsyncEnumerable<string> GetAsync([EnumeratorCancellation] CancellationToken cancellationToken = default) | ||
{ | ||
using var sr = new StreamReader(this.path); | ||
|
||
while (sr.Peek() >= 0) | ||
{ | ||
if (cancellationToken.IsCancellationRequested) | ||
{ | ||
break; | ||
} | ||
|
||
string? line = await sr.ReadLineAsync().ConfigureAwait(false); | ||
|
||
if (line is not null) { yield return line; } | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Solutions/Ais.Net.Receiver/Ais/Net/Receiver/Receiver/INmeaReceiver.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,14 @@ | ||
// <copyright file="NmeaReceiver.cs" company="Endjin Limited"> | ||
// Copyright (c) Endjin Limited. All rights reserved. | ||
// </copyright> | ||
|
||
namespace Ais.Net.Receiver.Receiver | ||
{ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
|
||
public interface INmeaReceiver | ||
{ | ||
IAsyncEnumerable<string> GetAsync(CancellationToken cancellationToken = default); | ||
} | ||
} |
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