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 DateTime evntDT = evnt.AllDay
? new DateTime(evnt.Date.Year, evnt.Date.Month, evnt.Date.Day, 0, 0, 0) ? 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 dt1 = evntDT;
DateTime dt2 = evntDT + new TimeSpan(8, 0, 0); DateTime dt2 = evntDT + new TimeSpan(8, 0, 0);
DateTime dt3 = evntDT + new TimeSpan(16, 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) else if (!evnt.TriggerOnExactDayOnly)
{ {
/// Trigger after event expires /// Trigger after event expires
return (currentDate >= evntDT); return (dateTimeNow >= evntDT);
} }
else else
{ {
/// Trigger event on exact date only /// 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; Rank = 2;
Hidden = false; Hidden = false;
ReadOnly = false; ReadOnly = false;
BackColor = unchecked((int)0xFFFF5050); BackColor = unchecked((int)0xFFFF5050); /// (MSB)AARRGGBB(LSB) ... pink
TextColor = unchecked((int)0xFFFFFFFF); TextColor = unchecked((int)0xFFFFFFFF); /// (MSB)AARRGGBB(LSB) ... white
TooltipEnabled = true; TooltipEnabled = true;
CustomRecurringFunction = null; 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"> <Compile Include="EventViewerWnd.Designer.cs">
<DependentUpon>EventViewerWnd.cs</DependentUpon> <DependentUpon>EventViewerWnd.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="EViewerDB.cs" />
<Compile Include="Forms\EventDetailsDlg.cs"> <Compile Include="Forms\EventDetailsDlg.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

View File

@ -102,9 +102,9 @@ namespace EventViewer
{ {
try try
{ {
DB.DbType = DBType.MySql; EViewerDB.DbType = DBType.MySql;
DB.ConnectionString = Program.LocalSettings.ConnectionString; EViewerDB.ConnectionString = Program.LocalSettings.ConnectionString;
session = DB.CreateSession(); session = EViewerDB.CreateSession();
subscribers = session.QueryOver<Subscriber>().List(); subscribers = session.QueryOver<Subscriber>().List();
unreadEventsRadioButton.Checked = true; 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;
using System.Collections.Generic; using System.Collections.Generic;
@ -15,156 +15,6 @@ namespace Events
{ {
public static class DB 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> /// <summary>
/// Shared data (initially empty) /// Shared data (initially empty)
/// </summary> /// </summary>
@ -180,7 +30,7 @@ namespace Events
DB.BenchName = benchName; DB.BenchName = benchName;
} }
/// <summary> /// <summary>
/// Loads shared data from the database /// Loads shared data from the database
/// </summary> /// </summary>
public static void LoadSubscribers(ISession session) public static void LoadSubscribers(ISession session)
@ -193,6 +43,7 @@ namespace Events
/// </summary> /// </summary>
public static void LoadRecentEvents(ISession session, string benchName, int days) public static void LoadRecentEvents(ISession session, string benchName, int days)
{ {
BenchName = benchName;
RecentEvents = session.QueryOver<Event>() RecentEvents = session.QueryOver<Event>()
.Where(e => (e.Bench == benchName)) .Where(e => (e.Bench == benchName))
.And(e => (e.TimeStamp >= DateTime.Now - new TimeSpan(days, 0, 0, 0))) .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) 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>(); IList<Subscriber> thisEventSubscribers = new List<Subscriber>();
foreach (var s in allSubscribers) foreach (var s in allSubscribers)
{ {
@ -211,10 +63,10 @@ namespace Events
thisEventSubscribers.Add(s); thisEventSubscribers.Add(s);
} }
} }
evnt.Bench = BenchName;
evnt.Subscribers = thisEventSubscribers; evnt.Subscribers = thisEventSubscribers;
evnt.Bench = BenchName;
session.SaveOrUpdate(evnt); session.SaveOrUpdate(evnt);
session.Flush();
} }
} }
} }

View File

@ -437,16 +437,6 @@ namespace TBF
} }
if (rsltDBSession != null && rsltDBSession.IsOpen) rsltDBSession.Close(); 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; retryLogin = false;
break; break;
} }

View File

