MP-IO & MapoDB:
- modifica DataLayer x gestione diretta redis x chiamate da channel e salvataggio in cache
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MapoDb
|
||||
{
|
||||
public class Constants
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
|
||||
public static readonly string BROADCAST_M_PIPE = $"BroadCastMsg";
|
||||
public static readonly string BROADCAST_CURR_KEY = $"{BASE_HASH}:Current:BroadCast";
|
||||
|
||||
// dati conf REDIS Cache
|
||||
public static readonly string BASE_HASH = "MAPO";
|
||||
|
||||
|
||||
private const string redisBaseAddr = "MP:";
|
||||
public static readonly string redisActionReq = redisBaseAddr + "IO:Action:Req";
|
||||
|
||||
#endregion Public Fields
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
using MapoSDK;
|
||||
using Newtonsoft.Json;
|
||||
using NLog.Fluent;
|
||||
using StackExchange.Redis;
|
||||
using SteamWare;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -145,6 +148,9 @@ namespace MapoDb
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
public MessagePipe BroadastMsgPipe { get; set; } = null;
|
||||
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
@@ -160,6 +166,69 @@ namespace MapoDb
|
||||
|
||||
// init oggetto MapoDb
|
||||
MapoDbObj = new MapoDb();
|
||||
|
||||
// init message channel...
|
||||
BroadastMsgPipe = new MessagePipe(connRedis, Constants.BROADCAST_M_PIPE);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connessione lazy a redis...
|
||||
/// </summary>
|
||||
private Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
|
||||
{
|
||||
string RedisConn = memLayer.ML.confReadString("RedisConn");
|
||||
if (string.IsNullOrEmpty(RedisConn))
|
||||
{
|
||||
RedisConn = "localhost,abortConnect=false,ssl=false";
|
||||
}
|
||||
|
||||
return ConnectionMultiplexer.Connect(RedisConn);
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Connessione lazy a redis...
|
||||
/// </summary>
|
||||
private Lazy<ConnectionMultiplexer> lazyConnectionAdmin = new Lazy<ConnectionMultiplexer>(() =>
|
||||
{
|
||||
string RedisConnAdmin = memLayer.ML.confReadString("RedisConnAdmin");
|
||||
if (string.IsNullOrEmpty(RedisConnAdmin))
|
||||
{
|
||||
RedisConnAdmin = "localhost,abortConnect=false,ssl=false,allowAdmin=true";
|
||||
}
|
||||
|
||||
return ConnectionMultiplexer.Connect(RedisConnAdmin);
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto statico connessione redis
|
||||
/// </summary>
|
||||
public ConnectionMultiplexer connRedis
|
||||
{
|
||||
get
|
||||
{
|
||||
return lazyConnection.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Salva richiesta azione
|
||||
/// </summary>
|
||||
/// <param name="act2save"></param>
|
||||
/// <returns></returns>
|
||||
public bool ActionSetReq(DisplayAction act2save)
|
||||
{
|
||||
bool fatto = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// cerco in redis...
|
||||
string rawData = JsonConvert.SerializeObject(act2save);
|
||||
// invio broadcast + salvo in redis
|
||||
BroadastMsgPipe.saveAndSendMessage(Constants.redisActionReq, rawData);
|
||||
//await redisDb.StringSetAsync(redisActionReq, rawData);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
logger.lg.scriviLog($"ActionSetReq REDIS send to broadcast + Write cache: {ts.TotalMilliseconds}ms");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
@@ -211,7 +211,9 @@
|
||||
<Link>MoonPro.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="AlarmsArchive.cs" />
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="DataLayer.cs" />
|
||||
<Compile Include="DisplayAction.cs" />
|
||||
<Compile Include="DS_applicazione.cs">
|
||||
<DependentUpon>DS_applicazione.xsd</DependentUpon>
|
||||
</Compile>
|
||||
@@ -272,6 +274,7 @@
|
||||
<Compile Include="FluxArchive.cs" />
|
||||
<Compile Include="IntServTrData.cs" />
|
||||
<Compile Include="MapoDb.cs" />
|
||||
<Compile Include="MessagePipe.cs" />
|
||||
<Compile Include="MtcDataModelArchive.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
|
||||
Reference in New Issue
Block a user