using System; using System.Collections.Generic; using System.Linq; namespace DatabaseImport { public class DASHardware : DbTimeStampBase, IComparable, IDASHardware { /// /// returns whether in the UI this device should be represented as a rack even though it isn't (SLICE6Db, ECM, SLE) /// /// public bool IsPseudoRack() { switch (GetHardwareTypeEnum()) { case HardwareTypes.SLICE_LabEthernet: case HardwareTypes.SLICE_EthernetController: case HardwareTypes.SLICE6DB: return true; default: return false; } } public string ParentDAS { get => _hardware.ParentDAS; set => _hardware.ParentDAS = value; } public int PositionOnDistributor { get => _hardware.PositionOnDistributor; set => _hardware.PositionOnDistributor = value; } public int CompareTo(DASHardware right) { if (null == right) { return 1; } if (this == right) { return 0; } if (SerialNumber == right.SerialNumber) { return 0; } //ensure that children of a das are sorted behind their parents if (!string.IsNullOrWhiteSpace(ParentDAS) && right.SerialNumber == ParentDAS) { return 1; } if (!string.IsNullOrWhiteSpace(right.ParentDAS) && right.ParentDAS == SerialNumber) { return -1; } if (!string.IsNullOrWhiteSpace(right.ParentDAS) && right.ParentDAS == ParentDAS) { if (PositionOnDistributor != right.PositionOnDistributor) { return PositionOnDistributor.CompareTo(right.PositionOnDistributor); } } return string.Compare(SerialNumber, right.SerialNumber, StringComparison.Ordinal); } private List _channels = new List(); public HardwareChannel[] Channels { get => _channels.ToArray(); set { var channels = new List(value); channels.Sort(); _channels = channels; //OnPropertyChanged(Tags.ChannelCount.ToString()); } } public string SerialNumber { get => _hardware.SerialNumber; set => _hardware.SerialNumber = value; } public int GetHardwareTypeInt() { return _hardware.DASType; } public HardwareTypes GetHardwareTypeEnum() { return (HardwareTypes)GetHardwareTypeInt(); } public long GetMaxMemoryLong() { return _hardware.MaxMemory; } public DASHardware(DASHardware copy, DASHardware parentDAS) { if (null != copy.Channels) { Channels = copy.Channels.Select(ch => new HardwareChannel(ch)).ToArray(); } _hardware = new Hardware(copy.GetHardware()); DbTimeStamp = copy.DbTimeStamp; } public string[] LinkedDASSerials { get; set; } private Hardware _hardware = new Hardware(); public Hardware GetHardware() { return _hardware; } /// /// note that if you use this constructor, you should set /// TimeStampDb explicitly /// /// public DASHardware(Hardware hardware) { _hardware = new Hardware(hardware); Channels = hardware.ISOChannels.Select(channel => new HardwareChannel(channel, this)).ToArray(); } public bool IsDummy() { return SerialNumber.Contains("Dummy"); } } }