diff --git a/MP.Data/Constants.cs b/MP.Data/Constants.cs index 8308ead4..0fde3879 100644 --- a/MP.Data/Constants.cs +++ b/MP.Data/Constants.cs @@ -8,6 +8,9 @@ public static readonly string ACT_MSE_DATA_KEY = $"{BASE_HASH}:Current:MSE"; + 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"; diff --git a/MP.Data/MessagePipe.cs b/MP.Data/MessagePipe.cs index dde3b73a..6b9cac0c 100644 --- a/MP.Data/MessagePipe.cs +++ b/MP.Data/MessagePipe.cs @@ -1,6 +1,8 @@ using NLog; using StackExchange.Redis; using System; +using System.Collections.Generic; +using System.Diagnostics; namespace MP.Data { @@ -27,9 +29,39 @@ namespace MP.Data #endregion Public Events #region Public Methods - + private Dictionary numSent = new Dictionary(); public bool saveAndSendMessage(string memKey, string message) { + bool answ = false; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + + // invio notifica tramite il canale richiesto + answ = sendMessage(message); + if (redisDb != null) + { + redisDb.StringSetAsync(memKey, message); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + if (numSent.ContainsKey(memKey)) + { + numSent[memKey]++; + } + else + { + numSent.Add(memKey, 1); + } + if (enableLog || numSent[memKey] > 30) + { + Log.Info($"saveAndSendMessage| mKey {memKey} x {numSent[memKey]} | {message.Length} size | {ts.TotalMilliseconds} ms"); + + numSent[memKey] = 0; + } + return answ; + +#if false + bool answ = false; // invio notifica tramite il canale richiesto answ = sendMessage(message); @@ -41,7 +73,8 @@ namespace MP.Data Log.Info($"Redis Cache Key: {memKey}"); } } - return answ; + return answ; +#endif } /// diff --git a/MP.SPEC/Components/CmpTop.razor.cs b/MP.SPEC/Components/CmpTop.razor.cs index 7668ad34..ab236b90 100644 --- a/MP.SPEC/Components/CmpTop.razor.cs +++ b/MP.SPEC/Components/CmpTop.razor.cs @@ -28,7 +28,6 @@ namespace MP.SPEC.Components [Inject] protected MpDataService MDService { get; set; } = null!; - protected bool ShowSearch { get => MService.ShowSearch; set => MService.ShowSearch = value; } #endregion Protected Properties @@ -36,7 +35,6 @@ namespace MP.SPEC.Components protected override async Task OnInitializedAsync() { - MService.EA_ShowSearch += MService_EA_ShowSearch; await forceReload(); } @@ -53,7 +51,6 @@ namespace MP.SPEC.Components [Inject] private NavigationManager NavManager { get; set; } = null!; - private string TipoSearch { get => MService.TipoSearch; set => MService.TipoSearch = value; } #endregion Private Properties diff --git a/MP.SPEC/Components/SearchMod.razor b/MP.SPEC/Components/SearchMod.razor index 9b4a379e..8d93eb3d 100644 --- a/MP.SPEC/Components/SearchMod.razor +++ b/MP.SPEC/Components/SearchMod.razor @@ -1,4 +1,4 @@ -@using MP.SPEC.Components +@*@using MP.SPEC.Components @using MP.SPEC.Data @inject MessageService AppMService @@ -52,4 +52,4 @@ searchVal = ""; } -} \ No newline at end of file +}*@ \ No newline at end of file diff --git a/MP.SPEC/Data/MessageService.cs b/MP.SPEC/Data/MessageService.cs index 512434b6..5e41a61d 100644 --- a/MP.SPEC/Data/MessageService.cs +++ b/MP.SPEC/Data/MessageService.cs @@ -4,121 +4,20 @@ { #region Public Events - public event Action EA_PageUpdated = null!; - - public event Action EA_SearchUpdated = null!; - - public event Action EA_ShowSearch = null!; - - public event Action EA_StatoSearch = null!; + public event Action EA_BroadCastMsg = null!; #endregion Public Events #region Public Properties - - public int currPage + public string newBCMsg { - get => _currPage; + get => _newBCMsg; set { - if (_currPage != value) + if(_newBCMsg != value) { - _currPage = value; - if (EA_PageUpdated != null) - { - EA_PageUpdated?.Invoke(); - } - } - } - } - - public int numRecord - { - get => _numRecord; - set - { - if (_numRecord != value) - { - _numRecord = value; - if (EA_PageUpdated != null) - { - EA_PageUpdated?.Invoke(); - } - } - } - } - - public string SearchVal - { - get => searchVal; - set - { - //if (searchVal != value) - //{ - searchVal = value; - - if (EA_SearchUpdated != null) - { - EA_SearchUpdated?.Invoke(); - } - //} - } - } - - public bool ShowSearch - { - get => showSearch; - set - { - if (showSearch != value) - { - showSearch = value; - if (EA_ShowSearch != null) - { - EA_ShowSearch?.Invoke(); - } - } - } - } - - public string StateSel - { - get => stateSel; - set - { - stateSel = value; - - if (EA_StatoSearch != null) - { - EA_StatoSearch?.Invoke(); - } - } - } - - public string TipoSearch - { - get => tipoSearch; - set - { - if (tipoSearch != value) - { - tipoSearch = value; - if (EA_ShowSearch != null) - { - EA_ShowSearch?.Invoke(); - } - } - } - } - - public int totalCount - { - get => _totalCount; - set - { - if (_totalCount != value) - { - _totalCount = value; + _newBCMsg = value; + reportMsg(); } } } @@ -127,19 +26,11 @@ #region Protected Methods - protected void reportPaging() + protected void reportMsg() { - if (EA_PageUpdated != null) + if (EA_BroadCastMsg != null) { - EA_PageUpdated?.Invoke(); - } - } - - protected void reportSearch() - { - if (EA_SearchUpdated != null) - { - EA_SearchUpdated?.Invoke(); + EA_BroadCastMsg?.Invoke(); } } @@ -147,19 +38,11 @@ #region Private Fields - private string searchVal = ""; - private bool showSearch; - private string stateSel = "*"; - private string tipoSearch = ""; - #endregion Private Fields #region Private Properties - private int _currPage { get; set; } = 1; - - private int _numRecord { get; set; } = 10; - private int _totalCount { get; set; } = 0; + private string _newBCMsg { get; set; } = ""; #endregion Private Properties } diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 5cb0397d..d146c80c 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -23,7 +23,7 @@ namespace MP.SPEC.Data redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis")); redisConnAdmin = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("RedisAdmin")); redisDb = redisConn.GetDatabase(); - + BroadastMsgPipe = new MessagePipe(redisConn, Constants.BROADCAST_M_PIPE); // leggo cache lungo periodo int.TryParse(_configuration.GetValue("ServerConf:redisLongTimeCache"), out redisLongTimeCache); @@ -1372,12 +1372,13 @@ namespace MP.SPEC.Data private const string redisPOdlByOdl = redisXdlData + ":POdlByOdl"; private const string redisPOdlByPOdl = redisXdlData + ":POdlByPOdl"; private const string redisPOdlList = redisXdlData + ":POdlList"; - private const string redisPOdlListNOOdl = redisXdlData + ":POdlListNOOdl"; private const string redisStatoCom = redisBaseAddr + "SPEC:Cache:StatoCom"; private const string redisTipoArt = redisBaseAddr + "SPEC:Cache:TipoArt"; private const string redisVocabolario = redisBaseAddr + "SPEC:Cache:Vocabolario"; private const string redisXdlData = redisBaseAddr + "SPEC:Cache:XDL"; private static IConfiguration _configuration = null!; + + public MessagePipe BroadastMsgPipe { get; set; } = null!; private static ILogger _logger = null!; diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index fa781fe8..83f09fd0 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2212.115 + 6.16.2212.216 diff --git a/MP.SPEC/Pages/Contacts.razor.cs b/MP.SPEC/Pages/Contacts.razor.cs index 8e8a2ef5..d2421bf3 100644 --- a/MP.SPEC/Pages/Contacts.razor.cs +++ b/MP.SPEC/Pages/Contacts.razor.cs @@ -24,7 +24,6 @@ namespace MP.SPEC.Pages { Titolo = "MP SPEC"; Messaggio = "I nostri contattatti e siti di supporto"; - AppMService.ShowSearch = false; } #endregion Protected Methods diff --git a/MP.SPEC/Pages/Index.razor.cs b/MP.SPEC/Pages/Index.razor.cs index 1193385d..421acf29 100644 --- a/MP.SPEC/Pages/Index.razor.cs +++ b/MP.SPEC/Pages/Index.razor.cs @@ -27,7 +27,6 @@ namespace MP.SPEC.Pages protected override async Task OnInitializedAsync() { // nascondo ricerca - MessageService.ShowSearch = false; // recupero elenco JQM ElencoLink = await MDService.ElencoLink(); #if false diff --git a/MP.SPEC/Pages/Test.razor b/MP.SPEC/Pages/Test.razor index be6e0035..180b8569 100644 --- a/MP.SPEC/Pages/Test.razor +++ b/MP.SPEC/Pages/Test.razor @@ -1,7 +1,7 @@ @page "/Test"

