///
/// Copyright (c) 2018-2020 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using log4net;
using Common;
using Config;
using TBF.Rig;
using TBF.Rig.Generic;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.DataContainers.BenchInfo.iPerl
{
///
/// Holds information identifying the test bench.
///
public class Component : ComponentBase, GenericDevices.IBenchInfo, GenericDevices.IHasCalendarEvents
{
private static readonly ILog log = LogManager.GetLogger(typeof(Component));
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly ComponentCfg myCfg;
public string TestBenchName { get { return myCfg.TestBenchName; } }
public int TestBenchId { get { return myCfg.TestBenchId; } }
public string Address1 { get { return myCfg.Address1; } }
public string Address2 { get { return myCfg.Address2; } }
public string Address3 { get { return myCfg.Address3; } }
public string Address4 { get { return myCfg.Address4; } }
public string Address5 { get { return myCfg.Address5; } }
public RemoteDBUse RemoteDBUse { get { return myCfg.RemoteDBUse; } }
public Unit VolumeUnit { get { return myCfg.VolumeUnit; } }
public Unit FlowUnit { get { return myCfg.FlowUnit; } }
public Unit MassUnit { get { return myCfg.MassUnit; } }
public Unit TempUnit { get { return myCfg.TempUnit; } }
public Unit PressUnit { get { return myCfg.PressUnit; } }
public Unit LengthUnit { get { return myCfg.LenghtUnit; } }
public Side Side { get { return myCfg.Side; } }
public int MaxTestIndex { get { return myCfg.MaxTestIndex; } } /// (MaxPruefindex % 100) value when to reject water meters completely if they are NOK
public Component() { }
public Component(Generic.IComponentCfg cfg)
: base(cfg)
{
myCfg = cfg as ComponentCfg;
}
public override void Initialize()
{
Events.DB.SetBenchName(myCfg.TestBenchName);
log.FatalFormat("{0} initialized: {1}", Name, this);
}
public List GetCalendarEvents()
{
var calEvents = new List();
DateTime calibDue = myCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Five weekly notifications
foreach (var days in new int[] { -35, -28, -21, -14 })
{
if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
{
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{
if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
{
/// Weekly reminders (last 5 weeks)
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calEvents;
}
}
}