using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Data; namespace DatabaseExport { public class TestObjectTemplateChannel //: INotifyPropertyChanged { public const string NONISOCHANNELTYPE = "NONISO"; private List _channelPropertyNames = new List(); private Dictionary _channelProperties = new Dictionary(); protected object GetProperty(string name, object defaultValue) { if (!_channelProperties.ContainsKey(name)) { _channelProperties[name] = new ChannelProperty(name, defaultValue); } return _channelProperties[name].Value; } protected void SetProperty(string name, object value) { if (!_channelProperties.ContainsKey(name)) { _channelProperties[name] = new ChannelProperty(name, value); } else { _channelProperties[name].Value = value; } //OnPropertyChanged("name"); // ? variable name instead of "name" } public MMEPossibleChannels Channel { get; } public const string SEPARATOR = "_X_"; private bool _bRequired = false; /// /// Required channel property raises the OnRequiredChanged event /// public bool Required { get => _bRequired; set { _bRequired = value; //OnRequiredChanged(new RequiredChangedEventArgs { NewValue = value }); _bRequired = value; } } public bool LocalOnly { get; set; } = false; public enum ReferenceChannelTypes { IMPLICIT, EXPLICIT, NOVALUE }; public enum DataSourceTypes { Transducer, Calculation, Camera, Simulation, Parameter }; public enum DataStatusTypes { OK, ChannelFailed, MeaninglessData, NoData, QuestionableData, ScalingFactorApplied, SystemFailed, LinearisedData, NOVALUE } public enum StandardChannelProperties { /*TestObjectNumber,*/ NameOfTheChannel, /*LaboratoryChannelCode, CustomerChannelCode, ChannelCode, Comments1, Location, Dimension, Direction, ChannelFrequencyClass, Unit, ReferenceSystem, TransducerType, TransducerId, PreFilterType, CutOffFrequency, ChannelAmplitudeClass, ReferenceChannel, ReferenceChannelName, DataSource, DataStatus, SamplingInterval, BitResolution, TimeOfFirstSample, NumberOfSamples, OffsetPostTest, TransducerNaturalFrequency, TransducerDampingRatio, Comments2, FirstGlobalMaximumValue, TimeOfMaximumValue, FirstGlobalMinimumValue, TimeOfMinimumValue, StartOffsetInterval, EndOffsetInterval,*/ DisplayOrder } public override string ToString() { if (null != Channel) { return string.Format("{0}({1})", Name, Channel.Id); } else { return Name; } } public TestObjectTemplateChannel(DataRow dr, ISO.TestObjectTemplate template, ref ISO13499FileDb db) { _template = template; AddStandardProperties(); /*_channelProperties[StandardChannelProperties.TestObjectNumber.ToString()].Value = (string)dr["TestObjectNumber"];*/ _channelProperties[StandardChannelProperties.NameOfTheChannel.ToString()].Value = (string)dr["NameOfTheChannel"]; /*_channelProperties[StandardChannelProperties.LaboratoryChannelCode.ToString()].Value = (string)dr["LaboratoryChannelCode"]; _channelProperties[StandardChannelProperties.CustomerChannelCode.ToString()].Value = (string)dr["CustomerChannelCode"]; _channelProperties[StandardChannelProperties.Comments1.ToString()].Value = (string)dr["Comments1"]; _channelProperties[StandardChannelProperties.Location.ToString()].Value = (string)dr["Location"]; _channelProperties[StandardChannelProperties.Dimension.ToString()].Value = (string)dr["Dimension"]; _channelProperties[StandardChannelProperties.Direction.ToString()].Value = (string)dr["Direction"]; _channelProperties[StandardChannelProperties.ChannelFrequencyClass.ToString()].Value = (string)dr["ChannelFrequencyClass"]; _channelProperties[StandardChannelProperties.Unit.ToString()].Value = (string)dr["Unit"]; _channelProperties[StandardChannelProperties.ReferenceSystem.ToString()].Value = (string)dr["ReferenceSystem"]; _channelProperties[StandardChannelProperties.TransducerType.ToString()].Value = (string)dr["TransducerType"]; _channelProperties[StandardChannelProperties.TransducerId.ToString()].Value = (string)dr["TransducerId"]; _channelProperties[StandardChannelProperties.PreFilterType.ToString()].Value = (string)dr["PreFilterType"]; _channelProperties[StandardChannelProperties.CutOffFrequency.ToString()].Value = (string)dr["CutOffFrequency"]; _channelProperties[StandardChannelProperties.ChannelAmplitudeClass.ToString()].Value = (string)dr["ChannelAmplitudeClass"]; _channelProperties[StandardChannelProperties.ReferenceChannel.ToString()].Value = (ReferenceChannelTypes)Enum.Parse(typeof(ReferenceChannelTypes), (string)dr["ReferenceChannel"]); _channelProperties[StandardChannelProperties.ReferenceChannelName.ToString()].Value = (string)dr["ReferenceChannelName"]; _channelProperties[StandardChannelProperties.DataSource.ToString()].Value = (DataSourceTypes)Enum.Parse(typeof(DataSourceTypes), (string)dr["DataSource"]); _channelProperties[StandardChannelProperties.DataStatus.ToString()].Value = (DataStatusTypes)Enum.Parse(typeof(DataStatusTypes), (string)dr["DataStatus"]); _channelProperties[StandardChannelProperties.SamplingInterval.ToString()].Value = (string)dr["SamplingInterval"]; _channelProperties[StandardChannelProperties.BitResolution.ToString()].Value = (string)dr["BitResolution"]; _channelProperties[StandardChannelProperties.TimeOfFirstSample.ToString()].Value = (string)dr["TimeOfFirstSample"]; _channelProperties[StandardChannelProperties.NumberOfSamples.ToString()].Value = (string)dr["NumberOfSamples"]; _channelProperties[StandardChannelProperties.OffsetPostTest.ToString()].Value = (string)dr["OffsetPostTest"]; _channelProperties[StandardChannelProperties.TransducerNaturalFrequency.ToString()].Value = (string)dr["TransducerNaturalFrequency"]; _channelProperties[StandardChannelProperties.TransducerDampingRatio.ToString()].Value = (string)dr["TransducerDampingRatio"]; _channelProperties[StandardChannelProperties.Comments2.ToString()].Value = (string)dr["Comments"]; _channelProperties[StandardChannelProperties.FirstGlobalMaximumValue.ToString()].Value = (string)dr["FirstGlobalMaximumValue"]; _channelProperties[StandardChannelProperties.TimeOfMaximumValue.ToString()].Value = (string)dr["TimeOfMaximumValue"]; _channelProperties[StandardChannelProperties.FirstGlobalMinimumValue.ToString()].Value = (string)dr["FirstGlobalMinimumValue"]; _channelProperties[StandardChannelProperties.TimeOfMinimumValue.ToString()].Value = (string)dr["TimeOfMinimumValue"]; _channelProperties[StandardChannelProperties.StartOffsetInterval.ToString()].Value = (string)dr["StartOffsetInterval"]; _channelProperties[StandardChannelProperties.EndOffsetInterval.ToString()].Value = (string)dr["EndOffsetInterval"]; */ _channelProperties[StandardChannelProperties.DisplayOrder.ToString()].Value = 0; if (!DBNull.Value.Equals(dr["DisplayOrder"])) { _channelProperties[StandardChannelProperties.DisplayOrder.ToString()].Value = Convert.ToInt32(dr["DisplayOrder"]).ToString(System.Globalization.CultureInfo.InvariantCulture); } _bRequired = Convert.ToBoolean(dr["Required"]); LocalOnly = Convert.ToBoolean(dr["LocalOnly"]); var channelId = Convert.ToInt64(dr["MMEChannelId"]); var channelType = Convert.ToInt32(dr["MMEChannelType"]); Channel = db.GetPossibleChannel(channelId, channelType); } private void AddStandardProperties() { if (null != _channelProperties) { _channelProperties.Clear(); _channelProperties = null; } _channelProperties = new Dictionary(); var scp = Enum.GetValues(typeof(StandardChannelProperties)).Cast().ToArray(); foreach (var p in scp) { ChannelProperty cp = null; switch (p) { /*case StandardChannelProperties.BitResolution: cp = new ChannelProperty("Bit resolution", "16"); break; case StandardChannelProperties.ChannelAmplitudeClass: cp = new ChannelProperty("Channel amplitude class", "NOVALUE"); break; case StandardChannelProperties.ChannelCode: cp = new ChannelProperty("Channel code", "NOVALUE"); break; case StandardChannelProperties.ChannelFrequencyClass: cp = new ChannelProperty("Channel frequency class", "NOVALUE"); break; case StandardChannelProperties.Comments1: cp = new ChannelProperty("Comments", "NOVALUE"); break;*/ case StandardChannelProperties.DisplayOrder: cp = new ChannelProperty(p.ToString(), "0"); break; /*case StandardChannelProperties.Comments2: cp = new ChannelProperty("Comments", "NOVALUE"); break; case StandardChannelProperties.CustomerChannelCode: cp = new ChannelProperty("Customer channel code", "NOVALUE"); break; case StandardChannelProperties.CutOffFrequency: cp = new ChannelProperty("Cut off frequency", "NOVALUE"); break; case StandardChannelProperties.DataSource: cp = new ChannelProperty("Data source", DataSourceTypes.Transducer); break; case StandardChannelProperties.DataStatus: cp = new ChannelProperty("Data status", DataStatusTypes.NOVALUE); break; case StandardChannelProperties.Dimension: cp = new ChannelProperty("Dimension", "NOVALUE"); break; case StandardChannelProperties.Direction: cp = new ChannelProperty("Direction", "NOVALUE"); break; case StandardChannelProperties.EndOffsetInterval: cp = new ChannelProperty("End Offset Interval", "NOVALUE"); break; case StandardChannelProperties.FirstGlobalMaximumValue: cp = new ChannelProperty("First global maximum value", "NOVALUE"); break; case StandardChannelProperties.FirstGlobalMinimumValue: cp = new ChannelProperty("First global minimum value", "NOVALUE"); break; case StandardChannelProperties.LaboratoryChannelCode: cp = new ChannelProperty("Laboratory channel code", "NOVALUE"); break; case StandardChannelProperties.Location: cp = new ChannelProperty("Location", "NOVALUE"); break;*/ case StandardChannelProperties.NameOfTheChannel: cp = new ChannelProperty("Name of the channel", "NOVALUE"); break; /*case StandardChannelProperties.NumberOfSamples: cp = new ChannelProperty("Number of samples", "NOVALUE"); break; case StandardChannelProperties.OffsetPostTest: cp = new ChannelProperty("Offset post test", "NOVALUE"); break; case StandardChannelProperties.PreFilterType: cp = new ChannelProperty("Pre-filter type", "NOVALUE"); break; case StandardChannelProperties.ReferenceChannel: cp = new ChannelProperty("Reference channel", ReferenceChannelTypes.NOVALUE); break; case StandardChannelProperties.ReferenceChannelName: cp = new ChannelProperty("Reference channel name", "NOVALUE"); break; case StandardChannelProperties.ReferenceSystem: cp = new ChannelProperty("Reference system", "NOVALUE"); break; case StandardChannelProperties.SamplingInterval: cp = new ChannelProperty("Sampling interval", "NOVALUE"); break; case StandardChannelProperties.StartOffsetInterval: cp = new ChannelProperty("Start offset interval", "NOVALUE"); break; case StandardChannelProperties.TestObjectNumber: cp = new ChannelProperty("Test object number", "NOVALUE"); break; case StandardChannelProperties.TimeOfFirstSample: cp = new ChannelProperty("Time of first sample", "NOVALUE"); break; case StandardChannelProperties.TimeOfMaximumValue: cp = new ChannelProperty("Time of maximum value", "NOVALUE"); break; case StandardChannelProperties.TimeOfMinimumValue: cp = new ChannelProperty("Time of minimum value", "NOVALUE"); break; case StandardChannelProperties.TransducerDampingRatio: cp = new ChannelProperty("Transducer damping ratio", "NOVALUE"); break; case StandardChannelProperties.TransducerId: cp = new ChannelProperty("Transducer id", "NOVALUE"); break; case StandardChannelProperties.TransducerNaturalFrequency: cp = new ChannelProperty("Transducer natural frequency", "NOVALUE"); break; case StandardChannelProperties.TransducerType: cp = new ChannelProperty("Transducer type", "NOVALUE"); break; case StandardChannelProperties.Unit: cp = new ChannelProperty("Unit", "NOVALUE"); break;*/ default: cp = new ChannelProperty(p.ToString(), "NOVALUE"); break; } _channelProperties.Add(p.ToString(), cp); } } public TestObjectTemplateChannel(TestObjectTemplateChannel copy, ISO.TestObjectTemplate template) { LocalOnly = copy.LocalOnly; _bRequired = copy.Required; Channel = new MMEPossibleChannels(copy.Channel); _channelProperties = new Dictionary(); var e = copy._channelProperties.GetEnumerator(); while (e.MoveNext()) { _channelProperties[e.Current.Key] = new ChannelProperty(e.Current.Value); } _channelPropertyNames = new List(copy._channelPropertyNames.ToArray()); _template = template; } public TestObjectTemplateChannel(MMEPossibleChannels channel) { Channel = channel; AddStandardProperties(); var scp = Enum.GetValues(typeof(StandardChannelProperties)).Cast().ToArray(); foreach (var p in scp) { switch (p) { case StandardChannelProperties.DisplayOrder: _channelProperties[StandardChannelProperties.DisplayOrder.ToString()].Value = (Convert.ToInt32(Channel.Id)).ToString(System.Globalization.CultureInfo.InvariantCulture); break; case StandardChannelProperties.NameOfTheChannel: break; /*case StandardChannelProperties.BitResolution: case StandardChannelProperties.ChannelAmplitudeClass: case StandardChannelProperties.ChannelCode: case StandardChannelProperties.ChannelFrequencyClass: case StandardChannelProperties.Comments1: case StandardChannelProperties.Comments2: case StandardChannelProperties.CustomerChannelCode: case StandardChannelProperties.CutOffFrequency: case StandardChannelProperties.DataSource: case StandardChannelProperties.DataStatus: break; case StandardChannelProperties.Dimension: _channelProperties[StandardChannelProperties.Dimension.ToString()].Value = _channel.Physical_Dimension; break; case StandardChannelProperties.Direction: _channelProperties[StandardChannelProperties.Direction.ToString()].Value = _channel.Direction; break; case StandardChannelProperties.EndOffsetInterval: case StandardChannelProperties.FirstGlobalMaximumValue: case StandardChannelProperties.FirstGlobalMinimumValue: case StandardChannelProperties.LaboratoryChannelCode: break; case StandardChannelProperties.Location: _channelProperties[StandardChannelProperties.Location.ToString()].Value = _channel.Trans_Main_Loc; break; case StandardChannelProperties.NumberOfSamples: case StandardChannelProperties.OffsetPostTest: case StandardChannelProperties.PreFilterType: case StandardChannelProperties.ReferenceChannel: case StandardChannelProperties.ReferenceChannelName: case StandardChannelProperties.ReferenceSystem: case StandardChannelProperties.SamplingInterval: case StandardChannelProperties.StartOffsetInterval: case StandardChannelProperties.TestObjectNumber: case StandardChannelProperties.TimeOfFirstSample: case StandardChannelProperties.TimeOfMaximumValue: case StandardChannelProperties.TimeOfMinimumValue: case StandardChannelProperties.TransducerDampingRatio: case StandardChannelProperties.TransducerId: case StandardChannelProperties.TransducerNaturalFrequency: case StandardChannelProperties.TransducerType: case StandardChannelProperties.Unit:*/ default: break; } } } private ISO.TestObjectTemplate _template; public void SetTemplate(ISO.TestObjectTemplate template) { _template = template; } public string Name { get { var tokens = Channel.Text_L1.Split(new string[] { SEPARATOR }, StringSplitOptions.None); return tokens.Last(); } } public const string TEST_SPECIFIC_DOUT = "TSD_"; public string NameOfTheChannel { get { var s = _channelProperties[StandardChannelProperties.NameOfTheChannel.ToString()].Value as string; if (string.IsNullOrWhiteSpace(s) || s == DataStatusTypes.NOVALUE.ToString()) { if (Name.StartsWith(TEST_SPECIFIC_DOUT)) { return "(Digital Output Setting)"; } else { return Name; } } return s; } set => _channelProperties[StandardChannelProperties.NameOfTheChannel.ToString()].Value = value; } public string LaboratoryCode { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string CustomerChannelCode { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public int DisplayOrder { get => Convert.ToInt32(_channelProperties[StandardChannelProperties.DisplayOrder.ToString()].Value, System.Globalization.CultureInfo.InvariantCulture); set => _channelProperties[StandardChannelProperties.DisplayOrder.ToString()].Value = value.ToString(System.Globalization.CultureInfo.InvariantCulture); } public string Comments1 { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string Location { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string Dimension { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string Direction { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string ChannelFrequencyClass { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string Unit { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string ReferenceSystem { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string TestObjectNumber { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string TransducerType { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string TransducerId { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string PreFilterType { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string CutOffFrequency { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string ChannelAmplitudeClass { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public ReferenceChannelTypes ReferenceChannel { get => ReferenceChannelTypes.NOVALUE; set {; } } public string ReferenceChannelName { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public DataSourceTypes DataSource { get => DataSourceTypes.Parameter; set {; } } public DataStatusTypes DataStatus { get => DataStatusTypes.NOVALUE; set {; } } public string SamplingInterval { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string BitResolution { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string TimeOfFirstSample { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string NumberOfSamples { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string OffsetPostTest { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string TransducerNaturalFrequency { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string TransducerDampingRatio { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string Comments2 { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string FirstGlobalMaximumValue { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string TimeOfMaximumValue { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string FirstGlobalMinimumValue { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string TimeOfMinimumValue { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string StartOffsetInterval { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public string EndOffsetInterval { get => DataStatusTypes.NOVALUE.ToString(); set {; } } public class ChannelProperty : ISerializable { public string Name { get; } public object Value { get; set; } = "NOVALUE"; public ChannelProperty(ChannelProperty copy) { Name = copy.Name; Value = copy.Value; } public ChannelProperty(string name, object value) { Name = name; Value = value; } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("PropertyName", Name); info.AddValue("PropertyValue", Value, Value.GetType()); } } } }