@ -10,6 +10,7 @@ using Config;
using TBF.Rig; using TBF.Rig;
using TBF.Rig.Generic; using TBF.Rig.Generic;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.DataContainers.BenchInfo.iPerl 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; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 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;
using System.Collections.Generic; using System.Collections.Generic;
using log4net; using log4net;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.DataContainers.Buoyancy 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; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 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;
using System.Collections.Generic; using System.Collections.Generic;
using log4net; using log4net;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.DataContainers.Density 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; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 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;
using System.Collections.Generic; using System.Collections.Generic;
@ -7,6 +7,7 @@ using log4net;
using Config.Entities; using Config.Entities;
using TBF.Rig.GenericDevices; using TBF.Rig.GenericDevices;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.DataContainers.Evaporation 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; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 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;
using System.Collections.Generic; using System.Collections.Generic;
@ -9,6 +9,7 @@ using Dirichlet.Numerics;
using TBF.Rig.Generic; using TBF.Rig.Generic;
using TBF.Boxes; using TBF.Boxes;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.Diverter namespace TBF.Rig.Elde.Diverter
{ {
@ -152,35 +153,51 @@ namespace TBF.Rig.Elde.Diverter
/// ///
/// Calendar support /// Calendar support
/// ///
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents() public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{ {
DateTime calibrationDue = diverterCfg.CalibValidDate; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 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;
using System.Collections.Generic; using System.Collections.Generic;
@ -7,6 +7,7 @@ using log4net;
using Config.Entities; using Config.Entities;
using TBF.Boxes; using TBF.Boxes;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.FlowMeter namespace TBF.Rig.Elde.FlowMeter
{ {
@ -68,7 +69,7 @@ namespace TBF.Rig.Elde.FlowMeter
{ {
for (int r = 0; r <= 5; r++) 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) && flowMeterCfg.GetCalibValidDate(r).Date < DateTime.Now.Date)
{ {
throw new Exception(string.Format("{0}/r{1}: {2}", Name, r, Strings.Calibration_certificate_validity_expired)); 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 /// Calendar support
/// ///
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents() public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{ {
DateTime calibrationDue = flowMeterCfg.CalibValidDate; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 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;
using System.Collections.Generic; using System.Collections.Generic;
@ -7,6 +7,7 @@ using log4net;
using TBF.Rig.Generic; using TBF.Rig.Generic;
using TBF.Boxes; using TBF.Boxes;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.PressureMeter 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; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 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 /// Author: Milan Hanajik
/// ///
using System; using System;
@ -8,6 +8,7 @@ using log4net;
using TBF.Rig.Generic; using TBF.Rig.Generic;
using TBF.Boxes; using TBF.Boxes;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.PressureMeterInternal 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; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 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;
using System.Collections.Generic; using System.Collections.Generic;
@ -8,6 +8,7 @@ using Common;
using TBF.Rig.Generic; using TBF.Rig.Generic;
using TBF.Boxes; using TBF.Boxes;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.TempMeter 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; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 calendarEvents;
return calEvents;
} }
public double ReadTemperature() 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;
using System.Collections.Generic; using System.Collections.Generic;
@ -7,6 +7,7 @@ using log4net;
using TBF.Rig.Generic; using TBF.Rig.Generic;
using TBF.Boxes; using TBF.Boxes;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.TempMeterInternal 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; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 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;
using System.Collections.Generic; using System.Collections.Generic;
using log4net; using log4net;
using TBF.Boxes; using TBF.Boxes;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Elde.TempMeterMeret 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; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 calendarEvents;
return calEvents;
} }

View File

@ -8,6 +8,6 @@ namespace TBF.Rig.GenericDevices
{ {
interface IHasCalendarEvents 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;
using System.Collections.Generic; using System.Collections.Generic;
@ -10,6 +10,7 @@ using TBF.Rig.GenericDevices;
using TBF.Boxes; using TBF.Boxes;
using TBF.Rig.Hart.Common; using TBF.Rig.Hart.Common;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Hart.Nivotrack namespace TBF.Rig.Hart.Nivotrack
{ {
@ -77,35 +78,51 @@ namespace TBF.Rig.Hart.Nivotrack
/// ///
/// Calendar support /// Calendar support
/// ///
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents() public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{ {
DateTime calibrationDue = nivotrackCfg.CalibValidDate; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 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;
using System.Collections.Generic; using System.Collections.Generic;
@ -8,6 +8,7 @@ using log4net;
using TBF.Boxes; using TBF.Boxes;
using TBF.Rig.Keithley.Multimeter_2010_RS232; using TBF.Rig.Keithley.Multimeter_2010_RS232;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.Keithley.TempMeter namespace TBF.Rig.Keithley.TempMeter
{ {
@ -49,35 +50,51 @@ namespace TBF.Rig.Keithley.TempMeter
/// ///
/// Calendar support /// Calendar support
/// ///
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents() public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{ {
DateTime calibrationDue = tempMtrCfg.CalibValidDate; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 calendarEvents;
return calEvents;
} }
public double ReadTemperature() 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;
using System.Collections.Generic; using System.Collections.Generic;
@ -12,6 +12,7 @@ using TBF.Rig.Generic;
using TBF.Rig.GenericDevices; using TBF.Rig.GenericDevices;
using TBF.Boxes; using TBF.Boxes;
using TBF.Resources; using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.MettlerToledo.Standard namespace TBF.Rig.MettlerToledo.Standard
{ {
@ -111,7 +112,7 @@ namespace TBF.Rig.MettlerToledo.Standard
Balances[nextBalanceIdx - 1] = this; 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)); 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; var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = 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 /// Five weekly notifications
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name, foreach (var days in new int[] { -35, -28, -21, -14 })
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{ {
/// Weekly reminders (last 5 weeks) if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name, {
string.Format(Strings.Calibration_due_date_is_0, calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calibDue.Date.AddDays(days),
false)); Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
} }
if (DateTime.Now.Date <= calibrationDue.Date)
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{ {
/// Daily reminders (last 5 days) if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name, {
string.Format(Strings.Calibration_due_date_is_0, /// Weekly reminders (last 5 weeks)
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)), calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
true)); 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 calendarEvents;
return calEvents;
} }

View File

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

View File

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

View File

@ -142,9 +142,10 @@ namespace TBF.Rig.Output.EventTriggers.Standard
return; return;
} }
ISession session = null;
try try
{ {
ISession session = Events.DB.CreateSession(); session = TBF.DB.EventsDBSessionFactory.OpenSession();
Events.DB.LoadSubscribers(session); Events.DB.LoadSubscribers(session);
/// ///
@ -226,15 +227,15 @@ namespace TBF.Rig.Output.EventTriggers.Standard
long eFlags = batch.ErrorFlags(); long eFlags = batch.ErrorFlags();
long iFlags = batch.InfoFlags(); long iFlags = batch.InfoFlags();
/// ///
if (triggerCfg.E1) OnExTriggerEvent(session, eFlags, iFlags, 1); if (triggerCfg.E1) OnExTriggerEvent(session, eFlags, iFlags, 1);
if (triggerCfg.E2) OnExTriggerEvent(session, eFlags, iFlags, 2); if (triggerCfg.E2) OnExTriggerEvent(session, eFlags, iFlags, 2);
if (triggerCfg.E3) OnExTriggerEvent(session, eFlags, iFlags, 3); if (triggerCfg.E3) OnExTriggerEvent(session, eFlags, iFlags, 3);
if (triggerCfg.E4) OnExTriggerEvent(session, eFlags, iFlags, 4); if (triggerCfg.E4) OnExTriggerEvent(session, eFlags, iFlags, 4);
if (triggerCfg.E5) OnExTriggerEvent(session, eFlags, iFlags, 5); if (triggerCfg.E5) OnExTriggerEvent(session, eFlags, iFlags, 5);
if (triggerCfg.E6) OnExTriggerEvent(session, eFlags, iFlags, 6); if (triggerCfg.E6) OnExTriggerEvent(session, eFlags, iFlags, 6);
if (triggerCfg.E7) OnExTriggerEvent(session, eFlags, iFlags, 7); if (triggerCfg.E7) OnExTriggerEvent(session, eFlags, iFlags, 7);
if (triggerCfg.E8) OnExTriggerEvent(session, eFlags, iFlags, 8); if (triggerCfg.E8) OnExTriggerEvent(session, eFlags, iFlags, 8);
if (triggerCfg.E9) OnExTriggerEvent(session, eFlags, iFlags, 9); if (triggerCfg.E9) OnExTriggerEvent(session, eFlags, iFlags, 9);
if (triggerCfg.E10) OnExTriggerEvent(session, eFlags, iFlags, 10); if (triggerCfg.E10) OnExTriggerEvent(session, eFlags, iFlags, 10);
if (triggerCfg.E11) OnExTriggerEvent(session, eFlags, iFlags, 11); if (triggerCfg.E11) OnExTriggerEvent(session, eFlags, iFlags, 11);
if (triggerCfg.E12) OnExTriggerEvent(session, eFlags, iFlags, 12); if (triggerCfg.E12) OnExTriggerEvent(session, eFlags, iFlags, 12);
@ -254,6 +255,10 @@ namespace TBF.Rig.Output.EventTriggers.Standard
{ {
log.ErrorFormat("Triggering event(s) failed: {0}", exc.Message); 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) void OnExTriggerEvent(ISession session, long eFlags, long iFlags, int x)

View File

@ -162,11 +162,12 @@ namespace TBF.Rig.Output.FileWriters.IperlLogger
opCompleted = true; opCompleted = true;
} }
if (anyError && !string.IsNullOrEmpty(Events.DB.ConnectionString)) if (TBF.DB.EventsDBSessionFactory != null && anyError)
{ {
NHibernate.ISession session = null;
try try
{ {
NHibernate.ISession session = Events.DB.CreateSession(); session = TBF.DB.EventsDBSessionFactory.OpenSession();
Events.DB.LoadSubscribers(session); Events.DB.LoadSubscribers(session);
TBF.UiBridge.Bridge.TriggerEvent(session, Name, EventClass.ComputerResources, Severity.Error, 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); log.ErrorFormat("Triggering event(s) failed: {0}", exc.Message);
} }
finally
{
if (session != null && session.IsOpen) session.Close();
}
} }
return anyError ? Event.ErrorProcessingResults: Event.ResultsWritten; 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 #elif BERLIN || GELSENWASSER || GENESIS || IZRAEL_200 || PETERSBURG_200 || PUCHONG_200 || SLM_150
public static void InitializeBoardEtc(ControlComponent_Izrael2014.UserControl1 ctrlBrdComponent) public static void InitializeBoardEtc(ControlComponent_Izrael2014.UserControl1 ctrlBrdComponent)
#else /// all newer benches #else /// all newer benches
public static void InitializeBoardEtc(ControlComponent_Torino2015.UserControl1 ctrlBrdComponent) public static void InitializeBoardEtc(ISession session, ControlComponent_Torino2015.UserControl1 ctrlBrdComponent)
#endif #endif
{ {
var session = TBF.DB.ConfigDBSessionFactory.OpenSession();
/// Load the list of components (entities) from the database. /// Load the list of components (entities) from the database.
/// Then create the components (derived from IComponent). /// Then create the components (derived from IComponent).
components = Rig.TbfComponents.LoadComponentsFromDB(session); components = Rig.TbfComponents.LoadComponentsFromDB(session);
@ -299,8 +297,6 @@ namespace TBF.Rig
if ((eldeValve != null) && eldeValve.Inverted) valvesToInvert |= eldeValve.Mask; if ((eldeValve != null) && eldeValve.Inverted) valvesToInvert |= eldeValve.Mask;
} }
session.Close();
/// Pre-initialize the control board (= buffer the arguments ctrlBrdComponent, tankCapacities) /// Pre-initialize the control board (= buffer the arguments ctrlBrdComponent, tankCapacities)
if (ControlBoard != null) if (ControlBoard != null)
{ {
@ -428,7 +424,7 @@ namespace TBF.Rig
/// Checks remote and local configuration DB paths and transitions for compatibility /// Checks remote and local configuration DB paths and transitions for compatibility
/// </summary> /// </summary>
/// <returns>true when DB-s are compatible</returns> /// <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.FeedingPath> remoteFeedingPaths = new List<Config.Entities.FeedingPath>();
IList<Config.Entities.BenchPath> remoteBenchPaths = new List<Config.Entities.BenchPath>(); IList<Config.Entities.BenchPath> remoteBenchPaths = new List<Config.Entities.BenchPath>();
@ -456,16 +452,12 @@ namespace TBF.Rig
return false; return false;
} }
var localSession = TBF.DB.ConfigDBSessionFactory.OpenSession();
var localFeedingPaths = localSession.QueryOver<Config.Entities.FeedingPath>().List(); var localFeedingPaths = localSession.QueryOver<Config.Entities.FeedingPath>().List();
var localBenchPaths = localSession.QueryOver<Config.Entities.BenchPath>().List(); var localBenchPaths = localSession.QueryOver<Config.Entities.BenchPath>().List();
var localOutputPaths = localSession.QueryOver<Config.Entities.OutputPath>().List(); var localOutputPaths = localSession.QueryOver<Config.Entities.OutputPath>().List();
var localMetersPaths = localSession.QueryOver<Config.Entities.MetersPath>().List(); var localMetersPaths = localSession.QueryOver<Config.Entities.MetersPath>().List();
var localTransitions = localSession.QueryOver<Config.Entities.TransitionSequence>().List(); var localTransitions = localSession.QueryOver<Config.Entities.TransitionSequence>().List();
localSession.Close();
string subMsg; string subMsg;
if (!IsCompatible(localFeedingPaths, remoteFeedingPaths, out subMsg)) if (!IsCompatible(localFeedingPaths, remoteFeedingPaths, out subMsg))
{ {
@ -583,7 +575,6 @@ namespace TBF.Rig
#if HEAT_METERS #if HEAT_METERS
heatMetersPaths = session.QueryOver<Config.Entities.HeatMetersPath>().OrderBy(x => x.ItemNr).Asc.List(); heatMetersPaths = session.QueryOver<Config.Entities.HeatMetersPath>().OrderBy(x => x.ItemNr).Asc.List();
#endif #endif
session.Flush();
} }
catch (Exception e) catch (Exception e)
{ {

View File

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

View File

@ -11,14 +11,14 @@ namespace TBF.UI.Calendar
{ {
public DateTime Date { get; set; } /// The Date that the event occurs public DateTime Date { get; set; } /// The Date that the event occurs
public Frequency Frequency { get; set; } /// A value indicating how often the event occurs public Frequency Frequency { get; set; } /// A value indicating how often the event occurs
public bool AllDay { get; set; } /// True if the time component of the date can be ignored public bool AllDay { get; set; } /// True if the time component of the date can be ignored
public bool TriggerOnExactDayOnly { get; set; } /// If this is a recurring event, set this to true to make the event show up only from the day specified forward public bool TriggerOnExactDayOnly { get; set; } /// If this is a recurring event, set this to true to make the event show up only from the day specified forward
public string Source { get; set; } /// Source of this calendar event (becomes the source of the triggered event) public string Source { get; set; } /// Source of this calendar event (becomes the source of the triggered event)
public string Title { get; set; } /// The name of the event (becomes the text of the triggered event) public string Title { get; set; } /// The name of the event (becomes the text of the triggered event)
public AutoAction AutoAction { get; set; } /// Automated action to be done or event to be triggered (becomes Severity) public AutoAction AutoAction { get; set; } /// Automated action to be done or event to be triggered (becomes Severity)
public string Parameters { get; set; } /// Automated action parameters (e.g. name of a procedure to start) public string Parameters { get; set; } /// Automated action parameters (e.g. name of a procedure to start)
public int Rank { get; set; } /// The ranking of the event that determines the order in which it is displayed on a particular day public int Rank { get; set; } /// The ranking of the event that determines the order in which it is displayed on a particular day
public bool Hidden { get; set; } /// True if the event is enabled, otherwise false public bool Hidden { get; set; } /// True if the event is enabled, otherwise false
public bool ReadOnly { get; set; } /// True if the event details cannot be modified public bool ReadOnly { get; set; } /// True if the event details cannot be modified
public int BackColor { get; set; } /// The color that the event show up in on the calendar: (MSB)AARRGGBB(LSB) public int BackColor { get; set; } /// The color that the event show up in on the calendar: (MSB)AARRGGBB(LSB)
public int TextColor { get; set; } /// The text color of the event: (MSB)AARRGGBB(LSB) public int TextColor { get; set; } /// The text color of the event: (MSB)AARRGGBB(LSB)

View File

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

View File

@ -25,7 +25,7 @@ namespace TBF.UI
static readonly ILog log = LogManager.GetLogger(typeof(MainWnd)); static readonly ILog log = LogManager.GetLogger(typeof(MainWnd));
const string ProcSeparator = " "; /// string separating procedure number and procedure name const string ProcSeparator = " "; /// string separating procedure number and procedure name
public static IDictionary<string, int> ProcedureNrs = new Dictionary<string, int>(); /// Used in PreviousResultsDlg public static IDictionary<string, int> ProcedureNrs = new Dictionary<string, int>(); /// Used in PreviousResultsDlg
public BenchControlPanel BenchControlPanel; public BenchControlPanel BenchControlPanel;
@ -34,6 +34,11 @@ namespace TBF.UI
public bool IsShutdownDisabled; public bool IsShutdownDisabled;
public bool IsShutdownPCAfterClosingTbf; 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> /// <summary>
/// This dialog is shown when emergency stop is activated /// This dialog is shown when emergency stop is activated
/// </summary> /// </summary>
@ -135,15 +140,17 @@ namespace TBF.UI
{ {
try try
{ {
startupSession = TBF.DB.ConfigDBSessionFactory.OpenSession();
/// Load components, initialize the control board, etc. /// Load components, initialize the control board, etc.
Rig.StateMachine.InitializeBoardEtc(ctrlBrdComponent); Rig.StateMachine.InitializeBoardEtc(startupSession, ctrlBrdComponent);
/// Check remote and local configuration DB compatibility /// Check remote and local configuration DB compatibility
string msg; string msg;
Rig.GenericDevices.IBenchInfo benchInfo = Rig.Sequences.ProcessData.BenchInfo; Rig.GenericDevices.IBenchInfo benchInfo = Rig.Sequences.ProcessData.BenchInfo;
RemoteDBUse remoteDbUse = (benchInfo != null) ? benchInfo.RemoteDBUse : RemoteDBUse.LocalDBOnly; RemoteDBUse remoteDbUse = (benchInfo != null) ? benchInfo.RemoteDBUse : RemoteDBUse.LocalDBOnly;
log.FatalFormat("RemoteDbUse = {0}", remoteDbUse); 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); 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)); 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 /// 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) foreach (var cmpnt in TBF.Rig.StateMachine.Components)
{ {
TBF.Rig.GenericDevices.IHasCalendarEvents cmpntWithCalEvents = cmpnt as TBF.Rig.GenericDevices.IHasCalendarEvents; var cmpntWithEvents = cmpnt as TBF.Rig.GenericDevices.IHasCalendarEvents;
if (cmpntWithCalEvents != null) 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(); Rig.StateMachine.Start();
log.Info("Test bench started"); log.Info("Test bench started");

View File

@ -272,29 +272,31 @@ namespace TBF.UI.Settings
{ {
try try
{ {
string connectionString = bench.EventsDBSettings.ConnectionString; MessageBox.Show("Not implemented yet");
string databaseName = Config.Utils.GetDBName(connectionString);
string userName = Config.Utils.GetDBUser(connectionString);
string password = Config.Utils.GetDBPassword(connectionString); /// TODO: Use password
if (connectionString == currentConfigDBConnStr || connectionString == currentResultsDBConnStr || connectionString == currentEventsDBConnStr) //string connectionString = bench.EventsDBSettings.ConnectionString;
{ //string databaseName = Config.Utils.GetDBName(connectionString);
CurrentDBChanged = true; //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); //Cursor.Current = Cursors.WaitCursor;
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); //log.ErrorFormat("Going to create an empty events database '{0}'", databaseName);
Cursor.Current = Cursors.Default; //ExecuteMySqlCmd(string.Format("DROP DATABASE `{0}`;", databaseName), userName, password);
DialogResult = DialogResult.None; //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) catch (Exception exception)
{ {