2020-03-05 12:59:43 +00:00
|
|
|
|
///
|
2023-04-18 12:01:23 +00:00
|
|
|
|
/// Copyright (c) 2020-2023 Sensus Slovensko a.s.
|
2020-03-05 12:59:43 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using FluentNHibernate.Cfg;
|
|
|
|
|
|
using FluentNHibernate.Cfg.Db;
|
|
|
|
|
|
using NHibernate;
|
|
|
|
|
|
using NHibernate.Cfg;
|
|
|
|
|
|
using NHibernate.Tool.hbm2ddl;
|
2021-09-23 09:46:40 +00:00
|
|
|
|
using Common;
|
2020-03-05 12:59:43 +00:00
|
|
|
|
using Events.Entities;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Events
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class DB
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Shared data (initially empty)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static string BenchName = "undefined";
|
|
|
|
|
|
public static IList<Entities.Event> RecentEvents = null;
|
|
|
|
|
|
static IList<Entities.Subscriber> allSubscribers = null;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set test bench name used in Events.Entities.Event constructors
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static void SetBenchName(string benchName)
|
|
|
|
|
|
{
|
|
|
|
|
|
DB.BenchName = benchName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-18 12:01:23 +00:00
|
|
|
|
/// <summary>
|
2020-03-05 12:59:43 +00:00
|
|
|
|
/// Loads shared data from the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static void LoadSubscribers(ISession session)
|
|
|
|
|
|
{
|
|
|
|
|
|
allSubscribers = session.QueryOver<Subscriber>().List();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Loads shared data from the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static void LoadRecentEvents(ISession session, string benchName, int days)
|
|
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
BenchName = benchName;
|
2020-03-05 12:59:43 +00:00
|
|
|
|
RecentEvents = session.QueryOver<Event>()
|
|
|
|
|
|
.Where(e => (e.Bench == benchName))
|
|
|
|
|
|
.And(e => (e.TimeStamp >= DateTime.Now - new TimeSpan(days, 0, 0, 0)))
|
|
|
|
|
|
.List();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void SaveEvent(ISession session, Event evnt, SubscriberGroup groups)
|
|
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
if (allSubscribers == null) LoadSubscribers(session);
|
|
|
|
|
|
|
2020-03-05 12:59:43 +00:00
|
|
|
|
IList<Subscriber> thisEventSubscribers = new List<Subscriber>();
|
|
|
|
|
|
foreach (var s in allSubscribers)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((s.Groups & (long)groups) != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Subscriber 's' belongs to at least one of SubscriberGroup(s) in 'groups' bit field
|
|
|
|
|
|
thisEventSubscribers.Add(s);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
evnt.Subscribers = thisEventSubscribers;
|
2023-04-18 12:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
evnt.Bench = BenchName;
|
2020-03-05 12:59:43 +00:00
|
|
|
|
session.SaveOrUpdate(evnt);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|