From 15328983299a7cf2a2977735dae7c0e35e8a3aba Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 26 May 2020 13:01:37 +0200 Subject: [PATCH 1/3] Fix client/server for Signal-r, test OK! --- Thermo.Active/App_Start/Startup.cs | 14 ++--- .../Listeners/SignalR/SignalRListener.cs | 4 +- Thermo.Active/wwwroot/index.html | 2 +- Thermo.Active/wwwroot/src/services/hub.ts | 54 ++++++++++++------- 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/Thermo.Active/App_Start/Startup.cs b/Thermo.Active/App_Start/Startup.cs index 29d585b8..6bf7ef02 100644 --- a/Thermo.Active/App_Start/Startup.cs +++ b/Thermo.Active/App_Start/Startup.cs @@ -64,7 +64,7 @@ namespace Thermo.Active.App_Start RequestPath = PathString.Empty, FileSystem = new PhysicalFileSystem(WEBSITE_DIRECTORY) }; - + app.UseFileServer(options); if (!ServerPortIsAvailable(ServerStartupConfig.ServerPort)) { @@ -106,12 +106,12 @@ namespace Thermo.Active.App_Start app.Map("/signalr", map => { map.UseCors(CorsOptions.AllowAll); - - //map.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions() - //{ - // Provider = new SignalROAuthBearerProvider(), - // AuthenticationType = AUTHENTICATION_TYPE - //}); + + map.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions() + { + Provider = new SignalROAuthBearerProvider(), + AuthenticationType = AUTHENTICATION_TYPE + }); var hubConfiguration = new HubConfiguration { Resolver = GlobalHost.DependencyResolver, diff --git a/Thermo.Active/Listeners/SignalR/SignalRListener.cs b/Thermo.Active/Listeners/SignalR/SignalRListener.cs index 68f08c27..7da335f9 100644 --- a/Thermo.Active/Listeners/SignalR/SignalRListener.cs +++ b/Thermo.Active/Listeners/SignalR/SignalRListener.cs @@ -304,7 +304,6 @@ namespace Thermo.Active.Listeners.SignalR var context = GlobalHost.ConnectionManager.GetHubContext(); context.Clients.Group("ncData").recipeFullData(diffData); - //context.Clients.Group("ncData").recipeFullData(currRecipeFull); } } @@ -352,7 +351,6 @@ namespace Thermo.Active.Listeners.SignalR { GaugeModel currGauge = gaugeData as GaugeModel; - // FIXME TODO: usare un foreach comparer? if (!LastGaugeData.Equals(currGauge)) { LastGaugeData = currGauge; @@ -433,6 +431,8 @@ namespace Thermo.Active.Listeners.SignalR group.recipeModulesData(LastModulesData); // Send THERMO Warmers data group.recipeWarmersData(LastWarmersData); + // THERMO Gauges + group.gaugeData(LastGaugeData); Debug.WriteLine(string.Format("{0} {1} Broadcast..completed", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), DateTime.Now.Millisecond)); Monitor.Exit(_broadcastlock); diff --git a/Thermo.Active/wwwroot/index.html b/Thermo.Active/wwwroot/index.html index fdd93267..132cf26d 100644 --- a/Thermo.Active/wwwroot/index.html +++ b/Thermo.Active/wwwroot/index.html @@ -13,7 +13,7 @@ - + diff --git a/Thermo.Active/wwwroot/src/services/hub.ts b/Thermo.Active/wwwroot/src/services/hub.ts index 391dd772..01c18c1f 100644 --- a/Thermo.Active/wwwroot/src/services/hub.ts +++ b/Thermo.Active/wwwroot/src/services/hub.ts @@ -66,33 +66,47 @@ export class Hub { this._hub = $.connection.ncHub; + $.connection.hub.error(function(error, exc) { + console.log('SignalrAdapter: ' + error, exc); + }); + + $.connection.hub.url="http://localhost:9000/signalr"; + +// debugger + try { $.connection.hub.logging = true; } catch{ } try { $.connection.ncHub.logging = true; } catch{ } // Registro le callback; - // this._hub.client.alarms = this.manageAlarmsCallbacks; + this._hub.client.alarms = this.manageAlarmsCallbacks; this._hub.client.powerOn = this.managePowerCallbacks; - // this._hub.client.ncNetworkStatus = Hub.manageNcStatus; - // this._hub.client.processesData = Hub.manageProcesses; - // this._hub.client.functionalityData = Hub.functionalityData; - // this._hub.client.expiredMaintenances = Hub.expiredMaintenances; + this._hub.client.ncNetworkStatus = Hub.manageNcStatus; + this._hub.client.processesData = Hub.manageProcesses; + this._hub.client.functionalityData = Hub.functionalityData; + this._hub.client.expiredMaintenances = Hub.expiredMaintenances; - // this._hub.client.ncSoftKeys = Hub.ncSoftKeyChanged; - // this._hub.client.userSoftKeys = Hub.userSoftKeyChanged; - // this._hub.client.headsData = Hub.headsDataChanged; - // this._hub.client.processesData = Hub.processDataChanged; - // this._hub.client.axesNames = Hub.axesNamesDataChanged; - // this._hub.client.axesPositions = Hub.axesPositionsDataChanged; - // this._hub.client.magazinesStatus = Hub.magazineStatusChanged; - // this._hub.client.activeProgramData = Hub.activeProgramData; + this._hub.client.ncSoftKeys = Hub.ncSoftKeyChanged; + this._hub.client.userSoftKeys = Hub.userSoftKeyChanged; + this._hub.client.headsData = Hub.headsDataChanged; + this._hub.client.processesData = Hub.processDataChanged; + this._hub.client.axesNames = Hub.axesNamesDataChanged; + this._hub.client.axesPositions = Hub.axesPositionsDataChanged; + this._hub.client.magazinesStatus = Hub.magazineStatusChanged; + this._hub.client.activeProgramData = Hub.activeProgramData; // this._hub.client.magazineIsActive = Hub.magazineIsActive; - // this._hub.client.m155Data = Hub.m155Data; - // this._hub.client.partProgramQueue = Hub.partProgramQueue; + this._hub.client.m155Data = Hub.m155Data; + this._hub.client.partProgramQueue = Hub.partProgramQueue; // this._hub.client.scadaData = Hub.scadaDataChanged; - // this._hub.client.cmsConnectGatewayRebbot = Hub.cmsConnectGatewayRebbot; + this._hub.client.cmsConnectGatewayRebbot = Hub.cmsConnectGatewayRebbot; + + // qui i NUOVI metodi NUOVI dal server (Recipe, gauges) da completare lato HUB + // this._hub.client.recipeFullData = Hub.recipeFullData; + // this._hub.client.recipeOverData = Hub.recipeOverData; + // this._hub.client.modulesData = Hub.modulesData; + // this._hub.client.warmersData = Hub.warmersData; + // this._hub.client.gaugeData = Hub.gaugeData; - // sottoscrivere qui i metodi NUOVI dal server (Recipe, gauges) this._hub.client.logout = this.logout; @@ -107,7 +121,8 @@ export class Hub { Hub.manageServerStatus("disconnected"); console.log("SERVER CONNECTION: restart-connection") setTimeout(function () { - $.connection.hub.start({ transport: ['serverSentEvents'] }); + $.connection.hub.start(); + // $.connection.hub.start({ transport: ['serverSentEvents'] }); }, 5000); // Restart connection after 5 seconds. }); // $.connection.hub.stateChanged(async (state) => { @@ -120,7 +135,8 @@ export class Hub { // } // }) - $.connection.hub.start({ transport: ['serverSentEvents'] }); + $.connection.hub.start(); + // $.connection.hub.start({ transport: ['serverSentEvents'] }); this.checkShowAxes(); From c020a5588b2ba73cf52e6e9a4803b05f0bfa8104 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 26 May 2020 13:04:10 +0200 Subject: [PATCH 2/3] Update vers number --- Thermo.Active/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Thermo.Active/Properties/AssemblyInfo.cs b/Thermo.Active/Properties/AssemblyInfo.cs index 8f4b9784..61cf208b 100644 --- a/Thermo.Active/Properties/AssemblyInfo.cs +++ b/Thermo.Active/Properties/AssemblyInfo.cs @@ -31,4 +31,4 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.2.3")] +[assembly: AssemblyVersion("0.3.2")] From 2e84a57cfbba6e567c3c6ef3323c4b77fc0af75f Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 26 May 2020 19:16:51 +0200 Subject: [PATCH 3/3] Added pause after thread start on init (it RUNS!) --- Thermo.Active.Core/ThreadsHandler.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Thermo.Active.Core/ThreadsHandler.cs b/Thermo.Active.Core/ThreadsHandler.cs index 49bc82d0..ff2a4420 100644 --- a/Thermo.Active.Core/ThreadsHandler.cs +++ b/Thermo.Active.Core/ThreadsHandler.cs @@ -48,6 +48,7 @@ namespace Thermo.Active.Core { Thread t = new Thread(() => ThreadSetupCmsConnect()); t.Start(); + Thread.Sleep(50); } } @@ -64,6 +65,8 @@ namespace Thermo.Active.Core threadFunction() ); t.Start(); + // aggiungo pausa x evitare sovrapposizioni chiamate + Thread.Sleep(50); // Add thread to running threads list lock (RunningThreadsList) RunningThreadsList.Add(t);