589 lines
26 KiB
C#
589 lines
26 KiB
C#
using EgwMultiEngineManager.Data;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using RestSharp;
|
|
using StackExchange.Redis;
|
|
|
|
namespace EgwCoreLib.Lux.Data.Services
|
|
{
|
|
public class ImageCacheService
|
|
{
|
|
#region Public Constructors
|
|
|
|
public ImageCacheService(IConfiguration config, IRedisService redisService, IConnectionMultiplexer redisConn)
|
|
{
|
|
_config = config;
|
|
_redisService = redisService;
|
|
_redisConn = redisConn;
|
|
_redisDb = redisConn.GetDatabase();
|
|
// conf channels x comunicazione broadcast
|
|
chBom = _config.GetValue<string>("ServerConf:ChannelBom") ?? "lux:bom";
|
|
chHwList = _config.GetValue<string>("ServerConf:ChannelHwList") ?? "lux:hw:list";
|
|
chHwOpt = _config.GetValue<string>("ServerConf:ChannelHwOpt") ?? "lux:hw:opt";
|
|
chPng = _config.GetValue<string>("ServerConf:ChannelPng") ?? "lux:png:img";
|
|
chProfList = _config.GetValue<string>("ServerConf:ChannelProfList") ?? "lux:prof";
|
|
chShape = _config.GetValue<string>("ServerConf:ChannelShape") ?? "lux:shape";
|
|
chSvg = _config.GetValue<string>("ServerConf:ChannelSvg") ?? "lux:svg:img";
|
|
chUpdate = _config.GetValue<string>("ServerConf:ChannelUpdate") ?? "lux:update";
|
|
// conf tag x cache
|
|
liveTag = _config.GetValue<string>("ServerConf:ImageLiveTag") ?? "svg";
|
|
cacheTag = _config.GetValue<string>("ServerConf:ImageFileTag") ?? "svgfile";
|
|
calcTag = _config.GetValue<string>("ServerConf:ImageCalcTag") ?? "svg-preview";
|
|
// verifico la url base
|
|
apiUrl = _config.GetValue<string>("ServerConf:Prog.ApiUrl") ?? "https://iis01.egalware.com/lux/srv/api";
|
|
imgBasePath = _config.GetValue<string>("ServerConf:ImageBaseUrl") ?? "window";
|
|
// fix opzioni base del RestClient
|
|
restOptStd = new RestClientOptions
|
|
{
|
|
Timeout = TimeSpan.FromSeconds(60),
|
|
BaseUrl = new Uri($"{apiUrl}/{imgBasePath}")
|
|
};
|
|
Log.Info("ImageCache Service Started");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Effettua una generica chiamata ApiRest
|
|
/// </summary>
|
|
/// <param name="ApiUrl">URL Api di base</param>
|
|
/// <param name="ApiRequest">Richiesta completa</param>
|
|
/// <returns></returns>
|
|
public async Task<RestResponse> CallRestGet(string ApiUrl, string ApiRequest)
|
|
{
|
|
RestResponse response;
|
|
// cerco online
|
|
using (RestClient client = new RestClient(ApiUrl))
|
|
{
|
|
var request = new RestRequest(ApiRequest, Method.Get);
|
|
response = await client.GetAsync(request);
|
|
}
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua una generica chiamata ApiRest
|
|
/// </summary>
|
|
/// <param name="ApiUrl">URL Api di base</param>
|
|
/// <param name="ApiRequest">Richiesta completa</param>
|
|
/// <param name="rawBody">Corpo Json trasmesso con richiesta</param>
|
|
/// <returns></returns>
|
|
public async Task<RestResponse> CallRestPost(string ApiUrl, string ApiRequest, object rawBody)
|
|
{
|
|
RestResponse response;
|
|
// cerco online
|
|
using (RestClient client = new RestClient(ApiUrl))
|
|
{
|
|
var request = new RestRequest(ApiRequest, Method.Post);
|
|
string rawData = JsonConvert.SerializeObject(rawBody);
|
|
request.AddJsonBody(rawData);
|
|
response = await client.ExecutePostAsync(request);
|
|
}
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue flush memoria redis dato pat2Flush
|
|
/// </summary>
|
|
/// <param name="pat2Flush"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ExecFlushRedisPatternAsync(RedisValue pat2Flush)
|
|
{
|
|
bool answ = false;
|
|
/*******************************
|
|
* Recupero elenco dei server da cui cancellare le chaivi:
|
|
* - prendo solo i server connessi
|
|
* - prendo solo NON repliche (= master)
|
|
* - me ne aspetto 1 in uscita / prendo primo o default
|
|
*******************************/
|
|
var connServ = _redisConn.GetEndPoints()
|
|
.Select(endpoint =>
|
|
{
|
|
var server = _redisConn.GetServer(endpoint);
|
|
return server;
|
|
})
|
|
.Where(x => x.IsConnected && !x.IsReplica)
|
|
.FirstOrDefault();
|
|
if (connServ != null)
|
|
{
|
|
// ciclo (anche se me ne aspetto 1 solo)
|
|
// se pat2Flush è "*" elimino intero DB...
|
|
if ((pat2Flush.Equals(new RedisValue("*")) || pat2Flush == RedisValue.Null))
|
|
{
|
|
connServ.FlushDatabase(database: _redisDb.Database);
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
var keys = connServ.Keys(database: _redisDb.Database, pattern: pat2Flush, pageSize: 1000);
|
|
|
|
var deleteTasks = new List<Task>();
|
|
foreach (var key in keys)
|
|
{
|
|
deleteTasks.Add(_redisDb.KeyDeleteAsync(key));
|
|
if (deleteTasks.Count >= 1000)
|
|
{
|
|
await Task.WhenAll(deleteTasks);
|
|
deleteTasks.Clear();
|
|
}
|
|
}
|
|
if (deleteTasks.Count > 0)
|
|
{
|
|
await Task.WhenAll(deleteTasks);
|
|
}
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ExecFlushRedisPatternAsync | pat2Flush: {pat2Flush}{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Log.Error($"Server REDIS master non trovato");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calcola URL immagine dato
|
|
/// </summary>
|
|
/// <param name="baseUrl">Base url IMG server (da config)</param>
|
|
/// <param name="isLive">Live = in fase di calcolo (cache REDIS), altrimenti da filesystem</param>
|
|
/// <param name="imgUID">UID elemento/immagine</param>
|
|
/// <param name="envir">Environment item</param>
|
|
/// <returns></returns>
|
|
public string ImageUrl(string baseUrl, bool isLive, string imgUID, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW)
|
|
{
|
|
string tag = isLive ? liveTag : cacheTag;
|
|
string fType = "undef";
|
|
if (imgUID.EndsWith(".svg"))
|
|
{
|
|
fType = "svg";
|
|
imgUID.Replace(".svg", "");
|
|
}
|
|
else if (imgUID.EndsWith(".png"))
|
|
{
|
|
fType = "png";
|
|
imgUID.Replace(".png", "");
|
|
}
|
|
switch (envir)
|
|
{
|
|
case Constants.EXECENVIRONMENTS.NULL:
|
|
break;
|
|
|
|
case Constants.EXECENVIRONMENTS.WINDOW:
|
|
fType = "svg";
|
|
break;
|
|
|
|
case Constants.EXECENVIRONMENTS.BEAM:
|
|
case Constants.EXECENVIRONMENTS.WALL:
|
|
case Constants.EXECENVIRONMENTS.CABINET:
|
|
default:
|
|
fType = "png";
|
|
break;
|
|
}
|
|
|
|
string rndImg = $"{DateTime.Now:HHmmssfff}";
|
|
string fullUrl = $"{baseUrl}/{tag}/{imgUID}-{rndImg}.{fType}?env={envir}".Replace("////", "//");
|
|
return fullUrl;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rilettura risposta da debug in formato string x riprocessare...
|
|
/// </summary>
|
|
/// <param name="uID"></param>
|
|
/// <param name="env"></param>
|
|
/// <returns></returns>
|
|
public async Task<string> LoadDebug(string uID, Constants.EXECENVIRONMENTS env)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:DEBUG:{env}:{uID}";
|
|
string answ = await _redisService.GetAsync(currKey) ?? "";
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera img redis PNG x id item richiesto
|
|
/// </summary>
|
|
/// <param name="imgUid">UID item</param>
|
|
/// <param name="envir">Environment item</param>
|
|
public string LoadPng(string imgUid, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW)
|
|
{
|
|
// recupero img da cache
|
|
string currKey = $"{redisBaseKey}:{envir}:Img:Png:{imgUid.Replace("/", ":")}";
|
|
var rawVal = _redisService.Get(currKey);
|
|
return $"{rawVal}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera img redis SVG x id item richiesto
|
|
/// </summary>
|
|
/// <param name="imgUid">UID item</param>
|
|
/// <param name="envir">Environment item</param>
|
|
public string LoadSvg(string imgUid, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW)
|
|
{
|
|
// recupero img da cache
|
|
string currKey = $"{redisBaseKey}:{envir}:Img:Svg:{imgUid.Replace("/", ":")}";
|
|
var rawVal = _redisService.Get(currKey);
|
|
return $"{rawVal}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera img redis SVG x id item richiesto async
|
|
/// </summary>
|
|
/// <param name="imgId">UID item</param>
|
|
/// <param name="envir">Environment item</param>
|
|
public async Task<string> LoadSvgAsync(string imgId, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW)
|
|
{
|
|
// recupero img da cache
|
|
string currKey = $"{redisBaseKey}:{envir}:Img:Svg:{imgId.Replace("/", ":")}";
|
|
var rawVal = await _redisService.GetAsync(currKey);
|
|
return $"{rawVal}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel richiesto un update x UID
|
|
/// è attesao un refresh per chi sottoscrive il canale
|
|
/// </summary>
|
|
/// <param name="env"></param>
|
|
/// <param name="uid"></param>
|
|
public async Task<bool> PublishUpdateAsync(string uid, Constants.EXECENVIRONMENTS env)
|
|
{
|
|
bool done = false;
|
|
// invio notifica sul canale di update generale...
|
|
string notifyChannel = $"{chUpdate}:{env}";
|
|
// contenuto è UID
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, $"{uid}");
|
|
done = numSent > 0;
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calcola URL immagine dato
|
|
/// </summary>
|
|
/// <param name="baseUrl">Base url IMG server (da config)</param>
|
|
/// <param name="imgUID">UID elemento/immagine</param>
|
|
/// <param name="serJwd">JWD serializzato di cui si richiede l'immagine aggiornata</param>
|
|
/// <returns></returns>
|
|
public string ReqUpdateSvg(string baseUrl, string imgUID, string serJwd)
|
|
{
|
|
string answ = "";
|
|
if (imgUID.EndsWith(".svg"))
|
|
{
|
|
imgUID.Replace(".svg", "");
|
|
}
|
|
string fullUrl = $"{baseUrl}/svg-preview/{imgUID}".Replace("////", "//");
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel BOM redis il doc richiesto
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="env"></param>
|
|
/// <param name="bomContent"></param>
|
|
public async Task<bool> SaveBomAsync(string uid, Constants.EXECENVIRONMENTS env, string bomContent)
|
|
{
|
|
// salvo in cache
|
|
string currKey = $"{redisBaseKey}:{env}:BOM:{uid.Replace("/", ":")}";
|
|
var done = await _redisService.SetAsync(currKey, bomContent);
|
|
// invio notifica nuova svg generata sul canale... viene inviato solo svg con ID nel canale
|
|
string notifyChannel = $"{chBom}:{uid}";
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, bomContent);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salvataggio risposta x debug in formato RAW...
|
|
/// </summary>
|
|
/// <param name="uID"></param>
|
|
/// <param name="env"></param>
|
|
/// <param name="rawData"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public async Task<bool> SaveDebug(string uID, Constants.EXECENVIRONMENTS env, string rawData)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:DEBUG:{env}:{uID}";
|
|
var done = await _redisService.SetAsync(currKey, rawData);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel risultato stima per POR (UID.GroupId) richiesto
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="env"></param>
|
|
/// <param name="estimContent"></param>
|
|
public async Task<bool> SaveProdEstimationAsync(string uid, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS env, string estimContent)
|
|
{
|
|
// salvo in cache
|
|
string currKey = $"{redisBaseKey}:{env}:Estimation:{uid}";
|
|
var done = await _redisService.SetAsync(currKey, estimContent);
|
|
// invio notifica nuova stima sul canale... viene inviato SOLO che è stata fatta (DONE) x UID (POR)...
|
|
string notifyChannel = $"{chEstimation}:{uid}";
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, "DONE");
|
|
//long numSent = await _redisService.PublishAsync(notifyChannel, estimContent);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel risultato balance per POR (UID.GroupId.Type) richiesto
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="env"></param>
|
|
/// <param name="estimContent"></param>
|
|
public async Task<bool> SaveProdBalanceAsync(string uid, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS env, string estimContent)
|
|
{
|
|
// salvo in cache
|
|
string currKey = $"{redisBaseKey}:{env}:Balance:{uid}";
|
|
var done = await _redisService.SetAsync(currKey, estimContent);
|
|
// invio notifica nuova stima sul canale... viene inviato SOLO che è stata fatta (DONE) x UID (POR)...
|
|
string notifyChannel = $"{chBalance}:{uid}";
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, "DONE");
|
|
//long numSent = await _redisService.PublishAsync(notifyChannel, estimContent);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel dedicato HML l'elenco degli HarwareModel (conf preferiti) gestiti
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="rawData"></param>
|
|
public async Task<bool> SaveHmlAsync(string uid, Constants.EXECENVIRONMENTS env, string rawData)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:{env}:HML:{uid.Replace("/", ":")}";
|
|
var done = await _redisService.SetAsync(currKey, rawData);
|
|
// invio notifica nuova svg generata sul canale... viene inviato solo svg con ID nel canale
|
|
string notifyChannel = $"{chHwList}:{uid}";
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, rawData);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel l'XML delle HW options per il doc richiesto
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="env"></param>
|
|
/// <param name="xmlContent"></param>
|
|
public async Task<bool> SaveHwOptAsync(string uid, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS env, string xmlContent)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:{env}:HwOpt:{uid.Replace("/", ":")}";
|
|
// lascio in cache 15 min x poterlo verificare
|
|
var done = await _redisService.SetAsync(currKey, xmlContent, TimeSpan.FromMinutes(15));
|
|
// invio notifica nuova XML sul canale (inviato solo XML pulito con ID nel canale)
|
|
string notifyChannel = $"{chHwOpt}:{uid}";
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, xmlContent);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel img redis SVG per il doc richiesto
|
|
/// </summary>
|
|
/// <param name="imgId"></param>
|
|
/// <param name="pngContent">contenuto PNG come string base64</param>
|
|
/// <returns></returns>
|
|
public bool SavePng(string imgId, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS env, string pngContent)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:{env}:Img:Png:{imgId.Replace("/", ":")}";
|
|
var done = _redisService.Set(currKey, pngContent);
|
|
// invio notifica nuova imgsvg sul canale... viene "reimbustata"
|
|
string notifyChannel = $"png-gen:{imgId}";
|
|
long numSent = _redisService.Publish(notifyChannel, pngContent);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel img redis PNG per il doc richiesto
|
|
/// </summary>
|
|
/// <param name="imgId"></param>
|
|
/// <param name="env"></param>
|
|
/// <param name="pngContent">contenuto PNG come string base64</param>
|
|
public async Task<bool> SavePngAsync(string imgId, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS env, string pngContent)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:{env}:Img:Png:{imgId.Replace("/", ":")}";
|
|
var done = await _redisService.SetAsync(currKey, pngContent);
|
|
// invio notifica nuova png generata sul canale... viene inviato solo contenuto con ID nel canale
|
|
string notifyChannel = $"{chPng}:{imgId}";
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, "PNG");
|
|
// NON pubblico contenuto che x PNG non serve...
|
|
//long numSent = await _redisService.PublishAsync(notifyChannel, pngContent);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel profile list gestiti
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="rawData"></param>
|
|
public async Task<bool> SaveProfileListAsync(string uid, Constants.EXECENVIRONMENTS env, string rawData)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:{env}:PROF:LIST:{uid.Replace("/", ":")}";
|
|
var done = await _redisService.SetAsync(currKey, rawData);
|
|
// invio notifica nuova svg generata sul canale... viene inviato solo svg con ID nel canale
|
|
string notifyChannel = $"{chProfList}:{uid}";
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, rawData);
|
|
return done;
|
|
}
|
|
/// <summary>
|
|
/// Salva e invia su channel profile threshold x profilo gestiti
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="rawData"></param>
|
|
public async Task<bool> SaveProfileThreshAsync(string uid, Constants.EXECENVIRONMENTS env, string rawData)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:{env}:PROF:THRESH:{uid.Replace("/", ":")}";
|
|
var done = await _redisService.SetAsync(currKey, rawData);
|
|
// invio notifica nuova svg generata sul canale... viene inviato solo svg con ID nel canale
|
|
string notifyChannel = $"{chProfThresh}:{uid}";
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, rawData);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel shape per item (UID.GroupId) richiesto
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="env"></param>
|
|
/// <param name="shapeContent"></param>
|
|
public async Task<bool> SaveShapeAsync(string uid, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS env, string shapeContent)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:{env}:Shape:{uid}";
|
|
var done = await _redisService.SetAsync(currKey, shapeContent);
|
|
// invio notifica nuova svg generata sul canale... viene inviato solo svg con ID nel canale
|
|
string notifyChannel = $"{chShape}:{uid}";
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, shapeContent);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel img redis SVG per il doc richiesto
|
|
/// </summary>
|
|
/// <param name="imgId"></param>
|
|
/// <param name="svgContent"></param>
|
|
/// <returns></returns>
|
|
public bool SaveSvg(string imgId, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS env, string svgContent)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:{env}:Img:Svg:{imgId.Replace("/", ":")}";
|
|
var done = _redisService.Set(currKey, svgContent);
|
|
// invio notifica nuova imgsvg sul canale... viene "reimbustata"
|
|
string notifyChannel = $"svg-gen:{imgId}";
|
|
long numSent = _redisService.Publish(notifyChannel, svgContent);
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva e invia su channel img redis SVG per il doc richiesto
|
|
/// </summary>
|
|
/// <param name="imgId"></param>
|
|
/// <param name="env"></param>
|
|
/// <param name="svgContent"></param>
|
|
public async Task<bool> SaveSvgAsync(string imgId, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS env, string svgContent)
|
|
{
|
|
// salvo img in cache
|
|
string currKey = $"{redisBaseKey}:{env}:Img:Svg:{imgId.Replace("/", ":")}";
|
|
var done = await _redisService.SetAsync(currKey, svgContent);
|
|
// invio notifica nuova svg generata sul canale... viene inviato solo contenuto con ID nel canale
|
|
string notifyChannel = $"{chSvg}:{imgId}";
|
|
long numSent = await _redisService.PublishAsync(notifyChannel, svgContent);
|
|
return done;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// Oggetto per la connessione a Redis utilizzato per operazioni di lettura/scrittura.
|
|
/// </summary>
|
|
protected IConnectionMultiplexer _redisConn = null!;
|
|
|
|
/// <summary>
|
|
/// Database Redis utilizzato per le operazioni di lettura/scrittura
|
|
/// nb: ottenuto tramite _redisConn.GetDatabase()
|
|
/// </summary>
|
|
protected IDatabase _redisDb = null!;
|
|
|
|
#endregion Protected Fields
|
|
|
|
/// <summary>
|
|
#if false
|
|
/// Effettua una generica chiamata ApiRest
|
|
/// </summary>
|
|
/// <param name="ApiUrl">URL Api di base</param>
|
|
/// <param name="ApiRequest">Richiesta completa</param>
|
|
/// <param name="JsonBody">Corpo Json trasmesso con richiesta</param>
|
|
/// <returns></returns>
|
|
public async Task<RestResponse> CallRestPost(string ApiUrl, string ApiRequest, string JsonBody)
|
|
{
|
|
RestResponse response;
|
|
// cerco online
|
|
using (RestClient client = new RestClient(ApiUrl))
|
|
{
|
|
var request = new RestRequest(ApiRequest, Method.Post);
|
|
string rawData = JsonConvert.SerializeObject(JsonBody);
|
|
request.AddJsonBody(rawData);
|
|
response = await client.ExecutePostAsync(request);
|
|
}
|
|
return response;
|
|
}
|
|
#endif
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private readonly IRedisService _redisService;
|
|
|
|
private readonly string apiUrl = "";
|
|
|
|
private readonly string cacheTag = "svgfile";
|
|
private readonly string calcTag = "svgpreview";
|
|
private readonly string chBalance = "balance:curr";
|
|
private readonly string chBom = "lux:bom";
|
|
private readonly string chEstimation = "estimation:curr";
|
|
private readonly string chHwList = "lux:hw:list";
|
|
private readonly string chHwOpt = "lux:hw:opt";
|
|
private readonly string chPng = "lux:png:img";
|
|
private readonly string chProfList = "lux:prof:list";
|
|
private readonly string chProfThresh = "lux:prof:thresh";
|
|
private readonly string chShape = "shape:curr";
|
|
private readonly string chSvg = "lux:svg:img";
|
|
private readonly string chUpdate = "lux::update";
|
|
private readonly string imgBasePath = "";
|
|
private readonly string liveTag = "svg";
|
|
private IConfiguration _config;
|
|
|
|
private string imageBaseUrl = "";
|
|
|
|
private string redisBaseKey = "Lux";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
/// <summary>
|
|
/// Conf client RestSharp standard:
|
|
/// - base URI al sito
|
|
/// - timeout 1 min
|
|
/// </summary>
|
|
private RestClientOptions restOptStd { get; set; } = new RestClientOptions();
|
|
|
|
#endregion Private Properties
|
|
}
|
|
} |