Events DB changes

This commit is contained in:
Milan Hanajik 2023-04-18 14:01:23 +02:00
parent 78d05fb1b9
commit bf67b4a4ec
32 changed files with 844 additions and 586 deletions

View File

@ -122,7 +122,7 @@ namespace Config.CalendarEvent
}
public static bool IsCalendarEventTrigerred(ICalendarEvent evnt, DateTime currentDate)
public static bool IsCalendarEventTrigerred(ICalendarEvent evnt, DateTime dateTimeNow)
{
DateTime evntDT = evnt.AllDay
? new DateTime(evnt.Date.Year, evnt.Date.Month, evnt.Date.Day, 0, 0, 0)
@ -133,17 +133,17 @@ namespace Config.CalendarEvent
DateTime dt1 = evntDT;
DateTime dt2 = evntDT + new TimeSpan(8, 0, 0);
DateTime dt3 = evntDT + new TimeSpan(16, 0, 0);
return (currentDate >= dt1) || (currentDate >= dt1) || (currentDate >= dt3);
return (dateTimeNow >= dt1) || (dateTimeNow >= dt1) || (dateTimeNow >= dt3);
}
else if (!evnt.TriggerOnExactDayOnly)
{
/// Trigger after event expires
return (currentDate >= evntDT);
return (dateTimeNow >= evntDT);
}
else
{
/// Trigger event on exact date only
return (currentDate >= evntDT) && DayMatchesExactly(evnt, currentDate);
return (dateTimeNow >= evntDT) && DayMatchesExactly(evnt, dateTimeNow);
}
}

View File

@ -46,8 +46,8 @@ namespace Config.Entities
Rank = 2;
Hidden = false;
ReadOnly = false;
BackColor = unchecked((int)0xFFFF5050);
TextColor = unchecked((int)0xFFFFFFFF);
BackColor = unchecked((int)0xFFFF5050); /// (MSB)AARRGGBB(LSB) ... pink
TextColor = unchecked((int)0xFFFFFFFF); /// (MSB)AARRGGBB(LSB) ... white
TooltipEnabled = true;
CustomRecurringFunction = null;
}

137
EventViewer/EViewerDB.cs Normal file
View File

@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using Common;
using Events;
namespace EventViewer
{
public static class EViewerDB
{
/// <summary> Session factory for all regular sessions, not for CreateEmptyResultsDB(). </summary>
public static ISessionFactory SessionFactory;
/// <summary> Connection string for all sessions </summary>
static string connectionString;
///
public static string ConnectionString
{
get { return connectionString; }
set
{
if (value != connectionString)
{
connectionString = value;
SessionFactory = null; /// Clear SessionFactory on connection string change
}
}
}
/// <summary> Database type (MySQL or SQLite) for all sessions </summary>
private static DBType dbType;
///
public static DBType DbType
{
get { return dbType; }
set { dbType = value; SessionFactory = null; }
}
/// <summary>
/// NHibernate session factory (to create the database session 'SessionFactory')
/// </summary>
/// <returns>A database session</returns>
static ISessionFactory CreateSessionFactory()
{
return CreateSessionFactory(false);
}
/// <summary>
/// NHibernate session factory (to create the database session 'SessionFactory')
/// </summary>
/// <param name="createDB">true = Create a new DB, false = Regular DB</param>
/// <returns>A database session</returns>
public static ISessionFactory CreateSessionFactory(bool createDB)
{
FluentConfiguration cfg = Fluently.Configure();
switch (dbType)
{
default:
case DBType.MySql:
cfg = cfg.Database(MySQLConfiguration.Standard.ConnectionString(connectionString));
break;
case DBType.SQLite:
cfg = cfg.Database(SQLiteConfiguration.Standard.UsingFile(connectionString));
break;
}
cfg = cfg.Mappings(m => m.FluentMappings.AddFromAssemblyOf<global::Events.Entities.Event>());
if (createDB)
{
return cfg.ExposeConfiguration(BuildSchemaCreate).BuildSessionFactory();
}
else
{
return cfg.ExposeConfiguration(BuildSchema).BuildSessionFactory();
}
}
static void BuildSchema(Configuration config)
{
/// This NHibernate tool takes a configuration with mapping info and exports a database schema
new SchemaExport(config).SetOutputFile("db_schema");
}
static void BuildSchemaCreate(Configuration config)
{
/// This NHibernate tool takes a configuration with mapping info and exports a database schema
new SchemaExport(config).Create(true, true);
}
/// Create a NHibernate session for the given database
public static ISession CreateSession()
{
if (string.IsNullOrEmpty(connectionString))
{
throw new Exception("Connection string was not specified");
}
if (SessionFactory == null) SessionFactory = CreateSessionFactory();
return SessionFactory.OpenSession();
}
/// <summary>
/// Create an empty users database.
/// Database contains only the user 'admin' and the control board component 'CB'.
/// </summary>
/// <param name="dbType">DBType.SQLite or DBType.MySql</param>
/// <param name="connectionString">Connection string</param>
/// <returns>true=success, false=error</returns>
public static bool CreateEmptyDB()
{
ISessionFactory sessionFactory = CreateSessionFactory(true);
if (sessionFactory == null) return false;
/// Populate the database
using (var session = sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
transaction.Commit();
}
}
return true;
}
}
}