Test

- +@* @@ -25,8 +25,8 @@ - +*@ + +@messaggio -@code { -} diff --git a/MP.SPEC/Pages/Test.razor.cs b/MP.SPEC/Pages/Test.razor.cs new file mode 100644 index 00000000..2bbd4e0a --- /dev/null +++ b/MP.SPEC/Pages/Test.razor.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using System.Net.Http; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Components.Routing; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.Web.Virtualization; +using Microsoft.JSInterop; +using MP.SPEC; +using MP.SPEC.Shared; +using MP.SPEC.Components; +using MP.Data; +using Newtonsoft.Json; +using MP.SPEC.Data; + +namespace MP.SPEC.Pages +{ + public partial class Test : IDisposable + { + [Inject] + protected MpDataService MMDataService { get; set; } = null!; + + protected string messaggio = "0"; + protected DateTime lastRec = DateTime.Now.AddMinutes(-1); + private void BroadCastMsg_EA_NewMessage(object? sender, EventArgs e) + { + DateTime adesso = DateTime.Now; + if (lastRec.AddSeconds(2) < adesso) + { + PubSubEventArgs currArgs = (PubSubEventArgs)e; + if (!string.IsNullOrEmpty(currArgs.newMessage)) + { + lastRec = adesso; + try + { + var result = JsonConvert.DeserializeObject(currArgs.newMessage); + if(result != null) + { + messaggio = result; + } + } + catch + { } + InvokeAsync(() => + { + StateHasChanged(); + }); + } + } + } + public void Dispose() + { + MMDataService.BroadastMsgPipe.EA_NewMessage += BroadCastMsg_EA_NewMessage; + } + + protected override async Task OnInitializedAsync() + { + await Task.Delay(1); + MMDataService.BroadastMsgPipe.EA_NewMessage += BroadCastMsg_EA_NewMessage; + } + + } +} \ No newline at end of file diff --git a/MP.SPEC/Pages/TestBtn.razor b/MP.SPEC/Pages/TestBtn.razor new file mode 100644 index 00000000..8b289ab2 --- /dev/null +++ b/MP.SPEC/Pages/TestBtn.razor @@ -0,0 +1,10 @@ +@page "/TestBtn" +

