/* * SoMat.File.Writer.cs * * Copyright © 2009 * Diversified Technical Systems, Inc. * All Rights Reserved */ using System; using System.IO; using System.Text; using DTS.Common.Utilities.Logging; namespace DTS.Serialization.SoMat { // *** see SoMat.File.Writer.cs *** public partial class File { /// /// /// Utility object for serializing s to disk /// in the Diadem /// /// public class Writer : Writer, IWriter { /// /// Initialize an instance of the SoMat.File.Writer class. /// /// /// /// The associated object. /// /// internal Writer(File fileType, int encoding) : base(fileType, encoding) { } /// /// Write the specified test to the specified pathname. /// /// /// /// The pathname to which the specified test should be serialized. /// /// /// /// The to be written out. /// /// public void Write(string pathname, string id, Test test, bool bFiltering, bool includeGroupNameInISOExport, double minStartTime, int dataCollectionLength) { throw new NotSupportedException("SoMat::File::Writer Write(pathname, id, test, bFiltering) not supported"); } private FilteredData[] _filterdData = null; public FilteredData[] FilteredData { get => _filterdData; set => _filterdData = value; } /// /// Write the representation file/files of the specified DTS.Serialization.Test /// at the given pathname. /// /// /// /// The pathname of the specified object's resulting file /// representation. /// /// public void Write(string pathname, string id, string dataFolder, Test test, bool bFiltering, bool includeGroupNameInISOExport, FilteredData fd, Test.Module.Channel tmChannel, int channelNumber, BeginEventHandler beginEventHandler, CancelEventHandler cancelEventHandler, EndEventHandler endEventHandler, TickEventHandler tickEventHandler, ErrorEventHandler errorEventHandler, CancelRequested cancelRequested, double minStartTime, int dataCollectionLength) { System.Exception exception = null; try { beginEventHandler?.Invoke(this, Convert.ToUInt32(test.Channels.Count)); var header = new SoMatTestHeader(test, FilteredData); using (var sw = new StreamWriter(pathname, false, Encoding.Default)) { header.Serialize(sw); foreach (var channel in header.Channels) { channel.Serialize(sw); } sw.Write("DM_Start=\r\n"); ulong maxSamples = 0; foreach (var module in test.Modules) { maxSamples = Math.Max(maxSamples, module.NumberOfSamples); } double totalWriteTicksDispatched = 0; double totalWriteTicksNeeded = 100; var DataSamplesPerTick = Convert.ToUInt64(maxSamples / (double)totalWriteTicksNeeded); for (uint i = 0; i < maxSamples; i++) { sw.WriteLine(); var bNeedTab = false; foreach (var fdvar in _filterdData) { if (bNeedTab) { sw.Write("\t"); } if (i < fdvar.Data.Length) { sw.Write(fdvar.Data[i].ToString("0.00000E+00")); } bNeedTab = true; } if (0 == i % DataSamplesPerTick) { if (null != tickEventHandler) { tickEventHandler(this, ((double)totalWriteTicksDispatched++) / totalWriteTicksNeeded * 100); System.Windows.Forms.Application.DoEvents(); } } } sw.Flush(); sw.Close(); } } catch (System.Exception ex) { exception = ex; APILogger.Log("encountered problem writing SoMat test files", ex); } tickEventHandler?.Invoke(this, 100D); if (null != errorEventHandler && null != exception) { endEventHandler(this); errorEventHandler(this, exception); } else if (null != exception) { throw exception; } else { tickEventHandler?.Invoke(this, 100.0); endEventHandler?.Invoke(this); } } public void Initialize(string pathname, string id, string dataFolder, Test test, bool bFiltering, bool includeGroupNameInISOExport, FilteredData fd, Test.Module.Channel tmChannel, int channelNumber, BeginEventHandler beginEventHandler, CancelEventHandler cancelEventHandler, EndEventHandler endEventHandler, TickEventHandler tickEventHandler, ErrorEventHandler errorEventHandler, CancelRequested cancelRequested) { } } } }