using System;
using System.Collections.Generic;
using System.Linq;
namespace Deltares.Dam.Data.Sensors
{
internal class SensorPLLineCreator
{
///
/// Creates an instance of a SensorPLLineCreator for PL1. PL3, PL4.
///
/// The sensor location.
/// The sensor values.
///
public static SensorPLLineCreator
CreateInstance(SensorLocation sensorLocation, IDictionary sensorValues)
{
return CreateInstance(sensorLocation, sensorValues, new[] {PLLineType.PL1, PLLineType.PL3, PLLineType.PL4,});
}
///
/// Creates an instance of a SensorPLLineCreator.
///
/// The sensor location.
/// The sensor values.
///
///
public static SensorPLLineCreator CreateInstance(SensorLocation sensorLocation, IDictionary sensorValues, IEnumerable lineTypes)
{
IPLLineCreator c1 = new SensorPLLine1Creator(sensorLocation, sensorValues);
IPLLineCreator c3 = new SensorPLLine3Creator(sensorLocation, sensorValues);
IPLLineCreator c4 = new SensorPLLine4Creator(sensorLocation, sensorValues);
var tuples = new List>();
foreach (var lineType in lineTypes)
{
switch(lineType)
{
case PLLineType.PL1:
tuples.Add(new Tuple(lineType, c1));
break;
case PLLineType.PL2:
// ignore
break;
case PLLineType.PL3:
tuples.Add(new Tuple(lineType, c3));
break;
case PLLineType.PL4:
tuples.Add(new Tuple(lineType, c4));
break;
default:
throw new ArgumentOutOfRangeException();
}
}
if (!lineTypes.Contains(PLLineType.PL3) && sensorLocation.SourceTypePl3 == DataSourceTypeSensors.LocationData)
{
tuples.Add(new Tuple(PLLineType.PL3, c3));
}
if (!lineTypes.Contains(PLLineType.PL4) && sensorLocation.SourceTypePl4 == DataSourceTypeSensors.LocationData)
{
tuples.Add(new Tuple(PLLineType.PL4, c4));
}
return new SensorPLLineCreator(tuples);
}
private readonly IDictionary creators = new Dictionary();
///
/// Initializes a new instance of the class.
///
/// The 'concrete' creator.
/// The type.
public SensorPLLineCreator(IPLLineCreator creator, PLLineType type)
{
this.creators.Add(type, creator);
}
///
/// Initializes a new instance of the class.
///
/// The 'concrete' creators.
public SensorPLLineCreator(IEnumerable> creators)
{
foreach (var creator in creators)
{
this.creators.Add(creator.Item1, creator.Item2);
}
}
///
/// Creates all PL lines.
///
/// A PLLines set
public PLLines CreateAllPLLines()
{
var lines = new PLLines();
foreach (var item in creators)
{
IPLLineCreator creator = item.Value;
PLLine plLine = creator.CreatePLLine();
lines.Lines[plLine.PLLineType] = plLine;
}
return lines;
}
///
/// Creates a PL line of the given type.
///
/// The type of the PL line.
/// A PLLine instance
public PLLine CreatePLLine(PLLineType type)
{
if (!creators.ContainsKey(type) || creators[type] == null)
throw new NotSupportedException("Creation of type " + type + " currently not supported");
return creators[type].CreatePLLine();
}
}
}