180 lines
7.3 KiB
C#
180 lines
7.3 KiB
C#
/*
|
|
* 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
|
|
{ ///
|
|
/// <summary>
|
|
/// Utility object for serializing <see cref="DTS.Serialization.Test"/>s to disk
|
|
/// in the Diadem
|
|
/// </summary>
|
|
///
|
|
public class Writer : Writer<File>, IWriter<Test>
|
|
{
|
|
/// <summary>
|
|
/// Initialize an instance of the SoMat.File.Writer class.
|
|
/// </summary>
|
|
///
|
|
/// <param name="fileType">
|
|
/// The associated <see cref="DTS.SErialization.Diadem.File"/> object.
|
|
/// </param>
|
|
///
|
|
internal Writer(File fileType, int encoding)
|
|
: base(fileType, encoding)
|
|
{
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Write the specified test to the specified pathname.
|
|
/// </summary>
|
|
///
|
|
/// <param name="pathname">
|
|
/// The <see cref="string"/> pathname to which the specified test should be serialized.
|
|
/// </param>
|
|
///
|
|
/// <param name="test">
|
|
/// The <see cref="DTS.Serialization.Test"/> to be written out.
|
|
/// </param>
|
|
///
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Write the representation file/files of the specified DTS.Serialization.Test
|
|
/// at the given pathname.
|
|
/// </summary>
|
|
///
|
|
/// <param name="targetPathname">
|
|
/// The <see cref="string"/> pathname of the specified object's resulting file
|
|
/// representation.
|
|
/// </param>
|
|
///
|
|
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)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|