Major upgrade

This commit is contained in:
Duc
2025-10-24 15:18:11 -07:00
parent fd85735c93
commit ce583d1664
478 changed files with 237518 additions and 47610 deletions

View File

@@ -0,0 +1,11 @@
namespace Raytheon.Common.PdelWriter.Utilities
{
public enum PassFailStatus
{
Pass,
Fail,
Unknown
}
}

View File

@@ -0,0 +1,81 @@
using System;
using System.Globalization;
namespace Raytheon.Common.PdelWriter
{
public static class PdelDataFormatter
{
#region Public Members
/// <summary>
/// Formats the specified measurement data type.
/// </summary>
/// <param name="measuredValue">The measured value.</param>
/// <returns>Returns a properly formatted string.</returns>
public static string Format(string measuredValue)
{
string prefix = string.Empty;
string extension = string.Empty;
double value;
DateTime datetime = default(DateTime);
if (double.TryParse(measuredValue, out value))
{
prefix = "R";
if (measuredValue.IndexOf('.') != -1)
{
extension = measuredValue.Substring(measuredValue.IndexOf('.') + 1).Length.ToString(CultureInfo.CurrentCulture);
}
else
{
// If we don't have a decimal point it must have converted to an integer value.
prefix = "I";
extension = measuredValue.Length.ToString(CultureInfo.CurrentCulture);
}
}
else if (DateTime.TryParse(measuredValue, out datetime))
{
prefix = "T";
extension = string.Empty;
}
else
{
try
{
int dummy = Convert.ToInt32(measuredValue, 16);
prefix = "H";
extension = measuredValue.Length.ToString(CultureInfo.CurrentCulture);
}
catch (Exception)
{
prefix = "S";
extension = measuredValue.Length.ToString(CultureInfo.CurrentCulture);
}
}
return prefix + extension;
}
/// <summary>
/// Determines whether [is null or empty] [the specified units].
/// </summary>
/// <param name="units">The units.</param>
/// <returns>Returns a string value for the units.</returns>
public static string IsNullOrEmpty(this string units)
{
var returnValue = "NONE";
if (!string.IsNullOrEmpty(units))
{
returnValue = units;
}
return returnValue;
}
#endregion
}
}

View File

