init
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <summary>
|
||||
/// we will want to remove or add hardware overriding what hardware would be in the test
|
||||
/// based solely on groups in the test
|
||||
/// this way we can have dasless groups
|
||||
/// </summary>
|
||||
public class HardwareInclusionInstruction
|
||||
{
|
||||
public string HardwareId { get; }
|
||||
|
||||
public enum Actions
|
||||
{
|
||||
Remove, //hardware may be included in test by a group, but ignore it and don't include the hardware...
|
||||
Add //hardware is not included in test by a group, but add it anyhow
|
||||
}
|
||||
|
||||
public Actions Action { get; }
|
||||
|
||||
public HardwareInclusionInstruction(string hardwareId, Actions action)
|
||||
{
|
||||
HardwareId = hardwareId;
|
||||
Action = action;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
//using DTS.Common.Interface.Hardware;
|
||||
//using DTS.SensorDB;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public interface ICachedContainer
|
||||
{
|
||||
DASHardware GetCachedHardware(string serialNumber);
|
||||
IISOHardware[] GetAllCachedHardware();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
[Serializable]
|
||||
public class RegionOfInterest : INotifyPropertyChanged
|
||||
{
|
||||
|
||||
public RegionOfInterest()
|
||||
{
|
||||
Suffix = string.Empty;
|
||||
Start = -1D;
|
||||
End = 1D;
|
||||
IsEnabled = true;
|
||||
IsDefault = true;
|
||||
}
|
||||
|
||||
public RegionOfInterest(bool isDefault = false)
|
||||
: this()
|
||||
{
|
||||
IsDefault = isDefault;
|
||||
}
|
||||
public RegionOfInterest(string suffix = "", bool isDefault = false, double start = -1D, double end = 1D)
|
||||
: this(isDefault)
|
||||
{
|
||||
Suffix = suffix;
|
||||
Start = start;
|
||||
End = end;
|
||||
}
|
||||
private string _suffix = string.Empty;
|
||||
public string Suffix
|
||||
{
|
||||
get => _suffix;
|
||||
set
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(value) && !(value.StartsWith("_") && string.IsNullOrWhiteSpace(value.Substring(1))))
|
||||
{
|
||||
_suffix = value.StartsWith("_") ? value : "_" + value;
|
||||
}
|
||||
OnPropertyChanged("Suffix");
|
||||
}
|
||||
}
|
||||
|
||||
private double _start = double.MinValue;
|
||||
public double Start
|
||||
{
|
||||
get => _start;
|
||||
set
|
||||
{
|
||||
if (value >= End)
|
||||
{
|
||||
value = End - 0.01;
|
||||
}
|
||||
if (value < PreTrigger)
|
||||
{
|
||||
value = PreTrigger;
|
||||
}
|
||||
_start = value;
|
||||
OnPropertyChanged("Start");
|
||||
}
|
||||
}
|
||||
|
||||
private double _end = double.MaxValue;
|
||||
public double End
|
||||
{
|
||||
get => _end;
|
||||
set
|
||||
{
|
||||
if (value <= Start)
|
||||
{
|
||||
value = Start + 0.01;
|
||||
}
|
||||
if (value > PostTrigger)
|
||||
{
|
||||
value = PostTrigger;
|
||||
}
|
||||
_end = value; OnPropertyChanged("End");
|
||||
}
|
||||
}
|
||||
|
||||
private double _preTrigger = double.MinValue;
|
||||
public double PreTrigger
|
||||
{
|
||||
get => _preTrigger;
|
||||
set
|
||||
{
|
||||
_preTrigger = value;
|
||||
OnPropertyChanged("PreTrigger");
|
||||
if (Start < PreTrigger)
|
||||
{
|
||||
Start = PreTrigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double _postTrigger = double.MaxValue;
|
||||
public double PostTrigger
|
||||
{
|
||||
get => _postTrigger;
|
||||
set
|
||||
{
|
||||
_postTrigger = value;
|
||||
OnPropertyChanged("PostTrigger");
|
||||
if (End > PostTrigger)
|
||||
{
|
||||
End = PostTrigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled = true;
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
set { _isEnabled = value; OnPropertyChanged("IsEnabled"); }
|
||||
}
|
||||
|
||||
public bool IsDefault { get; private set; }
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,272 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class TestTemplateList //: BasePropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// this property is to hold a template in memory temporarily
|
||||
/// without committing it to the db, but to still act as if it is in the db
|
||||
/// </summary>
|
||||
public TestTemplate TemporaryTemplate { get; set; }
|
||||
public static SensorData GetSensorFromSettings(string settings, string serial, Dictionary<string, SensorData> lookup)
|
||||
{
|
||||
SensorData sd = null;
|
||||
if (null != lookup && lookup.ContainsKey(serial)) { sd = lookup[serial]; }
|
||||
if (null == sd) { sd = SensorsCollection.SensorsList.GetSensorBySerialNumber(serial); }
|
||||
|
||||
if (string.IsNullOrWhiteSpace(serial))
|
||||
{
|
||||
sd = new SensorData { SerialNumber = "" };
|
||||
}
|
||||
if (null == sd) { return null; }
|
||||
sd = new SensorData(sd);
|
||||
var tokens = settings.Split(',');
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
var subtokens = token.Split('=');
|
||||
var setting = (ISO.TestObject.SensorSettings)int.Parse(subtokens[0]);
|
||||
switch (setting)
|
||||
{
|
||||
case ISO.TestObject.SensorSettings.CFC:
|
||||
sd.FilterClassIso = subtokens[1];
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.Position:
|
||||
sd.Position = subtokens[1];
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.Polarity:
|
||||
sd.Invert = subtokens[1] == "-";
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.Range:
|
||||
sd.Capacity = double.Parse(subtokens[1], System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.Delay:
|
||||
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.DelayMS = double.Parse(subtokens[1], System.Globalization.CultureInfo.InvariantCulture); sd.DigitalOutputDelayMS = sd.DelayMS; }
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.Duration:
|
||||
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.DurationMS = double.Parse(subtokens[1], System.Globalization.CultureInfo.InvariantCulture); sd.DigitalOutputDurationMS = sd.DurationMS; }
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.OutputMode:
|
||||
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.DigitalOutputMode = (DigitalOutputModes)Convert.ToInt32(subtokens[1]); }
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.SQMode:
|
||||
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.SquibFireMode = (SquibFireMode)Convert.ToInt32(subtokens[1]); }
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.DIMode:
|
||||
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.InputMode = (DigitalInputModes)Convert.ToInt32(subtokens[1]); }
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.LimitDuration:
|
||||
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.LimitDuration = bool.Parse(subtokens[1]); }
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.ActiveValue:
|
||||
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.ScaleMultiplier.ActiveValue = Convert.ToDouble(subtokens[1]); }
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.DefaultValue:
|
||||
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.ScaleMultiplier.DefaultValue = Convert.ToDouble(subtokens[1]); }
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sd;
|
||||
}
|
||||
public static SensorData GetSensorFromSettings(string settings, string serial)
|
||||
{
|
||||
return GetSensorFromSettings(settings, serial, null);
|
||||
}
|
||||
public static string GetSensorSettings(SensorData sd)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var settings = Enum.GetValues(typeof(ISO.TestObject.SensorSettings)).Cast<ISO.TestObject.SensorSettings>().ToArray();
|
||||
var bNeedComma = false;
|
||||
foreach (var setting in settings)
|
||||
{
|
||||
if (bNeedComma) { sb.Append(","); }
|
||||
bNeedComma = true;
|
||||
sb.AppendFormat("{0}=", (int)setting);
|
||||
switch (setting)
|
||||
{
|
||||
case ISO.TestObject.SensorSettings.CFC:
|
||||
sb.Append(sd.FilterClassIso);
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.Position:
|
||||
sb.Append(sd.Position);
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.Polarity:
|
||||
sb.Append(sd.Invert ? "-" : "+");
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.Range:
|
||||
sb.Append(sd.Capacity.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.SQMode:
|
||||
sb.Append(((int)sd.SquibFireMode).ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.LimitDuration:
|
||||
sb.Append(sd.LimitDuration.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.Duration:
|
||||
sb.Append(sd.DurationMS.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.OutputMode:
|
||||
sb.Append(((int)sd.DigitalOutputMode).ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.Delay:
|
||||
sb.Append(sd.DelayMS.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.DIMode:
|
||||
sb.Append(((int)sd.InputMode).ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.DefaultValue:
|
||||
sb.Append(sd.ScaleMultiplier.DefaultValue.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case ISO.TestObject.SensorSettings.ActiveValue:
|
||||
sb.Append(
|
||||
sd.ScaleMultiplier.ActiveValue.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
private static TestTemplateList _list;
|
||||
private static readonly object OBJECT_LOCK = new object();
|
||||
public static TestTemplateList TestTemplatesList
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (OBJECT_LOCK)
|
||||
{
|
||||
if (null == _list) { _list = new TestTemplateList(); }
|
||||
}
|
||||
return _list;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
lock (OBJECT_LOCK)
|
||||
{
|
||||
if (!(Application.Current is App app)) return;
|
||||
app.IsoDb.RefreshAllData();
|
||||
CustomChannelList.List.ReloadAll();
|
||||
SensorsCollection.SensorsList.Reload();
|
||||
SensorCalibrationList.Reload();
|
||||
DASHardwareList.GetList().ReloadAll();
|
||||
TestEngineerDetailsList.TestEngineerList.ReloadAll();
|
||||
TestObjectTemplateCollection.TemplateCollection.ReloadAll(false);
|
||||
TestObjectList.TestObjectsList.ReloadAll(false);
|
||||
Load();
|
||||
}
|
||||
}
|
||||
public static bool SysBuiltObject(string serialNumber)
|
||||
{
|
||||
var temp = false;
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TestObjectsGet.ToString();
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@TestObjectName", SqlDbType.NVarChar, 50) { Value = serialNumber });
|
||||
cmd.Parameters.Add(new SqlParameter("@TemplateName", SqlDbType.NVarChar, 255) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@SysBuilt", SqlDbType.Bit) { Value = null });
|
||||
|
||||
using (var ds2 = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds2.Tables.Count <= 0 || ds2.Tables[0].Rows.Count <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (DataRow row in ds2.Tables[0].Rows)
|
||||
{
|
||||
//really only 1 row
|
||||
temp = Convert.ToBoolean(row["SysBuilt"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { cmd.Connection.Dispose(); }
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
public static void ConvertToDictionary(DataTable dt, ref Dictionary<string, List<Dictionary<string, object>>> lookup, string key)
|
||||
{
|
||||
var count = dt.Columns.Count;
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
var thiskey = Convert.ToString(dr[key]);
|
||||
if (!lookup.ContainsKey(thiskey)) { lookup.Add(thiskey, new List<Dictionary<string, object>>()); }
|
||||
var properties = new Dictionary<string, object>(count);
|
||||
foreach (DataColumn c in dt.Columns)
|
||||
{
|
||||
properties[c.ColumnName] = dr[c.ColumnName];
|
||||
}
|
||||
lookup[thiskey].Add(properties);
|
||||
}
|
||||
}
|
||||
private void Load()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// deletes all test setups originally designed so TDM imports could clear all tables except DAS
|
||||
/// </summary>
|
||||
public void DeleteAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TestSetupsDeleteAll.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
#region Output
|
||||
|
||||
var errorMessageParam =
|
||||
new SqlParameter("@ErrorMessage", SqlDbType.NVarChar, 250)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cmd.Parameters.Add(errorMessageParam);
|
||||
|
||||
var errorSeverityParam =
|
||||
new SqlParameter("@ErrorSeverity", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorSeverityParam);
|
||||
|
||||
var errorNumberParam =
|
||||
new SqlParameter("@ErrorState", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumberParam);
|
||||
|
||||
#endregion Output
|
||||
|
||||
#endregion params
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
if (DBNull.Value != errorNumberParam.Value)
|
||||
{
|
||||
var error = int.Parse(errorNumberParam.Value.ToString());
|
||||
if (error != 0)
|
||||
{
|
||||
var message = int.Parse(errorNumberParam.Value.ToString());
|
||||
var state = int.Parse(errorNumberParam.Value.ToString());
|
||||
//APILogger.Log(
|
||||
// $"Error:{Convert.ToString(error)}, State:{Convert.ToString(state)} Error: {message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { cmd.Connection.Dispose(); }
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to delete all test setups, ", ex);*/ }
|
||||
//Reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <summary>
|
||||
/// this is a lightweight version of test TestTemplate, holding just the essential information
|
||||
/// [updated]: this concept is already present in testtemplate,
|
||||
/// by default it only loads information in the tblTestSetup, and then uses the IsLoaded flag to
|
||||
/// check whether it's populated information from other tables or not.
|
||||
/// I'll leave the class here for now in case we want to expand on it in the future, also I cleaned up a few things in the process anyhow
|
||||
/// </summary>
|
||||
public class TestTemplateLite : ITestSetup
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; } = "";
|
||||
|
||||
public RecordingModes RecordingMode { get; set; }
|
||||
private double _preTriggerSeconds;
|
||||
public double PreTriggerSeconds
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (RecordingMode)
|
||||
{
|
||||
case RecordingModes.Recorder:
|
||||
case RecordingModes.HybridRecorder:
|
||||
return 0D;
|
||||
case RecordingModes.CircularBuffer:
|
||||
return _preTriggerSeconds;
|
||||
default:
|
||||
return _preTriggerSeconds;
|
||||
}
|
||||
}
|
||||
set => _preTriggerSeconds = value;
|
||||
}
|
||||
|
||||
public string ErrorMessage { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// returns the error messages for a test setup
|
||||
/// calculated at the same time is complete is calculated, however doesn't have a check against
|
||||
/// is dirty, like IsComplete does ...
|
||||
/// </summary>
|
||||
public string CompletionErrorMessage => ErrorMessage.Length > 250 ? ErrorMessage.Substring(0, 250) : ErrorMessage;
|
||||
public double PostTriggerSeconds { get; set; }
|
||||
public DateTime LastModified { get; set; }
|
||||
public string LastModifiedBy { get; set; }
|
||||
public bool IsComplete { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user