Load job into queue and load&Activate
WIP get active job information
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(JsonConvert.SerializeObject(new ErrorContainer("corrupted_model")));
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_corrupted_model")));
|
||||
return;
|
||||
}
|
||||
else
|
||||
@@ -713,7 +713,7 @@ namespace CMS_Client.Browser_Tools
|
||||
metasFromFile = JsonConvert.DeserializeObject<MetadataToFile>(reader.ReadToEnd());
|
||||
if (metasFromFile == null)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("corrupted_model")));
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_corrupted_model")));
|
||||
return;
|
||||
}
|
||||
else
|
||||
@@ -737,19 +737,25 @@ namespace CMS_Client.Browser_Tools
|
||||
{
|
||||
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;
|
||||
{
|
||||
List<ZipArchiveEntry> files = archive.Entries.Where(x => x.FullName == JOB_MAIN_FILENAME || x.FullName == JOB_METADATA_FILENAME).ToList();
|
||||
|
||||
if(files.Count() < 2)
|
||||
return new ErrorContainer("error_job_not_valid");
|
||||
else
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
result = new ErrorContainer("error_file_not_found");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -761,7 +767,7 @@ namespace CMS_Client.Browser_Tools
|
||||
JobToStep job = JsonConvert.DeserializeObject<JobToStep>(e.Arguments[1].StringValue);
|
||||
if (job == null)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("corrupted_model")));
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_corrupted_model")));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -778,7 +784,7 @@ namespace CMS_Client.Browser_Tools
|
||||
var file = zipArchive.Entries.Where(x => x.FullName == JOB_METADATA_FILENAME).FirstOrDefault();
|
||||
if(file == null)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("corrupted_model")));
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_corrupted_model")));
|
||||
return;
|
||||
}
|
||||
// Update metadata file
|
||||
@@ -842,7 +848,7 @@ namespace CMS_Client.Browser_Tools
|
||||
JobToStep job = JsonConvert.DeserializeObject<JobToStep>(e.Arguments[0].StringValue);
|
||||
if (job == null)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("corrupted_model")));
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_corrupted_model")));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -892,7 +898,7 @@ namespace CMS_Client.Browser_Tools
|
||||
JobToStep job = JsonConvert.DeserializeObject<JobToStep>(e.Arguments[0].StringValue);
|
||||
if (job == null)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("corrupted_model")));
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_corrupted_model")));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -203,7 +203,7 @@ namespace Step.Model
|
||||
|
||||
// File paths
|
||||
public const string MAINTENANCE_ATTACHMENT_PATH = @"C:\CMS\STEP\attachment\";
|
||||
public const string TEMP_FOLDER = @"C:\CMS\STEP\tmp\";
|
||||
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\";
|
||||
|
||||
+52
-26
@@ -81,10 +81,39 @@ namespace Step.NC
|
||||
{
|
||||
fileInfo = new InfoFile();
|
||||
|
||||
if (File.Exists(path))
|
||||
return GetQueueFileInfo(path, out fileInfo);
|
||||
PROGRAM_TYPE_ENUM program = PROGRAM_TYPE_ENUM.NONE;
|
||||
CmsError cmsError = numericalControl.FILES_RGetProgramType(ref program);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// If the program is a job
|
||||
if(program == PROGRAM_TYPE_ENUM.JOB)
|
||||
{
|
||||
ushort selectedProcess = 0;
|
||||
cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
|
||||
string jobFolderPath = JOB_TMP_DIRECTORY + "\\" + selectedProcess + "\\";
|
||||
|
||||
DTOJobModel job = SupportFunctions.ReadExtractedJobMetadata(path);
|
||||
fileInfo = new InfoFile()
|
||||
{
|
||||
AbsolutePath = path,
|
||||
Content = job.IsoMainProgram.Split('\n').ToList(),
|
||||
PreviewBase64 = job.Metadata.Generics.Images[0].Base64,
|
||||
};
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
else
|
||||
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)
|
||||
@@ -226,10 +255,9 @@ namespace Step.NC
|
||||
}
|
||||
else
|
||||
{
|
||||
DTOJobModel job = SupportFunctions.UnpackJobAndReadMetadata(localPath + fileName);
|
||||
DTOJobModel job = SupportFunctions.UnpackJobAndReadMetadata(localPath + fileName, selectedProcess);
|
||||
return numericalControl.FILES_WUploadJobFilesAndActivate(selectedProcess, JOB_TMP_DIRECTORY, JOB_MAIN_FILENAME);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public CmsError UploadPartProgramAndAddToQueue(string localPath, string fileName, int reps, out DTOQueueModel queueItem)
|
||||
@@ -268,16 +296,9 @@ namespace Step.NC
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
public CmsError UploadJob(string path)
|
||||
{
|
||||
DTOJobModel jobData = SupportFunctions.UnpackJobAndReadMetadata(path);
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public CmsError UpdateQueue()
|
||||
{
|
||||
// Get selectedProcess id
|
||||
// Get queue data
|
||||
List<QueueStatusModel> queueData = new List<QueueStatusModel>();
|
||||
|
||||
CmsError cmsError = numericalControl.FILES_RQueueData(ref queueData);
|
||||
@@ -304,7 +325,6 @@ 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))
|
||||
//{
|
||||
@@ -315,12 +335,21 @@ namespace Step.NC
|
||||
// if next part program exists, set next pp as current pp
|
||||
QueueRunningIndexes[item.ProcessId] += 1;
|
||||
|
||||
// Change part program
|
||||
cmsError = numericalControl
|
||||
.FILES_WLoadNextPartProgram(
|
||||
PartProgramQueue[item.ProcessId][QueueRunningIndexes[item.ProcessId]].AbsolutePath,
|
||||
QUEUE_FILE_NAME
|
||||
);
|
||||
// Check if file is a valid job
|
||||
if (SupportFunctions.IsValidJob(PartProgramQueue[item.ProcessId][QueueRunningIndexes[item.ProcessId]].AbsolutePath))
|
||||
{
|
||||
// Unpack job
|
||||
DTOJobModel job = SupportFunctions.UnpackJobAndReadMetadata(PartProgramQueue[item.ProcessId][QueueRunningIndexes[item.ProcessId]].AbsolutePath, item.ProcessId);
|
||||
// Load JOB to NC
|
||||
return numericalControl.FILES_WUploadJobFilesAndActivate(item.ProcessId, JOB_TMP_DIRECTORY, JOB_MAIN_FILENAME);
|
||||
}
|
||||
else
|
||||
// Upload & activate new part program
|
||||
cmsError = numericalControl
|
||||
.FILES_WLoadNextPartProgram(
|
||||
PartProgramQueue[item.ProcessId][QueueRunningIndexes[item.ProcessId]].AbsolutePath,
|
||||
QUEUE_FILE_NAME
|
||||
);
|
||||
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
@@ -343,11 +372,6 @@ namespace Step.NC
|
||||
PartProgramQueue[item.ProcessId][QueueRunningIndexes[item.ProcessId]].Status = QUEUE_ITEM_STATUS.WAITING_OPERATOR;
|
||||
}
|
||||
}
|
||||
// Update data
|
||||
//using (QueueController queueController = new QueueController())
|
||||
//{
|
||||
// queueController.UpdateQueue();
|
||||
//}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
@@ -501,6 +525,8 @@ namespace Step.NC
|
||||
// Clean directory
|
||||
SupportFunctions.EmptyFolder(JOB_TMP_DIRECTORY);
|
||||
|
||||
QueueRunningIndexes[processId] = 0;
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,14 +126,18 @@ namespace Step.Utils
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static DTOJobModel UnpackJobAndReadMetadata(string filePath)
|
||||
public static DTOJobModel UnpackJobAndReadMetadata(string filePath, int processId)
|
||||
{
|
||||
DTOJobModel job = new DTOJobModel();
|
||||
string jobFolderPath = JOB_TMP_DIRECTORY + "\\" + processId + "\\";
|
||||
if (!Directory.Exists(jobFolderPath))
|
||||
Directory.CreateDirectory(jobFolderPath);
|
||||
|
||||
// Check if job exists
|
||||
if (!File.Exists(filePath))
|
||||
return null;
|
||||
|
||||
EmptyFolder(JOB_TMP_DIRECTORY);
|
||||
EmptyFolder(jobFolderPath);
|
||||
|
||||
using (ZipArchive zipExtractor = ZipFile.OpenRead(filePath))
|
||||
{
|
||||
@@ -144,7 +148,7 @@ namespace Step.Utils
|
||||
foreach (ZipArchiveEntry entry in zipExtractor.Entries)
|
||||
{
|
||||
// Extract file
|
||||
entry.ExtractToFile(JOB_TMP_DIRECTORY + entry.Name, true);
|
||||
entry.ExtractToFile(jobFolderPath + entry.Name, true);
|
||||
|
||||
// Get main program content
|
||||
if (entry.Name.Equals(JOB_MAIN_FILENAME, StringComparison.OrdinalIgnoreCase))
|
||||
@@ -192,7 +196,7 @@ namespace Step.Utils
|
||||
// Consider other file as part program
|
||||
else
|
||||
{
|
||||
job.PartPrograms.Add(JOB_TMP_DIRECTORY + entry.Name);
|
||||
job.PartPrograms.Add(jobFolderPath + entry.Name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,5 +212,92 @@ namespace Step.Utils
|
||||
foreach (DirectoryInfo dir in di.GetDirectories())
|
||||
dir.Delete(true);
|
||||
}
|
||||
|
||||
public static bool IsValidJob(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
using (var archive = ZipFile.OpenRead(filePath))
|
||||
{
|
||||
// Find key files
|
||||
List<ZipArchiveEntry> files = archive
|
||||
.Entries
|
||||
.Where(x => x.FullName == JOB_MAIN_FILENAME || x.FullName == JOB_METADATA_FILENAME)
|
||||
.ToList();
|
||||
// if there aren't both
|
||||
if (files.Count() < 2)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static DTOJobModel ReadExtractedJobMetadata(string filePath)
|
||||
{
|
||||
// Check if zip is valid
|
||||
if (!IsValidJob(filePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Open zip archive
|
||||
using (ZipArchive zipArchive = ZipFile.OpenRead(filePath))
|
||||
{
|
||||
// Setup main Fields
|
||||
DTOJobModel jobData = new DTOJobModel()
|
||||
{
|
||||
Name = Path.GetFileName(filePath),
|
||||
LastEditTimestamp = new FileInfo(filePath).LastAccessTime
|
||||
};
|
||||
|
||||
foreach (ZipArchiveEntry entry in zipArchive.Entries)
|
||||
{
|
||||
// Get images content without extract files
|
||||
if (VALID_IMAGE_EXTENSIONS.Contains(Path.GetExtension(entry.Name).ToLower()))
|
||||
{
|
||||
using (var memoryReader = new MemoryStream())
|
||||
{
|
||||
entry.Open().CopyTo(memoryReader);
|
||||
jobData.Metadata.Generics.Images.Add(new DTOImageParamModel()
|
||||
{
|
||||
Name = Path.GetFileName(entry.Name),
|
||||
Base64 = "data:image/" + Path.GetExtension(entry.Name).ToLower().TrimStart('.') + ";base64," + Convert.ToBase64String(memoryReader.ToArray())
|
||||
});
|
||||
}
|
||||
}
|
||||
// Metadata
|
||||
else if (entry.Name.Equals(JOB_METADATA_FILENAME, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
DTOMetadataFieldsModel metasFromFile = new DTOMetadataFieldsModel();
|
||||
|
||||
using (var reader = new StreamReader(entry.Open()))
|
||||
{
|
||||
metasFromFile = JsonConvert.DeserializeObject<DTOMetadataFieldsModel>(reader.ReadToEnd());
|
||||
if (metasFromFile == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
jobData.Metadata.Generics.Description = metasFromFile.Description;
|
||||
jobData.Metadata.Generics.ExecutionTime = metasFromFile.ExecutionTime;
|
||||
jobData.Metadata.Tools = metasFromFile.Tools;
|
||||
jobData.Metadata.Customs = metasFromFile.Customs;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return jobData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user