2019-09-18 07:09:00 +00:00
|
|
|
|
///
|
2023-04-18 12:01:23 +00:00
|
|
|
|
/// Copyright (c) 2019-2023 Sensus Slovensko a.s.
|
2019-09-18 07:09:00 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2020-05-06 07:45:23 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-09-18 07:09:00 +00:00
|
|
|
|
using log4net;
|
2020-05-06 07:45:23 +00:00
|
|
|
|
using TBF.Resources;
|
2023-04-18 12:01:23 +00:00
|
|
|
|
using TBF.UI.Calendar;
|
2019-09-18 07:09:00 +00:00
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig.DataContainers.Density
|
2019-09-18 07:09:00 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Holds measured (true) density value.
|
|
|
|
|
|
/// </summary>
|
2020-05-06 07:45:23 +00:00
|
|
|
|
public class Component : ComponentBase, GenericDevices.IHasCalendarEvents
|
2019-09-18 07:09:00 +00:00
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(Component));
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
2019-09-18 07:09:00 +00:00
|
|
|
|
|
|
|
|
|
|
readonly ComponentCfg myCfg;
|
|
|
|
|
|
|
|
|
|
|
|
public double RealDensity { get { return myCfg.RealDensity; } }
|
|
|
|
|
|
public double AtTemperature { get { return myCfg.AtTemperature; } }
|
|
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
|
|
|
|
|
|
public Component() { }
|
2019-09-18 07:09:00 +00:00
|
|
|
|
|
|
|
|
|
|
public Component(Generic.IComponentCfg cfg)
|
|
|
|
|
|
: base(cfg)
|
|
|
|
|
|
{
|
|
|
|
|
|
myCfg = cfg as ComponentCfg;
|
2021-04-07 07:57:42 +00:00
|
|
|
|
}
|
2019-09-18 07:09:00 +00:00
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
/// This is to use sample density and temp. from this component in formulas
|
2019-09-18 07:09:00 +00:00
|
|
|
|
Config.Data.RealDensity = RealDensity;
|
|
|
|
|
|
Config.Data.AtTemperature = AtTemperature;
|
2021-04-07 07:57:42 +00:00
|
|
|
|
log.FatalFormat("{0} initialized: {1}", Name, this);
|
2019-09-18 07:09:00 +00:00
|
|
|
|
}
|
2020-05-06 07:45:23 +00:00
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
|
2023-04-18 12:01:23 +00:00
|
|
|
|
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
|
2020-05-06 07:45:23 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
|
2020-05-06 07:45:23 +00:00
|
|
|
|
|
2023-04-18 12:01:23 +00:00
|
|
|
|
DateTime calibDue = myCfg.CalibValidDate;
|
|
|
|
|
|
if (calibDue > TBF.UI.Constants.MinDate)
|
2020-05-06 07:45:23 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
/// Five weekly notifications
|
|
|
|
|
|
foreach (var days in new int[] { -35, -28, -21, -14 })
|
2020-05-06 07:45:23 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
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))));
|
|
|
|
|
|
}
|
2020-05-06 07:45:23 +00:00
|
|
|
|
}
|
2023-04-18 12:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
/// Five daily warnings
|
|
|
|
|
|
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
|
2020-05-06 07:45:23 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
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))));
|
2020-05-06 07:45:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-04-18 12:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
return calEvents;
|
2020-05-06 07:45:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-18 07:09:00 +00:00
|
|
|
|
}
|