diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 55650ee8..8a669a71 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Model/Constants.cs b/Step.Model/Constants.cs index 578e4f7d..9eb665f6 100644 --- a/Step.Model/Constants.cs +++ b/Step.Model/Constants.cs @@ -7,7 +7,10 @@ namespace Step.Model public static class Constants { public static readonly string[] VALID_FILE_EXTENSIONS = { "", ".txt", ".cnc", ".ini", ".mpf", ".spf" }; - public const double EPSILON = 0.001; + public static readonly string[] VALID_IMAGE_EXTENSIONS = { ".jpg", ".jpeg", ".png" }; + public const double EPSILON = 0.001; + public static string QUEUE_FILE_NAME = "pp"; + public enum ROLE_IDS { @@ -202,7 +205,8 @@ namespace Step.Model // File paths public const string MAINTENANCE_ATTACHMENT_PATH = "C:\\CMS\\STEP\\attachment\\"; - public const string TEMP_FILE = @"C:/CMS/STEP/tmp/pp/"; - public const string PART_PRG_IMAGES = @"C:/CMS/STEP/pp_img/"; + public const string TEMP_FILE = @"C:\CMS\STEP\tmp\pp\"; + public const string QUEUE_TMP_FILE = @"C:\CMS\STEP\tmp\pp\queue\"; + public const string PART_PRG_IMAGES = @"C:\CMS\STEP\pp_img/"; } } diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 531c224b..c17662d0 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -80,7 +80,47 @@ namespace Step.NC public CmsError GetFileInfo(string path, out InfoFile fileInfo) { fileInfo = new InfoFile(); - return numericalControl.FILES_RGetFileInfo(path, ref fileInfo); + + if (File.Exists(path)) + return GetQueueFileInfo(path, out fileInfo); + else + return numericalControl.FILES_RGetFileInfo(path, ref fileInfo); + } + + public CmsError GetQueueFileInfo(string path, out InfoFile fileInfo) + { + FileInfo fileData = new FileInfo(path); + StreamReader fileRead = new StreamReader(path); + int count = 0; + string line = ""; + + fileInfo = new InfoFile() + { + Name = fileData.Name, + CreationDate = fileData.CreationTime, + LastModDate = fileData.LastAccessTime, + AbsolutePath = path + }; + + fileInfo.Content = new List(); + while ((line = fileRead.ReadLine()) != null && count < 10) + { + fileInfo.Content.Add(line); + count++; + } + fileRead.Close(); + + foreach (string ext in VALID_IMAGE_EXTENSIONS) + { + string imagePath = IMAGES_PATH + "/" + fileInfo.Name + ext; + if (File.Exists(imagePath)) + { + fileInfo.PreviewBase64 = "data:image/" + ext + ";base64," + Convert.ToBase64String(File.ReadAllBytes(imagePath)); + break; + } + } + + return NO_ERROR; } public CmsError GetActiveProgramInfo(out DTOActiveProgramDataModel dtoData) @@ -182,15 +222,13 @@ namespace Step.NC return numericalControl.FILES_WSetActiveProgram(selectedProcess, newFilePath, ref programData); } - public CmsError UploadPartProgramAddToQueue(string localPath, string fileName, int reps, out DTOQueueModel queueItem) + public CmsError UploadPartProgramAndAddToQueue(string localPath, string fileName, int reps, out DTOQueueModel queueItem) { queueItem = new DTOQueueModel(); - // Upload to NC - CmsError cmsError = UploadPartProgram(localPath, fileName, out string newFilePath); - + // Get selectedProcess id ushort selectedProcess = 0; - cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); + CmsError cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); if (cmsError.IsError()) return cmsError; @@ -199,7 +237,7 @@ namespace Step.NC PartProgramName = fileName, Reps = reps, RemainingReps = reps, - AbsolutePath = newFilePath, + AbsolutePath = localPath + fileName, Status = QUEUE_ITEM_STATUS.NOT_ACTIVE }; @@ -250,6 +288,9 @@ namespace Step.NC QueueRunningIndex += 1; // Change part program + cmsError = numericalControl.FILES_WLoadNextPartProgram(PartProgramQueue[selectedProcess][QueueRunningIndex].AbsolutePath, QUEUE_FILE_NAME); + if (cmsError.IsError()) + return cmsError; } } } diff --git a/Step/Controllers/WebApi/NcFileController.cs b/Step/Controllers/WebApi/NcFileController.cs index b6f6f12b..f4320232 100644 --- a/Step/Controllers/WebApi/NcFileController.cs +++ b/Step/Controllers/WebApi/NcFileController.cs @@ -181,7 +181,7 @@ namespace Step.Controllers.WebApi { ncHandler.Connect(); - File.WriteAllBytes(TEMP_FILE + item.FileName, item.Data); + File.WriteAllBytes(QUEUE_TMP_FILE + item.FileName, item.Data); // Get reps var repsParam = formItems.Where(x => x.ParameterName == "reps").FirstOrDefault(); @@ -189,7 +189,7 @@ namespace Step.Controllers.WebApi if (repsParam == null || !Int32.TryParse(repsParam.Value, out int reps)) return BadRequest(); - CmsError cmsError = ncHandler.UploadPartProgramAddToQueue(TEMP_FILE, item.FileName, reps, out queueItem); + CmsError cmsError = ncHandler.UploadPartProgramAndAddToQueue(QUEUE_TMP_FILE, item.FileName, reps, out queueItem); if (cmsError.IsError()) return BadRequest(cmsError.localizationKey); }