Merge branch 'develop' of https://bitbucket.org/ncarminati/cms_step into develop
This commit is contained in:
@@ -636,7 +636,7 @@ namespace CMS_Client.Browser_Tools
|
||||
metasFromFile = JsonConvert.DeserializeObject<MetadataToFile>(reader.ReadToEnd());
|
||||
if (metasFromFile == null)
|
||||
{
|
||||
e.SetReturnValue(null);
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("corrupted_model")));
|
||||
return;
|
||||
}
|
||||
else
|
||||
@@ -670,11 +670,11 @@ namespace CMS_Client.Browser_Tools
|
||||
{
|
||||
// Get file path
|
||||
string filePath = e.Arguments[0].StringValue;
|
||||
|
||||
// Check if file exists
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
// Check if zip is valid
|
||||
var zipIsValid = ValidateZip(filePath);
|
||||
if (zipIsValid != null)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_file_not_found")));
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(zipIsValid));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -733,6 +733,26 @@ namespace CMS_Client.Browser_Tools
|
||||
}
|
||||
}
|
||||
|
||||
public static ErrorContainer ValidateZip(string filePath)
|
||||
{
|
||||
ErrorContainer result = null;
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
{
|
||||
return new ErrorContainer("error_file_not_found");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var archive = ZipFile.OpenRead(filePath))
|
||||
result = null;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
result = new ErrorContainer("error_file_not_found");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void updateJobMetadata(object sender, CfrV8HandlerExecuteEventArgs e)
|
||||
{
|
||||
MetadataToFile metafile = new MetadataToFile();
|
||||
@@ -856,6 +876,7 @@ namespace CMS_Client.Browser_Tools
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(job));
|
||||
return;
|
||||
}
|
||||
|
||||
e.SetReturnValue(null);
|
||||
return;
|
||||
}
|
||||
@@ -922,6 +943,7 @@ namespace CMS_Client.Browser_Tools
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(job));
|
||||
return;
|
||||
}
|
||||
|
||||
e.SetReturnValue(null);
|
||||
return;
|
||||
}
|
||||
|
||||
+14
-16
@@ -6,17 +6,6 @@ namespace Step.Model
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public static readonly string[] VALID_FILE_EXTENSIONS = { "", ".txt", ".cnc", ".ini", ".mpf", ".spf" };
|
||||
public static readonly string[] VALID_IMAGE_EXTENSIONS = { ".jpg", ".jpeg", ".png" };
|
||||
public const double EPSILON = 0.001;
|
||||
public static string QUEUE_FILE_NAME = "pp";
|
||||
public const string JOB_MAIN_FILENAME = "main.cnc";
|
||||
public const string JOB_METADATA_FILENAME = "metadata.json";
|
||||
|
||||
public static String JOB_OPENING_PATH = BASE_PATH + "TempJob\\";
|
||||
|
||||
|
||||
|
||||
public enum ROLE_IDS
|
||||
{
|
||||
CMS_SERVICE_ONLY = 1,
|
||||
@@ -213,10 +202,19 @@ 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 JOB_TMP_DIRECTORY = @"C:\CMS\STEP\tmp\pp\job\";
|
||||
public const string QUEUE_TMP_FILE = @"C:\CMS\STEP\tmp\pp\queue\";
|
||||
public const string PART_PRG_IMAGES = @"C:\CMS\STEP\pp_img/";
|
||||
public const string MAINTENANCE_ATTACHMENT_PATH = @"C:\CMS\STEP\attachment\";
|
||||
public const string TEMP_FOLDER = @"C:\CMS\STEP\tmp\";
|
||||
public const string TEMP_PP_FOLDER = TEMP_FOLDER + @"pp\";
|
||||
public const string JOB_TMP_DIRECTORY = TEMP_PP_FOLDER + @"job\";
|
||||
public const string QUEUE_TMP_FOLDER = TEMP_PP_FOLDER + @"queue\";
|
||||
public const string PART_PRG_IMAGES = @"C:\CMS\STEP\pp_img\";
|
||||
|
||||
public static readonly string[] VALID_FILE_EXTENSIONS = { "", ".txt", ".cnc", ".ini", ".mpf", ".spf" };
|
||||
public static readonly string[] VALID_IMAGE_EXTENSIONS = { ".jpg", ".jpeg", ".png" };
|
||||
public const double EPSILON = 0.001;
|
||||
public static string QUEUE_FILE_NAME = "pp";
|
||||
public const string JOB_MAIN_FILENAME = "main.cnc";
|
||||
public const string JOB_METADATA_FILENAME = "metadata.json";
|
||||
public static string[] JOB_EXTENSIONS = { ".job", ".zip" };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Step.Model.DTOModels.JobModels
|
||||
{
|
||||
@@ -8,10 +9,12 @@ namespace Step.Model.DTOModels.JobModels
|
||||
public DateTime LastEditTimestamp;
|
||||
public string IsoMainProgram;
|
||||
public DTOMetadataModel Metadata;
|
||||
public List<string> PartPrograms;
|
||||
|
||||
public DTOJobModel()
|
||||
{
|
||||
Metadata = new DTOMetadataModel();
|
||||
PartPrograms = new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
-9
@@ -207,21 +207,31 @@ namespace Step.NC
|
||||
{
|
||||
programData = new ActiveProgramDataModel();
|
||||
|
||||
// Upload to NC
|
||||
CmsError cmsError = UploadPartProgram(localPath, fileName, out string newFilePath);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Get selectedProcess id
|
||||
ushort selectedProcess = 0;
|
||||
cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess);
|
||||
CmsError cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Activate updated program
|
||||
return numericalControl.FILES_WSetActiveProgram(selectedProcess, newFilePath, ref programData);
|
||||
}
|
||||
if (!JOB_EXTENSIONS.Contains(Path.GetExtension(fileName)))
|
||||
{
|
||||
// Upload to NC
|
||||
cmsError = UploadPartProgram(localPath, fileName, out string newFilePath);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
|
||||
// Activate updated program
|
||||
return numericalControl.FILES_WSetActiveProgram(selectedProcess, newFilePath, ref programData);
|
||||
}
|
||||
else
|
||||
{
|
||||
DTOJobModel job = SupportFunctions.UnpackJobAndReadMetadata(localPath + fileName);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public CmsError UploadPartProgramAndAddToQueue(string localPath, string fileName, int reps, out DTOQueueModel queueItem)
|
||||
{
|
||||
queueItem = new DTOQueueModel();
|
||||
@@ -294,6 +304,13 @@ namespace Step.NC
|
||||
// Set as finished
|
||||
actualItem.RemainingReps = 0;
|
||||
actualItem.Status = QUEUE_ITEM_STATUS.FINISHED;
|
||||
|
||||
|
||||
//while(PartProgramQueue[item.ProcessId].ElementAtOrDefault(QueueRunningIndexes[item.ProcessId] + 1) != null && !File.Exists(PartProgramQueue[item.ProcessId][QueueRunningIndexes[item.ProcessId]].AbsolutePath))
|
||||
//{
|
||||
// QueueRunningIndexes[item.ProcessId] += 1;
|
||||
//}
|
||||
|
||||
if (PartProgramQueue[item.ProcessId].ElementAtOrDefault(QueueRunningIndexes[item.ProcessId] + 1) != null)
|
||||
// if next part program exists, set next pp as current pp
|
||||
QueueRunningIndexes[item.ProcessId] += 1;
|
||||
@@ -459,6 +476,9 @@ namespace Step.NC
|
||||
|
||||
if (tmpQueueItem != null)
|
||||
PartProgramQueue[processId].Remove(tmpQueueItem);
|
||||
|
||||
if (File.Exists(tmpQueueItem.AbsolutePath))
|
||||
File.Delete(tmpQueueItem.AbsolutePath);
|
||||
}
|
||||
|
||||
// Update database data
|
||||
@@ -478,6 +498,9 @@ namespace Step.NC
|
||||
using (QueueController queueController = new QueueController())
|
||||
queueController.UpdateQueue();
|
||||
|
||||
// Clean directory
|
||||
SupportFunctions.EmptyFolder(JOB_TMP_DIRECTORY);
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,37 +126,37 @@ namespace Step.Utils
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static DTOJobModel UnpackJobAndReadMetadata(string path)
|
||||
public static DTOJobModel UnpackJobAndReadMetadata(string filePath)
|
||||
{
|
||||
DTOJobModel job = new DTOJobModel();
|
||||
// Check if job exists
|
||||
if (!File.Exists(path))
|
||||
if (!File.Exists(filePath))
|
||||
return null;
|
||||
|
||||
EmptyFolder(path);
|
||||
|
||||
string fileName = Path.GetFileName(path);
|
||||
|
||||
using (ZipArchive zipExtractor = ZipFile.OpenRead(fileName))
|
||||
EmptyFolder(JOB_TMP_DIRECTORY);
|
||||
|
||||
using (ZipArchive zipExtractor = ZipFile.OpenRead(filePath))
|
||||
{
|
||||
// Setup main job fields
|
||||
job.Name = Path.GetFileName(fileName);
|
||||
job.LastEditTimestamp = new FileInfo(fileName).LastAccessTime;
|
||||
job.Name = Path.GetFileName(filePath);
|
||||
job.LastEditTimestamp = new FileInfo(filePath).LastAccessTime;
|
||||
|
||||
foreach (ZipArchiveEntry entry in zipExtractor.Entries)
|
||||
{
|
||||
// Extract file
|
||||
entry.ExtractToFile(JOB_TMP_DIRECTORY + entry.Name, true);
|
||||
|
||||
// Get main program content
|
||||
if (entry.Name.Equals(JOB_MAIN_FILENAME, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
using (var reader = new StreamReader(entry.Open()))
|
||||
job.IsoMainProgram = (reader.ReadToEnd());
|
||||
}
|
||||
|
||||
// Read images
|
||||
else if (VALID_IMAGE_EXTENSIONS.Contains(Path.GetExtension(entry.Name).ToLower()))
|
||||
{
|
||||
var bytes = default(byte[]);
|
||||
entry.ExtractToFile(JOB_OPENING_PATH + entry.Name, true);
|
||||
// Populate metadata
|
||||
using (var memstream = new MemoryStream())
|
||||
{
|
||||
entry.Open().CopyTo(memstream);
|
||||
@@ -191,7 +191,9 @@ namespace Step.Utils
|
||||
}
|
||||
// Consider other file as part program
|
||||
else
|
||||
entry.ExtractToFile(JOB_OPENING_PATH + entry.Name, true);
|
||||
{
|
||||
job.PartPrograms.Add(JOB_TMP_DIRECTORY + entry.Name);
|
||||
}
|
||||
}
|
||||
|
||||
return job;
|
||||
|
||||
@@ -144,8 +144,8 @@ namespace Step.App_Start
|
||||
if (!Directory.Exists(MAINTENANCE_ATTACHMENT_PATH))
|
||||
Directory.CreateDirectory(MAINTENANCE_ATTACHMENT_PATH);
|
||||
|
||||
if (!Directory.Exists(TEMP_FILE))
|
||||
Directory.CreateDirectory(TEMP_FILE);
|
||||
if (!Directory.Exists(TEMP_PP_FOLDER))
|
||||
Directory.CreateDirectory(TEMP_PP_FOLDER);
|
||||
|
||||
if (!Directory.Exists(PART_PRG_IMAGES))
|
||||
Directory.CreateDirectory(PART_PRG_IMAGES);
|
||||
@@ -153,8 +153,8 @@ namespace Step.App_Start
|
||||
if (!Directory.Exists(JOB_TMP_DIRECTORY))
|
||||
Directory.CreateDirectory(JOB_TMP_DIRECTORY);
|
||||
|
||||
if (!Directory.Exists(QUEUE_TMP_FILE))
|
||||
Directory.CreateDirectory(QUEUE_TMP_FILE);
|
||||
if (!Directory.Exists(QUEUE_TMP_FOLDER))
|
||||
Directory.CreateDirectory(QUEUE_TMP_FOLDER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,9 +101,9 @@ namespace Step.Controllers.WebApi
|
||||
{
|
||||
ncHandler.Connect();
|
||||
|
||||
File.WriteAllBytes(TEMP_FILE + item.FileName, item.Data);
|
||||
File.WriteAllBytes(TEMP_PP_FOLDER + item.FileName, item.Data);
|
||||
|
||||
CmsError cmsError = ncHandler.UploadPartProgramAndActivate(TEMP_FILE, item.FileName, out ActiveProgramDataModel programData);
|
||||
CmsError cmsError = ncHandler.UploadPartProgramAndActivate(TEMP_PP_FOLDER, item.FileName, out ActiveProgramDataModel programData);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ namespace Step.Controllers.WebApi
|
||||
{
|
||||
ncHandler.Connect();
|
||||
|
||||
File.WriteAllBytes(QUEUE_TMP_FILE + item.FileName, item.Data);
|
||||
File.WriteAllBytes(QUEUE_TMP_FOLDER + item.FileName, item.Data);
|
||||
|
||||
// Get reps
|
||||
var repsParam = formItems.Where(x => x.ParameterName == "reps").FirstOrDefault();
|
||||
@@ -190,7 +190,7 @@ namespace Step.Controllers.WebApi
|
||||
if (repsParam == null || !Int32.TryParse(repsParam.Value, out int reps))
|
||||
return BadRequest();
|
||||
|
||||
CmsError cmsError = ncHandler.UploadPartProgramAndAddToQueue(QUEUE_TMP_FILE, item.FileName, reps, out queueItem);
|
||||
CmsError cmsError = ncHandler.UploadPartProgramAndAddToQueue(QUEUE_TMP_FOLDER, item.FileName, reps, out queueItem);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user