using System; using System.Collections.Generic; using System.Linq; using System.Threading; using DTS.Common; using DTS.DASLib.Service; using DTS.Common.Utilities.Logging; using DTS.Common.Interface.DASFactory; using DTS.Common.Enums.DASFactory; using System.Collections.Concurrent; namespace DTS.DASLib.DASFactory { internal class EthernetHandling : DeviceHandling { /// /// Timeout in milliseconds to connect an Ethernet Slice device /// public int ConnectEthernetSliceTimeout { get; set; } /// /// Timeout in milliseconds to connect an Ethernet Ribeye device /// public int ConnectEthernetRibeyeTimeout { get; set; } /// /// Timeout in milliseconds to connect an Ethernet Slice2 device /// public int ConnectEthernetSlice2Timeout { get; set; } /// /// Timeout in milliseconds to connect an Ethernet Slice1.5 device /// public int ConnectEthernetSlice15Timeout { get; set; } /// /// Timeout in milliseconds to connect an Ethernet Slice6 device /// public int ConnectEthernetSlice6Timeout { get; set; } /// /// Timeout in milliseconds to connect an Ethernet TSR AIR device /// public int ConnectEthernetTsrAirTimeout { get; set; } public int ConnectEthernetSliceProDBTimeout { get; set; } private ManualResetEvent _slicedbCanConnectEvent = new ManualResetEvent(false); private bool _slicedbCanConnect = true; private volatile bool _slicedbShouldDisconnect; //17649 Issues connecting/disconnecting to SLICE Distributor //expose this so that thread within dasfactory has access public bool SLICEDBShouldDisconnect => _slicedbShouldDisconnect; private DASFactory factory { get; set; } // device type 1 private IDeviceSetup SLICEHandler { get; set; } // device type 2 private IDeviceSetup RibeyeHandler { get; set; } // device type 3 private IDeviceSetup SLICE2Handler { get; set; } // device type 4 private IDeviceSetup SLICE15Handler { get; set; } // device type 6 private IDeviceSetup SLICE6Handler { get; set; } // device type 8 private IDeviceSetup SLICE6AirHandler { get; set; } // device type 12 private IDeviceSetup SLICE6AirBridgeHandler { get; set; } // device type 7 private IDeviceSetup slice6dbHandler { get; set; } // device type 9 private IDeviceSetup powerproHandler { get; set; } // device type 10 private IDeviceSetup tsrAirHandler { get; set; } // device type 11 private IDeviceSetup slice6db3Handler { get; set; } // device type 12 private IDeviceSetup sliceprodbHandler { get; set; } private IDeviceSetup SLICE6AirTcHandler { get; set; } private string _sliceDBHostName; public string SliceDBHostName { get => _sliceDBHostName; set { _sliceDBHostName = value; } } /// /// we want to allow SLICE ATDs to offset their connections to avoid flooding system /// we do this by allowing subnets to connect separately /// this property indentifies which index among subnets the current ip address belongs to /// public int HandlerIndex { get; set; } = 0; private static readonly Random _random = new Random(DateTime.Now.Millisecond); public EthernetHandling(DASFactory _factory, UpdateFinishedEventHandler serialUpdateFinished, IDeviceSetup slice, IDeviceSetup rib, IDeviceSetup slice2, IDeviceSetup slice15, IDeviceSetup slice6, IDeviceSetup slice6Air, IDeviceSetup slice6AirBridge, IDeviceSetup _slice6db, IDeviceSetup _powerpro, IDeviceSetup tsrAir, IDeviceSetup slice6db3, IDeviceSetup sliceprodb, IDeviceSetup slice6AirTc, BlockingCollection> queueActionPerDevice) : base(_factory, serialUpdateFinished, queueActionPerDevice) { SLICEHandler = slice; RibeyeHandler = rib; SLICE2Handler = slice2; SLICE15Handler = slice15; SLICE6Handler = slice6; SLICE6AirHandler = slice6Air; SLICE6AirBridgeHandler = slice6AirBridge; slice6dbHandler = _slice6db; powerproHandler = _powerpro; tsrAirHandler = tsrAir; slice6db3Handler = slice6db3; sliceprodbHandler = sliceprodb; SLICE6AirTcHandler = slice6AirTc; ConnectEthernetSliceTimeout = 60000; ConnectEthernetRibeyeTimeout = 60000; ConnectEthernetSlice2Timeout = 60000; ConnectEthernetSlice15Timeout = 60000; ConnectEthernetSlice6Timeout = (int)_factory.S6ConnectNewTimeout; ConnectEthernetTsrAirTimeout = 60000; ConnectEthernetSliceProDBTimeout = 60000; factory = _factory; } public override void Dispose() { try { _bKillSliceDBThread.Set(); //FB18389 Set this to true to end the loop in ConnectHosts when disposing _slicedbShouldDisconnect = true; } catch (Exception) { //ignore } base.Dispose(); } internal override bool DetachAllDevices() { var devicesWhereRemoved = false; lock (ConnectedDevicesLock) { _slicedbCanConnect = false; _slicedbShouldDisconnect = true; if (null != _sock && _sock.IsConnected()) { _sock.Disconnect(); } _slicedbCanConnectEvent.Reset(); foreach (var dev in ConnectedDevices) { dev.Dispose(); devicesWhereRemoved = true; } ConnectedDevices.Clear(); } // let our caller know if something was removed return devicesWhereRemoved; } #region Slice DB Event Listener Thread public class DistributorMsg { private enum ResponseMsgPos { ActionPos = 0, DevTypePos = 1, ConnectStringPos = 2 } const int NUMBER_OF_TOKENS = 3; private const string CONNECT_ACTION = "hello"; private const string DISCONNECT_ACTION = "goodbye"; const string SLICE_DEV_TYPE = "slicebase"; private const string RIBEYE_DEV_TYPE = "ribeye"; private const string SLICE2_DEV_TYPE = "slice2base"; private const string SLICE_1_5_DEV_TYPE = "slice_1_5_base"; private const string SLICE_6_DEV_TYPE = "slice6base"; private const string SLICE_6_AIR_DEV_TYPE = "slice6Air"; private const string SLICE_6_AIR_BR_DEV_TYPE = "slice6_falcon"; private const string SLICE_6_AIR_TC_DEV_TYPE = "SliceTC"; private const string slice_6_db_dev_type = "slice6db"; private const string PowerPro_dev_type = "PowerPro"; private const string TSR_AIR_DEV_TYPE = "tsrair"; private const string slice_6_db_3_dev_type = "slice6db3"; private const string SLICE_PRO_DB_DEV_TYPE = "sliceprodb"; // the raw message string public readonly string Msg; // is this a connect message? public bool IsConnect; // is this a slice message? public readonly bool IsSlice; // is this a slice 1.5 message? public readonly bool IsSlice15; // is this a slice 6 message? public readonly bool IsSlice6; // is this a slice 6 air message? public readonly bool IsSlice6Air; // is this a slice 6 air-bridge ('falcon-id') message? public readonly bool IsSlice6AirBridge; // Is this a SLICE6 AIR-Tc message? public bool IsSlice6AirTc; // is this a slice 6 DB message? public readonly bool IsSlice_6_DB; public readonly bool IsSliceProDB; // is this a PowerPRO message? public bool IsPowerPro; // is this a TSR AIR message? public bool IsTsrAir; public bool IsSlice_6_DB_3; public bool IsSlice6_Family { get { //this seems awfully wrong, but I'm copying what FWTU is doing ... //it seems wrong because the SLICEPRODb shouldn't probably be a member of the S6 family, also maybe the powerpro doesn't belong here //for now FWTU says put it in here, but maybe this should not longer be called "Slice6 Family"? return IsSlice6 || IsSlice6Air || IsSlice6AirBridge || IsSlice_6_DB || IsPowerPro || IsSlice_6_DB_3 || IsSliceProDB || IsSlice6AirTc; } } // supports KeepAlive public bool SupportsKeepAlive; // is this a slice 2 message? public readonly bool IsSlice2; // the connect string public readonly string ConnectString; public DistributorMsg(string msg) { try { Msg = msg; var tokens = Msg.Split(' '); if (tokens.Length != NUMBER_OF_TOKENS) { //FB43867 applied the patch //Check if we're connecting the command port if (tokens.Length == 2 && tokens[0] == DASFactory.COMMAND_PORT_CONNECT_OVERRIDE_MESSAGE) { IsConnect = true; IsSlice15 = true; ConnectString = tokens[1]; return; } else { throw new ArgumentException($"DistributorMsg: Invalid message: {Msg}"); } } // is it connect? IsConnect = tokens[(int)ResponseMsgPos.ActionPos] == CONNECT_ACTION; // is it slice? IsSlice = tokens[(int)ResponseMsgPos.DevTypePos] == SLICE_DEV_TYPE; // is it slice? IsSlice15 = tokens[(int)ResponseMsgPos.DevTypePos] == SLICE_1_5_DEV_TYPE; IsSlice6 = tokens[(int)ResponseMsgPos.DevTypePos] == SLICE_6_DEV_TYPE; IsSlice6Air = tokens[(int)ResponseMsgPos.DevTypePos] == SLICE_6_AIR_DEV_TYPE; IsSlice6AirBridge = tokens[(int)ResponseMsgPos.DevTypePos] == SLICE_6_AIR_BR_DEV_TYPE; // Is it a SLICE6 AIR-Tc? IsSlice6AirTc = tokens[(int)ResponseMsgPos.DevTypePos] == SLICE_6_AIR_TC_DEV_TYPE; // is it slice2? IsSlice2 = tokens[(int)ResponseMsgPos.DevTypePos] == SLICE2_DEV_TYPE; // is it sliceDB? IsSlice_6_DB = tokens[(int)ResponseMsgPos.DevTypePos] == slice_6_db_dev_type; IsSlice_6_DB_3 = tokens[(int)ResponseMsgPos.DevTypePos] == slice_6_db_3_dev_type; //is it SlicePRO DB? IsSliceProDB = tokens[(int)ResponseMsgPos.DevTypePos] == SLICE_PRO_DB_DEV_TYPE; // is it powerpro? IsPowerPro = tokens[(int)ResponseMsgPos.DevTypePos] == PowerPro_dev_type; // is it next gen tsr? IsTsrAir = tokens[(int)ResponseMsgPos.DevTypePos] == TSR_AIR_DEV_TYPE; SupportsKeepAlive = IsSlice6 || IsSlice6Air || IsSlice6AirBridge || IsSlice_6_DB || IsPowerPro || IsSlice_6_DB_3 || IsTsrAir || IsSliceProDB || IsSlice6AirTc; ConnectString = tokens[(int)ResponseMsgPos.ConnectStringPos]; } catch (Exception ex) { APILogger.Log("Exception in DistributorMsg", ex); throw; } } public static bool IsValidMsg(string msg) { try { var tokens = msg.Split(' '); if (string.IsNullOrEmpty(msg)) { if (tokens[0] == DASFactory.COMMAND_PORT_CONNECT_OVERRIDE_MESSAGE) { return true; } return false; } if (tokens.Length != NUMBER_OF_TOKENS) { //FB43867 applied the patch if (tokens[0] == DASFactory.COMMAND_PORT_CONNECT_OVERRIDE_MESSAGE) { return true; } return false; } if (tokens[(int)ResponseMsgPos.ActionPos] != CONNECT_ACTION && tokens[(int)ResponseMsgPos.ActionPos] != DISCONNECT_ACTION) { return false; } return true; } catch (Exception ex) { APILogger.Log("Exception in IsValidMsg", ex); throw; } } } /// /// Here we keep track of devices connected to distributors, key is SliceDB hostname /// private readonly Dictionary> _connectedDBDevices = new Dictionary>(); public bool UpdateConnectedDBDevices(string name, DistributorMsg msg) { try { if (!_connectedDBDevices.ContainsKey(name)) { var msgtmp = new DistributorMsg(msg.Msg) { IsConnect = !msg.IsConnect }; var listtmp = new List { msgtmp }; _connectedDBDevices.Add(name, listtmp); } // are we adding or removing? if (msg.IsConnect) { // make sure we don't have it already if (_connectedDBDevices[name].Contains(msg)) { return false; } // no, add it _connectedDBDevices[name].Add(msg); } else { for (var i = _connectedDBDevices[name].Count - 1; i >= 0; i--) { if (_connectedDBDevices[name][i].ConnectString == msg.ConnectString) { _connectedDBDevices[name].RemoveAt(i); } } } // we did change something return true; } catch (Exception ex) { APILogger.Log("Exception in UpdateConnectedDBDevices", ex); throw; } } private DistributorSocket _sock; private readonly ManualResetEvent _bKillSliceDBThread = new ManualResetEvent(false); /// /// set to true once a keep alive command has been acknowledged by a Ethernet device /// some devices will not support keep alive. /// having keep alive alleviates the need to use the heartbeat port on S6DB, reducing CPU and I/O load /// public bool KeepAliveEnabled { get; set; } /// /// set to true once the command port has been connected, part of /// 10947 SLICE6 don't disconnect HB port UNTIL command port is connected when using keep alive /// public volatile bool CommandPortConnected = false; //FB43867 applied the patch public volatile bool CommandPortConnectSignaled = false; public override void ReportDisconnect(object obj) { factory.ReportRemoved(obj); base.ReportDisconnect(obj); } private List GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType dasType) { var list = new List(); if (_connectedDBDevices == null) { return list; } switch (dasType) { case DFConstantsAndEnums.DASType.ETHERNET_SLICE: foreach (var pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsSlice select msg.ConnectString); var enumerableConnectStrings = connectStrings as string[] ?? connectStrings.ToArray(); if (enumerableConnectStrings.Any()) { list.AddRange(enumerableConnectStrings.ToArray()); } } break; case DFConstantsAndEnums.DASType.ETHERNET_SLICE1_5: foreach (var pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsSlice15 select msg.ConnectString); var enumerableConnectStrings = connectStrings as string[] ?? connectStrings.ToArray(); if (enumerableConnectStrings.Any()) { list.AddRange(enumerableConnectStrings.ToArray()); } } break; case DFConstantsAndEnums.DASType.ETHERNET_SLICE2: foreach (var pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsSlice2 select msg.ConnectString); var enumerableConnectStrings = connectStrings as string[] ?? connectStrings.ToArray(); if (enumerableConnectStrings.Any()) { list.AddRange(enumerableConnectStrings.ToArray()); } } break; case DFConstantsAndEnums.DASType.ETHERNET_SLICE6: { foreach (var pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsSlice6 select msg.ConnectString); var enumerableConnectStrings = connectStrings as string[] ?? connectStrings.ToArray(); if (enumerableConnectStrings.Any()) { list.AddRange(enumerableConnectStrings.ToArray()); } } } break; case DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR: { foreach (var pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsSlice6Air select msg.ConnectString); var enumerableConnectStrings = connectStrings as string[] ?? connectStrings.ToArray(); if (enumerableConnectStrings.Any()) { list.AddRange(enumerableConnectStrings.ToArray()); } } } break; case DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR_BR: { foreach (var pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsSlice6AirBridge select msg.ConnectString); var enumerableConnectStrings = connectStrings as string[] ?? connectStrings.ToArray(); if (enumerableConnectStrings.Any()) { list.AddRange(enumerableConnectStrings.ToArray()); } } } break; case DFConstantsAndEnums.DASType.ETHERNET_SLICE6DB: { foreach (var pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsSlice_6_DB select msg.ConnectString); var enumerableConnectStrings = connectStrings as string[] ?? connectStrings.ToArray(); if (enumerableConnectStrings.Any()) { list.AddRange(enumerableConnectStrings.ToArray()); } } } break; case DFConstantsAndEnums.DASType.ETHERNET_POWERPRO: { foreach (KeyValuePair> pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsPowerPro select msg.ConnectString); if (connectStrings != null && connectStrings.Any()) { list.AddRange(connectStrings.ToArray()); } } } break; case DFConstantsAndEnums.DASType.ETHERNET_TSR_AIR: { foreach (KeyValuePair> pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsTsrAir select msg.ConnectString); if (connectStrings != null && connectStrings.Any()) { list.AddRange(connectStrings.ToArray()); } } } break; case DFConstantsAndEnums.DASType.ETHERNET_SLICE6DB3: { foreach (KeyValuePair> pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsSlice_6_DB_3 select msg.ConnectString); if (connectStrings != null && connectStrings.Any()) { list.AddRange(connectStrings.ToArray()); } } } break; case DFConstantsAndEnums.DASType.ETHERNET_SLICEPRODB: { foreach (KeyValuePair> pair in _connectedDBDevices) { var connectStrings = from msg in pair.Value where msg.IsSliceProDB select msg.ConnectString; if (connectStrings != null && connectStrings.Any()) { list.AddRange(connectStrings.ToArray()); } } } break; case DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR_TC: { foreach (var pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsSlice6AirTc select msg.ConnectString); var enumerableConnectStrings = connectStrings as string[] ?? connectStrings.ToArray(); if (enumerableConnectStrings.Any()) { list.AddRange(enumerableConnectStrings.ToArray()); } } } break; } //eliminate duplicates for (var i = list.Count - 1; i > 0; i--) { var index = list.IndexOf(list[i]); if (index < i) { list.RemoveAt(i); } } return list; } private List GetConnectedEthernetDeviceSDBString(bool slice) { var list = new List(); if (!factory.AllowSDBCommandPort) { return list; } if (_connectedDBDevices == null) { return list; } list.AddRange(from pair in _connectedDBDevices where !(pair.Value[0].IsSlice6 || pair.Value[0].IsSlice6Air || pair.Value[0].IsSlice6AirBridge || pair.Value[0].IsSlice_6_DB || pair.Value[0].IsSlice_6_DB_3 || pair.Value[0].IsTsrAir || pair.Value[0].IsPowerPro || pair.Value[0].IsSliceProDB || pair.Value[0].IsSlice6AirTc) select pair.Key into s select s + ":8201"); return list; } private List GetActiveConnectedEthernetDeviceStrings(bool slice) { var list = new List(); if (_connectedDBDevices == null) { return list; } var devs = ConnectedDevices.ToArray(); foreach (var dev in devs) { if (!dev.Dev.Comm.Connected) { continue; } if ((slice && dev.DasType == SLICEHandler.GetDASType()) || (!slice && dev.DasType == RibeyeHandler.GetDASType()) || (slice && dev.DasType == SLICE2Handler.GetDASType()) || (slice && dev.DasType == SLICE15Handler.GetDASType()) || (slice && dev.DasType == SLICE6Handler.GetDASType()) || (slice && dev.DasType == SLICE6AirHandler.GetDASType()) || (slice && dev.DasType == SLICE6AirBridgeHandler.GetDASType()) || (slice && dev.DasType == slice6dbHandler.GetDASType()) || (slice && dev.DasType == powerproHandler.GetDASType()) || (slice && dev.DasType == tsrAirHandler.GetDASType()) || (slice && dev.DasType == slice6db3Handler.GetDASType()) || (slice && dev.DasType == sliceprodbHandler.GetDASType()) || (slice && dev.DasType == SLICE6AirTcHandler.GetDASType()) ) { list.Add(dev.Dev.ConnectString); } } return list; } private List GetActiveConnectedEthernetSDBDeviceStrings(bool slice) { var list = new List(); if (!factory.AllowSDBCommandPort) { return list; } if (_connectedDBDevices == null) { return list; } var devs = ConnectedDevices.ToArray(); list.AddRange(from dev in devs where dev.Dev.Comm.Connected where dev.DasType == DFConstantsAndEnums.DASType.SLICE_DB select dev.Dev.ConnectString); return list; } #region Slice connect private void UpdateConnectedEthernetSlices() { ConnectNewDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE), () => GetActiveConnectedEthernetDeviceStrings(true), () => SLICEHandler.GetICommunication(), comm => SLICEHandler.GetIConnectedDevice(comm), SLICEHandler.GetDASType(), SLICEHandler, ConnectEthernetSliceTimeout); } /// /// returns all connectable devices reported by ECM/SDBs /// the connect strings are in the form of IP:Port as reported by /// HELLO SLICEBASE xxx.xxx.xxx.xxx:yyyy /// 14157 Refresh/Stability Issue in Data Acquisition Tile /// /// public string[] GetConnectedEthernetDeviceStrings() { var list = new List(); if (_connectedDBDevices == null) { return list.ToArray(); } foreach (var pair in _connectedDBDevices) { var connectStrings = (from msg in pair.Value where msg.IsConnect select msg.ConnectString); var enumerableConnectStrings = connectStrings as string[] ?? connectStrings.ToArray(); if (enumerableConnectStrings.Any()) { list.AddRange(enumerableConnectStrings.ToArray()); } } list = list.Distinct().ToList(); return list.ToArray(); } private void UpdateConnectedEthernetSlice2s() { ConnectNewDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE2), () => GetActiveConnectedEthernetDeviceStrings(true), () => SLICE2Handler.GetICommunication(), comm => SLICE2Handler.GetIConnectedDevice(comm), SLICE2Handler.GetDASType(), SLICE2Handler, ConnectEthernetSlice2Timeout); } private void UpdateConnectedEthernetSlice1_5s() { ConnectNewDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE1_5), () => GetActiveConnectedEthernetDeviceStrings(true), () => SLICE15Handler.GetICommunication(), comm => SLICE15Handler.GetIConnectedDevice(comm), SLICE15Handler.GetDASType(), SLICE15Handler, ConnectEthernetSlice15Timeout); } private void UpdateConnectedEthernetSlice6s() { ConnectNewDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE6), () => GetActiveConnectedEthernetDeviceStrings(true), () => SLICE6Handler.GetICommunication(), comm => SLICE6Handler.GetIConnectedDevice(comm), SLICE6Handler.GetDASType(), SLICE6Handler, ConnectEthernetSlice6Timeout); } private void UpdateConnectedEthernetSlice6Airs() { ConnectNewDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR), () => GetActiveConnectedEthernetDeviceStrings(true), () => SLICE6AirHandler.GetICommunication(), comm => SLICE6AirHandler.GetIConnectedDevice(comm), SLICE6AirHandler.GetDASType(), SLICE6AirHandler, ConnectEthernetSlice6Timeout); } private void UpdateConnectedEthernetSlice6AirBridges() { ConnectNewDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR_BR), () => GetActiveConnectedEthernetDeviceStrings(true), () => SLICE6AirBridgeHandler.GetICommunication(), comm => SLICE6AirBridgeHandler.GetIConnectedDevice(comm), SLICE6AirBridgeHandler.GetDASType(), SLICE6AirBridgeHandler, ConnectEthernetSlice6Timeout); } private void UpdateConnectedEthernetSlice6DBs() { ConnectNewDevices( () => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE6DB), () => GetActiveConnectedEthernetDeviceStrings(true), () => slice6dbHandler.GetICommunication(), comm => slice6dbHandler.GetIConnectedDevice(comm), slice6dbHandler.GetDASType(), slice6dbHandler, ConnectEthernetSlice6Timeout); } private void UpdateConnectedEthernetPowerPros() { ConnectNewDevices( () => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_POWERPRO), () => GetActiveConnectedEthernetDeviceStrings(true), () => powerproHandler.GetICommunication(), comm => powerproHandler.GetIConnectedDevice(comm), powerproHandler.GetDASType(), powerproHandler, ConnectEthernetSlice6Timeout); } private void UpdateConnectedEthernetTsrAirs() { ConnectNewDevices( () => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_TSR_AIR), () => GetActiveConnectedEthernetDeviceStrings(true), () => tsrAirHandler.GetICommunication(), comm => tsrAirHandler.GetIConnectedDevice(comm), tsrAirHandler.GetDASType(), tsrAirHandler, ConnectEthernetSlice6Timeout); } private void UpdateConnectedEthernetSlice6DB3s() { ConnectNewDevices( () => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE6DB3), () => GetActiveConnectedEthernetDeviceStrings(true), () => slice6db3Handler.GetICommunication(), comm => slice6db3Handler.GetIConnectedDevice(comm), slice6db3Handler.GetDASType(), slice6db3Handler, ConnectEthernetSlice6Timeout); } private void UpdateConnectedEthernetSliceProDBs() { ConnectNewDevices( () => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICEPRODB), () => GetActiveConnectedEthernetDeviceStrings(true), () => sliceprodbHandler.GetICommunication(), comm => sliceprodbHandler.GetIConnectedDevice(comm), sliceprodbHandler.GetDASType(), sliceprodbHandler, ConnectEthernetSliceProDBTimeout); } private void UpdateConnectedEthernetSDBs() { ConnectNewDevices( () => GetConnectedEthernetDeviceSDBString(true), () => GetActiveConnectedEthernetSDBDeviceStrings(true), () => new EthernetSliceDB(), comm => ((EthernetSliceHandling)SLICEHandler).GetIConnectedSDBDevice(comm), DFConstantsAndEnums.DASType.SLICE_DB, SLICEHandler, ConnectEthernetSliceTimeout); } private void UpdateConnectedEthernetSlice6AirTCs() { ConnectNewDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR_TC), () => GetActiveConnectedEthernetDeviceStrings(true), () => SLICE6AirTcHandler.GetICommunication(), comm => SLICE6AirTcHandler.GetIConnectedDevice(comm), SLICE6AirTcHandler.GetDASType(), SLICE6AirTcHandler, ConnectEthernetSlice6Timeout); } public override void UpdateConnectedDevices() { if (!_slicedbCanConnect) { //well, we were told to stop connecting (stop monitoring) //it is okay for us to connect again now. _slicedbCanConnect = true; _slicedbShouldDisconnect = false; _slicedbCanConnectEvent.Set(); //just a courtesy before we call update connected ethernet devices Thread.Sleep(200); } UpdateConnectedEthernetSlices(); if (factory.AllowSDBCommandPort) { UpdateConnectedEthernetSDBs(); } UpdateConnectedEthernetSlice6s(); UpdateConnectedEthernetSlice6Airs(); UpdateConnectedEthernetSlice6AirBridges(); UpdateConnectedEthernetSlice6DBs(); UpdateConnectedEthernetSlice6DB3s(); UpdateConnectedEthernetRibeyes(); UpdateConnectedEthernetSlice2s(); UpdateConnectedEthernetSlice1_5s(); UpdateConnectedEthernetPowerPros(); UpdateConnectedEthernetTsrAirs(); UpdateConnectedEthernetSliceProDBs(); UpdateConnectedEthernetSlice6AirTCs(); } #endregion #region Slice disconnect private void UpdateDisconnectedEthernetSlices() { DisconnectRemovedDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE), dev => SLICEHandler.IsCorrectType(dev), dev => SLICEHandler.GetICommunication(dev), SLICEHandler.GetDASType(), ConnectEthernetSliceTimeout); } private void UpdateDisconnectedEthernetSlice2s() { DisconnectRemovedDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE2), dev => SLICE2Handler.IsCorrectType(dev), dev => SLICE2Handler.GetICommunication(dev), SLICE2Handler.GetDASType(), ConnectEthernetSlice2Timeout); } private void UpdateDisconnectedEthernetSlice1_5s() { DisconnectRemovedDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE1_5), dev => SLICE15Handler.IsCorrectType(dev), dev => SLICE15Handler.GetICommunication(dev), SLICE15Handler.GetDASType(), ConnectEthernetSlice15Timeout); } private void UpdateDisconnectedEthernetSliceProDBs() { DisconnectRemovedDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICEPRODB), dev => sliceprodbHandler.IsCorrectType(dev), dev => sliceprodbHandler.GetICommunication(dev), sliceprodbHandler.GetDASType(), ConnectEthernetSliceProDBTimeout); } private void UpdateDisconnectedEthernetSlice6s() { DisconnectRemovedDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE6), dev => SLICE6Handler.IsCorrectType(dev), dev => SLICE6Handler.GetICommunication(dev), SLICE6Handler.GetDASType(), ConnectEthernetSlice6Timeout); } private void UpdateDisconnectedEthernetSlice6Airs() { DisconnectRemovedDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR), dev => SLICE6AirHandler.IsCorrectType(dev), dev => SLICE6AirHandler.GetICommunication(dev), SLICE6AirHandler.GetDASType(), ConnectEthernetSlice6Timeout); } private void UpdateDisconnectedEthernetSlice6AirBridges() { DisconnectRemovedDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR_BR), dev => SLICE6AirBridgeHandler.IsCorrectType(dev), dev => SLICE6AirBridgeHandler.GetICommunication(dev), SLICE6AirBridgeHandler.GetDASType(), ConnectEthernetSlice6Timeout); } private void UpdateDisconnectedEthernetTsrAirs() { DisconnectRemovedDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_TSR_AIR), dev => tsrAirHandler.IsCorrectType(dev), dev => tsrAirHandler.GetICommunication(dev), tsrAirHandler.GetDASType(), ConnectEthernetSlice6Timeout); } private void UpdateDisconnectedEthernetSlice6AirTCs() { DisconnectRemovedDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR_TC), dev => SLICE6AirTcHandler.IsCorrectType(dev), dev => SLICE6AirTcHandler.GetICommunication(dev), SLICE6AirTcHandler.GetDASType(), ConnectEthernetSlice6Timeout); } public override void UpdateDisconnectedDevices() { UpdateDisconnectedEthernetSlices(); UpdateDisconnectedEthernetRibeyes(); UpdateDisconnectedEthernetSlice2s(); UpdateDisconnectedEthernetSlice1_5s(); UpdateDisconnectedEthernetSlice6s(); UpdateDisconnectedEthernetSlice6Airs(); UpdateDisconnectedEthernetSlice6AirBridges(); UpdateDisconnectedEthernetTsrAirs(); UpdateDisconnectedEthernetSliceProDBs(); UpdateDisconnectedEthernetSlice6AirTCs(); } #endregion #region Ribeye connect private void UpdateConnectedEthernetRibeyes() { ConnectNewDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_RIBEYE), () => GetActiveConnectedEthernetDeviceStrings(false), () => RibeyeHandler.GetICommunication(), comm => RibeyeHandler.GetIConnectedDevice(comm), RibeyeHandler.GetDASType(), RibeyeHandler, ConnectEthernetRibeyeTimeout); } private void UpdateDisconnectedEthernetRibeyes() { DisconnectRemovedDevices(() => GetConnectedEthernetDeviceString(DFConstantsAndEnums.DASType.ETHERNET_RIBEYE), dev => RibeyeHandler.IsCorrectType(dev), dev => RibeyeHandler.GetICommunication(dev), RibeyeHandler.GetDASType(), ConnectEthernetRibeyeTimeout); } #endregion private void RemoveAll() { _connectedDBDevices.Clear(); EnqueueConnect(); } #endregion public override void UpdateDeviceSetups() { RibeyeHandler.SetHandler(this); SLICEHandler.SetHandler(this); SLICE2Handler.SetHandler(this); SLICE15Handler.SetHandler(this); SLICE6Handler.SetHandler(this); SLICE6AirHandler.SetHandler(this); SLICE6AirBridgeHandler.SetHandler(this); slice6dbHandler.SetHandler(this); powerproHandler.SetHandler(this); tsrAirHandler.SetHandler(this); slice6db3Handler.SetHandler(this); sliceprodbHandler.SetHandler(this); SLICE6AirTcHandler.SetHandler(this); } } }