View File

@ -66,6 +66,7 @@
<Compile Include="EventViewerWnd.Designer.cs">
<DependentUpon>EventViewerWnd.cs</DependentUpon>
</Compile>
<Compile Include="EViewerDB.cs" />
<Compile Include="Forms\EventDetailsDlg.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -102,9 +102,9 @@ namespace EventViewer
{
try
{
DB.DbType = DBType.MySql;
DB.ConnectionString = Program.LocalSettings.ConnectionString;
session = DB.CreateSession();
EViewerDB.DbType = DBType.MySql;
EViewerDB.ConnectionString = Program.LocalSettings.ConnectionString;
session = EViewerDB.CreateSession();
subscribers = session.QueryOver<Subscriber>().List();
unreadEventsRadioButton.Checked = true;
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2020 Sensus Slovensko a.s.
/// Copyright (c) 2020-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -15,156 +15,6 @@ namespace Events
{
public static class DB
{
/// <summary> Session factory for all regular sessions, not for CreateEmptyResultsDB(). </summary>
public static ISessionFactory SessionFactory;
/// <summary> Connection string for all sessions </summary>
static string connectionString;
///
public static string ConnectionString
{
get { return connectionString; }
set
{
if (value != connectionString)
{
connectionString = value;
SessionFactory = null; /// Clear SessionFactory on connection string change
}
}
}
/// <summary> Database type (MySQL or SQLite) for all sessions </summary>
private static DBType dbType;
///
public static DBType DbType
{
get { return dbType; }
set { dbType = value; SessionFactory = null; }
}
/// <summary>
/// NHibernate session factory (to create the database session 'SessionFactory')
/// </summary>
/// <returns>A database session</returns>
static ISessionFactory CreateSessionFactory()
{
return CreateSessionFactory(false);
}
/// <summary>
/// NHibernate session factory (to create the database session 'SessionFactory')
/// </summary>
/// <param name="createDB">true = Create a new DB, false = Regular DB</param>
/// <returns>A database session</returns>
public static ISessionFactory CreateSessionFactory(bool createDB)
{
FluentConfiguration cfg = Fluently.Configure();
switch (dbType)
{
default:
case DBType.MySql:
cfg = cfg.Database(MySQLConfiguration.Standard.ConnectionString(connectionString));
break;
case DBType.SQLite:
cfg = cfg.Database(SQLiteConfiguration.Standard.UsingFile(connectionString));
break;
}
cfg = cfg.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Entities.Event>());
if (createDB)
{
return cfg.ExposeConfiguration(BuildSchemaCreate).BuildSessionFactory();
}
else
{
return cfg.ExposeConfiguration(BuildSchema).BuildSessionFactory();
}
}
static void BuildSchema(Configuration config)
{
/// This NHibernate tool takes a configuration with mapping info and exports a database schema
new SchemaExport(config).SetOutputFile("db_schema");
}
static void BuildSchemaCreate(Configuration config)
{
/// This NHibernate tool takes a configuration with mapping info and exports a database schema
new SchemaExport(config).Create(true, true);
}
/// Create a NHibernate session for the given database
public static ISession CreateSession()
{
if (string.IsNullOrEmpty(connectionString))
{
throw new Exception("Connection string was not specified");
}
if (SessionFactory == null) SessionFactory = CreateSessionFactory();
return SessionFactory.OpenSession();
}
public static void SaveObject(object obj)
{
SaveObject(CreateSession(), obj);
}
///
public static void SaveObject(ISession session, object obj)
{
using (var transaction = session.BeginTransaction())
{
session.SaveOrUpdate(obj);
try { transaction.Commit(); }
catch { }
}
}
public static void DeleteObject(object obj)
{
DeleteObject(CreateSession(), obj);
}
///
public static void DeleteObject(ISession session, object obj)
{
using (var transaction = session.BeginTransaction())
{
session.Delete(obj);
transaction.Commit();
}
}
/// <summary>
/// Create an empty users database.
/// Database contains only the user 'admin' and the control board component 'CB'.
/// </summary>
/// <param name="dbType">DBType.SQLite or DBType.MySql</param>
/// <param name="connectionString">Connection string</param>
/// <returns>true=success, false=error</returns>
public static bool CreateEmptyDB()
{
ISessionFactory sessionFactory = CreateSessionFactory(true);
if (sessionFactory == null) return false;
/// Populate the database
using (var session = sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
transaction.Commit();
}
}
return true;
}
/// <summary>
/// Shared data (initially empty)
/// </summary>
@ -193,6 +43,7 @@ namespace Events
/// </summary>
public static void LoadRecentEvents(ISession session, string benchName, int days)
{
BenchName = benchName;
RecentEvents = session.QueryOver<Event>()
.Where(e => (e.Bench == benchName))
.And(e => (e.TimeStamp >= DateTime.Now - new TimeSpan(days, 0, 0, 0)))
@ -201,7 +52,8 @@ namespace Events
public static void SaveEvent(ISession session, Event evnt, SubscriberGroup groups)
{
if (allSubscribers == null) return;
if (allSubscribers == null) LoadSubscribers(session);
IList<Subscriber> thisEventSubscribers = new List<Subscriber>();
foreach (var s in allSubscribers)
{
@ -211,10 +63,10 @@ namespace Events
thisEventSubscribers.Add(s);
}
}
evnt.Bench = BenchName;
evnt.Subscribers = thisEventSubscribers;
evnt.Bench = BenchName;
session.SaveOrUpdate(evnt);
session.Flush();
}
}
}

