using DTS.Common.Base; using DTS.Common.Enums; using DTS.Common.Interface.Sensors; using System; using System.Data; using System.Linq; namespace DTS.Common.Classes.Sensors { public class DigitalOutDbRecord : BasePropertyChanged, IDigitalOutDbRecord { private string _serialNumber = ""; public string SerialNumber { get => _serialNumber; set => SetProperty(ref _serialNumber, value, "SerialNumber"); } private double _doDelay = 0D; public double DODelay { get => _doDelay; set => SetProperty(ref _doDelay, value, "DODelay"); } private double _doDuration = 0D; public double DODuration { get => _doDuration; set => SetProperty(ref _doDuration, value, "DODuration"); } private string _modifiedBy = ""; public string ModifiedBy { get => _modifiedBy; set => SetProperty(ref _modifiedBy, value, "ModifiedBy"); } private DateTime _lastModified = DateTime.MinValue; public DateTime LastModified { get => _lastModified; set => SetProperty(ref _lastModified, value, "LastModified"); } private int _databaseId = -1; public int DatabaseId { get => _databaseId; set => SetProperty(ref _databaseId, value, "DatabaseId"); } private string _isoCode = ""; public string ISOCode { get => _isoCode; set => SetProperty(ref _isoCode, value, "ISOCode"); } private string _isoChannelName = ""; public string ISOChannelName { get => _isoChannelName; set => SetProperty(ref _isoChannelName, value, "ISOChannelName"); } private string _userCode = ""; public string UserCode { get => _userCode; set => SetProperty(ref _userCode, value, "UserCode"); } private string _userChannelName = ""; public string UserChannelName { get => _userChannelName; set => SetProperty(ref _userChannelName, value, "UserChannelName"); } private bool _broken = false; public bool Broken { get => _broken; set => SetProperty(ref _broken, value, "Broken"); } private bool _doNotUse = false; public bool DoNotUse { get => _doNotUse; set => SetProperty(ref _doNotUse, value, "DoNotUse"); } private DigitalOutputModes _doMode = DigitalOutputModes.CCNC; public DigitalOutputModes DOMode { get => _doMode; set => SetProperty(ref _doMode, value, "DOMode"); } private bool _limitDuration = true; public bool LimitDuration { get => _limitDuration; set => SetProperty(ref _limitDuration, value, "LimitDuration"); } private int _version = 0; public int Version { get => _version; set => SetProperty(ref _version, value, "Version"); } private byte[] _tagsBlobBytes = null; public byte [] TagsBlobBytes { get => _tagsBlobBytes; set => SetProperty(ref _tagsBlobBytes, value, "TagsBlobBytes"); } public DigitalOutDbRecord() { } public DigitalOutDbRecord(ISensorData copy, byte [] tagsBlobBytes) { SerialNumber = copy.SerialNumber; DatabaseId = copy.DatabaseId; Broken = copy.Broken; DoNotUse = copy.DoNotUse; Version = copy.Version; DOMode = copy.DigitalOutputMode; LimitDuration = copy.DigitalOutputLimitDuration; ModifiedBy = copy.LastUpdatedBy; LastModified = copy.LastModified; DODuration = copy.DigitalOutputDurationMS; DODelay = copy.DigitalOutputDelayMS; if (null == tagsBlobBytes) { TagsBlobBytes = null; } else if (tagsBlobBytes.Any()) { var bytes = new byte[tagsBlobBytes.Length]; Array.Copy(tagsBlobBytes, bytes, tagsBlobBytes.Length); TagsBlobBytes = bytes; } else { TagsBlobBytes = new byte[0]; } } public DigitalOutDbRecord(IDigitalOutDbRecord copy) { SerialNumber = copy.SerialNumber; DatabaseId = copy.DatabaseId; Broken = copy.Broken; DoNotUse = copy.DoNotUse; Version = copy.Version; DOMode = copy.DOMode; LimitDuration = copy.LimitDuration; ModifiedBy = copy.ModifiedBy; LastModified = copy.LastModified; DODuration = copy.DODuration; DODelay = copy.DODelay; if( null == copy.TagsBlobBytes) { TagsBlobBytes = null; } else if(copy.TagsBlobBytes.Any()) { var tagsBlobBytes = new byte[copy.TagsBlobBytes.Length]; Array.Copy(copy.TagsBlobBytes, tagsBlobBytes, copy.TagsBlobBytes.Length); TagsBlobBytes = tagsBlobBytes; } else { TagsBlobBytes = new byte[0]; } } public DigitalOutDbRecord(IDataReader reader) { DatabaseId = Utility.GetInt(reader, "Id", -1); Broken = Utility.GetBool(reader, "Broken", false); DoNotUse = Utility.GetBool(reader, "DoNotUse"); SerialNumber = Utility.GetString(reader, "SerialNumber"); Version = Utility.GetInt(reader, "Version"); DOMode = (DigitalOutputModes)Utility.GetInt(reader, "OutputMode"); LimitDuration = Utility.GetBool(reader, "LimitDuration", true); ModifiedBy = Utility.GetString(reader, "LastModifiedBy", string.Empty); LastModified = Utility.GetDateTime(reader, "LastModified", DateTime.MinValue); DODuration = Utility.GetDouble(reader, "DurationMSFloat"); DODelay = Utility.GetDouble(reader, "DelayMS"); TagsBlobBytes = (byte[])reader["UserTags"]; } } }