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(); 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 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..6730692f 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); @@ -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() @@ -798,23 +837,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); diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index 03cee48c..afe21404 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 /// diff --git a/Thermo.Active/makeSimVersion.ps1 b/Thermo.Active/makeSimVersion.ps1 index d5378b47..56737572 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() @@ -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 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()