TestBtn

+ + + + + + + + diff --git a/MP.SPEC/Pages/TestBtn.razor.cs b/MP.SPEC/Pages/TestBtn.razor.cs new file mode 100644 index 00000000..4f88a6c7 --- /dev/null +++ b/MP.SPEC/Pages/TestBtn.razor.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using System.Net.Http; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Components.Routing; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.Web.Virtualization; +using Microsoft.JSInterop; +using MP.SPEC; +using MP.SPEC.Shared; +using MP.SPEC.Components; +using MP.SPEC.Data; +using System.Text; + +namespace MP.SPEC.Pages +{ + public partial class TestBtn + { + [Inject] + protected MessageService MService { get; set; } = null!; + + public EventCallback newBcMsg { get; set; } + + protected override async Task OnInitializedAsync() + { + await Task.Delay(1); + MService.EA_BroadCastMsg += OnNewBCMsg; + } + + public async void OnNewBCMsg() + { + await InvokeAsync(() => + { + StateHasChanged(); + }); + } + StringBuilder sb = new StringBuilder(); + protected async Task addOne() + { + await Task.Delay(1); + sb.Append("1"); + countMsg = sb.ToString(); + } + + public string countMsg + { + get + { + return MService.newBCMsg; + } + set + { + MService.newBCMsg = value; + reportChange(); + } + } + + private void reportChange() + { + newBcMsg.InvokeAsync(countMsg); + } + } +} \ No newline at end of file diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 8a8db222..517a957d 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2212.115

+

Versione: 6.16.2212.216


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index cbfb93c9..93ac9c74 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2212.115 +6.16.2212.216 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index f0ccd759..e54eca76 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2212.115 + 6.16.2212.216 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false