using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTS.SensorDB.TDCINI
{
///
/// helper class for the rack inventory section of the INI
///
public class INIRackInventory
{
///
/// helper class for an entry in the INI RackInventory section
///
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 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 _racks = new List();
public INIRackInfo[] Racks
{
get { return _racks.ToArray(); }
set { _racks = new List(value); }
}
public bool ReadFrom(string[] lines, ref int iCurLine, ref List errors)
{
bool bDone = false;
List racks = new List();
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;
}
}
}