using System;
using System.Collections.Generic;
using System.Linq;
using Wayne.ForecourtControl.Fusion.ReadDeviceStatus;
using Wayne.Lib;
namespace Wayne.ForecourtControl.Fusion
{
public static class ConfigurationSetExtensions
{
///
/// Returns a list of pump numbers from the given configuration set
///
///
///
public static int[] PumpNumbers(this ConfigurationSet configurationSet)
{
return configurationSet.DspConfiguration.FDCdata.
WhereNotNull()
.SelectMany(x => x.DeviceClass.WhereNotNull())
.Select(x => Strings.ParseInt(x.DeviceID))
.Where(x => x.HasValue)
.Select(x => x.Value)
.ToArray();
}
///
/// Returns an array of strings the denormalized nozzle information
/// containing pumpnumber|nozzlenumber|productnumber|Tank1|Tank2 from the given configurationset.
///
///
///
public static IEnumerable NozzleSetup(this ConfigurationSet configurationSet)
{
foreach (var deviceClassDsp in configurationSet.DspConfiguration.FDCdata
.WhereNotNull()
.SelectMany(x => x.DeviceClass.WhereNotNull()))
{
foreach (var deviceClassFp in deviceClassDsp.DeviceClass.WhereNotNull())
{
foreach (var nozzle in deviceClassFp.FPNozzle.WhereNotNull())
{
foreach (var product in nozzle.FPProductId)
{
yield return string.Join("|",
new []{deviceClassDsp.DeviceID,
nozzle.FPNozzleNo,
product.PIFPProductNo,
product.PIFPTankNo1,
product.PIFPTankNo2});
}
}
}
}
}
///
/// Returns an enumerable of the product numbers in the supplied configuration set.
///
///
///
public static IEnumerable ProductNumbers(this ConfigurationSet configurationSet)
{
return configurationSet.ProductTable.FDCdata
.WhereNotNull()
.SelectMany(x => x.FuelProducts.WhereNotNull())
.SelectMany(x => x.Product.WhereNotNull())
.Select(x => Strings.ParseInt(x.ProductNo))
.Where(x => x.HasValue)
.Select(x => x.Value)
.ToArray();
}
}
}