init
This commit is contained in:
294
Common/DTS.Common.Serialization/Iso/Iso.File.cs
Normal file
294
Common/DTS.Common.Serialization/Iso/Iso.File.cs
Normal file
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Iso.File.cs
|
||||
*
|
||||
* Copyright © 2009
|
||||
* Diversified Technical Systems, Inc.
|
||||
* All Rights Reserved
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using DTS.Common.Utilities.DotNetProgrammingConstructs;
|
||||
using DTS.Serialization.Iso.Report;
|
||||
|
||||
// ISO implementation items:
|
||||
// ------------------------
|
||||
// * Do properly dynamically-presented/not-there-at-all comments.
|
||||
// * Comments.txt file.
|
||||
// * Progress reporting.
|
||||
|
||||
namespace DTS.Serialization.Iso
|
||||
{
|
||||
public partial class File
|
||||
: Serialization.File,
|
||||
IWritable<Test>
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether to export a summary report with the iso export
|
||||
/// http://manuscript.dts.local/f/cases/43833/SW-Test-Summary-Report-for-data-collection-THF
|
||||
/// </summary>
|
||||
public bool ExportSummaryReport { get; set; } = false;
|
||||
|
||||
private readonly Common.ISO.TestPlan _testPlan = null;
|
||||
public Common.ISO.TestPlan GetTestPlan() { return _testPlan; }
|
||||
///
|
||||
/// <summary>
|
||||
/// Initialize an instance of the Iso.File class.
|
||||
/// </summary>
|
||||
///
|
||||
public File(Common.ISO.TestPlan testplan)
|
||||
: base("ISO")
|
||||
{
|
||||
_testPlan = testplan;
|
||||
}
|
||||
public bool UseZeroForUnfiltered { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// when true forces the isocode for filter to by determined by the software filter for the channel
|
||||
/// </summary>
|
||||
public bool UseIsoCodeFilterMapping { get; set; }
|
||||
public bool FilteredExport { get; set; } = false;
|
||||
public bool ExportISOChannelName { get; set; } = false;
|
||||
|
||||
public void AddChannel(string dasserial, int moduleNumber, int number, string description, FilteredData data)
|
||||
{
|
||||
(Exporter as Writer).AddChannel(dasserial, moduleNumber, number, description, data);
|
||||
}
|
||||
|
||||
public void ApplyTestPlan(Serialization.Test test)
|
||||
{
|
||||
foreach (Common.ISO.TestPlan.IsoFields field in Enum.GetValues(typeof(Common.ISO.TestPlan.IsoFields)))
|
||||
{
|
||||
var value = GetTestPlan().GetField(field);
|
||||
switch (field)
|
||||
{
|
||||
case Common.ISO.TestPlan.IsoFields.CustName:
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.CustomerCostUnit:
|
||||
TestInstance.CustomerCostUnit = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.CustomerName:
|
||||
TestInstance.CustomerName = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.CustomerOrderNumber:
|
||||
TestInstance.CustomerOrderNumber = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.CustomerProjectReferenceNumber:
|
||||
TestInstance.CustomerProjectReferenceNumber = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.TEName:
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.TestEngineerEmail:
|
||||
TestInstance.TestEngineerEmail = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.TestEngineerFax:
|
||||
TestInstance.TestEngineerFax = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.TestEngineerName:
|
||||
TestInstance.TestEngineerName = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.TestEngineerPhone:
|
||||
TestInstance.TestEngineerPhone = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.CustomerTestReferenceNumber:
|
||||
TestInstance.CustomerTestReferenceNumber = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.Date:
|
||||
if (DateTime.TryParse(value, out var temp))
|
||||
{
|
||||
TestInstance.Date = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
TestInstance.Date = test.InceptionDate;
|
||||
}
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.ExtraProperties:
|
||||
TestInstance.ExtraProperties = GetTestPlan().ExtraProperties.Select(kvp => new Test.ExtraProperty(kvp.Key, kvp.Value)).ToList();
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.LabName:
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.LaboratoryContactEmail:
|
||||
TestInstance.LaboratoryContactEmail = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.LaboratoryContactFax:
|
||||
TestInstance.LaboratoryContactFax = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.LaboratoryContactName:
|
||||
TestInstance.LaboratoryContactName = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.LaboratoryContactPhone:
|
||||
TestInstance.LaboratoryContactPhone = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.LaboratoryName:
|
||||
TestInstance.LaboratoryName = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.LaboratoryTestReferenceNumber:
|
||||
TestInstance.LaboratoryTestReferenceNumber = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.LaboratoryProjectReferenceNumber:
|
||||
TestInstance.LaboratoryProjectReferenceNumber = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.NumberOfMedia:
|
||||
TestInstance.NumberOfMedia = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.NumberOfTestObjects:
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.ReferenceTemperature:
|
||||
TestInstance.ReferenceTemperature = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.Regulation:
|
||||
TestInstance.Regulation = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.RelativeAirHumidity:
|
||||
TestInstance.RelativeAirHumidity = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.Subtype:
|
||||
TestInstance.Subtype = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.TestComment:
|
||||
TestInstance.TestComment = value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.Title:
|
||||
TestInstance.Title = value == NoValue ? test.Id : value;
|
||||
break;
|
||||
case Common.ISO.TestPlan.IsoFields.Type:
|
||||
TestInstance.Type = value;
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("unsupported iso field");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Get the file writer for this file type.
|
||||
/// </summary>
|
||||
public IWriter<Serialization.Test> Exporter
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_Exporter == null)
|
||||
{
|
||||
var writer = new Writer(this, DefaultEncoding, this);
|
||||
writer.UseZeroForUnfiltered = UseZeroForUnfiltered;
|
||||
writer.UseIsoCodeFilterMapping = UseIsoCodeFilterMapping;
|
||||
writer.FilteredExport = FilteredExport;
|
||||
writer.ExportISOChannelName = ExportISOChannelName;
|
||||
writer.ExportSummaryReport = ExportSummaryReport;
|
||||
_Exporter = writer;
|
||||
}
|
||||
return _Exporter;
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception("encountered problem getting exporter", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
private IWriter<Serialization.Test> _Exporter = null;
|
||||
|
||||
/// <summary>
|
||||
/// File extension for the disk entity that contains the serialized test information.
|
||||
/// </summary>
|
||||
public static string TestFileExtension
|
||||
{
|
||||
get => _TestFileExtension.Value;
|
||||
private set => _TestFileExtension.Value = value;
|
||||
}
|
||||
private static readonly Property<string> _TestFileExtension = new Property<string>("TestFileExtension", ".mme", true);
|
||||
|
||||
/// <summary>
|
||||
/// File extension for the disk entity that contains serialized channel information.
|
||||
/// </summary>
|
||||
public static string ChannelFileExtension
|
||||
{
|
||||
get => _ChannelFileExtension.Value;
|
||||
private set => _ChannelFileExtension.Value = value;
|
||||
}
|
||||
private static readonly Property<string> _ChannelFileExtension = new Property<string>("ChannelFileExtension", ".chn", true);
|
||||
|
||||
/// <summary>
|
||||
/// String representation of a value-less field.
|
||||
/// </summary>
|
||||
private const string NoValue = "NOVALUE";
|
||||
|
||||
/// <summary>
|
||||
/// Line terminator to use when printing out files.
|
||||
/// </summary>
|
||||
private static readonly string Eol = Environment.NewLine;
|
||||
|
||||
/// <summary>
|
||||
/// Attribute/value seperator to use when printing out files.
|
||||
/// </summary>
|
||||
private const string Separator = ":";
|
||||
|
||||
/// <summary>
|
||||
/// Offset to use for attribute/value seperator when printing out files.
|
||||
/// </summary>
|
||||
private const int SeparatorOffset = 28;
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for extracting the value of a field in a controllable context e.g., in
|
||||
/// a try/catch block.
|
||||
/// </summary>
|
||||
///
|
||||
/// <returns>
|
||||
/// The <see cref="string"/> representation of the field.
|
||||
/// </returns>
|
||||
///
|
||||
private delegate string FieldValueStringExtractor();
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of the field wrapped within the extractor delegate.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="extractor">
|
||||
/// The <see cref="DTS.Serialization.File.Iso.File.FieldValueStringExtractor"/> wrapping the
|
||||
/// field to be stringified.
|
||||
/// </param>
|
||||
///
|
||||
/// <returns>
|
||||
/// A <see cref="string"/> version of the field; "NOVALUE" if the field has not been initialized.
|
||||
/// </returns>
|
||||
///
|
||||
private static string GetFieldString(FieldValueStringExtractor extractor)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{ //
|
||||
// Empty string is no value.
|
||||
//
|
||||
|
||||
var fieldString = extractor();
|
||||
return (!string.IsNullOrEmpty(fieldString) ? fieldString : NoValue);
|
||||
}
|
||||
|
||||
catch (System.Exception)
|
||||
{
|
||||
return NoValue;
|
||||
}
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception("encountered problem getting field string from field extractor", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the <see cref="Iso.File.Test"/> associated with this file.
|
||||
/// </summary>
|
||||
public Test TestInstance => _TestInstance.Value;
|
||||
|
||||
private readonly Property<Test> _TestInstance
|
||||
= new Property<Test>(
|
||||
typeof(Test).Namespace + ".Iso.File.TestInstance",
|
||||
new Test(),
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user