335 lines
13 KiB
C#
335 lines
13 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Data;
|
|||
|
|
|
|||
|
|
namespace DatabaseExport
|
|||
|
|
{
|
|||
|
|
public class Hardware //: INotifyPropertyChanged
|
|||
|
|
{
|
|||
|
|
public enum HardwareTypes
|
|||
|
|
{
|
|||
|
|
SLICE_Base = 0,
|
|||
|
|
SLICE_Bridge = 1,
|
|||
|
|
SLICE_Distributor = 2,
|
|||
|
|
TDAS_Pro_Rack = 3,
|
|||
|
|
SLICE2_IEPE_Hi = 4,
|
|||
|
|
SLICE2_IEPE_Lo = 5,
|
|||
|
|
SLICE2_Bridge_Hi = 6,
|
|||
|
|
SLICE2_Bridge_Lo = 7,
|
|||
|
|
SLICE2_Base = 8,
|
|||
|
|
TOM = 9,
|
|||
|
|
SIM = 10,
|
|||
|
|
DIM = 11,
|
|||
|
|
G5VDS = 12,
|
|||
|
|
Ribeye = 13,
|
|||
|
|
RibeyeLED = 14,
|
|||
|
|
SLICE_IEPE = 15,
|
|||
|
|
SLICE1_5_Nano_Base = 16,
|
|||
|
|
SLICE_Micro_Base = 17,
|
|||
|
|
SLICE_NANO_Base = 18,
|
|||
|
|
SLICE2_SIM = 19,
|
|||
|
|
SLICE2_DIM = 20,
|
|||
|
|
SLICE2_TOM = 21,
|
|||
|
|
//G5IPORT=22,
|
|||
|
|
G5INDUMMY = 23,
|
|||
|
|
SLICE_EthernetController = 24,
|
|||
|
|
SLICE1_5_Micro_Base = 25,
|
|||
|
|
SLICE_LabEthernet = 26,
|
|||
|
|
SLICE2_SLS = 27,
|
|||
|
|
SLICE1_G5Stack = 28,
|
|||
|
|
SLICE2_SLT = 29,
|
|||
|
|
SLICE2_SLD = 30,
|
|||
|
|
TDAS_LabRack = 31,
|
|||
|
|
SLICE6_Base = 32
|
|||
|
|
}
|
|||
|
|
public static DateTime INVALIDDATE => new DateTime(1970, 1, 1);
|
|||
|
|
public string SerialNumber { get; set; } = "";
|
|||
|
|
public int CalInterval { get; set; } = 365;
|
|||
|
|
|
|||
|
|
public int DASType { get; set; } = 0;
|
|||
|
|
|
|||
|
|
public int MaxModules { get; set; } = 0;
|
|||
|
|
|
|||
|
|
public long MaxMemory { get; set; } = 0;
|
|||
|
|
|
|||
|
|
public double MinSampleRate { get; set; } = 0;
|
|||
|
|
|
|||
|
|
public double MaxSampleRate { get; set; } = 1000000;
|
|||
|
|
|
|||
|
|
public string FirmwareVersion { get; set; } = "";
|
|||
|
|
|
|||
|
|
private DateTime _calDate = INVALIDDATE;
|
|||
|
|
public DateTime CalDate
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if (_calDate < INVALIDDATE) { return INVALIDDATE; }
|
|||
|
|
return _calDate;
|
|||
|
|
}
|
|||
|
|
set => _calDate = value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public int ProtocolVersion { get; set; } = 0;
|
|||
|
|
|
|||
|
|
public DateTime LastModified { get; set; } = DateTime.Now;
|
|||
|
|
|
|||
|
|
public string LastModifiedBy { get; set; } = "";
|
|||
|
|
|
|||
|
|
public int Version { get; set; } = 1;
|
|||
|
|
|
|||
|
|
public bool LocalOnly { get; set; } = false;
|
|||
|
|
|
|||
|
|
public DateTime LastUsed { get; set; } = INVALIDDATE;
|
|||
|
|
|
|||
|
|
public string LastUsedBy { get; set; } = "";
|
|||
|
|
|
|||
|
|
public string IPAddress { get; set; } = "";
|
|||
|
|
|
|||
|
|
public int Channels { get; set; } = 0;
|
|||
|
|
|
|||
|
|
public string Position { get; set; } = "";
|
|||
|
|
|
|||
|
|
public bool IsProgrammable { get; set; } = false;
|
|||
|
|
|
|||
|
|
public bool IsModule { get; set; } = false;
|
|||
|
|
|
|||
|
|
public bool IsReconfigurable { get; set; } = false;
|
|||
|
|
|
|||
|
|
private int[] _channelTypes = null;
|
|||
|
|
public int[] ChannelTypes
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if (null == _channelTypes) { _channelTypes = new int[0]; }
|
|||
|
|
return _channelTypes;
|
|||
|
|
}
|
|||
|
|
set => _channelTypes = value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public Hardware()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public Hardware(Hardware copy)
|
|||
|
|
{
|
|||
|
|
Version = copy.Version;
|
|||
|
|
SerialNumber = copy.SerialNumber;
|
|||
|
|
ProtocolVersion = copy.ProtocolVersion;
|
|||
|
|
Position = copy.Position;
|
|||
|
|
MinSampleRate = copy.MinSampleRate;
|
|||
|
|
MaxSampleRate = copy.MaxSampleRate;
|
|||
|
|
MaxModules = copy.MaxModules;
|
|||
|
|
MaxMemory = copy.MaxMemory;
|
|||
|
|
LocalOnly = copy.LocalOnly;
|
|||
|
|
LastUsedBy = copy.LastUsedBy;
|
|||
|
|
LastUsed = copy.LastUsed;
|
|||
|
|
LastModifiedBy = copy.LastModifiedBy;
|
|||
|
|
LastModified = copy.LastModified;
|
|||
|
|
IsReconfigurable = copy.IsReconfigurable;
|
|||
|
|
IsProgrammable = copy.IsProgrammable;
|
|||
|
|
var channels = new List<ISOHardwareChannel>();
|
|||
|
|
foreach (var c in copy.ISOChannels)
|
|||
|
|
{
|
|||
|
|
channels.Add(new ISOHardwareChannel(c, this));
|
|||
|
|
}
|
|||
|
|
ISOChannels = channels.ToArray();
|
|||
|
|
IPAddress = copy.IPAddress;
|
|||
|
|
FirmwareVersion = copy.FirmwareVersion;
|
|||
|
|
DASType = copy.DASType;
|
|||
|
|
var channeltypes = new int[copy.ChannelTypes.Length];
|
|||
|
|
Array.Copy(copy.ChannelTypes, channeltypes, copy.ChannelTypes.Length);
|
|||
|
|
ChannelTypes = channeltypes;
|
|||
|
|
Channels = copy.Channels;
|
|||
|
|
CalInterval = copy.CalInterval;
|
|||
|
|
CalDate = copy.CalDate;
|
|||
|
|
IsModule = copy.IsModule;
|
|||
|
|
}
|
|||
|
|
public Hardware(DataRow dr)
|
|||
|
|
{
|
|||
|
|
var fields = Enum.GetValues(typeof(DbOperations.DAS.Fields)).Cast<DbOperations.DAS.Fields>().ToArray();
|
|||
|
|
foreach (var field in fields)
|
|||
|
|
{
|
|||
|
|
var o = dr[field.ToString()];
|
|||
|
|
if (DBNull.Value.Equals(o)) { continue; }
|
|||
|
|
switch (field)
|
|||
|
|
{
|
|||
|
|
case DbOperations.DAS.Fields.CalDate:
|
|||
|
|
CalDate = Convert.ToDateTime(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.Channels:
|
|||
|
|
Channels = Convert.ToInt32(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.Connection:
|
|||
|
|
IPAddress = Convert.ToString(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.FirmwareVersion:
|
|||
|
|
FirmwareVersion = Convert.ToString(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.LastModified:
|
|||
|
|
LastModified = Convert.ToDateTime(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.LastModifiedBy:
|
|||
|
|
LastModifiedBy = Convert.ToString(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.LastUsed:
|
|||
|
|
LastUsed = Convert.ToDateTime(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.LastUsedBy:
|
|||
|
|
LastUsedBy = Convert.ToString(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.LocalOnly:
|
|||
|
|
LocalOnly = Convert.ToBoolean(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.MaxMemory:
|
|||
|
|
MaxMemory = Convert.ToInt64(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.MaxModules:
|
|||
|
|
MaxModules = Convert.ToInt32(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.MaxSampleRate:
|
|||
|
|
MaxSampleRate = Convert.ToDouble(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.MinSampleRate:
|
|||
|
|
MinSampleRate = Convert.ToDouble(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.Position:
|
|||
|
|
Position = Convert.ToString(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.Reconfigurable:
|
|||
|
|
IsReconfigurable = Convert.ToBoolean(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.IsModule:
|
|||
|
|
IsModule = Convert.ToBoolean(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.Reprogramable:
|
|||
|
|
IsProgrammable = Convert.ToBoolean(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.ProtocolVersion:
|
|||
|
|
ProtocolVersion = Convert.ToInt32(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.SerialNumber:
|
|||
|
|
SerialNumber = Convert.ToString(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.Type:
|
|||
|
|
DASType = Convert.ToInt32(o);
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.ChannelTypes:
|
|||
|
|
{
|
|||
|
|
var s = o as string;
|
|||
|
|
var tokens = s.Split(new char[] { ',' });
|
|||
|
|
var types = new List<int>();
|
|||
|
|
foreach (var token in tokens)
|
|||
|
|
{
|
|||
|
|
if (int.TryParse(token, out var itemp)) { types.Add(itemp); }
|
|||
|
|
}
|
|||
|
|
ChannelTypes = types.ToArray();
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case DbOperations.DAS.Fields.Version:
|
|||
|
|
Version = Convert.ToInt32(o);
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
throw new NotSupportedException("Unknown field: " + field.ToString());
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
var channels = new List<ISOHardwareChannel>();
|
|||
|
|
var requery = true;
|
|||
|
|
using (var sql = DbOperations.GetCommand())
|
|||
|
|
{
|
|||
|
|
sql.CommandText = string.Format("SELECT * FROM [{0}] WHERE [{1}]=@{1}", DbOperations.DAS.TableDASChannels, DbOperations.DAS.DASChannelFields.HardwareId.ToString());
|
|||
|
|
DbOperations.CreateParam(sql, string.Format("@{0}", DbOperations.DAS.DASChannelFields.HardwareId.ToString()), SqlDbType.NVarChar, GetId());
|
|||
|
|
using (var ds = DbOperations.Connection.QueryDataSet(sql))
|
|||
|
|
{
|
|||
|
|
if (null != ds.Tables && ds.Tables.Count > 0)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
foreach (DataRow row in ds.Tables[0].Rows)
|
|||
|
|
{
|
|||
|
|
requery = false;
|
|||
|
|
channels.Add(new ISOHardwareChannel(row, this));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (requery)
|
|||
|
|
{
|
|||
|
|
using (var sql = DbOperations.GetCommand())
|
|||
|
|
{
|
|||
|
|
sql.CommandText = string.Format("SELECT * FROM [{0}] WHERE [{1}]=@{1}", DbOperations.DAS.TableDASChannels, DbOperations.DAS.DASChannelFields.HardwareId.ToString());
|
|||
|
|
DbOperations.CreateParam(sql, string.Format("@{0}", DbOperations.DAS.DASChannelFields.HardwareId.ToString()), SqlDbType.NVarChar, GetIdOld());
|
|||
|
|
using (var ds = DbOperations.Connection.QueryDataSet(sql))
|
|||
|
|
{
|
|||
|
|
if (null != ds.Tables && ds.Tables.Count > 0)
|
|||
|
|
{
|
|||
|
|
foreach (DataRow row in ds.Tables[0].Rows)
|
|||
|
|
{
|
|||
|
|
channels.Add(new ISOHardwareChannel(row, this));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
channels.Sort(ISOHardwareChannel.PhysicalCompare);
|
|||
|
|
_isoChannels = channels;
|
|||
|
|
}
|
|||
|
|
private List<ISOHardwareChannel> _isoChannels = new List<ISOHardwareChannel>();
|
|||
|
|
public ISOHardwareChannel[] ISOChannels
|
|||
|
|
{
|
|||
|
|
get => _isoChannels.ToArray();
|
|||
|
|
set => _isoChannels = new List<ISOHardwareChannel>(value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static Hardware[] GetAllDAS()
|
|||
|
|
{
|
|||
|
|
var list = new List<Hardware>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (var sql = DbOperations.GetCommand())
|
|||
|
|
{
|
|||
|
|
sql.CommandText = string.Format("SELECT * FROM [{0}]", DbOperations.DAS.Table);
|
|||
|
|
using (var ds = DbOperations.Connection.QueryDataSet(sql))
|
|||
|
|
{
|
|||
|
|
if (null != ds.Tables && ds.Tables.Count > 0)
|
|||
|
|
{
|
|||
|
|
foreach (DataRow dr in ds.Tables[0].Rows)
|
|||
|
|
{
|
|||
|
|
list.Add(new Hardware(dr));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
//DTS.Utilities.Logging.APILogger.Log("failed to retrieve all das, ", ex);
|
|||
|
|
}
|
|||
|
|
list.Sort(new HardwareCompare());
|
|||
|
|
return list.ToArray();
|
|||
|
|
}
|
|||
|
|
public class HardwareCompare : Comparer<Hardware>
|
|||
|
|
{
|
|||
|
|
public override int Compare(Hardware x, Hardware y)
|
|||
|
|
{
|
|||
|
|
var ret = x.SerialNumber.CompareTo(y.SerialNumber);
|
|||
|
|
if (0 == ret) { ret = x.IPAddress.CompareTo(y.IPAddress); }
|
|||
|
|
return ret;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public string GetId()
|
|||
|
|
{
|
|||
|
|
return GetId(SerialNumber, DASType.ToString(), IPAddress);
|
|||
|
|
}
|
|||
|
|
public string GetIdOld()
|
|||
|
|
{
|
|||
|
|
return string.Format("{0}_{1}_{2}", SerialNumber, DASType.ToString(), IPAddress);
|
|||
|
|
}
|
|||
|
|
public static string GetId(string sn, string dastype, string ip)
|
|||
|
|
{
|
|||
|
|
return string.Format("{0}_{1}", sn, dastype);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|