View File

@ -437,16 +437,6 @@ namespace TBF
}
if (rsltDBSession != null && rsltDBSession.IsOpen) rsltDBSession.Close();
///
/// Connect to Events database (if any) and load recent events from this test bench.
///
if (TBF.DB.EventsDBSessionFactory != null)
{
var evntsDBsession = TBF.DB.EventsDBSessionFactory.OpenSession();
Events.DB.LoadRecentEvents(evntsDBsession, loginDlgBench.BenchName, 7); /// Last 7 days
evntsDBsession.Close();
}
retryLogin = false;
break;
}

View File

@ -10,6 +10,7 @@ using Config;
using TBF.Rig;
using TBF.Rig.Generic;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.DataContainers.BenchInfo.iPerl
{
@ -56,35 +57,51 @@ namespace TBF.Rig.DataContainers.BenchInfo.iPerl
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = myCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = myCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}
}
}

View File

@ -1,10 +1,11 @@
///
/// Copyright (c) 2019-2020 Sensus Slovensko a.s.
/// Copyright (c) 2019-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.DataContainers.Buoyancy
{
@ -36,35 +37,51 @@ namespace TBF.Rig.DataContainers.Buoyancy
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = myCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = myCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}
}
}

View File

@ -1,10 +1,11 @@
///
/// Copyright (c) 2019-2020 Sensus Slovensko a.s.
/// Copyright (c) 2019-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.DataContainers.Density
{
@ -39,35 +40,51 @@ namespace TBF.Rig.DataContainers.Density
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = myCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = myCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}
}
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2020 Sensus Slovensko a.s.
/// Copyright (c) 2020-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -7,6 +7,7 @@ using log4net;
using Config.Entities;
using TBF.Rig.GenericDevices;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.DataContainers.Evaporation
{
@ -40,35 +41,51 @@ namespace TBF.Rig.DataContainers.Evaporation
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = myCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = myCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}
}
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -9,6 +9,7 @@ using Dirichlet.Numerics;
using TBF.Rig.Generic;
using TBF.Boxes;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.Diverter
{
@ -152,35 +153,51 @@ namespace TBF.Rig.Elde.Diverter
///
/// Calendar support
///
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = diverterCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = diverterCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}
///

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2018 Sensus Slovensko a.s.
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -7,6 +7,7 @@ using log4net;
using Config.Entities;
using TBF.Boxes;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.FlowMeter
{
@ -68,7 +69,7 @@ namespace TBF.Rig.Elde.FlowMeter
{
for (int r = 0; r <= 5; r++)
{
if (RangeEnabled(r) && flowMeterCfg.GetCalibValidDate(r) != DateTime.MinValue
if (RangeEnabled(r) && flowMeterCfg.GetCalibValidDate(r) > DateTime.MinValue
&& flowMeterCfg.GetCalibValidDate(r).Date < DateTime.Now.Date)
{
throw new Exception(string.Format("{0}/r{1}: {2}", Name, r, Strings.Calibration_certificate_validity_expired));
@ -86,35 +87,51 @@ namespace TBF.Rig.Elde.FlowMeter
///
/// Calendar support
///
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = flowMeterCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = flowMeterCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -7,6 +7,7 @@ using log4net;
using TBF.Rig.Generic;
using TBF.Boxes;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.PressureMeter
{
@ -55,35 +56,51 @@ namespace TBF.Rig.Elde.PressureMeter
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = pressureMeterCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = pressureMeterCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2015 Sensus Metering Systems
/// Copyright (c) 2015-2023 Sensus Slovensko a.s.
/// Author: Milan Hanajik
///
using System;
@ -8,6 +8,7 @@ using log4net;
using TBF.Rig.Generic;
using TBF.Boxes;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.PressureMeterInternal
{
@ -49,35 +50,51 @@ namespace TBF.Rig.Elde.PressureMeterInternal
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = pressureMeterCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = pressureMeterCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -8,6 +8,7 @@ using Common;
using TBF.Rig.Generic;
using TBF.Boxes;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.TempMeter
{
@ -52,35 +53,51 @@ namespace TBF.Rig.Elde.TempMeter
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = tempMtrCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = tempMtrCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}
public double ReadTemperature()

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2015 Sensus Metering Systems
/// Copyright (c) 2015-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -7,6 +7,7 @@ using log4net;
using TBF.Rig.Generic;
using TBF.Boxes;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.TempMeterInternal
{
@ -46,35 +47,51 @@ namespace TBF.Rig.Elde.TempMeterInternal
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = tempMtrCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = tempMtrCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}

View File

@ -1,11 +1,12 @@
///
/// Copyright (c) 2018 Sensus Slovensko a.s.
/// Copyright (c) 2018-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using TBF.Boxes;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.TempMeterMeret
{
@ -39,35 +40,51 @@ namespace TBF.Rig.Elde.TempMeterMeret
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = tempMtrCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = tempMtrCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}

View File

@ -8,6 +8,6 @@ namespace TBF.Rig.GenericDevices
{
interface IHasCalendarEvents
{
IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents();
List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents();
}
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2018 Sensus Slovensko a.s.
/// Copyright (c) 2018-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -10,6 +10,7 @@ using TBF.Rig.GenericDevices;
using TBF.Boxes;
using TBF.Rig.Hart.Common;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Hart.Nivotrack
{
@ -77,35 +78,51 @@ namespace TBF.Rig.Hart.Nivotrack
///
/// Calendar support
///
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = nivotrackCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = nivotrackCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2016-2020 Sensus Metering Systems
/// Copyright (c) 2016-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -8,6 +8,7 @@ using log4net;
using TBF.Boxes;
using TBF.Rig.Keithley.Multimeter_2010_RS232;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Keithley.TempMeter
{
@ -49,35 +50,51 @@ namespace TBF.Rig.Keithley.TempMeter
///
/// Calendar support
///
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = tempMtrCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = tempMtrCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}
public double ReadTemperature()

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -12,6 +12,7 @@ using TBF.Rig.Generic;
using TBF.Rig.GenericDevices;
using TBF.Boxes;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.MettlerToledo.Standard
{
@ -111,7 +112,7 @@ namespace TBF.Rig.MettlerToledo.Standard
Balances[nextBalanceIdx - 1] = this;
}
if (balanceCfg.CalibValidDate != DateTime.MinValue && balanceCfg.CalibValidDate.Date < DateTime.Now.Date)
if (balanceCfg.CalibValidDate > DateTime.MinValue && balanceCfg.CalibValidDate.Date < DateTime.Now.Date)
{
throw new Exception(string.Format("{0}: {1}", Name, Strings.Calibration_certificate_validity_expired));
}
@ -137,35 +138,51 @@ namespace TBF.Rig.MettlerToledo.Standard
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = balanceCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
DateTime calibDue = balanceCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
/// 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,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
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)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
if (DateTime.Now.Date <= calibrationDue.Date)
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calendarEvents;
return calEvents;
}

View File

@ -275,11 +275,12 @@ namespace TBF.Rig.Output.DB.ProductionTracing
opCompleted = true;
if (SaveTracingRecords(batch) != Retv.OK) anyError = true;
if (anyError && !string.IsNullOrEmpty(Events.DB.ConnectionString))
if (TBF.DB.EventsDBSessionFactory != null && anyError)
{
NHibernate.ISession session = null;
try
{
NHibernate.ISession session = Events.DB.CreateSession();
session = TBF.DB.EventsDBSessionFactory.OpenSession();
Events.DB.LoadSubscribers(session);
TBF.UiBridge.Bridge.TriggerEvent(session, Name, EventClass.ComputerResources, Severity.Error,
@ -291,17 +292,22 @@ namespace TBF.Rig.Output.DB.ProductionTracing
{
log.ErrorFormat("Triggering event(s) failed: {0}", exc.Message);
}
finally
{
if (session != null && session.IsOpen) session.Close();
}
}
return anyError ? Event.ErrorProcessingResults : Event.ResultsWritten;
}
else
{
if (anyError && !string.IsNullOrEmpty(Events.DB.ConnectionString))
if (TBF.DB.EventsDBSessionFactory != null && anyError)
{
NHibernate.ISession session = null;
try
{
NHibernate.ISession session = Events.DB.CreateSession();
session = TBF.DB.EventsDBSessionFactory.OpenSession();
Events.DB.LoadSubscribers(session);
TBF.UiBridge.Bridge.TriggerEvent(session, Name, EventClass.ComputerResources, Severity.Error,
@ -313,6 +319,10 @@ namespace TBF.Rig.Output.DB.ProductionTracing
{
log.ErrorFormat("Triggering event(s) failed: {0}", exc.Message);
}
finally
{
if (session != null && session.IsOpen) session.Close();
}
}
return anyError ? Event.ErrorProcessingResults : Event.ResultsWritten;

View File

@ -357,11 +357,12 @@ namespace TBF.Rig.Output.DB.SensusOracle
opCompleted = true;
}
if (anyError && !string.IsNullOrEmpty(Events.DB.ConnectionString))
if (TBF.DB.EventsDBSessionFactory != null && anyError)
{
NHibernate.ISession session = null;
try
{
NHibernate.ISession session = Events.DB.CreateSession();
session = TBF.DB.EventsDBSessionFactory.OpenSession();
Events.DB.LoadSubscribers(session);
TBF.UiBridge.Bridge.TriggerEvent(session, Name, EventClass.ComputerResources, Severity.Error,
@ -373,6 +374,10 @@ namespace TBF.Rig.Output.DB.SensusOracle
{
log.ErrorFormat("Triggering event(s) failed: {0}", exc.Message);
}
finally
{
if (session != null && session.IsOpen) session.Close();
}
}
return anyError ? Event.ErrorProcessingResults : Event.ResultsWritten;

View File

@ -142,9 +142,10 @@ namespace TBF.Rig.Output.EventTriggers.Standard
return;
}
ISession session = null;
try
{
ISession session = Events.DB.CreateSession();
session = TBF.DB.EventsDBSessionFactory.OpenSession();
Events.DB.LoadSubscribers(session);
///
@ -254,6 +255,10 @@ namespace TBF.Rig.Output.EventTriggers.Standard
{
log.ErrorFormat("Triggering event(s) failed: {0}", exc.Message);
}
finally
{
if (session != null && session.IsOpen) session.Close();
}
}
void OnExTriggerEvent(ISession session, long eFlags, long iFlags, int x)

View File

@ -162,11 +162,12 @@ namespace TBF.Rig.Output.FileWriters.IperlLogger
opCompleted = true;
}
if (anyError && !string.IsNullOrEmpty(Events.DB.ConnectionString))
if (TBF.DB.EventsDBSessionFactory != null && anyError)
{
NHibernate.ISession session = null;
try
{
NHibernate.ISession session = Events.DB.CreateSession();
session = TBF.DB.EventsDBSessionFactory.OpenSession();
Events.DB.LoadSubscribers(session);
TBF.UiBridge.Bridge.TriggerEvent(session, Name, EventClass.ComputerResources, Severity.Error,
@ -178,6 +179,10 @@ namespace TBF.Rig.Output.FileWriters.IperlLogger
{
log.ErrorFormat("Triggering event(s) failed: {0}", exc.Message);
}
finally
{
if (session != null && session.IsOpen) session.Close();
}
}
return anyError ? Event.ErrorProcessingResults: Event.ResultsWritten;

View File

@ -209,11 +209,9 @@ namespace TBF.Rig
#elif BERLIN || GELSENWASSER || GENESIS || IZRAEL_200 || PETERSBURG_200 || PUCHONG_200 || SLM_150
public static void InitializeBoardEtc(ControlComponent_Izrael2014.UserControl1 ctrlBrdComponent)
#else /// all newer benches
public static void InitializeBoardEtc(ControlComponent_Torino2015.UserControl1 ctrlBrdComponent)
public static void InitializeBoardEtc(ISession session, ControlComponent_Torino2015.UserControl1 ctrlBrdComponent)
#endif
{
var session = TBF.DB.ConfigDBSessionFactory.OpenSession();
/// Load the list of components (entities) from the database.
/// Then create the components (derived from IComponent).
components = Rig.TbfComponents.LoadComponentsFromDB(session);
@ -299,8 +297,6 @@ namespace TBF.Rig
if ((eldeValve != null) && eldeValve.Inverted) valvesToInvert |= eldeValve.Mask;
}
session.Close();
/// Pre-initialize the control board (= buffer the arguments ctrlBrdComponent, tankCapacities)
if (ControlBoard != null)
{
@ -428,7 +424,7 @@ namespace TBF.Rig
/// Checks remote and local configuration DB paths and transitions for compatibility
/// </summary>
/// <returns>true when DB-s are compatible</returns>
public static bool IsRemoteDBCompatible(out string message)
public static bool IsRemoteDBCompatible(ISession localSession, out string message)
{
IList<Config.Entities.FeedingPath> remoteFeedingPaths = new List<Config.Entities.FeedingPath>();
IList<Config.Entities.BenchPath> remoteBenchPaths = new List<Config.Entities.BenchPath>();
@ -456,16 +452,12 @@ namespace TBF.Rig
return false;
}
var localSession = TBF.DB.ConfigDBSessionFactory.OpenSession();
var localFeedingPaths = localSession.QueryOver<Config.Entities.FeedingPath>().List();
var localBenchPaths = localSession.QueryOver<Config.Entities.BenchPath>().List();
var localOutputPaths = localSession.QueryOver<Config.Entities.OutputPath>().List();
var localMetersPaths = localSession.QueryOver<Config.Entities.MetersPath>().List();
var localTransitions = localSession.QueryOver<Config.Entities.TransitionSequence>().List();
localSession.Close();
string subMsg;
if (!IsCompatible(localFeedingPaths, remoteFeedingPaths, out subMsg))
{
@ -583,7 +575,6 @@ namespace TBF.Rig
#if HEAT_METERS
heatMetersPaths = session.QueryOver<Config.Entities.HeatMetersPath>().OrderBy(x => x.ItemNr).Asc.List();
#endif
session.Flush();
}
catch (Exception e)
{

View File

@ -9,9 +9,7 @@ using NHibernate;
using Common;
using Config.Entities;
using Config.CalendarEvent;
using Events.Entities;
using TBF.Resources;
using TBF.UiBridge;
namespace TBF.UI.Calendar
{
@ -19,16 +17,15 @@ namespace TBF.UI.Calendar
{
static readonly ILog log = LogManager.GetLogger(typeof(CalendarTabPageCtrl));
IList<ICalendarEvent> eventsFromComponents;
IList<CustomEvent> customEvents; /// Custom events loaded from the local config DB
public IList<ICalendarEvent> EventsFromComponents;
Timer timer;
DateTime lastTimeCalendarEventsServed;
DateTime LastTimeCalendarEventsServed;
public CalendarTabPageCtrl()
{
InitializeComponent();
eventsFromComponents = new List<ICalendarEvent>();
EventsFromComponents = new List<ICalendarEvent>();
Localize();
}
@ -61,16 +58,22 @@ namespace TBF.UI.Calendar
calendarEventsListViewEx.Items.Add(lvi);
}
/// <summary>
/// Initializes 'public IList<...> EventsFromComponents.
///
/// </summary>
/// <param name="eventsFromComponents"></param>
/// <param name="session"></param>
public void StartCalendar(IList<ICalendarEvent> eventsFromComponents, ISession session = null)
{
this.EventsFromComponents = eventsFromComponents;
bool openAndCloseSession = (session == null);
this.eventsFromComponents = eventsFromComponents;
try
{
/// Read custom events from the database
if (openAndCloseSession) session = TBF.DB.ConfigDBSessionFactory.OpenSession();
customEvents = session.QueryOver<CustomEvent>().List();
var customEvents = session.QueryOver<CustomEvent>().List();
TripplicateShiftCustomEvents(customEvents);
@ -84,15 +87,16 @@ namespace TBF.UI.Calendar
foreach (var e in eventsFromComponents) if (!e.Hidden) AddOne(e);
/// Serve events (determine if any event was triggered)
lastTimeCalendarEventsServed = DateTime.Now;
ServeCalendarEventsNotifWarnErrorFatal(lastTimeCalendarEventsServed, session, customEvents);
if (openAndCloseSession) session.Close();
ServeCalendarEventsNotifWarnErrorFatal(DateTime.Now, session, customEvents);
}
catch (Exception)
{
customEvents = new List<CustomEvent>();
log.ErrorFormat("Failed to load custom events from the LOCAL config database");
}
finally
{
if (openAndCloseSession && session != null && session.IsOpen) session.Close();
}
calendarCtrl1.CalendarView = CalendarViews.Month;
@ -109,35 +113,34 @@ namespace TBF.UI.Calendar
/// <param name="args"></param>
void timer_Tick(object sender, EventArgs args)
{
DateTime currentTime = DateTime.Now;
DateTime dateTimeNow = DateTime.Now;
if ((currentTime.Hour != lastTimeCalendarEventsServed.Hour) ||
(currentTime.Minute % 30) != (lastTimeCalendarEventsServed.Minute % 30))
if ((dateTimeNow.Hour != LastTimeCalendarEventsServed.Hour) ||
(dateTimeNow.Minute % 30) != (LastTimeCalendarEventsServed.Minute % 30))
{
/// Serve events at the beginning of each half hour
ServeCalendarEventsNotifWarnErrorFatal(currentTime);
lastTimeCalendarEventsServed = currentTime;
ServeCalendarEventsNotifWarnErrorFatal(dateTimeNow);
}
}
/// <summary>
/// Triggers events corresponding to triggered motification.warning/error calendar events.
/// </summary>
/// <param name="currentTime">Current time</param>
void ServeCalendarEventsNotifWarnErrorFatal(DateTime currentTime, ISession session = null, IList<CustomEvent> customEventsFromDB = null)
/// <param name="dateTimeNow">Current time</param>
void ServeCalendarEventsNotifWarnErrorFatal(DateTime dateTimeNow, ISession session = null, IList<CustomEvent> customEventsFromDB = null)
{
bool openAndCloseSession = (session == null);
LastTimeCalendarEventsServed = dateTimeNow;
IList<Events.Entities.Event> eventsToTrigger = new List<Events.Entities.Event>();
var eventsToTrigger = new List<Events.Entities.Event>();
for (int i = eventsFromComponents.Count - 1; i >= 0; i--)
for (int i = EventsFromComponents.Count - 1; i >= 0; i--)
{
ICalendarEvent calEvent = eventsFromComponents[i];
ICalendarEvent calEvent = EventsFromComponents[i];
AutoAction a = calEvent.AutoAction;
if (a == AutoAction.Notification || a == AutoAction.Warning || a == AutoAction.Error || a == AutoAction.FatalErr)
{
if (Config.CalendarEvent.Utils.IsCalendarEventTrigerred(calEvent, currentTime))
if (Config.CalendarEvent.Utils.IsCalendarEventTrigerred(calEvent, dateTimeNow))
{
eventsToTrigger.Add(new Events.Entities.Event(null,
calEvent.Source,
@ -151,21 +154,23 @@ namespace TBF.UI.Calendar
if (calEvent.Frequency == Frequency.Once)
{
eventsFromComponents.Remove(calEvent);
EventsFromComponents.Remove(calEvent);
}
else
{
Config.CalendarEvent.Utils.UpdateRecurringDate(calEvent, currentTime);
Config.CalendarEvent.Utils.UpdateRecurringDate(calEvent, dateTimeNow);
}
}
}
}
bool openAndCloseSession = (session == null);
///
try
{
if (openAndCloseSession) session = TBF.DB.ConfigDBSessionFactory.OpenSession();
var customEvents = (customEventsFromDB != null) ? customEventsFromDB : session.QueryOver<CustomEvent>() .List();
var customEvents = (customEventsFromDB != null) ? customEventsFromDB : session.QueryOver<CustomEvent>().List();
for (int i = customEvents.Count - 1; i >= 0; i--)
{
@ -174,7 +179,7 @@ namespace TBF.UI.Calendar
AutoAction a = calEvent.AutoAction;
if (a == AutoAction.Notification || a == AutoAction.Warning || a == AutoAction.Error || a == AutoAction.FatalErr)
{
if (Config.CalendarEvent.Utils.IsCalendarEventTrigerred(calEvent, currentTime))
if (Config.CalendarEvent.Utils.IsCalendarEventTrigerred(calEvent, dateTimeNow))
{
eventsToTrigger.Add(new Events.Entities.Event(null,
calEvent.Source,
@ -190,7 +195,7 @@ namespace TBF.UI.Calendar
{
session.Delete(calEvent);
}
else if (calEvent.UpdateRecurringDate(currentTime))
else if (calEvent.UpdateRecurringDate(dateTimeNow))
{
session.SaveOrUpdate(calEvent);
}
@ -198,12 +203,15 @@ namespace TBF.UI.Calendar
}
}
session.Flush();
if (openAndCloseSession) session.Close();
}
catch (Exception exc)
{
log.ErrorFormat("Failed to load or update CustomEvent-s in ServeTriggerEvtCalendarEvents(): {0}", exc.Message);
}
finally
{
if (openAndCloseSession && session != null && session.IsOpen) session.Close();
}
if (eventsToTrigger.Count > 0 && TBF.DB.EventsDBSessionFactory != null)
{
@ -214,6 +222,7 @@ namespace TBF.UI.Calendar
{
TBF.UiBridge.Bridge.TriggerEvent(evtDBSession, e);
}
evtDBSession.Flush();
evtDBSession.Close();
}
}
@ -258,6 +267,7 @@ namespace TBF.UI.Calendar
if (parametersList.Count >= maxCount) break;
}
}
session.Flush();
}
catch (Exception exc)
{
@ -327,18 +337,18 @@ namespace TBF.UI.Calendar
session.SaveOrUpdate(dlg.NewEvent as CustomEvent);
session.Flush();
customEvents = session.QueryOver<CustomEvent>().List();
var customEvents = session.QueryOver<CustomEvent>().List();
TripplicateShiftCustomEvents(customEvents);
/// Calendar
calendarCtrl1.ClearEvents();
foreach (var e in eventsFromComponents) calendarCtrl1.AddEvent(e);
foreach (var e in EventsFromComponents) calendarCtrl1.AddEvent(e);
foreach (var e in customEvents) calendarCtrl1.AddEvent(e);
/// List view in the right pane
calendarEventsListViewEx.Items.Clear();
foreach (var e in customEvents) AddOne(e);
foreach (var e in eventsFromComponents) if (!e.Hidden) AddOne(e);
foreach (var e in EventsFromComponents) if (!e.Hidden) AddOne(e);
}
catch (Exception)
{
@ -388,18 +398,18 @@ namespace TBF.UI.Calendar
session.SaveOrUpdate(cEvents[0]);
session.Flush();
customEvents = session.QueryOver<CustomEvent>().List();
var customEvents = session.QueryOver<CustomEvent>().List();
TripplicateShiftCustomEvents(customEvents);
/// Calendar
calendarCtrl1.ClearEvents();
foreach (var e in eventsFromComponents) calendarCtrl1.AddEvent(e);
foreach (var e in EventsFromComponents) calendarCtrl1.AddEvent(e);
foreach (var e in customEvents) calendarCtrl1.AddEvent(e);
/// List view in the right pane
calendarEventsListViewEx.Items.Clear();
foreach (var e in customEvents) AddOne(e);
foreach (var e in eventsFromComponents) if (!e.Hidden) AddOne(e);
foreach (var e in EventsFromComponents) if (!e.Hidden) AddOne(e);
}
}
catch (Exception)

View File

@ -26,29 +26,32 @@ namespace TBF.UI.Calendar
public Config.CalendarEvent.CustomRecurringFrequenciesHandler CustomRecurringFunction { get; set; }
private CalibrationReminderEvent() { }
/// <summary>
/// CalibrationReminderEvent Constructor
/// </summary>
public CalibrationReminderEvent(bool daily = false)
public CalibrationReminderEvent(AutoAction autoAction)
{
/// Date
Frequency = daily ? Frequency.Daily : Frequency.Weekly;
Frequency = Frequency.Once;
AllDay = true;
TriggerOnExactDayOnly = false;
/// Source
/// Text
AutoAction = daily ? AutoAction.Warning : AutoAction.Notification;
AutoAction = autoAction;
Parameters = string.Empty;
Rank = 1;
Hidden = true;
ReadOnly = true;
BackColor = unchecked((int)0xFFA00000);
TextColor = unchecked((int)0xFFFFFFFF);
BackColor = unchecked((int)0xFFA00000); /// (MSB)AARRGGBB(LSB) ... red
TextColor = unchecked((int)0xFFFFFFFF); /// (MSB)AARRGGBB(LSB) ... white
TooltipEnabled = true;
}
public CalibrationReminderEvent(DateTime date, string source, string text, bool daily = false)
: this(daily)
public CalibrationReminderEvent(AutoAction autoAction, DateTime date, string source, string text)
: this(autoAction)
{
Date = date;
Source = source;

View File

@ -34,6 +34,11 @@ namespace TBF.UI
public bool IsShutdownDisabled;
public bool IsShutdownPCAfterClosingTbf;
/// <summary>
/// This local configuration DB session is opened in the constructor and closed at the end of MainWnd_Load( )
/// </summary>
ISession startupSession;
/// <summary>
/// This dialog is shown when emergency stop is activated
/// </summary>
@ -135,15 +140,17 @@ namespace TBF.UI
{
try
{
startupSession = TBF.DB.ConfigDBSessionFactory.OpenSession();
/// Load components, initialize the control board, etc.
Rig.StateMachine.InitializeBoardEtc(ctrlBrdComponent);
Rig.StateMachine.InitializeBoardEtc(startupSession, ctrlBrdComponent);
/// Check remote and local configuration DB compatibility
string msg;
Rig.GenericDevices.IBenchInfo benchInfo = Rig.Sequences.ProcessData.BenchInfo;
RemoteDBUse remoteDbUse = (benchInfo != null) ? benchInfo.RemoteDBUse : RemoteDBUse.LocalDBOnly;
log.FatalFormat("RemoteDbUse = {0}", remoteDbUse);
if ((remoteDbUse != RemoteDBUse.LocalDBOnly) && !Rig.StateMachine.IsRemoteDBCompatible(out msg))
if ((remoteDbUse != RemoteDBUse.LocalDBOnly) && !Rig.StateMachine.IsRemoteDBCompatible(startupSession, out msg))
{
log.FatalFormat("{0} {1}", Strings.Remote_db_is_not_compatible, msg);
throw new Exception(string.Format("{0}{1}{2}", Strings.Remote_db_is_not_compatible, Environment.NewLine, msg));
@ -321,16 +328,18 @@ namespace TBF.UI
///
/// Populate calendar with calendar events from components
///
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
foreach (var cmpnt in TBF.Rig.StateMachine.Components)
{
TBF.Rig.GenericDevices.IHasCalendarEvents cmpntWithCalEvents = cmpnt as TBF.Rig.GenericDevices.IHasCalendarEvents;
if (cmpntWithCalEvents != null)
var cmpntWithEvents = cmpnt as TBF.Rig.GenericDevices.IHasCalendarEvents;
if (cmpntWithEvents != null)
{
foreach (var evnt in cmpntWithCalEvents.GetCalendarEvents()) calendarEvents.Add(evnt);
foreach (var evnt in cmpntWithEvents.GetCalendarEvents()) calEvents.Add(evnt);
}
}
calendarTabPageCtrl.StartCalendar(calendarEvents);
calendarTabPageCtrl.StartCalendar(calEvents, startupSession);
if (startupSession != null && startupSession.IsOpen) startupSession.Close();
Rig.StateMachine.Start();
log.Info("Test bench started");

View File

@ -272,29 +272,31 @@ namespace TBF.UI.Settings
{
try
{
string connectionString = bench.EventsDBSettings.ConnectionString;
string databaseName = Config.Utils.GetDBName(connectionString);
string userName = Config.Utils.GetDBUser(connectionString);
string password = Config.Utils.GetDBPassword(connectionString); /// TODO: Use password
MessageBox.Show("Not implemented yet");
if (connectionString == currentConfigDBConnStr || connectionString == currentResultsDBConnStr || connectionString == currentEventsDBConnStr)
{
CurrentDBChanged = true;
}
//string connectionString = bench.EventsDBSettings.ConnectionString;
//string databaseName = Config.Utils.GetDBName(connectionString);
//string userName = Config.Utils.GetDBUser(connectionString);
//string password = Config.Utils.GetDBPassword(connectionString); /// TODO: Use password
Cursor.Current = Cursors.WaitCursor;
//if (connectionString == currentConfigDBConnStr || connectionString == currentResultsDBConnStr || connectionString == currentEventsDBConnStr)
//{
// CurrentDBChanged = true;
//}
log.ErrorFormat("Going to create an empty events database '{0}'", databaseName);
ExecuteMySqlCmd(string.Format("DROP DATABASE `{0}`;", databaseName), userName, password);
ExecuteMySqlCmd(string.Format("CREATE DATABASE `{0}` CHARACTER SET utf8 COLLATE utf8_unicode_ci;", databaseName), userName, password);
global::Events.DB.DbType = (DBType)bench.EventsDBSettings.DbType;
global::Events.DB.ConnectionString = connectionString;
global::Events.DB.CreateEmptyDB();
log.ErrorFormat("An empty events database '{0}' was created", databaseName);
//Cursor.Current = Cursors.WaitCursor;
MessageBox.Show(Strings.DB_was_successfully_created, Strings.Notification);
Cursor.Current = Cursors.Default;
DialogResult = DialogResult.None;
//log.ErrorFormat("Going to create an empty events database '{0}'", databaseName);
//ExecuteMySqlCmd(string.Format("DROP DATABASE `{0}`;", databaseName), userName, password);
//ExecuteMySqlCmd(string.Format("CREATE DATABASE `{0}` CHARACTER SET utf8 COLLATE utf8_unicode_ci;", databaseName), userName, password);
//global::Events.DB.DbType = (DBType)bench.EventsDBSettings.DbType;
//global::Events.DB.ConnectionString = connectionString;
//global::Events.DB.CreateEmptyDB();
//log.ErrorFormat("An empty events database '{0}' was created", databaseName);
//MessageBox.Show(Strings.DB_was_successfully_created, Strings.Notification);
//Cursor.Current = Cursors.Default;
//DialogResult = DialogResult.None;
}
catch (Exception exception)
{