-
-
Notifications
You must be signed in to change notification settings - Fork 2
Stream data to export file #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DanielSpindler83
wants to merge
32
commits into
TurnerSoftware:main
Choose a base branch
from
DanielSpindler83:stream-data-to-export-file
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
17d04c9
Started on two unit test methods for PingSession
DanielSpindler83 4016c16
Refactor, cleanup comments. Add assert for TestPingStatisticsDivideBy…
DanielSpindler83 73e5182
merge in dividebyzero fix
DanielSpindler83 87f9151
add asserts to main stats test and resolve some decimal rounding issues
DanielSpindler83 2481171
add in the divide by zero fix for AverageRoundTrip
DanielSpindler83 959bc0e
merge main into unit-testing - resolve conflicts manually.
DanielSpindler83 92145f6
Apply code style changes already done elsewhere.
DanielSpindler83 9443cf7
redesign PingSession to be stateful. No longer requires a list of Pin…
DanielSpindler83 d210dd1
Add command line arg ExportFile to PingRequestOptions - so we can use…
DanielSpindler83 3c7b265
remove old export code from program.cs
DanielSpindler83 e387fb9
redesign PingRequestAgent to use new stateful PingSession.
DanielSpindler83 9de8574
redesign unit tests to cater for new PingSession stateful design.
DanielSpindler83 3d5c170
change TotalRoundtrip to a double so we can round AverageRoundTrip to…
DanielSpindler83 0d226ea
remove unused pingRequests List
DanielSpindler83 4927bef
Add export file components to PingRequestAgent.
DanielSpindler83 4a60b6b
closes TurnerSoftware/Pingalot#6
DanielSpindler83 f2aed7c
create a TestPingResult method. https://github.com/TurnerSoftware/Pin…
DanielSpindler83 9cf489c
remove for loops creating test pingrequests.
DanielSpindler83 8a5c277
missed one test ping for ConfirmPingSessionStatistics. Added in.
DanielSpindler83 4adf00f
remove uneccesary link
DanielSpindler83 75876f4
experiment with single write file stream
DanielSpindler83 50106c2
add new -e flag for default export, refactor main perform pings loop,…
DanielSpindler83 ed1984c
setup and test FileExporter event
DanielSpindler83 8a925ab
add new -e flag for default export and refactor pingarguments
DanielSpindler83 fc6db54
file exporter working with event. No using and no dispose.
DanielSpindler83 a5082fa
tested and working export
DanielSpindler83 69b6ea5
merge in export event branch
DanielSpindler83 3e6d31d
remove unused export methods
DanielSpindler83 ab892e7
bug fix missing parameter
DanielSpindler83 51ba350
bug fix
DanielSpindler83 a092cfd
removed commented out code
DanielSpindler83 5ea55e7
added filexporter to traditional ping and tested
DanielSpindler83 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,50 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using CsvHelper; | ||
|
|
||
| namespace Pingalot | ||
| { | ||
| public class PingRequestFileExporter : IDisposable | ||
| { | ||
| private FileStream stream; | ||
| private StreamWriter writer; | ||
| private CsvWriter csv; | ||
|
|
||
| public PingRequestFileExporter(string ExportFileFullPath) | ||
| { | ||
|
|
||
| stream = File.Open(ExportFileFullPath, FileMode.Append,FileAccess.Write, FileShare.Read); | ||
| writer = new StreamWriter(stream, Encoding.UTF8, 1024, true); | ||
| csv = new CsvWriter(writer, CultureInfo.InvariantCulture); | ||
| csv.WriteHeader<PingRequestExportModel>(); | ||
| csv.NextRecord(); | ||
|
|
||
| } | ||
|
|
||
| public void ExportSingleResultToFile(object sender, PingCompletedEventArgs pingCompletedEventArgs) | ||
| { | ||
| // write a single pingrequest record to export file | ||
| var singleExportablePingResult = new PingRequestExportModel(pingCompletedEventArgs.CompletedPing); | ||
| csv.WriteRecord(singleExportablePingResult); | ||
| csv.Flush(); | ||
| csv.NextRecord(); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| csv.Dispose(); | ||
| writer.Dispose(); | ||
| stream.Dispose(); | ||
| } | ||
|
|
||
| ~PingRequestFileExporter() | ||
| { | ||
| this.Dispose(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see why you had trouble trying to dispose of it. A quick-and-dirty workaround would be to declare
PingRequestFileExporter? pingRequestFileExporter = null;before the if-statement and then wrap the rest of the code in a try/finally. Then in the finally, we gopingRequestFileExporter?.Dispose();.For a more complete solution, it might be a more ground-up redesign of how the classes interact with each other so we don't even need the file exporter within the specific visual implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean by the last part is that some of the difficulty is really just how the classes call each other. Ideal world would have something like each "layout" just register events rather than handle the life cycle itself. The ping session is kinda redundant now as we don't do anything with it. Remove the replication from the cancel key press etc logic in each layout.
If I were to name what I'm thinking, something like "pipelines". Each thing (a layout, exporting, etc) is just an item on the pipeline. I guess kinda like how the middleware works for ASP.NET Core but more around events than just calling a
next();action.