From 76b51ea3c59497ff5d02ecee505454ed574b49ad Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Tue, 20 Feb 2018 17:03:03 +0100 Subject: [PATCH] Refactor --- .../Controllers/MachinesController.cs | 1 - .../Controllers/MachinesUsersController.cs | 3 +- .../Controllers/MaintenancesController.cs | 13 +-- Step.Database/DatabaseContext.cs | 7 +- Step.Database/Migrations/Configuration.cs | 11 +- Step.Tasks/ThreadsFunctions.cs | 100 ++---------------- Step.Tasks/ThreadsHandler.cs | 14 ++- Step.Utils/LanguageController.cs | 12 +-- Step.Utils/StepLogger.cs | 11 +- Step/Attributes/SignalRAuthorizeAttribute.cs | 13 ++- Step/Controllers/SignalR/DataHub.cs | 17 --- Step/Controllers/SignalR/NcHub.cs | 5 + .../WebApi/AuthorizationController.cs | 11 +- .../WebApi/ConfigurationController.cs | 6 +- Step/Controllers/WebApi/LanguageController.cs | 16 ++- Step/Controllers/WebApi/NcApiController.cs | 16 +-- Step/Controllers/WebApi/UserController.cs | 25 +++-- Step/Listeners/ListenersHandler.cs | 9 -- Step/Listeners/SignalR/SignalRListener.cs | 6 -- Step/Provider/SignalROAuthBearerProvider.cs | 15 +-- Step/Step.csproj | 1 - 21 files changed, 84 insertions(+), 228 deletions(-) delete mode 100644 Step/Controllers/SignalR/DataHub.cs diff --git a/Step.Database/Controllers/MachinesController.cs b/Step.Database/Controllers/MachinesController.cs index aeea468d..a4ea416a 100644 --- a/Step.Database/Controllers/MachinesController.cs +++ b/Step.Database/Controllers/MachinesController.cs @@ -42,7 +42,6 @@ namespace Step.Database.Controllers // Create database machine model MachineModel machine = new MachineModel() { - MachineId = 1, Model = NcConfig.NcName, UniqueId = uniqueId }; diff --git a/Step.Database/Controllers/MachinesUsersController.cs b/Step.Database/Controllers/MachinesUsersController.cs index 906f7df6..7f392597 100644 --- a/Step.Database/Controllers/MachinesUsersController.cs +++ b/Step.Database/Controllers/MachinesUsersController.cs @@ -44,7 +44,8 @@ namespace Step.Database.Controllers public MachineUserModel Create(int machineId, int userId, int roleId) { // Create database model - MachineUserModel machine = new MachineUserModel() { + MachineUserModel machine = new MachineUserModel() + { MachineId = machineId, UserId = userId, RoleId = roleId diff --git a/Step.Database/Controllers/MaintenancesController.cs b/Step.Database/Controllers/MaintenancesController.cs index 20821a8a..8f3db2ae 100644 --- a/Step.Database/Controllers/MaintenancesController.cs +++ b/Step.Database/Controllers/MaintenancesController.cs @@ -1,6 +1,4 @@ -using Step.Model.ConfigModels; -using Step.Model.DatabaseModels; -using Step.Model.DTOModels; +using Step.Model.DatabaseModels; using System; using System.Collections.Generic; using System.Linq; @@ -29,7 +27,7 @@ namespace Step.Database.Controllers List lastMaintenances = new List(); // Find last performed maintenance lastMaintenances = (from maintenances in dbCtx.PerformedMaintenances - where maintenances.Date == (from m1 in dbCtx.PerformedMaintenances // Select max data of performed maintenance + where maintenances.Date == (from m1 in dbCtx.PerformedMaintenances // Select max data of performed maintenance where m1.MaintenanceId == maintenances.MaintenanceId select m1.Date ).Max() @@ -58,7 +56,7 @@ namespace Step.Database.Controllers .Maintenances .ToList(); - // Find database rows that + // Find database rows that List toDeleteMaint = dbMaintenances.Where(x => !MaintenancesConfig.Select(y => y.Id).Contains(x.MaintenanceId) ).ToList(); @@ -68,7 +66,7 @@ namespace Step.Database.Controllers dbCtx.Maintenances.Remove(item); dbCtx.SaveChanges(); - // Find common data from + // Find common data from List toUpdateMaint = dbMaintenances.Where(x => MaintenancesConfig.Select(y => y.Id).Contains(x.MaintenanceId) ) @@ -90,7 +88,6 @@ namespace Step.Database.Controllers old.Type = x.Type; old.CounterId = x.CouterId; return old; - }).FirstOrDefault(); } @@ -130,4 +127,4 @@ namespace Step.Database.Controllers } } } -} +} \ No newline at end of file diff --git a/Step.Database/DatabaseContext.cs b/Step.Database/DatabaseContext.cs index e865ff0d..4610909f 100644 --- a/Step.Database/DatabaseContext.cs +++ b/Step.Database/DatabaseContext.cs @@ -26,7 +26,6 @@ namespace Step.Database public DbSet Maintenances { get; set; } public DbSet PerformedMaintenances { get; set; } - public DatabaseContext() : base("mySQLDatabaseConnection") { @@ -63,12 +62,11 @@ namespace Step.Database { maintenancesController.CheckDifferencesFromDbAndXml(); } - + using (FunctionsAccessController functionsAccess = new FunctionsAccessController()) { FunctionsAccessConfig = functionsAccess.FindAll(); } - } catch (MySql.Data.MySqlClient.MySqlException ex) { @@ -132,14 +130,17 @@ namespace Step.Database MachineConfig = machinesController.FindMachineByUniqueId(uniqueId); if (MachineConfig == null) { + // Create Machine inside database MachineConfig = machinesController.Create(uniqueId); using (UsersController usersController = new UsersController()) { + // Create default CMS user usersController.CreateCmsDefaultUserIfNotExists(MachineConfig.MachineId); } } else { + // if config name is different than dabase name, update db if (MachineConfig.Model != NcConfig.NcName) machinesController.UpdateMachineName(MachineConfig.MachineId, NcConfig.NcName); } diff --git a/Step.Database/Migrations/Configuration.cs b/Step.Database/Migrations/Configuration.cs index 8bef0dec..e71df2f6 100644 --- a/Step.Database/Migrations/Configuration.cs +++ b/Step.Database/Migrations/Configuration.cs @@ -1,12 +1,7 @@ namespace Step.Database.Migrations { - using Step.Database.Controllers; using Step.Model.DatabaseModels; - using System; - using System.Data.Entity; using System.Data.Entity.Migrations; - using System.Globalization; - using System.Linq; using static Step.Utils.Constants; public sealed class Configuration : DbMigrationsConfiguration @@ -27,16 +22,16 @@ namespace Step.Database.Migrations ); context.FunctionsAccess.AddOrUpdate( - // General Function + // General Function new FunctionAccessModel() { FunctionAccessId = 1, Name = "functionAccess", Area = AREAS.GENERAL_KEY, Enabled = true, WriteLevelMin = 100, ReadLevelMin = 1, PlcId = -1 }, new FunctionAccessModel() { FunctionAccessId = 2, Name = "logout", Area = AREAS.GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = -1 }, new FunctionAccessModel() { FunctionAccessId = 3, Name = "userData", Area = AREAS.GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = -1 }, new FunctionAccessModel() { FunctionAccessId = 4, Name = "ncData", Area = AREAS.GENERAL_KEY, Enabled = true, WriteLevelMin = 10, ReadLevelMin = 1, PlcId = -1 }, new FunctionAccessModel() { FunctionAccessId = 5, Name = "startupIcons", Area = AREAS.GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0 }, - new FunctionAccessModel() { FunctionAccessId = 6, Name = "alarmCmd", Area = AREAS.GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 1} + new FunctionAccessModel() { FunctionAccessId = 6, Name = "alarmCmd", Area = AREAS.GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 1 } ); context.SaveChanges(); } } -} +} \ No newline at end of file diff --git a/Step.Tasks/ThreadsFunctions.cs b/Step.Tasks/ThreadsFunctions.cs index ed73f826..b2cdcdf5 100644 --- a/Step.Tasks/ThreadsFunctions.cs +++ b/Step.Tasks/ThreadsFunctions.cs @@ -13,7 +13,6 @@ public static class ThreadsFunctions { public static bool reconnectionIsRunning = false; private static long ReadAlarmsTimer = 0, ReadAlarmsTimes = 0; - private static long ReadNcGenericInfoTimer = 0, ReadNcGenericInfoTimes = 0; private static long ReadAxesTimer = 0, ReadAxesTimes = 0; private static long ReadPowerOnTimer = 0, ReadPowerOnTimes = 0; private static long ReadProcPPTimer = 0, ReadProcPPTimes = 0; @@ -67,89 +66,6 @@ public static class ThreadsFunctions } } - public static void ReadNcGenericInfo() - { - NcHandler ncHandler = new NcHandler(); - Stopwatch sw = new Stopwatch(); - - try - { - CmsError libraryError = ncHandler.Connect(); - if (libraryError.errorCode != 0) - ManageLibraryError(libraryError); - - while (true) - { - sw.Restart(); - if (ncHandler.numericalControl.NC_IsConnected()) - { - // Get Generic data from NC - libraryError = ncHandler.GetNcGenericData(out DTONcGenericDataModel genericData); - if (libraryError.errorCode != 0) - ManageLibraryError(libraryError); - else - // Send through signalR - MessageServices.Current.Publish(SEND_GENERIC_DATA, null, genericData); - } - else - TryNcConnection(); - - sw.Stop(); - - //Send to the UI the time - ReadNcGenericInfoTimer += sw.ElapsedMilliseconds; - ReadNcGenericInfoTimes++; - - Thread.Sleep(1000); - } - } - catch (ThreadAbortException) - { - ncHandler.Dispose(); - } - } - - public static void ReadAxes() - { - NcHandler ncHandler = new NcHandler(); - Stopwatch sw = new Stopwatch(); - - try - { - CmsError libraryError = ncHandler.Connect(); - if (libraryError.errorCode != 0) - ManageLibraryError(libraryError); - - while (true) - { - sw.Restart(); - if (ncHandler.numericalControl.NC_IsConnected()) - { - // Get the list of the axes - libraryError = ncHandler.GetAxesPositions(out List genericData); - if (libraryError.errorCode != 0) - ManageLibraryError(libraryError); - else - // Send through signalR - MessageServices.Current.Publish(SEND_AXES, null, genericData); - } - else - TryNcConnection(); - sw.Stop(); - - //Send to the UI the time - ReadAxesTimer += sw.ElapsedMilliseconds; - ReadAxesTimes++; - - Thread.Sleep(200); - } - } - catch (ThreadAbortException) - { - ncHandler.Dispose(); - } - } - public static void ReadPowerOnData() { NcHandler ncHandler = new NcHandler(); @@ -434,13 +350,6 @@ public static class ThreadsFunctions ReadAlarmsTimes = 0; } - if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadNcGenericInfo") && ReadNcGenericInfoTimes != 0) - { - ThreadsHandler.RunningThreadStatus["ReadNcGenericInfo"] = (ReadNcGenericInfoTimer / ReadNcGenericInfoTimes) + " mS"; - ReadNcGenericInfoTimer = 0; - ReadNcGenericInfoTimes = 0; - } - if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadAxes") && ReadAxesTimes != 0) { ThreadsHandler.RunningThreadStatus["ReadAxes"] = (ReadAxesTimer / ReadAxesTimes) + " mS"; @@ -474,7 +383,6 @@ public static class ThreadsFunctions ReadMaintenanceTimer = 0; ReadMaintenanceTimes = 0; } - MessageServices.Current.Publish(SEND_THREADS_STATUS, null, ThreadsHandler.RunningThreadStatus); @@ -487,10 +395,14 @@ public static class ThreadsFunctions { ReadAlarmsTimer = 0; ReadAlarmsTimes = 0; - ReadNcGenericInfoTimer = 0; - ReadNcGenericInfoTimes = 0; ReadAxesTimer = 0; ReadAxesTimes = 0; + ReadProcPPTimer = 0; + ReadProcPPTimes = 0; + ReadFunctionTimer = 0; + ReadFunctionTimes = 0; + ReadMaintenanceTimer = 0; + ReadMaintenanceTimes = 0; } #endregion SupportFunctions diff --git a/Step.Tasks/ThreadsHandler.cs b/Step.Tasks/ThreadsHandler.cs index e3db4438..297887d1 100644 --- a/Step.Tasks/ThreadsHandler.cs +++ b/Step.Tasks/ThreadsHandler.cs @@ -11,8 +11,6 @@ namespace Step.Core private static List ThreadFunctionsList = new List { ThreadsFunctions.ReadAlarms, - ThreadsFunctions.ReadNcGenericInfo, - ThreadsFunctions.ReadAxes, ThreadsFunctions.ReadPowerOnData, ThreadsFunctions.StatThread, ThreadsFunctions.ReadProcessesPPStatus, @@ -36,13 +34,13 @@ namespace Step.Core // For each function run in the list a thread ThreadFunctionsList.ForEach(threadFunction => { - // Run new Thread in the list - Thread t = new Thread(() => - threadFunction() - ); + // Run new Thread in the list + Thread t = new Thread(() => + threadFunction() + ); t.Start(); - // Add thread to running threads list - lock (RunningThreadsList) + // Add thread to running threads list + lock (RunningThreadsList) RunningThreadsList.Add(t); RunningThreadStatus.Add(threadFunction.Method.Name, "---"); diff --git a/Step.Utils/LanguageController.cs b/Step.Utils/LanguageController.cs index 60b5ca77..4fe07744 100644 --- a/Step.Utils/LanguageController.cs +++ b/Step.Utils/LanguageController.cs @@ -1,15 +1,11 @@ -using System; +using Step.Model.DTOModels; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Xml.Linq; using System.Xml.Schema; -using Step.Model.DTOModels; using static Step.Utils.Constants; - namespace Step.Utils { @@ -29,7 +25,7 @@ namespace Step.Utils return true; } - + public static Dictionary GetTranslationsFromFile(string language) { CultureInfo lang = CultureInfo.CreateSpecificCulture(language); @@ -43,7 +39,7 @@ namespace Step.Utils //if (!ValidateTranslationsFile(xmlLanguageFile, LANGUAGE_SCHEMA_PATH)) // return null; - // Read file content + // Read file content return xmlLanguageFile .Root .Elements() @@ -114,4 +110,4 @@ namespace Step.Utils FileIsValid = false; } } -} +} \ No newline at end of file diff --git a/Step.Utils/StepLogger.cs b/Step.Utils/StepLogger.cs index 689c5211..b2db30f7 100644 --- a/Step.Utils/StepLogger.cs +++ b/Step.Utils/StepLogger.cs @@ -1,5 +1,5 @@ -using System; -using NLog; +using NLog; +using System; using static Step.Utils.Constants; namespace Step.Utils @@ -7,7 +7,7 @@ namespace Step.Utils public static class StepLogger { private static Logger Log = LogManager.GetCurrentClassLogger(); - + public static void LogException(Exception ex, ERROR_LEVEL errorLevel) { LogMessage(ex.Message, errorLevel); @@ -22,16 +22,19 @@ namespace Step.Utils Log.Info(message); } break; + case ERROR_LEVEL.WARNING: { Log.Warn(message); } break; + case ERROR_LEVEL.ERROR: { Log.Error(message); } break; + case ERROR_LEVEL.FATAL: { Log.Fatal(message); @@ -60,4 +63,4 @@ namespace Step.Utils Log.Fatal(message); } } -} +} \ No newline at end of file diff --git a/Step/Attributes/SignalRAuthorizeAttribute.cs b/Step/Attributes/SignalRAuthorizeAttribute.cs index af050436..899e6d09 100644 --- a/Step/Attributes/SignalRAuthorizeAttribute.cs +++ b/Step/Attributes/SignalRAuthorizeAttribute.cs @@ -19,10 +19,10 @@ namespace Step.Attributes public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request) { - string token = request.Headers["Authorization"]; - if (string.IsNullOrWhiteSpace(token)) - return false; - + string token = request.QueryString["connectionToken"]; + //if (string.IsNullOrWhiteSpace(token)) + // return false; + //request.Environment["server.User"] = "ciao"; return base.AuthorizeHubConnection(hubDescriptor, request); } @@ -53,6 +53,11 @@ namespace Step.Attributes return true; } + public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod) + { + return base.AuthorizeHubMethodInvocation(hubIncomingInvokerContext, appliesToMethod); + } + private bool CheckAuthorization(int machineId, int userId, string functionName, string token) { // Check if the machine is the same where the user logged in diff --git a/Step/Controllers/SignalR/DataHub.cs b/Step/Controllers/SignalR/DataHub.cs deleted file mode 100644 index 9e636dac..00000000 --- a/Step/Controllers/SignalR/DataHub.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using Microsoft.AspNet.SignalR; -using Microsoft.AspNet.SignalR.Hubs; - -namespace Step.Controllers.SignalR -{ - public class DataHub : Hub - { - public void Hello() - { - Clients.All.hello("Ciao"); - } - } -} diff --git a/Step/Controllers/SignalR/NcHub.cs b/Step/Controllers/SignalR/NcHub.cs index 29969a6e..ebb63f06 100644 --- a/Step/Controllers/SignalR/NcHub.cs +++ b/Step/Controllers/SignalR/NcHub.cs @@ -4,17 +4,21 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.SignalR; +using Step.Attributes; using Step.NC; using TeamDev.SDK.MVVM; using static Step.Utils.Constants; namespace Step.Controllers.SignalR { + [SignalRAuthorize(FunctionAccess = "functionAccess", Action = ACTIONS.READ)] + public class NcHub : Hub { public static List ConnectedClients = new List(); public static bool NewConnectedClients = false; + public override Task OnConnected() { Groups.Add(Context.ConnectionId, "ncData"); @@ -55,6 +59,7 @@ namespace Step.Controllers.SignalR } } + [SignalRAuthorize(FunctionAccess = "functionAccess", Action = ACTIONS.READ)] public void RefreshAllAlarms() { using (NcHandler ncHandler = new NcHandler()) diff --git a/Step/Controllers/WebApi/AuthorizationController.cs b/Step/Controllers/WebApi/AuthorizationController.cs index 0262f202..371da28d 100644 --- a/Step/Controllers/WebApi/AuthorizationController.cs +++ b/Step/Controllers/WebApi/AuthorizationController.cs @@ -1,22 +1,21 @@ -using System; +using Step.Database.Controllers; +using Step.Model.DTOModels; +using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Web.Http; -using Step.Database.Controllers; -using Step.Model.DTOModels; using static Step.Utils.Constants; namespace Step.Controllers.WebApi { - [RoutePrefix("api/authorization")] public class AuthorizationController : ApiController { [Route("functions"), HttpGet] [WebApiAuthorize(FunctionAccess = "functionAccess", Action = ACTIONS.READ)] public IHttpActionResult GetFunctionsConfig() - { + { using (FunctionsAccessController acController = new FunctionsAccessController()) { var identity = User.Identity as ClaimsIdentity; @@ -32,4 +31,4 @@ namespace Step.Controllers.WebApi } } } -} +} \ No newline at end of file diff --git a/Step/Controllers/WebApi/ConfigurationController.cs b/Step/Controllers/WebApi/ConfigurationController.cs index 8b8e749c..93c206b9 100644 --- a/Step/Controllers/WebApi/ConfigurationController.cs +++ b/Step/Controllers/WebApi/ConfigurationController.cs @@ -14,10 +14,10 @@ namespace Step.Controllers.WebApi { ProductionConfig = ProductionConfig, AlarmsConfig = AlarmsConfig, - ScadaConfig = ScadaConfig, + ScadaConfig = ScadaConfig, MaintenanceConfig = MaintenanceConfig, ReportConfig = ReportConfig, - ToolingConfig = ToolingConfig, + ToolingConfig = ToolingConfig, UtilitiesConfig = UtilitiesConfig }; @@ -37,4 +37,4 @@ namespace Step.Controllers.WebApi return Ok(clientConfiguration); } } -} +} \ No newline at end of file diff --git a/Step/Controllers/WebApi/LanguageController.cs b/Step/Controllers/WebApi/LanguageController.cs index 2a706817..d8e949d6 100644 --- a/Step/Controllers/WebApi/LanguageController.cs +++ b/Step/Controllers/WebApi/LanguageController.cs @@ -1,14 +1,11 @@ -using System; +using Step.Model.ConfigModels; +using Step.Model.DTOModels; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Web.Http; -using Step.Model.ConfigModels; -using Step.Model.DTOModels; using static Step.Config.ServerConfig; -using static Step.Utils.LanguageController; using static Step.Utils.Constants; +using static Step.Utils.LanguageController; namespace Step.Controllers.WebApi { @@ -24,7 +21,7 @@ namespace Step.Controllers.WebApi return Ok(availableLanguages); } - + [Route("{language}"), HttpGet()] public IHttpActionResult GetTranslations(string language) { @@ -48,7 +45,6 @@ namespace Step.Controllers.WebApi return Ok(translations); } - public static Dictionary GetLocalizeMaintenanceName(string language, List maitenancesConfig) { Dictionary returnDictionary = new Dictionary(); @@ -64,11 +60,11 @@ namespace Step.Controllers.WebApi { // Find text from names by language id var value = localizedNames.Where(y => y.Key == language).FirstOrDefault(); - // Set default value + // Set default value if (value.Key == null) return "Maintenance string not found for id: " + maintenanceId; else return value.Value; } } -} +} \ No newline at end of file diff --git a/Step/Controllers/WebApi/NcApiController.cs b/Step/Controllers/WebApi/NcApiController.cs index 8951e892..c60a6e51 100644 --- a/Step/Controllers/WebApi/NcApiController.cs +++ b/Step/Controllers/WebApi/NcApiController.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Http; -using CMS_CORE; -using Step.Model.DTOModels; +using Step.Model.DTOModels; using Step.NC; -using static CMS_CORE.Nc; +using System; +using System.Diagnostics; +using System.Web.Http; using static CMS_CORE_Library.DataStructures; using static Step.Utils.Constants; @@ -41,4 +35,4 @@ namespace Step.Controllers.WebApi } } } -} +} \ No newline at end of file diff --git a/Step/Controllers/WebApi/UserController.cs b/Step/Controllers/WebApi/UserController.cs index b568cb26..a32e78bf 100644 --- a/Step/Controllers/WebApi/UserController.cs +++ b/Step/Controllers/WebApi/UserController.cs @@ -1,15 +1,14 @@ -using System.Web.Http; -using static Step.Utils.Constants; -using Step.Database.Controllers; -using System; -using Step.Model.DatabaseModels; -using System.Security.Claims; -using System.Linq; -using static Step.Utils.LanguageController; -using Step.Model.DTOModels; -using System.Globalization; using Microsoft.AspNet.SignalR; using Step.Controllers.SignalR; +using Step.Database.Controllers; +using Step.Model.DatabaseModels; +using System; +using System.Globalization; +using System.Linq; +using System.Security.Claims; +using System.Web.Http; +using static Step.Utils.Constants; +using static Step.Utils.LanguageController; namespace Step.Controllers.WebApi { @@ -79,7 +78,7 @@ namespace Step.Controllers.WebApi if (userId == null) return Unauthorized(); - + // Parse body data and validate language var newLanguage = (string)user.language; @@ -88,7 +87,7 @@ namespace Step.Controllers.WebApi // Find if language is Available in the server directory if (!LanguageIsAvailable(newLanguage)) return NotFound(); - + using (UsersController usersController = new UsersController()) { // Update database with new language @@ -98,4 +97,4 @@ namespace Step.Controllers.WebApi } } } -} +} \ No newline at end of file diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs index 10967098..bd8bcaf3 100644 --- a/Step/Listeners/ListenersHandler.cs +++ b/Step/Listeners/ListenersHandler.cs @@ -18,21 +18,12 @@ namespace Step.Listeners public static void Start() { - infos.Add(MessageServices.Current.Subscribe("testdb", async (a, b) => - { - DatabaseTest.DbTest(a.ToString()); - })); infos.Add(MessageServices.Current.Subscribe(SEND_ALARMS, async (a, b) => { SignalRListener.SendAlarmsToClient(a as DTOAlarmsModel); })); - infos.Add(MessageServices.Current.Subscribe(SEND_AXES, async (a, b) => - { - SignalRListener.SendAxesToClient(a as DTOAxesModel); - })); - infos.Add(MessageServices.Current.Subscribe(SEND_POWER_ON_DATA, async (a, b) => { SignalRListener.SendPowerOnDataToClient(a); diff --git a/Step/Listeners/SignalR/SignalRListener.cs b/Step/Listeners/SignalR/SignalRListener.cs index 9e6429d8..439c006e 100644 --- a/Step/Listeners/SignalR/SignalRListener.cs +++ b/Step/Listeners/SignalR/SignalRListener.cs @@ -28,12 +28,6 @@ namespace Step.Listeners.SignalR } } - public static void SendAxesToClient(DTOAxesModel newAxesData) - { - var context = GlobalHost.ConnectionManager.GetHubContext(); - context.Clients.Group("ncData").axes(newAxesData); - } - public static void SendPowerOnDataToClient(object powerOnData) { var context = GlobalHost.ConnectionManager.GetHubContext(); diff --git a/Step/Provider/SignalROAuthBearerProvider.cs b/Step/Provider/SignalROAuthBearerProvider.cs index 3afbcba9..77abc7a0 100644 --- a/Step/Provider/SignalROAuthBearerProvider.cs +++ b/Step/Provider/SignalROAuthBearerProvider.cs @@ -1,20 +1,13 @@ using Microsoft.Owin.Security.OAuth; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; -using System.Web; namespace Step.Provider { public class SignalROAuthBearerProvider : OAuthBearerAuthenticationProvider { - public override Task RequestToken(OAuthRequestTokenContext context) { - - var token = context.OwinContext.Request.Query["connectionToken"]; + var token = context.OwinContext.Request.Query["connectionToken"]; if (!string.IsNullOrWhiteSpace(token)) { @@ -26,14 +19,10 @@ namespace Step.Provider } return Task.FromResult(null); } + public override Task ValidateIdentity(OAuthValidateIdentityContext context) { return base.ValidateIdentity(context); } } - - class TokenValue - { - public string token { get; set; } - } } \ No newline at end of file diff --git a/Step/Step.csproj b/Step/Step.csproj index b58c4171..bd97be3e 100644 --- a/Step/Step.csproj +++ b/Step/Step.csproj @@ -166,7 +166,6 @@ -