diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-02 15:05:44 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-02 15:05:44 +0300 |
| commit | 05fca4fe321600c4a9c0698b1e4c161e3ed79c9f (patch) | |
| tree | fda984b5a9ff3a3980bf9b6b5a560b3edaa4e668 /Software/Visual_Studio/Tango.CSV/CsvDestination.cs | |
| parent | 3499090dce4acc5b5d4bbb02f07f138950790b25 (diff) | |
| download | Tango-05fca4fe321600c4a9c0698b1e4c161e3ed79c9f.tar.gz Tango-05fca4fe321600c4a9c0698b1e4c161e3ed79c9f.zip | |
Added Tango.CSV project!
Implemented Single/Multi graph recording to CSV!
Diffstat (limited to 'Software/Visual_Studio/Tango.CSV/CsvDestination.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.CSV/CsvDestination.cs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.CSV/CsvDestination.cs b/Software/Visual_Studio/Tango.CSV/CsvDestination.cs new file mode 100644 index 000000000..d88a34684 --- /dev/null +++ b/Software/Visual_Studio/Tango.CSV/CsvDestination.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Collections.Concurrent; +using System.Threading.Tasks; + +namespace Tango.CSV +{ + /// <summary> + /// Represents a <see cref="CsvFile"/> destination. + /// </summary> + public class CsvDestination + { + public StreamWriter StreamWriter; + + /// <summary> + /// Performs an implicit conversion from <see cref="System.String"/> to <see cref="CsvDestination"/>. + /// </summary> + /// <param name="path">The path.</param> + /// <returns> + /// The result of the conversion. + /// </returns> + public static implicit operator CsvDestination(string path) + { + return new CsvDestination(path); + } + + /// <summary> + /// Initializes a new instance of the <see cref="CsvDestination"/> class. + /// </summary> + /// <param name="streamWriter">The stream writer.</param> + private CsvDestination(StreamWriter streamWriter) + { + this.StreamWriter = streamWriter; + } + + /// <summary> + /// Initializes a new instance of the <see cref="CsvDestination"/> class. + /// </summary> + /// <param name="stream">The stream.</param> + private CsvDestination(Stream stream) + { + this.StreamWriter = new StreamWriter(stream); + } + + /// <summary> + /// Initializes a new instance of the <see cref="CsvDestination"/> class. + /// </summary> + /// <param name="fullName">The full name.</param> + public CsvDestination(string fullName) + { + FixCsvFileName(ref fullName); + this.StreamWriter = new StreamWriter(fullName); + } + + /// <summary> + /// Fixes the name of the CSV file. + /// </summary> + /// <param name="fullName">The full name.</param> + private static void FixCsvFileName(ref string fullName) + { + fullName = Path.GetFullPath(fullName); + var path = Path.GetDirectoryName(fullName); + if (path != null && !Directory.Exists(path)) + Directory.CreateDirectory(path); + if (!String.Equals(Path.GetExtension(fullName), ".csv")) + fullName += ".csv"; + } + } +} |