@@ -0,0 +1,311 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
namespace Raytheon.Common.PdelWriter.Utilities
{
[XmlType("TestExecutive-PdelInformation")]
public class PdelInformation
{
#region Public Properties
/// <summary>
/// Gets or sets the Test Data Standard Version.
/// </summary>
/// <value>The Test Data Standard Version.</value>
[XmlElement("TestDataStandardVersion")]
public string TestDataStandardVersion { get; set; }
/// <summary>
/// Gets or sets the UUT Identification.
/// </summary>
/// <value>The UUT Identification.</value>
[XmlElement("UutIdentification")]
public string UutIdentification { get; set; }
/// <summary>
/// Gets or sets the UUT Revision.
/// Drawing Number Revision of the Unit Under Test (also know as Dash Number)
/// </summary>
/// <value>The UUT Revision.</value>
[XmlElement("UutRevision")]
public string UutRevision { get; set; }
/// <summary>
/// Gets or sets the UUT Serial Number.
/// </summary>
/// <value>The UUT Serial Number.</value>
[XmlElement("UutSerialNumber")]
public string UutSerialNumber { get; set; }
/// <summary>
/// Gets or sets the Test Procedure Revision.
/// </summary>
/// <value>The Test Procedure Revision.</value>
[XmlElement("TestProcedureRevision")]
public string TestProcedureRevision { get; set; }
/// <summary>
/// Gets or sets the Test Procedure Identification.
/// </summary>
/// <value>The Test Procedure Identification.</value>
[XmlElement("TestProcedureIdentification")]
public string TestProcedureIdentification { get; set; }
/// <summary>
/// Gets or sets the work order.
/// Work order number for the test being run
/// </summary>
/// <value>The work order.</value>
[XmlElement("WorkOrder")]
public string WorkOrder { get; set; }
/// <summary>
/// Gets or sets the Work Order Operation.
/// </summary>
/// <value>The Work Order Operation.</value>
[XmlElement("WorkOrderOperation")]
public string WorkOrderOperation { get; set; }
/// <summary>
/// Gets or sets the Test Software Identification.
/// </summary>
/// <value>The Test Software Identification.</value>
[XmlElement("TestSoftwareIdentification")]
public string TestSoftwareIdentification { get; set; }
/// <summary>
/// Gets or sets the Test Software Revision.
/// </summary>
/// <value>The Test Software Revision.</value>
[XmlElement("TestSoftwareRevision")]
public string TestSoftwareRevision { get; set; }
/// <summary>
/// Gets or sets the Test Set Identification.
/// </summary>
/// <value>The Test Set Identification.</value>
[XmlElement("TestSetIdentification")]
public string TestSetIdentification { get; set; }
/// <summary>
/// Gets or sets the Test Set Revision.
/// </summary>
/// <value>The Test Set Revision.</value>
[XmlElement("TestSetRevision")]
public string TestSetRevision { get; set; }
/// <summary>
/// Gets or sets the Test Set Serial Number.
/// </summary>
/// <value>The Test Set Serial Number.</value>
[XmlElement("TestSetSerialNumber")]
public string TestSetSerialNumber { get; set; }
/// <summary>
/// Gets or sets the Test Chamber Identification.
/// </summary>
/// <value>The Test Chamber Identification.</value>
[XmlElement("TestChamberIdentification")]
public string TestChamberIdentification { get; set; }
/// <summary>
/// Gets or sets the Test Chamber Revision.
/// </summary>
/// <value>The Test Chamber Revision.</value>
[XmlElement("TestChamberRevision")]
public string TestChamberRevision { get; set; }
/// <summary>
/// Gets or sets the Test Chamber Serial Number.
/// </summary>
/// <value>The Test Chamber Serial Number.</value>
[XmlElement("TestChamberSerialNumber")]
public string TestChamberSerialNumber { get; set; }
/// <summary>
/// Gets or sets the Interface Adapter Identification.
/// </summary>
/// <value>The Interface Adapter Identification.</value>
[XmlElement("InterfaceAdapterIdentification")]
public string InterfaceAdapterIdentification { get; set; }
/// <summary>
/// Gets or sets the Interface Adapter Revision.
/// </summary>
/// <value>The Interface Adapter Revision.</value>
[XmlElement("InterfaceAdapterRevision")]
public string InterfaceAdapterRevision { get; set; }
/// <summary>
/// Gets or sets the Interface Adapter Serial Number.
/// </summary>
/// <value>The Interface Adapter Serial Number.</value>
[XmlElement("InterfaceAdapterSerialNumber")]
public string InterfaceAdapterSerialNumber { get; set; }
/// <summary>
/// Gets or sets the test category.
/// </summary>
/// <value>The test category.</value>
[XmlElement("Address")]
public TestCategory TestCategory { get; set; }
/// <summary>
/// Gets or sets the Test Location.
/// </summary>
/// <value>The Test Location.</value>
[XmlElement("TestLocation")]
public string TestLocation { get; set; }
/// <summary>
/// Gets or sets the Test operator.
/// </summary>
/// <value>The Test Operator.</value>
[XmlElement("TestOperator")]
public string TestOperator { get; set; }
/// <summary>
/// Gets or sets the Test Temperature.
/// </summary>
/// <value>The Test Temperature.</value>
[XmlElement("TestTemperature")]
public string TestTemperature { get; set; }
/// <summary>
/// Gets or sets the Test Start Time.
/// </summary>
/// <value>The Test start time.</value>
[XmlElement("TestStartTime")]
public DateTime TestStartTime { get; set; }
/// <summary>
/// Gets or sets the Test Stop Time.
/// </summary>
/// <value>The Test Stop Time.</value>
[XmlElement("TestStopTime")]
public DateTime TestStopTime { get; set; }
/// <summary>
/// Gets or sets the UUT Test Status.
/// </summary>
/// <value>The UUT Test Status.</value>
[XmlElement("UutTestStatus")]
public PassFailStatus UutTestStatus { get; set; }
/// <summary>
/// Gets or sets the test comments.
/// </summary>
/// <value>The test comments.</value>
[XmlElement("TestComments")]
public string TestComments { get; set; }
[XmlElement("ECIDNumber")]
public string ECIDNumber { get; set; }
/// <summary>
/// Physical slot number the UUT is tested in.
/// </summary>
[XmlElement("SlotNumber")]
public int SlotNumber { get; set; } = 1;
#endregion
#region Constructors
public PdelInformation()
{
}
/// <summary>
/// ICloneable is depreciated so we have to create a basic copy constructor.
/// </summary>
/// <param name="copyThis"></param>
public PdelInformation(PdelInformation copyThis)
{
Clone(copyThis);
}
#endregion
#region Public Members
/// <summary>
/// Clones the PdelInformation from copyThis to this.
/// </summary>
/// <param name="copyThis"></param>
void Clone(PdelInformation cloneThis)
{
UutSerialNumber = cloneThis.UutSerialNumber;
UutIdentification = cloneThis.UutIdentification;
UutRevision = cloneThis.UutRevision;
WorkOrder = cloneThis.WorkOrder;
WorkOrderOperation = cloneThis.WorkOrderOperation;
TestProcedureIdentification = cloneThis.TestProcedureIdentification;
TestProcedureRevision = cloneThis.TestProcedureRevision;
TestSetIdentification = cloneThis.TestSetIdentification;
TestSoftwareRevision = cloneThis.TestSoftwareRevision;
TestSoftwareIdentification = cloneThis.TestSoftwareIdentification;
TestSetRevision = cloneThis.TestSetRevision;
TestSetSerialNumber = cloneThis.TestSetSerialNumber;
TestChamberIdentification = cloneThis.TestChamberIdentification;
TestChamberRevision = cloneThis.TestChamberRevision;
TestChamberSerialNumber = cloneThis.TestChamberSerialNumber;
InterfaceAdapterIdentification = cloneThis.InterfaceAdapterIdentification;
InterfaceAdapterRevision = cloneThis.InterfaceAdapterRevision;
InterfaceAdapterSerialNumber = cloneThis.InterfaceAdapterSerialNumber;
TestLocation = cloneThis.TestLocation;
TestCategory = cloneThis.TestCategory;
TestTemperature = cloneThis.TestTemperature;
ECIDNumber = cloneThis.ECIDNumber;
SlotNumber = cloneThis.SlotNumber;
}
/// <summary>
/// Returns all the public properties of the current System.Type.
/// </summary>
/// <returns>Dictionary of key/value pairs representing PDEL Header values.</returns>
public Dictionary<string, string> GetDetails()
{
Dictionary<string, string> details = new Dictionary<string, string>();
PropertyInfo[] propertyInfos = this.GetType().GetProperties();
foreach (PropertyInfo info in propertyInfos)
{
var value = string.Empty;
foreach (var test in info.CustomAttributes)
{
if (test.NamedArguments != null && test.NamedArguments.Count > 0 && test.NamedArguments[0].MemberName == "EmitDefaultValue")
{
value = "DoNotWriteToPDEL";
break;
}
else
{
value = info.GetValue(this) == null ? "NA" : info.GetValue(this).ToString();
break;
}
}
string name = Regex.Replace(info.Name, @"(?<!_|^)([A-Z])", "_$1").ToUpper();
// Some of the values might be blank. They are still allowed because when a replace gets done on the HTMLWriter,
// the placeholders will be replaced with an empty string.
details.Add(name, value);
// Look to see when the test start time label got added and set the time.
if (name == "TEST_START_TIME" || name == "TEST_STOP_TIME")
{
details[name] = Convert.ToDateTime(value).ToString("yyyyMMdd:HHmmss");
}
}
return details;
}
public object Clone()
{
return TestProcedureRevision.Clone();
}
#endregion
}
}

