/* * 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 { /// /// 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 /// public bool ExportSummaryReport { get; set; } = false; private readonly Common.ISO.TestPlan _testPlan = null; public Common.ISO.TestPlan GetTestPlan() { return _testPlan; } /// /// /// Initialize an instance of the Iso.File class. /// /// public File(Common.ISO.TestPlan testplan) : base("ISO") { _testPlan = testplan; } public bool UseZeroForUnfiltered { get; set; } = false; /// /// when true forces the isocode for filter to by determined by the software filter for the channel /// 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"); } } } /// /// Get the file writer for this file type. /// public IWriter 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 _Exporter = null; /// /// File extension for the disk entity that contains the serialized test information. /// public static string TestFileExtension { get => _TestFileExtension.Value; private set => _TestFileExtension.Value = value; } private static readonly Property _TestFileExtension = new Property("TestFileExtension", ".mme", true); /// /// File extension for the disk entity that contains serialized channel information. /// public static string ChannelFileExtension { get => _ChannelFileExtension.Value; private set => _ChannelFileExtension.Value = value; } private static readonly Property _ChannelFileExtension = new Property("ChannelFileExtension", ".chn", true); /// /// String representation of a value-less field. /// private const string NoValue = "NOVALUE"; /// /// Line terminator to use when printing out files. /// private static readonly string Eol = Environment.NewLine; /// /// Attribute/value seperator to use when printing out files. /// private const string Separator = ":"; /// /// Offset to use for attribute/value seperator when printing out files. /// private const int SeparatorOffset = 28; /// /// Delegate for extracting the value of a field in a controllable context e.g., in /// a try/catch block. /// /// /// /// The representation of the field. /// /// private delegate string FieldValueStringExtractor(); /// /// Get a string representation of the field wrapped within the extractor delegate. /// /// /// /// The wrapping the /// field to be stringified. /// /// /// /// A version of the field; "NOVALUE" if the field has not been initialized. /// /// 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); } } /// /// Get the associated with this file. /// public Test TestInstance => _TestInstance.Value; private readonly Property _TestInstance = new Property( typeof(Test).Namespace + ".Iso.File.TestInstance", new Test(), true ); } }