93 lines
3.3 KiB
C#
93 lines
3.3 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace DTS.SensorDB.TDCINI
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// helper class for the rack inventory section of the INI
|
|||
|
|
/// </summary>
|
|||
|
|
public class INIRackInventory
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// helper class for an entry in the INI RackInventory section
|
|||
|
|
/// </summary>
|
|||
|
|
public class INIRackInfo
|
|||
|
|
{
|
|||
|
|
public int Number { get; set; }
|
|||
|
|
public string SerialNumber { get; set; }
|
|||
|
|
public int Size { get; set; }
|
|||
|
|
public string IPAddress { get; set; }
|
|||
|
|
public bool ReadFrom(string line, ref List<TDCINIError> errors)
|
|||
|
|
{
|
|||
|
|
string[] tokens = line.Split(new char[] { ',' });
|
|||
|
|
if (tokens.Length != 4)
|
|||
|
|
{
|
|||
|
|
errors.Add(new TDCINIError(TDCINIError.INIErrors.INI_RACKINVENTORY_INVALID, line));
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int i;
|
|||
|
|
if (!int.TryParse(tokens[0], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out i))
|
|||
|
|
{
|
|||
|
|
errors.Add(new TDCINIError(TDCINIError.INIErrors.INI_RACKINVENTORY_INVALID, tokens[0]));
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
else { Number = i; }
|
|||
|
|
|
|||
|
|
SerialNumber = tokens[1];
|
|||
|
|
|
|||
|
|
if (!int.TryParse(tokens[2], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out i))
|
|||
|
|
{
|
|||
|
|
errors.Add(new TDCINIError(TDCINIError.INIErrors.INI_RACKINVENTORY_INVALID, tokens[2]));
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
else { Size = i; }
|
|||
|
|
|
|||
|
|
IPAddress = tokens[3];
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
public TSFRackDescription ToTSFRackDescription()
|
|||
|
|
{
|
|||
|
|
TSFRackDescription rack = new TSFRackDescription();
|
|||
|
|
rack.Number = Number;
|
|||
|
|
rack.HWIPAddress = IPAddress;
|
|||
|
|
rack.HWSerialNumber = SerialNumber.Trim();
|
|||
|
|
|
|||
|
|
return rack;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private List<INIRackInfo> _racks = new List<INIRackInfo>();
|
|||
|
|
public INIRackInfo[] Racks
|
|||
|
|
{
|
|||
|
|
get { return _racks.ToArray(); }
|
|||
|
|
set { _racks = new List<INIRackInfo>(value); }
|
|||
|
|
}
|
|||
|
|
public bool ReadFrom(string[] lines, ref int iCurLine, ref List<TDCINIError> errors)
|
|||
|
|
{
|
|||
|
|
bool bDone = false;
|
|||
|
|
List<INIRackInfo> racks = new List<INIRackInfo>();
|
|||
|
|
while (!bDone)
|
|||
|
|
{
|
|||
|
|
string line = TDCINIFile.GetNextLine(lines, ref iCurLine, ref errors, TDCINIError.INIErrors.INI_RACKINVENTORY_INVALID);
|
|||
|
|
if (null == line) { return false; }
|
|||
|
|
|
|||
|
|
if (line.StartsWith("----")) { bDone = true; }
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
INIRackInfo rack = new INIRackInfo();
|
|||
|
|
if (!rack.ReadFrom(line, ref errors))
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
else { racks.Add(rack); }
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
Racks = racks.ToArray();
|
|||
|
|
iCurLine--;
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|