From 91b6131d759be8744a15f8f22b03362ae9fead01 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 14 Jul 2020 14:31:00 +0200 Subject: [PATCH 1/7] update conf x userSoftKeys starred --- .../Config/userSoftKeyConfig.xml | 713 +++++++++--------- .../Config/userSoftKeyConfigValidator.xsd | 180 ++--- 2 files changed, 448 insertions(+), 445 deletions(-) diff --git a/Thermo.Active.Config/Config/userSoftKeyConfig.xml b/Thermo.Active.Config/Config/userSoftKeyConfig.xml index 6ba43874..b7f89126 100644 --- a/Thermo.Active.Config/Config/userSoftKeyConfig.xml +++ b/Thermo.Active.Config/Config/userSoftKeyConfig.xml @@ -1,367 +1,368 @@  - - true - 1 - false - 1 - - Reset - Reset - - true - - - - true - 2 - false - 2 - - Refresh alarms - Refresh allarmi - - true - - - - true - 3 - false - 3 - - Termoregulator - Termoregolatori - - true - - - - true - 4 - false - 4 - - Front gate - Portellone frontale - - true - - - - false - 5 - false - 5 - - Pause cycle - Pausa ciclo - - true - + + true + 1 + false + 1 + + Reset + Reset + + true + + + + true + 2 + false + 2 + + Refresh alarms + Refresh allarmi + + true + + + + true + 3 + false + 3 + + Termoregulator + Termoregolatori + + true + true + + + + true + 4 + false + 4 + + Front gate + Portellone frontale + + true + - - true - 7 - false - 7 - - Heaters - Riflettori - - true - - - true - 1 - false - 9 - - Vacuum pumps - Pompe vuoto - - true - - - - true - 1 - true - 12 - - Reset hours pump 1 - Reset contaore pompa 1 - - true - + false + 5 + false + 5 + + Pause cycle + Pausa ciclo + + true + - - true - 1 - true - 13 - - Reset hours pump 2 - Reset contaore pompa 2 - - true - + + true + 7 + false + 7 + + Heaters + Riflettori + + true + - - true - 1 - false - 14 - - Reset hours pump 3 - Reset contaore pompa 3 - - true - - - - true - 1 - false - 15 - - Extra 10s upper heater - Extra 10s riscaldo superiore - - true - - - - true - 1 - false - 16 - - Extra 10s lower heater - Extra 10s riscaldo inferiore - - true - - - - true - 4 - false - 17 - - Open/Close pliers - Apertura/chiusura pinze - - true - - - - true - 4 - false - 18 - - Loader forward - Carrello avanti - - true - + + true + 1 + false + 9 + + Vacuum pumps + Pompe vuoto + + true + - - true - 7 - false - 19 - - Loader backward - Carrello indietro - - true - - - - true - 7 - false - 20 - - Suckers up - Ventose su - - true - - - - true - 7 - false - 21 - - Suckers down - Ventose giu - - true - - - - true - 7 - false - 22 - - Suckers setup - Ventose setup - - true - - - - true - 7 - false - 23 - - Suckers park - Ventose parcheggio - - true - - - - true - 7 - false - 24 - - Ejection - Espulsione - - true - - - - true - 7 - false - 25 - - Suckers lock/unlock - Blocco/sblocco telaio ventose - - true - - - - true - 7 - false - 26 - - Suckers vacuum - Vuoto ventose - - true - - - - true - 7 - false - 27 - - Suckers air - Aria ventose - - true - - - - true - 7 - false - 28 - - Mould unload - Scarico stampo - - true - - - - true - 7 - false - 29 - - Upperplate lock/unlock - Blocco/sblocco controstampo - - true - - - - true - 7 - false - 30 - - Frame X - Apertura cornice - - true - - - - true - 7 - false - 31 - - Frame Y - Profondità cornice - - true - - - - true - 7 - false - 32 - - Windowplate X - Larghezza piastrafinestra - - true - - - - true - 7 - false - 33 - - Windowplate Y - Profondità piastrafinestra - - true - - - - true - 7 - false - 34 - - Preheating cycles - Cicli di preriscaldo - - true - + + true + 1 + true + 12 + + Reset hours pump 1 + Reset contaore pompa 1 + + true + - - + \ No newline at end of file diff --git a/Thermo.Active.Config/Config/userSoftKeyConfigValidator.xsd b/Thermo.Active.Config/Config/userSoftKeyConfigValidator.xsd index d96b4068..a57f9bec 100644 --- a/Thermo.Active.Config/Config/userSoftKeyConfigValidator.xsd +++ b/Thermo.Active.Config/Config/userSoftKeyConfigValidator.xsd @@ -1,99 +1,101 @@  - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From c5fea9fa43a93fc4d789004ec23e0cfc2c0b56e0 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 14 Jul 2020 14:31:54 +0200 Subject: [PATCH 2/7] ancora update favorite UserStarredSoftkey --- .../DTOModels/DTOUserSoftKeyModel.cs | 1 + .../WebApi/FavoriteUserSoftKeyController.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Thermo.Active.Model/DTOModels/DTOUserSoftKeyModel.cs b/Thermo.Active.Model/DTOModels/DTOUserSoftKeyModel.cs index 1fe00640..3348e440 100644 --- a/Thermo.Active.Model/DTOModels/DTOUserSoftKeyModel.cs +++ b/Thermo.Active.Model/DTOModels/DTOUserSoftKeyModel.cs @@ -18,6 +18,7 @@ namespace Thermo.Active.Model.DTOModels public int Category { get; set; } public bool Active { get; set; } public bool Visible { get; set; } + public bool Starred { get; set; } = false; public bool Value { get; set; } public override bool Equals(object obj) diff --git a/Thermo.Active/Controllers/WebApi/FavoriteUserSoftKeyController.cs b/Thermo.Active/Controllers/WebApi/FavoriteUserSoftKeyController.cs index bb565f86..e2100054 100644 --- a/Thermo.Active/Controllers/WebApi/FavoriteUserSoftKeyController.cs +++ b/Thermo.Active/Controllers/WebApi/FavoriteUserSoftKeyController.cs @@ -50,5 +50,22 @@ namespace Thermo.Active.Controllers.WebApi return Ok(favorite); } } + + + [Route("starred"), HttpGet] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.USER_FUNCTIONS, Action = ACTIONS.READ)] + public IHttpActionResult GetStarredSoftkeys() + { + var identity = User.Identity as ClaimsIdentity; + // Find user id from the bearer token + var userId = identity.Claims.FirstOrDefault(c => c.Type == USER_ID_KEY); + int userIdInt = Convert.ToInt32(userId.Value); + using (UserSoftkeysController controller = new UserSoftkeysController()) + { + return Ok( + controller.GetStarredSoftkeys(userIdInt) + ); + } + } } } From 3801b9ba0e739a7365a2cdcf2e0042e51d1fe387 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 14 Jul 2020 14:32:58 +0200 Subject: [PATCH 3/7] COmpletata prima review Starred Softkey --- Thermo.Active.Config/ServerConfigController.cs | 1 + .../Controllers/UserSoftkeysController.cs | 15 +++++++++++++++ .../ConfigModels/UserSoftKeyConfigModel.cs | 1 + Thermo.Active.NC/NcAdapter.cs | 2 ++ 4 files changed, 19 insertions(+) diff --git a/Thermo.Active.Config/ServerConfigController.cs b/Thermo.Active.Config/ServerConfigController.cs index 18dc9845..61690efb 100644 --- a/Thermo.Active.Config/ServerConfigController.cs +++ b/Thermo.Active.Config/ServerConfigController.cs @@ -517,6 +517,7 @@ namespace Thermo.Active.Config PlcId = Convert.ToInt32(x.Element("plcId")?.Value), // If exists IsActive = Convert.ToBoolean(x.Element("active").Value), IsVisible = Convert.ToBoolean(x.Element("visible").Value), + IsStarred = Convert.ToBoolean(x.Element("starred").Value), Category = Convert.ToInt32(x.Element("category").Value), LocalizedNames = x.Element("localizedNames").Elements().ToDictionary( // Read localized names and convert into a dictionary y => y.Attribute("langKey").Value, y => y.Value diff --git a/Thermo.Active.Database/Controllers/UserSoftkeysController.cs b/Thermo.Active.Database/Controllers/UserSoftkeysController.cs index cc86becc..15e23ad6 100644 --- a/Thermo.Active.Database/Controllers/UserSoftkeysController.cs +++ b/Thermo.Active.Database/Controllers/UserSoftkeysController.cs @@ -76,6 +76,21 @@ namespace Thermo.Active.Database.Controllers .ToList(); } + + public List GetStarredSoftkeys(int userId) + { + // Find user softkey stored in the database + List favoriteKey = FindUserFavoriteSoftkeys(userId); + // Get config + List userSoftkey = GetUserSoftkeyConfig(); + + return userSoftkey + .Where(x => + favoriteKey.Any(y => y.SoftkeyId == x.Id + )) + .ToList(); + } + public List InsertUserSoftkeyModel(List softKeyIds, int userId) { List softKeys = new List(); diff --git a/Thermo.Active.Model/ConfigModels/UserSoftKeyConfigModel.cs b/Thermo.Active.Model/ConfigModels/UserSoftKeyConfigModel.cs index c3f1713f..bf84c04b 100644 --- a/Thermo.Active.Model/ConfigModels/UserSoftKeyConfigModel.cs +++ b/Thermo.Active.Model/ConfigModels/UserSoftKeyConfigModel.cs @@ -10,6 +10,7 @@ namespace Thermo.Active.Model.ConfigModels public int Category { get; set; } public bool IsActive { get; set; } public bool IsVisible { get; set; } + public bool IsStarred { get; set; } = false; public bool OperatorConfirmationNeeded { get; set; } public List SubKeys { get; set; } public int PlcId { get; set; } diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 6c3366fb..04f13f2f 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1009,6 +1009,7 @@ namespace Thermo.Active.NC { Id = subkey.Id, Active = plcSoftKey.Active, + Starred = softKey.IsStarred, Category = softKey.Category, Value = plcSoftKey.Value }); @@ -1029,6 +1030,7 @@ namespace Thermo.Active.NC { Id = softKey.Id, Active = plcSoftKey.Active, + Starred=softKey.IsStarred, Category = softKey.Category, Visible = softKey.IsVisible, Value = plcSoftKey.Value From a4b8162355ef2710268e892b728e57c2502e09a8 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 14 Jul 2020 14:34:02 +0200 Subject: [PATCH 4/7] COnf x recupero user in recipe --- Thermo.Active.Core/ThreadsFunctions.cs | 19 ---------- .../Migrations/Configuration.cs | 3 +- Thermo.Active.Model/Constants.cs | 1 + .../Controllers/WebApi/RecipeController.cs | 35 ++++++++++++++++--- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index 5b097c2a..cd76ced8 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -210,7 +210,6 @@ public static class ThreadsFunctions ncAdapter.Dispose(); } } - public static void ReadAlarms() { NcAdapter ncAdapter = new NcAdapter(); @@ -254,7 +253,6 @@ public static class ThreadsFunctions ncAdapter.Dispose(); } } - public static void ReadPowerOnData() { NcAdapter ncAdapter = new NcAdapter(); @@ -296,7 +294,6 @@ public static class ThreadsFunctions ncAdapter.Dispose(); } } - public static void ReadProcessesPPStatus() { NcAdapter ncAdapter = new NcAdapter(); @@ -350,7 +347,6 @@ public static class ThreadsFunctions ncAdapter.Dispose(); } } - public static void ReadEnabledFunctionality() { NcAdapter ncAdapter = new NcAdapter(); @@ -394,7 +390,6 @@ public static class ThreadsFunctions ncAdapter.Dispose(); } } - public static void ReadExpiredMaintenances() { NcAdapter ncAdapter = new NcAdapter(); @@ -450,7 +445,6 @@ public static class ThreadsFunctions } } - public static void ReadUserSoftKeysData() { NcAdapter ncAdapter = new NcAdapter(); @@ -494,7 +488,6 @@ public static class ThreadsFunctions ncAdapter.Dispose(); } } - public static void ReadAxesNamesData() { NcAdapter ncAdapter = new NcAdapter(); @@ -538,7 +531,6 @@ public static class ThreadsFunctions ncAdapter.Dispose(); } } - public static void ReadAxesPositionsData() { NcAdapter ncAdapter = new NcAdapter(); @@ -582,7 +574,6 @@ public static class ThreadsFunctions ncAdapter.Dispose(); } } - public static void ReadScadaData() { NcAdapter ncAdapter = new NcAdapter(); @@ -1256,7 +1247,6 @@ public static class ThreadsFunctions reconnectionIsRunning = false; } } - public static void RestoreConnection() { if (reconnectionIsRunning == false) @@ -1271,13 +1261,11 @@ public static class ThreadsFunctions ConnThread.Start(); } } - public static void AbortNcConnection() { if (ConnThread != null && ConnThread.IsAlive) ConnThread.Abort(); } - public static void ManageLibraryError(CmsError libraryError) { switch (libraryError.errorCode) @@ -1309,7 +1297,6 @@ public static class ThreadsFunctions break; } } - internal static void UpdateStat(string functionName, long timer) { if (!Timers.ContainsKey(functionName)) @@ -1323,7 +1310,6 @@ public static class ThreadsFunctions else Counter[functionName]++; } - internal static void StatThread() { while (true) @@ -1343,7 +1329,6 @@ public static class ThreadsFunctions Thread.Sleep(2000); } } - private static void StatReset() { foreach (var value in Counter) @@ -1352,7 +1337,6 @@ public static class ThreadsFunctions Counter[value.Key] = 0; } } - private static int CalcSleepTime(int maxSleep, int execTime) { int sleep = 0; @@ -1378,7 +1362,6 @@ public static class ThreadsFunctions ThreadsHandler.StartClient.Start(); } } - private static void clientProcess() { string CMSClientPath = ""; @@ -1399,7 +1382,6 @@ public static class ThreadsFunctions } } } - private static bool ClientIsRunning() { Process[] p = Process.GetProcessesByName(CLIENT_EXE_NAME_NOEXT); @@ -1414,7 +1396,6 @@ public static class ThreadsFunctions } return false; } - private static Dictionary GetPlcAlarmsTranslations(string language) { using (NcAdapter ncAdapter = new NcAdapter()) diff --git a/Thermo.Active.Database/Migrations/Configuration.cs b/Thermo.Active.Database/Migrations/Configuration.cs index fb926f21..c0c193b7 100644 --- a/Thermo.Active.Database/Migrations/Configuration.cs +++ b/Thermo.Active.Database/Migrations/Configuration.cs @@ -53,7 +53,8 @@ namespace Thermo.Active.Database.Migrations new FunctionAccessModel() { Name = "scadaArea", Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0 }, new FunctionAccessModel() { Name = "usersArea", Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 30, ReadLevelMin = 1, PlcId = 0 }, new FunctionAccessModel() { Name = "jobeditorArea", Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 20, ReadLevelMin = 1, PlcId = 0 }, - new FunctionAccessModel() { Name = "utilitiesArea", Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0 } + new FunctionAccessModel() { Name = "utilitiesArea", Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0 }, + new FunctionAccessModel() { Name = RECIPE_MANAGER, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0 } ); context.SaveChanges(); diff --git a/Thermo.Active.Model/Constants.cs b/Thermo.Active.Model/Constants.cs index 7c5ff9df..bf6fa060 100644 --- a/Thermo.Active.Model/Constants.cs +++ b/Thermo.Active.Model/Constants.cs @@ -347,6 +347,7 @@ namespace Thermo.Active.Model public const string AXES_SELECTION = "axesSoftkeys"; public const string THERMO_MANAGER = "thermoManager"; public const string RISC_MANAGER = "riscManager"; + public const string RECIPE_MANAGER = "thermoRecipeManager"; } public static class API_ERROR_KEYS diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index 1a98d457..1ce8f766 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -314,10 +314,10 @@ namespace Thermo.Active.Controllers.WebApi /// /// [Route("save"), HttpPut] - //[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.USER_FUNCTIONS, Action = ACTIONS.READ)] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)] public IHttpActionResult Save() { -#if false + int currUserId = 0; // recupero dati utente loggato var identity = User.Identity as ClaimsIdentity; // Find user id from the bearer token @@ -328,9 +328,8 @@ namespace Thermo.Active.Controllers.WebApi using (UsersController usersController = new UsersController()) { var userData = usersController.GetUserInfo(Convert.ToInt32(userId.Value)); + currUserId = userData.Id; } -#endif - // recupero i dati LIVE dei parametri HMI della ricetta... @@ -357,6 +356,19 @@ namespace Thermo.Active.Controllers.WebApi [Route("saveAs"), HttpPut] public IHttpActionResult SaveAs(string newName) { +#if false + // recupero dati utente loggato + var identity = User.Identity as ClaimsIdentity; + // Find user id from the bearer token + var userId = identity.Claims.FirstOrDefault(c => c.Type == USER_ID_KEY); + if (userId == null) + return Unauthorized(); + + using (UsersController usersController = new UsersController()) + { + var userData = usersController.GetUserInfo(Convert.ToInt32(userId.Value)); + } +#endif // recupero i dati LIVE dei parametri HMI della ricetta... CmsError libraryError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); if (libraryError.IsError()) @@ -458,8 +470,23 @@ namespace Thermo.Active.Controllers.WebApi [Route("saveAll"), HttpPost] + //[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.USER_FUNCTIONS, Action = ACTIONS.READ)] public async Task SaveAll(string newName, double estimTimeSec) { +#if false + // recupero dati utente loggato + var identity = User.Identity as ClaimsIdentity; + // Find user id from the bearer token + var userId = identity.Claims.FirstOrDefault(c => c.Type == USER_ID_KEY); + if (userId == null) + return Unauthorized(); + + using (UsersController usersController = new UsersController()) + { + var userData = usersController.GetUserInfo(Convert.ToInt32(userId.Value)); + } +#endif + bool imageUploaded = false; if (!Request.Content.IsMimeMultipartContent()) From 13456c473fac51339d77768ace7aac11e7694390 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 14 Jul 2020 19:25:49 +0200 Subject: [PATCH 5/7] Update x StarredSoftkey --- .../ServerConfigController.cs | 2 +- .../Controllers/UserSoftkeysController.cs | 15 ------- Thermo.Active.NC/NcAdapter.cs | 33 +++++++++++++++- .../WebApi/FavoriteUserSoftKeyController.cs | 16 -------- .../WebApi/StarredUserSoftKeyController.cs | 39 +++++++++++++++++++ Thermo.Active/Thermo.Active.csproj | 1 + 6 files changed, 73 insertions(+), 33 deletions(-) create mode 100644 Thermo.Active/Controllers/WebApi/StarredUserSoftKeyController.cs diff --git a/Thermo.Active.Config/ServerConfigController.cs b/Thermo.Active.Config/ServerConfigController.cs index 61690efb..6b8361b2 100644 --- a/Thermo.Active.Config/ServerConfigController.cs +++ b/Thermo.Active.Config/ServerConfigController.cs @@ -517,7 +517,7 @@ namespace Thermo.Active.Config PlcId = Convert.ToInt32(x.Element("plcId")?.Value), // If exists IsActive = Convert.ToBoolean(x.Element("active").Value), IsVisible = Convert.ToBoolean(x.Element("visible").Value), - IsStarred = Convert.ToBoolean(x.Element("starred").Value), + IsStarred = x.Element("starred") != null ? Convert.ToBoolean(x.Element("starred").Value) : false, Category = Convert.ToInt32(x.Element("category").Value), LocalizedNames = x.Element("localizedNames").Elements().ToDictionary( // Read localized names and convert into a dictionary y => y.Attribute("langKey").Value, y => y.Value diff --git a/Thermo.Active.Database/Controllers/UserSoftkeysController.cs b/Thermo.Active.Database/Controllers/UserSoftkeysController.cs index 15e23ad6..cc86becc 100644 --- a/Thermo.Active.Database/Controllers/UserSoftkeysController.cs +++ b/Thermo.Active.Database/Controllers/UserSoftkeysController.cs @@ -76,21 +76,6 @@ namespace Thermo.Active.Database.Controllers .ToList(); } - - public List GetStarredSoftkeys(int userId) - { - // Find user softkey stored in the database - List favoriteKey = FindUserFavoriteSoftkeys(userId); - // Get config - List userSoftkey = GetUserSoftkeyConfig(); - - return userSoftkey - .Where(x => - favoriteKey.Any(y => y.SoftkeyId == x.Id - )) - .ToList(); - } - public List InsertUserSoftkeyModel(List softKeyIds, int userId) { List softKeys = new List(); diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 04f13f2f..e4d4a6ef 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1030,7 +1030,38 @@ namespace Thermo.Active.NC { Id = softKey.Id, Active = plcSoftKey.Active, - Starred=softKey.IsStarred, + Starred = softKey.IsStarred, + Category = softKey.Category, + Visible = softKey.IsVisible, + Value = plcSoftKey.Value + }); + } + } + + return libraryError; + } + + public CmsError GetStarredUserSoftKeys(out List softKeys) + { + softKeys = new List(); + List plcSoftKeys = new List(); + + // Get softkeys data from PLC + CmsError libraryError = numericalControl.PLC_RUserSoftKeys(ref plcSoftKeys); + if (libraryError.IsError() || plcSoftKeys.Count == 0) + return libraryError; + + foreach (var softKey in SoftKeysConfig) + { + // Find the plc matching data + var plcSoftKey = plcSoftKeys.Find(x => x.Id == softKey.PlcId); + if (softKey.IsStarred) + { + softKeys.Add(new DTOUserSoftKeyModel() + { + Id = softKey.Id, + Active = plcSoftKey.Active, + Starred = softKey.IsStarred, Category = softKey.Category, Visible = softKey.IsVisible, Value = plcSoftKey.Value diff --git a/Thermo.Active/Controllers/WebApi/FavoriteUserSoftKeyController.cs b/Thermo.Active/Controllers/WebApi/FavoriteUserSoftKeyController.cs index e2100054..88c15662 100644 --- a/Thermo.Active/Controllers/WebApi/FavoriteUserSoftKeyController.cs +++ b/Thermo.Active/Controllers/WebApi/FavoriteUserSoftKeyController.cs @@ -51,21 +51,5 @@ namespace Thermo.Active.Controllers.WebApi } } - - [Route("starred"), HttpGet] - [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.USER_FUNCTIONS, Action = ACTIONS.READ)] - public IHttpActionResult GetStarredSoftkeys() - { - var identity = User.Identity as ClaimsIdentity; - // Find user id from the bearer token - var userId = identity.Claims.FirstOrDefault(c => c.Type == USER_ID_KEY); - int userIdInt = Convert.ToInt32(userId.Value); - using (UserSoftkeysController controller = new UserSoftkeysController()) - { - return Ok( - controller.GetStarredSoftkeys(userIdInt) - ); - } - } } } diff --git a/Thermo.Active/Controllers/WebApi/StarredUserSoftKeyController.cs b/Thermo.Active/Controllers/WebApi/StarredUserSoftKeyController.cs new file mode 100644 index 00000000..e27b6964 --- /dev/null +++ b/Thermo.Active/Controllers/WebApi/StarredUserSoftKeyController.cs @@ -0,0 +1,39 @@ +using CMS_CORE_Library.Models; +using System.Collections.Generic; +using System.Web.Http; +using Thermo.Active.Model.DTOModels; +using Thermo.Active.NC; +using Thermo.Active.Utils; + +namespace Thermo.Active.Controllers.WebApi +{ + [RoutePrefix("api/starred_softkey")] + public class StarredUserSoftKeyController : ApiController + { + /// + /// Oggetto adapter condiviso da WebAPI + /// + protected static NcAdapter ncAdapter = new NcAdapter(); + + [Route("get"), HttpGet] + public IHttpActionResult GetStarredUserSoftkey() + { + // // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"ncAdapter Not connected! | GetOverview | {libraryError.exception}"); + } + + libraryError = ncAdapter.GetStarredUserSoftKeys(out List softKeys); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"GetStarredUserSoftkey error | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + + return Ok(softKeys); + } + + } +} \ No newline at end of file diff --git a/Thermo.Active/Thermo.Active.csproj b/Thermo.Active/Thermo.Active.csproj index b4a827b7..339a3652 100644 --- a/Thermo.Active/Thermo.Active.csproj +++ b/Thermo.Active/Thermo.Active.csproj @@ -224,6 +224,7 @@ + From 0610284b97996a93b009f4dd18b48e971e0c9546 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 15 Jul 2020 07:58:35 +0200 Subject: [PATCH 6/7] Aggiunta verifica user auth token x PUT Recipe --- .../Controllers/WebApi/RecipeController.cs | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index 1ce8f766..8c984eef 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -317,21 +317,19 @@ namespace Thermo.Active.Controllers.WebApi [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)] public IHttpActionResult Save() { - int currUserId = 0; // recupero dati utente loggato var identity = User.Identity as ClaimsIdentity; // Find user id from the bearer token var userId = identity.Claims.FirstOrDefault(c => c.Type == USER_ID_KEY); if (userId == null) return Unauthorized(); - + // salvo utente! using (UsersController usersController = new UsersController()) { var userData = usersController.GetUserInfo(Convert.ToInt32(userId.Value)); - currUserId = userData.Id; + NcFileAdapter.RecipeLiveData.UserSave = userData.Id.ToString(); } - // recupero i dati LIVE dei parametri HMI della ricetta... CmsError libraryError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); if (libraryError.IsError()) @@ -354,21 +352,22 @@ namespace Thermo.Active.Controllers.WebApi /// /// [Route("saveAs"), HttpPut] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)] public IHttpActionResult SaveAs(string newName) { -#if false // recupero dati utente loggato var identity = User.Identity as ClaimsIdentity; // Find user id from the bearer token var userId = identity.Claims.FirstOrDefault(c => c.Type == USER_ID_KEY); if (userId == null) return Unauthorized(); - + // salvo utente! using (UsersController usersController = new UsersController()) { var userData = usersController.GetUserInfo(Convert.ToInt32(userId.Value)); - } -#endif + NcFileAdapter.RecipeLiveData.UserSave = userData.Id.ToString(); + } + // recupero i dati LIVE dei parametri HMI della ricetta... CmsError libraryError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); if (libraryError.IsError()) @@ -470,22 +469,21 @@ namespace Thermo.Active.Controllers.WebApi [Route("saveAll"), HttpPost] - //[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.USER_FUNCTIONS, Action = ACTIONS.READ)] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)] public async Task SaveAll(string newName, double estimTimeSec) { -#if false // recupero dati utente loggato var identity = User.Identity as ClaimsIdentity; // Find user id from the bearer token var userId = identity.Claims.FirstOrDefault(c => c.Type == USER_ID_KEY); if (userId == null) return Unauthorized(); - + // salvo utente! using (UsersController usersController = new UsersController()) { var userData = usersController.GetUserInfo(Convert.ToInt32(userId.Value)); - } -#endif + NcFileAdapter.RecipeLiveData.UserSave = userData.Id.ToString(); + } bool imageUploaded = false; @@ -537,7 +535,6 @@ namespace Thermo.Active.Controllers.WebApi return Ok(); } - /// /// Do actual recipe parameters FileSave /// From ea2508a798a7ccfd097e6cf6e74ada8e8032a41e Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 15 Jul 2020 08:00:41 +0200 Subject: [PATCH 7/7] nuova vers stabile .39 --- 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 8beaf5b9..090e3f3a 100644 --- a/Thermo.Active/Properties/AssemblyInfo.cs +++ b/Thermo.Active/Properties/AssemblyInfo.cs @@ -30,4 +30,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.9.38")] \ No newline at end of file +[assembly: AssemblyVersion("0.9.39")] \ No newline at end of file