From 06755f69a0322c1c44a4ca4ea6037318e16b69c1 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 10:46:34 +0200 Subject: [PATCH 1/8] modifications for file type selection --- Client/Browser_Tools/BrowserJSObject.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Client/Browser_Tools/BrowserJSObject.cs b/Client/Browser_Tools/BrowserJSObject.cs index d5401224..146eafbd 100644 --- a/Client/Browser_Tools/BrowserJSObject.cs +++ b/Client/Browser_Tools/BrowserJSObject.cs @@ -36,7 +36,8 @@ namespace Active_Client.Browser_Tools private MainForm mainForm; - private static readonly string[] _validExtensions = { "", ".txt", ".cnc", ".cn", ".cno", ".ini", ".mpf", ".spf", ".tap", ".anc", ".iso", /*".job", ".zip"*/ }; + private static readonly string[] _validExtensions = { "", ".json", ".rcp", ".tpl" }; + //private static readonly string[] _validExtensions = { "", ".txt", ".cnc", ".cn", ".cno", ".ini", ".mpf", ".spf", ".tap", ".anc", ".iso" }; private static readonly string[] _validImages = { ".jpg", ".jpeg", ".png" }; private static string jobPath = ""; private static Dictionary _editorOpened = new Dictionary(); From 0f2906c38637dff67074c13c6c25d92c2fd49b6d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 10:48:41 +0200 Subject: [PATCH 2/8] reset log msg --- Thermo.Active/makeSimVersion.ps1 | 2 +- Thermo.Active/makeTestVersion.ps1 | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Thermo.Active/makeSimVersion.ps1 b/Thermo.Active/makeSimVersion.ps1 index d5378b47..328c9ea2 100644 --- a/Thermo.Active/makeSimVersion.ps1 +++ b/Thermo.Active/makeSimVersion.ps1 @@ -12,7 +12,7 @@ function DoLog($txt2log) } -DoLog("-------------------------------- START script --------------------------------") +Write-Output "-------------------------------- START script --------------------------------" | Out-File c:\tmp\Script.log $StopWatch = New-Object System.Diagnostics.Stopwatch $StopWatch.Start() diff --git a/Thermo.Active/makeTestVersion.ps1 b/Thermo.Active/makeTestVersion.ps1 index 5d1d177c..24016651 100644 --- a/Thermo.Active/makeTestVersion.ps1 +++ b/Thermo.Active/makeTestVersion.ps1 @@ -27,8 +27,7 @@ function DoLog($txt2log) Write-Output "$(Get-TimeStamp) $txt2log" | Out-File c:\tmp\Script.log -Append } - -DoLog("-------------------------------- START script --------------------------------") +Write-Output "-------------------------------- START script --------------------------------" | Out-File c:\tmp\Script.log $StopWatch = New-Object System.Diagnostics.Stopwatch $StopWatch.Start() From 4e2395f192c097b9968932a19c369fdd054ba787 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 11:54:42 +0200 Subject: [PATCH 3/8] Modifica template/ricetta --- .../Config/Recipes/{template.json => template.tpl} | 0 Thermo.Active.Config/Recipes/{Startup1.json => Startup1.rcp} | 0 Thermo.Active.Config/Recipes/{Startup2.json => Startup2.rcp} | 0 Thermo.Active.Config/Recipes/{testa.json => testa.rcp} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename Thermo.Active.Config/Config/Recipes/{template.json => template.tpl} (100%) rename Thermo.Active.Config/Recipes/{Startup1.json => Startup1.rcp} (100%) rename Thermo.Active.Config/Recipes/{Startup2.json => Startup2.rcp} (100%) rename Thermo.Active.Config/Recipes/{testa.json => testa.rcp} (100%) diff --git a/Thermo.Active.Config/Config/Recipes/template.json b/Thermo.Active.Config/Config/Recipes/template.tpl similarity index 100% rename from Thermo.Active.Config/Config/Recipes/template.json rename to Thermo.Active.Config/Config/Recipes/template.tpl diff --git a/Thermo.Active.Config/Recipes/Startup1.json b/Thermo.Active.Config/Recipes/Startup1.rcp similarity index 100% rename from Thermo.Active.Config/Recipes/Startup1.json rename to Thermo.Active.Config/Recipes/Startup1.rcp diff --git a/Thermo.Active.Config/Recipes/Startup2.json b/Thermo.Active.Config/Recipes/Startup2.rcp similarity index 100% rename from Thermo.Active.Config/Recipes/Startup2.json rename to Thermo.Active.Config/Recipes/Startup2.rcp diff --git a/Thermo.Active.Config/Recipes/testa.json b/Thermo.Active.Config/Recipes/testa.rcp similarity index 100% rename from Thermo.Active.Config/Recipes/testa.json rename to Thermo.Active.Config/Recipes/testa.rcp From 1a211bbb8d1eceb36cb3008fc2758b6ebb6624b1 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 11:54:53 +0200 Subject: [PATCH 4/8] update naming x ricetta --- .../Thermo.Active.Config.csproj | 10 +++---- Thermo.Active.Model/Constants.cs | 4 +-- Thermo.Active.NC/NcFileAdapter.cs | 30 +++++++++++-------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Thermo.Active.Config/Thermo.Active.Config.csproj b/Thermo.Active.Config/Thermo.Active.Config.csproj index 193c41d7..9b9c7d61 100644 --- a/Thermo.Active.Config/Thermo.Active.Config.csproj +++ b/Thermo.Active.Config/Thermo.Active.Config.csproj @@ -200,21 +200,21 @@ - + Always - + Designer Always - + PreserveNewest - + PreserveNewest - + PreserveNewest diff --git a/Thermo.Active.Model/Constants.cs b/Thermo.Active.Model/Constants.cs index c6d26990..38f717c7 100644 --- a/Thermo.Active.Model/Constants.cs +++ b/Thermo.Active.Model/Constants.cs @@ -221,8 +221,8 @@ namespace Thermo.Active.Model #endif public const string CONFIG_DIRECTORY = "Config\\"; public const string RECIPE_DIRECTORY = "Recipes\\"; - public const string RECIPE_TEMPLATE_PATH = CONFIG_DIRECTORY + RECIPE_DIRECTORY + "template.json"; - public const string LIVE_RECIPE_PATH = TEMP_FOLDER + RECIPE_DIRECTORY + "current.json"; + public const string RECIPE_TEMPLATE_PATH = CONFIG_DIRECTORY + RECIPE_DIRECTORY + "template.tpl"; + public const string LIVE_RECIPE_PATH = TEMP_FOLDER + RECIPE_DIRECTORY + "current.rcp"; public const string RESOURCE_DIRECTORY = @"Thermo.Active.Config.Config."; public const string SERVER_CONFIG_SCHEMA_PATH = RESOURCE_DIRECTORY + @"serverConfigValidator.xsd"; public const string SERVER_CONFIG_PATH = CONFIG_DIRECTORY + "serverConfig.xml"; diff --git a/Thermo.Active.NC/NcFileAdapter.cs b/Thermo.Active.NC/NcFileAdapter.cs index 6ba142ee..7992ce0f 100644 --- a/Thermo.Active.NC/NcFileAdapter.cs +++ b/Thermo.Active.NC/NcFileAdapter.cs @@ -681,11 +681,11 @@ namespace Thermo.Active.NC public static bool LoadRecipe(string filePath) { bool answ = false; - - // check file extension - if (!filePath.EndsWith(".json")) + // check file extension: accetta json / rcp / tpl + if (!(filePath.EndsWith(".json") || filePath.EndsWith(".rcp") || filePath.EndsWith(".tpl"))) { - filePath += ".json"; + // default: ricetta! + filePath += ".rcp"; } string fileName = Path.GetFileName(filePath); @@ -798,23 +798,29 @@ namespace Thermo.Active.NC try { answ = true; - string fileName = Path.GetFileName(filePath); - if (!fileName.EndsWith(".json")) + // check file extension: accetta json / rcp / tpl + if (!(filePath.EndsWith(".json") || filePath.EndsWith(".rcp") || filePath.EndsWith(".tpl"))) { - fileName += ".json"; - filePath += ".json"; + // default: ricetta! + filePath += ".rcp"; } + string fileName = Path.GetFileName(filePath); + // fix name! currRecipe.RecipeName = fileName; // serialize string rawData = JsonConvert.SerializeObject(currRecipe); // save live! File.WriteAllText(LIVE_RECIPE_PATH, rawData); - // check filePath... - if (!filePath.Contains(RECIPE_DIRECTORY) && filePath != RECIPE_TEMPLATE_PATH) + // verifica path + if (!Path.IsPathRooted(filePath)) { - // aggiungo base path! - filePath = RECIPE_DIRECTORY + filePath; + // controllo se ha path della recipe directory + if (!filePath.Contains(RECIPE_DIRECTORY) && filePath != RECIPE_TEMPLATE_PATH) + { + // aggiungo base path! + filePath = RECIPE_DIRECTORY + filePath; + } } // save! File.WriteAllText(filePath, rawData); From acad63969b7f6c6ad719aa77404f124455a68929 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 16:10:28 +0200 Subject: [PATCH 5/8] re-add NcFileMan per ispezione --- Thermo.Active.NC/NcFileAdapter.cs | 41 ++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Thermo.Active.NC/NcFileAdapter.cs b/Thermo.Active.NC/NcFileAdapter.cs index 7992ce0f..6730692f 100644 --- a/Thermo.Active.NC/NcFileAdapter.cs +++ b/Thermo.Active.NC/NcFileAdapter.cs @@ -755,7 +755,7 @@ namespace Thermo.Active.NC return answ; } /// - /// Try to write live data to json persistence file + /// Write live data to json persistence file /// public static bool SaveRecipeCurrent() { @@ -779,6 +779,45 @@ namespace Thermo.Active.NC return answ; } /// + /// Write image data for recipe + /// + /// + /// + /// + public static bool SaveRecipeImage(string filePath, byte[] fileData) + { + bool imageUploaded = false; + try + { + // save live! + var dir = Path.GetDirectoryName(RECIPE_DIRECTORY); + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + + // Delete previous image + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + + if (!Path.IsPathRooted(filePath)) + { + // aggiungo base path! + filePath = RECIPE_DIRECTORY + filePath; + } + + // Save NEW image + File.WriteAllBytes(filePath, fileData); + imageUploaded = true; + } + catch + { } + + return imageUploaded; + } + /// /// Try to save live recipe as NEW template /// public static bool SaveRecipeTemplate() From ed7fe8efea229e18bd529cb3ad99be66c7b19292 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 16:10:49 +0200 Subject: [PATCH 6/8] Metodo uploadImage che richiede nome ricetta... --- .../Controllers/WebApi/RecipeController.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index 03cee48c..68a8c312 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -1,6 +1,11 @@ using CMS_CORE_Library.Models; using System; using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using System.Web; using System.Web.Http; using Thermo.Active.Config; using Thermo.Active.Model.DTOModels.ThRecipe; @@ -402,6 +407,33 @@ namespace Thermo.Active.Controllers.WebApi return Ok(); } + [Route("uploadImage"), HttpPost] + public async Task UpdloadImage() + { + bool imageUploaded = false; + + if (!Request.Content.IsMimeMultipartContent()) + { + throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); + } + + List formItems = await MultipartHandler.ManageMultiPartFileAsync(Request); + + foreach (FormItem item in formItems) + { + if (item.IsAFile) + { + if (item.ParameterName == "image" || item.MediaType.StartsWith"image/") + { + string filePath = item.FileName; + imageUploaded = NcFileAdapter.SaveRecipeImage(item.FileName, item.Data); + } + } + } + + return Ok(); + } + /// /// Do actual recipe parameters FileSave @@ -421,6 +453,7 @@ namespace Thermo.Active.Controllers.WebApi ThermoActiveLogger.LogError($"Recipe | SaveCurrentRecipeParams exception | {exc}"); } } + /// /// write current recipe to PLC /// From 30b2e92f436d916fdc98e0f8676f638f03c28738 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 16:15:37 +0200 Subject: [PATCH 7/8] update fix directory x sim script --- Thermo.Active/makeSimVersion.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Thermo.Active/makeSimVersion.ps1 b/Thermo.Active/makeSimVersion.ps1 index 328c9ea2..56737572 100644 --- a/Thermo.Active/makeSimVersion.ps1 +++ b/Thermo.Active/makeSimVersion.ps1 @@ -34,6 +34,9 @@ DoLog("START npm run build ") npm run build | Out-File c:\tmp\Script.log -Append DoLog("END npm run build ") +# torno in folder base +cd .. + $StopWatch.Stop() $StopWatch.Elapsed | Out-File c:\tmp\Script.log -Append -DoLog("-------------------------------- END script --------------------------------") +DoLog("-------------------------------- END script --------------------------------") \ No newline at end of file From 32f80ca5be5e34694ce4c362e3c3691d45c65082 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 16:16:48 +0200 Subject: [PATCH 8/8] typo fix!!! --- Thermo.Active/Controllers/WebApi/RecipeController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index 68a8c312..afe21404 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -423,7 +423,7 @@ namespace Thermo.Active.Controllers.WebApi { if (item.IsAFile) { - if (item.ParameterName == "image" || item.MediaType.StartsWith"image/") + if (item.ParameterName == "image" || item.MediaType.StartsWith("image/")) { string filePath = item.FileName; imageUploaded = NcFileAdapter.SaveRecipeImage(item.FileName, item.Data);