Ok messaggi in ingresso x allarmi attivati
This commit is contained in:
@@ -26,6 +26,7 @@ namespace MP.MONO.Core
|
||||
|
||||
// Dati correnti
|
||||
public static readonly string ACT_LOG_CURR_KEY = $"{BASE_HASH}:Current:ActivityLog";
|
||||
public static readonly string ALARM_ACT_KEY = $"{BASE_HASH}:Current:AlarmsVal";
|
||||
public static readonly string ALARM_CURR_KEY = $"{BASE_HASH}:Current:Alarms";
|
||||
public static readonly string EVENT_LOG_CURR_KEY = $"{BASE_HASH}:Current:EventsLog";
|
||||
public static readonly string MACH_STATS_CURR_KEY = $"{BASE_HASH}:Current:MachStats";
|
||||
@@ -37,6 +38,7 @@ namespace MP.MONO.Core
|
||||
|
||||
// Canali messaggi REDIS
|
||||
public static readonly string ACT_LOG_M_QUEUE = $"ActivityLog";
|
||||
public static readonly string ALARM_ACT_VAL = $"AlarmsActVal";
|
||||
public static readonly string ALARM_M_QUEUE = $"Alarms";
|
||||
public static readonly string EVENT_LOG_M_QUEUE = $"EventsLog";
|
||||
public static readonly string MACH_STATS_M_QUEUE = $"MachStats";
|
||||
|
||||
@@ -8,6 +8,18 @@
|
||||
<Platforms>AnyCPU;x86;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="NLog" Version="4.7.14" />
|
||||
@@ -15,6 +27,10 @@
|
||||
<PackageReference Include="StackExchange.Redis" Version="2.5.43" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MP.MONO.Data\MP.MONO.Data.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="conf\ConfMode.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
||||
@@ -1,9 +1,58 @@
|
||||
using NLua;
|
||||
using MP.MONO.DECODER;
|
||||
using MP.MONO.Data;
|
||||
using MP.MONO.Core;
|
||||
using StackExchange.Redis;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using MP.MONO.Core.DTO;
|
||||
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Start DECODER with LUA integration!");
|
||||
|
||||
// init parte config, vedere https://blog.hildenco.com/2020/05/configuration-in-net-core-console.html
|
||||
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile($"appsettings.json", true, true)
|
||||
.AddJsonFile($"appsettings.{env}.json", true, true)
|
||||
.AddEnvironmentVariables();
|
||||
var config = builder.Build();
|
||||
|
||||
// init oggetti messagePipe...
|
||||
ConnectionMultiplexer redisConn = ConnectionMultiplexer.Connect(config.GetConnectionString("Redis"));
|
||||
|
||||
MessagePipe alarmPipe = new MessagePipe(redisConn, Constants.ALARM_M_QUEUE);
|
||||
MessagePipe alarmValPipe = new MessagePipe(redisConn, Constants.ALARM_ACT_VAL);
|
||||
|
||||
alarmValPipe.EA_NewMessage += AlarmValPipe_EA_NewMessage;
|
||||
|
||||
void AlarmValPipe_EA_NewMessage(object? sender, EventArgs e)
|
||||
{
|
||||
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
||||
// conversione on-the-fly List<string> --> allarmi
|
||||
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
||||
{
|
||||
try
|
||||
{
|
||||
var alarmList = JsonConvert.DeserializeObject<List<int>>(currArgs.newMessage);
|
||||
if (alarmList != null)
|
||||
{
|
||||
// per ogni valore (è una lista di INT, iuno x bank) devo fare la verifica...
|
||||
|
||||
//var ListRecords = new List<DisplayDataDTO>();
|
||||
//ListRecords = alarmList.Select(x => new DisplayDataDTO()
|
||||
//{
|
||||
// IsNumeric = false,
|
||||
// Title = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}",
|
||||
// Value = x,
|
||||
// Order = ListRecords == null ? 0 : ListRecords.Count
|
||||
//}).ToList();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
Lua state;
|
||||
state = new Lua();
|
||||
@@ -118,6 +167,11 @@ if (numTest == 1)
|
||||
// Console.WriteLine(item);
|
||||
//}
|
||||
|
||||
do
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
} while (true);
|
||||
|
||||
}
|
||||
else if (numTest == 2)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"Redis": "nkcredis.steamware.net:6379,DefaultDatabase=7,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,password=nkc.password",
|
||||
"AuthConnection": "Server=localhost;port=3306;database=GWMS;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;",
|
||||
"DefaultConnection": "Server=localhost;port=3306;database=MAPO.MONO;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;",
|
||||
"AdminConnection": "Server=localhost;port=3306;database=MAPO.MONO;user=root;pwd=Egalware_24068!;sslmode=None;",
|
||||
"MP.MONO.Data": "Server=localhost;port=3306;database=MAPO.MONO;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;"
|
||||
},
|
||||
"DbConfig": {
|
||||
"Server": "localhost",
|
||||
"nKey": "MONO",
|
||||
"sKey": "M3T@n0-CH4"
|
||||
},
|
||||
"maxRecord": 15,
|
||||
"ExternalProviders": {
|
||||
"MailKit": {
|
||||
"SMTP": {
|
||||
"Address": "smtp.gmail.com",
|
||||
"Port": "465",
|
||||
"Account": "steamwarebot@gmail.com",
|
||||
"Password": "drmfsls16",
|
||||
"SenderEmail": "steamwarebot@gmail.com",
|
||||
"SenderName": "Steamware Email BOT"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,12 @@ namespace MP.MONO.Data
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
#if false
|
||||
|
||||
public MapoMonoContext()
|
||||
{
|
||||
}
|
||||
|
||||
#if false
|
||||
|
||||
public MapoMonoContext(DbContextOptions<MapoMonoContext> options) : base(options)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -43,7 +43,7 @@ IDatabase? redisDb = redis.GetDatabase();
|
||||
setupConf();
|
||||
var currSimGen = new Simulator(confPath, modeList.Count, statusList.Count);
|
||||
|
||||
//preparo la lista dei contatori invio...
|
||||
// preparo la lista dei contatori invio...
|
||||
LogSimulator.Add(Constants.ACT_LOG_M_QUEUE, 0);
|
||||
LogSimulator.Add(Constants.ALARM_M_QUEUE, 0);
|
||||
LogSimulator.Add(Constants.EVENT_LOG_M_QUEUE, 0);
|
||||
@@ -221,11 +221,13 @@ void simAlarms()
|
||||
|
||||
do
|
||||
{
|
||||
List<int> currAlarmsVal = new List<int>();
|
||||
List<string> activeAlarms = new List<string>();
|
||||
//int alarmCode = rand.Next(0, 255);
|
||||
int alarmCode = rand.Next(0, 160);
|
||||
// se >= 128 --> 0 (no alarm)
|
||||
alarmCode = alarmCode <= 127 ? alarmCode : 0;
|
||||
currAlarmsVal.Add(alarmCode);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if ((alarmCode & (1 << i)) != 0)
|
||||
@@ -233,9 +235,11 @@ void simAlarms()
|
||||
activeAlarms.Add($"Alarm {i:000}");
|
||||
}
|
||||
}
|
||||
string rawDataVal = JsonConvert.SerializeObject(currAlarmsVal);
|
||||
string rawData = JsonConvert.SerializeObject(activeAlarms);
|
||||
// decodifico allarme e lo trasformo in List<String> di allarmi attivi...
|
||||
// decodifico allarme e lo trasformo in List<String> + List<int> di allarmi attivi...
|
||||
saveAndSendMessage(Constants.ALARM_CURR_KEY, rawData, Constants.ALARM_M_QUEUE, rawData);
|
||||
saveAndSendMessage(Constants.ALARM_ACT_KEY, rawDataVal, Constants.ALARM_ACT_VAL, rawDataVal);
|
||||
// attesa random
|
||||
Thread.Sleep(rand.Next(minPeriod, maxPeriod));
|
||||
} while (true);
|
||||
|
||||
Reference in New Issue
Block a user