View File

@@ -0,0 +1,202 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Raytheon.Common.PdelWriter.Utilities;
namespace Raytheon.Common.PdelWriter
{
public class PdelWriter
{
#region Private Class Members
/// <summary>
/// Will hold the PDEL header line length that this the longest.
/// </summary>
private int maxLength = 0;
#endregion
#region Private Properties
// Get Test Executive's PDEL report storage locations from the app.config file.
public string TestResultsLocalFolder { get; set; }
public string PdelDataResultsSubfolder { get; set; }
public string TestResultsNetworkFolder { get; set; }
public bool OutputTestResultsToSubfolder { get; set; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="PdelWriter" /> class.
/// </summary>
public PdelWriter()
{
}
#endregion
#region Public Members
/// <summary>
/// Remove extraneous punctuation that causes errors in the PDEL report generation.
/// </summary>
/// <param name="dataString - data to scan for and remove extraneous punctuation"></param>
/// <returns>Returns a string without extraneous punctuation.</returns>
public string RemovePunctuation(string dataString)
{
// Remove all commas, single quotes and double quotes and semi-colons from string.
return Regex.Replace(dataString, "[,'\";]+", "");
}
/// <summary>
/// Moved outside of CreatePdelFile to set the local properties that make up the PDEL report file path.
/// </summary>
/// <param name="pdelInformation"></param>
/// <param name="filename"></param>
/// <returns></returns>
public string CreateFilePath(PdelInformation pdelInformation, string localFolderPath, out string filename)
{
// Get Test Executive's PDEL report storage locations from the app.config file.
TestResultsLocalFolder = localFolderPath;
return CreateTestResultsFolder(pdelInformation, out filename);
}
/// <summary>
/// Writes PDEL data to a file.
/// </summary>
/// <param name="item">The item.</param>
public void CreatePdelFile(List<TestResult> testResults, PdelInformation pdelInformation, string localFolderPath)
{
if (pdelInformation != null)
{
var hasFailure = from s in testResults
where s.Result == PassFailStatus.Fail
select s;
pdelInformation.UutTestStatus = hasFailure.Count() > 0 ? PassFailStatus.Fail : PassFailStatus.Pass;
string filename = string.Empty;
string testResultsFolder = CreateFilePath(pdelInformation, localFolderPath, out filename);
// Find the header line that is the longest. This will help us to align the headers items together.
foreach (KeyValuePair<string, string> kvp in pdelInformation.GetDetails())
{
if (maxLength < kvp.Key.Length)
{
maxLength = kvp.Key.Length;
}
}
var startTime = new TimeSpan();
var stopTime = new TimeSpan();
string pdelFilePath = Path.Combine(testResultsFolder, filename + ".pdel");
using (System.IO.StreamWriter writer = new StreamWriter(pdelFilePath))
{
string comment = string.Empty;
writer.Write(string.Format("COMMENT = **********START OF HEADER***************;{0}", Environment.NewLine));
foreach (KeyValuePair<string, string> kvp in pdelInformation.GetDetails())
{
// If there are test comments, the entry needs to be defined.
if (kvp.Key == "TEST_COMMENTS")
{
writer.Write(string.Format("{0} {1} = {2}{3};{4}", "DEFINE_HEADER", kvp.Key, "User comments for test, ", pdelInformation.UutIdentification, Environment.NewLine));
}
else if (kvp.Key == "E_C_I_D_NUMBER")
{
writer.Write(string.Format("{0} {1} = {2}{3};{4}", "DEFINE_HEADER", kvp.Key, "ECID number for test, ", pdelInformation.ECIDNumber, Environment.NewLine));
}
else if
(kvp.Key == "SLOT_NUMBER")
{
writer.Write(string.Format("{0} {1} = {2}{3};{4}", "DEFINE_HEADER", kvp.Key, "Slot number for test, ", pdelInformation.SlotNumber, Environment.NewLine));
}
// Some UutDetails are used for housekeeping and do not get written to the PDEL file.
if (kvp.Value != "DoNotWriteToPDEL")
{
writer.Write(string.Format("{0} = {1};{2}", kvp.Key.PadRight(maxLength), kvp.Value == string.Empty ? "N/A" : RemovePunctuation(kvp.Value), Environment.NewLine));
}
}
writer.Write(string.Format("COMMENT = **********END OF HEADER***************;{0}{1}", Environment.NewLine, Environment.NewLine));
writer.Write(string.Format("COMMENT = **********START OF DATA***************;{0}{1}", Environment.NewLine, Environment.NewLine));
foreach (var result in testResults)
{
writer.Write(string.Format(
"DEFINE_DATA {0} = {1}, {2}, {3};{4}",
result.PCode,
RemovePunctuation(result.TestName),
PdelDataFormatter.Format(result.MeasuredValue.ToString()),
PdelDataFormatter.IsNullOrEmpty(result.UnitOfMeasure),
Environment.NewLine));
writer.Write(string.Format("{0} = {1};{2}{3}", result.PCode, result.MeasuredValue.ToString(), Environment.NewLine, Environment.NewLine));
}
writer.Write(string.Format("COMMENT = **********END OF DATA***************;{0}{1}", Environment.NewLine, Environment.NewLine));
writer.Flush();
}
}
}
#endregion
#region Private Methods
public static string BuildFilename(PdelInformation pdelInformation, string separator)
{
return string.Format(!string.IsNullOrEmpty(pdelInformation.UutIdentification) ? (pdelInformation.UutIdentification + separator) : string.Empty)
+ string.Format(!string.IsNullOrEmpty(pdelInformation.UutSerialNumber) ? (pdelInformation.UutSerialNumber + separator) : string.Empty)
+ string.Format(!string.IsNullOrEmpty(pdelInformation.WorkOrder) ? (pdelInformation.WorkOrder + separator) : string.Empty)
+ string.Format(!string.IsNullOrEmpty(pdelInformation.TestTemperature) ? (pdelInformation.TestTemperature + separator) : string.Empty)
+ DateTime.Now.ToString("yyyyMMdd_HHmmss");
}
/// <summary>
/// Create a PDEl report file based on information in the PdelInformation class and operator's values.
/// </summary>
/// <param name="pdelInformation"></param>
/// <param name="filename"></param>
/// <returns></returns>
private string CreateTestResultsFolder(PdelInformation pdelInformation, out string filename)
{
var details = pdelInformation.GetDetails();
// Check to see if user selected to save data in a subfolder.
var subFolder = PdelDataResultsSubfolder != null ? PdelDataResultsSubfolder : string.Empty;
// If the folder is not null or empty, get the matching UUT details value.
if (!string.IsNullOrEmpty(subFolder) && subFolder != "None Selected")
{
subFolder = Regex.Replace(subFolder, @"(?<!_|^)([A-Z])", "_$1").ToUpper();
foreach (var detail in details)
{
if (subFolder == detail.Key)
{
subFolder = detail.Value;
}
}
}
else
{
// subFolder is not being used set it to empty string.
subFolder = string.Empty;
}
filename = BuildFilename(pdelInformation, "_");
string testResultsFolder = Path.Combine(TestResultsLocalFolder, subFolder);
// Make sure the folder exists.
if (!Directory.Exists(testResultsFolder))
{
Directory.CreateDirectory(testResultsFolder);
}
return testResultsFolder;
}
#endregion
}
}

View File

@@ -0,0 +1,25 @@
namespace Raytheon.Common.PdelWriter.Utilities
{
public enum TestCategory
{
/// <summary>
/// An Acceptance Test
/// </summary>
ACCEPTANCE_TEST,
/// <summary>
/// A Manufacturing Test
/// </summary>
MANUFACTURING_TEST,
/// <summary>
/// An Engineering Test
/// </summary>
ENGINEERING_TEST,
/// <summary>
/// A Calibration Test
/// </summary>
CALIBRATION_TEST,
}
}

View File

@@ -0,0 +1,140 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Xml.Serialization;
namespace Raytheon.Common.PdelWriter.Utilities
{
[XmlType("ASICTestExecutive-UutTestConfiguration")]
public class TestResultList
{
[XmlArray("TestResultList")]
[XmlArrayItem("TestResult")]
public List<TestResult> List { get; set; }
public TestResultList()
{
List = new List<TestResult>();
}
}
public class TestResult : INotifyPropertyChanged
{
[XmlElement("PCode")]
public string PCode { get; set; }
[XmlElement("TestName")]
public string TestName { get; set; }
[XmlElement("UnitOfMeasure")]
public string UnitOfMeasure { get; set; }
[XmlIgnore]
public string MethodName { get; set; }
[XmlIgnore]
private string messages;
[XmlIgnore]
public string Messages
{
get { return messages; }
set
{
if (value != messages)
{
messages = value;
OnPropertyChanged("Messages");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
[XmlIgnore]
private PassFailStatus result;
[XmlIgnore]
public PassFailStatus Result
{
get { return result; }
set
{
if (value != result)
{
result = value;
OnPropertyChanged("Result");
}
}
}
[XmlElement]
public object MeasuredValue { get; set; }
[XmlIgnore]
public StringBuilder AdditionalInformation { get; set; }
[XmlIgnore]
private bool testHasAdditionalInformation;
[XmlIgnore]
public bool TestHasAdditionalInformation
{
get { return testHasAdditionalInformation; }
set
{
if (value != testHasAdditionalInformation)
{
testHasAdditionalInformation = value;
OnPropertyChanged("TestHasAdditionalInformation");
}
}
}
public TestResult()
{
AdditionalInformation = new StringBuilder();
Result = PassFailStatus.Unknown;
}
/// <summary>
/// Copy constructor.
/// </summary>
/// <param name="copyThis"></param>
public TestResult(TestResult copyThis)
{
AdditionalInformation = new StringBuilder(copyThis.AdditionalInformation.ToString());
result = copyThis.result;
PCode = copyThis.PCode;
MethodName = copyThis.MethodName;
testHasAdditionalInformation = copyThis.testHasAdditionalInformation;
TestName = copyThis.TestName;
UnitOfMeasure = copyThis.UnitOfMeasure;
messages = copyThis.messages;
PropertyChanged = copyThis.PropertyChanged;
}
/// <summary>
/// Handles property change events for all public properties that are bound to the view.
/// </summary>
/// <param name="propertyName"></param>
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}
/// <summary>
/// Sets the test results to the grid for the user to view.
/// </summary>
/// <param name="testHasAdditionalInformation"></param>
public void SetTestResults(bool testHasAdditionalInformation)
{
TestHasAdditionalInformation = testHasAdditionalInformation;
}
}
}