Load job into queue and load&Activate
WIP get active job information
This commit is contained in:
@@ -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