94 lines
2.9 KiB
C#
94 lines
2.9 KiB
C#
using Common;
|
|
using Config.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Rig.Input.DataStorage.UniDataStorageReader.Readers;
|
|
using TBF.Rig.Scales.MettlerToledo;
|
|
using static TBF.Rig.Input.DataStorage.UniDataStorageReader.ReaderCfg;
|
|
|
|
namespace TBF.Rig.Input.DataStorage.UniDataStorageReader
|
|
{
|
|
/// <summary>
|
|
/// Main component that selects appropriate data reader based on configuration.
|
|
/// Acts as a dispatcher between different storage implementations.
|
|
/// </summary>
|
|
public class Reader : IComponent
|
|
{
|
|
private readonly ReaderCfg cfg;
|
|
|
|
public Reader(ReaderCfg cfg)
|
|
{
|
|
this.cfg = cfg ?? throw new ArgumentNullException(nameof(cfg));
|
|
}
|
|
|
|
public string Name { get { return cfg.Name; } }
|
|
|
|
public string ClassName { get { return cfg.ClassName; } }
|
|
|
|
public string ParentName { get { return cfg.ParentName; } }
|
|
|
|
public DebugMode DebugLevel { get { return cfg.DebugLevel; } }
|
|
|
|
public LogLevel LogLevel { get { return cfg.LogLevel; } }
|
|
|
|
public IComponentCfg Cfg { get { return cfg; } }
|
|
|
|
public IList<MeasurementCorrection> Corrections { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
|
public IList<Uncertainty> Uncertainties { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
|
|
|
public object GetDataFromStorageByParameter(DataQuery query)
|
|
{
|
|
string storageType = (cfg.DataStorageType ?? string.Empty).Trim();
|
|
|
|
IDataStorageReader reader;
|
|
|
|
switch (storageType)
|
|
{
|
|
case StorageTypes.RestApi:
|
|
reader = new RestApiReader(cfg);
|
|
break;
|
|
|
|
case StorageTypes.RemoteDatabase:
|
|
case StorageTypes.LocalDatabase:
|
|
reader = new DatabaseReader(cfg);
|
|
break;
|
|
|
|
case StorageTypes.RemoteJson:
|
|
case StorageTypes.LocalJson:
|
|
reader = new JsonReader(cfg);
|
|
break;
|
|
|
|
case StorageTypes.RemoteCsv:
|
|
case StorageTypes.LocalCsv:
|
|
reader = new CsvReader(cfg);
|
|
break;
|
|
|
|
default:
|
|
throw new NotSupportedException(
|
|
$"Unsupported DataStorageType: '{cfg.DataStorageType}'");
|
|
}
|
|
|
|
return reader.GetData(query);
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
//throw new NotImplementedException();
|
|
}
|
|
|
|
public void StartChangeHandler()
|
|
{
|
|
//throw new NotImplementedException();
|
|
}
|
|
|
|
public void StopChangeHandler()
|
|
{
|
|
//throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|