Added Save & Open JOBS in Client
This commit is contained in:
@@ -20,15 +20,18 @@ namespace Client.Utils
|
||||
public static String CEF_LOCALES_PATH = BASE_PATH + "CEF\\Resources\\locales";
|
||||
public static String CEF_EXCEPTIONLOG_PATH = BASE_PATH + "ExceptionLog";
|
||||
public static String errorPageFile = BASE_PATH + "error.pg";
|
||||
|
||||
|
||||
//Config Names
|
||||
public static String JOB_OPENING_PATH = BASE_PATH + "TempJob\\";
|
||||
|
||||
|
||||
//Config Names
|
||||
public const string CONFIG_KEY = "Config";
|
||||
public const string CLIENT_CONFIG_KEY = "Client";
|
||||
public const string CONNECTION_CONFIG_KEY = "Connection";
|
||||
public const string VENDORHMI_CONFIG_KEY = "VendorHmi";
|
||||
public const string EXTSFT_CONFIG_KEY = "ExtSoftwares";
|
||||
public const string SFT_CONFIG_KEY = "Software";
|
||||
public const string JOB_MAIN_FILENAME = "main.cnc";
|
||||
public const string JOB_METADATA_FILENAME = "metadata.json";
|
||||
public enum Rendering {GPU = 0, CPU = 1 };
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
@@ -63,7 +64,9 @@ namespace CMS_Client.Browser_Tools
|
||||
|
||||
AddFunction("uploadAndActivateProgram").Execute += uploadAndActivateProgram;
|
||||
AddFunction("uploadAndAddToQueue").Execute += uploadAndAddToQueue;
|
||||
|
||||
AddFunction("openJob").Execute += openJob;
|
||||
AddFunction("saveJob").Execute += saveJob;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -603,5 +606,174 @@ namespace CMS_Client.Browser_Tools
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#region JOB_METHODS
|
||||
|
||||
//Read all job
|
||||
public void openJob(object sender, CfrV8HandlerExecuteEventArgs e)
|
||||
{
|
||||
JobToStep job = new JobToStep();
|
||||
OpenFileDialog jobOpenFileDialog = new OpenFileDialog();
|
||||
jobOpenFileDialog.Filter = "CMS Job Files(*.JOB,*.ZIP)|*.job;*.zip";
|
||||
jobOpenFileDialog.Multiselect = false;
|
||||
|
||||
if (jobOpenFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (!Directory.Exists(JOB_OPENING_PATH))
|
||||
Directory.CreateDirectory(JOB_OPENING_PATH);
|
||||
|
||||
ClearTempPath();
|
||||
|
||||
using (ZipArchive archive = ZipFile.OpenRead(jobOpenFileDialog.FileName))
|
||||
{
|
||||
|
||||
//Setup main Fields
|
||||
job.Name = Path.GetFileName(jobOpenFileDialog.FileName);
|
||||
job.LastEditTimestamp = new FileInfo(jobOpenFileDialog.FileName).LastAccessTime;
|
||||
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
{
|
||||
//Main program
|
||||
if (entry.Name.Equals(JOB_MAIN_FILENAME, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
using (var reader = new StreamReader(entry.Open()))
|
||||
{
|
||||
job.IsoMainProgram = (reader.ReadToEnd());
|
||||
}
|
||||
}
|
||||
//Add all images
|
||||
else if (_validImages.Contains(Path.GetExtension(entry.Name).ToLower()))
|
||||
{
|
||||
var bytes = default(byte[]);
|
||||
using (var memstream = new MemoryStream())
|
||||
{
|
||||
entry.Open().CopyTo(memstream);
|
||||
bytes = memstream.ToArray();
|
||||
job.Metadata.Generics.Images.Add("data:image/" + Path.GetExtension(entry.Name).ToLower().TrimStart('.') + ";base64," + Convert.ToBase64String(bytes));
|
||||
}
|
||||
}
|
||||
//Metadata
|
||||
else if(entry.Name.Equals(JOB_METADATA_FILENAME, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
MetadataToFile metasFromFile = new MetadataToFile();
|
||||
|
||||
using (var reader = new StreamReader(entry.Open()))
|
||||
{
|
||||
metasFromFile = JsonConvert.DeserializeObject<MetadataToFile>(reader.ReadToEnd());
|
||||
if(metasFromFile == null)
|
||||
{
|
||||
e.SetReturnValue(null);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
job.Metadata.Generics.Description = metasFromFile.Description;
|
||||
job.Metadata.Generics.ExecutionTime = metasFromFile.ExecutionTime;
|
||||
job.Metadata.Tools = metasFromFile.Tools;
|
||||
job.Metadata.Customs = metasFromFile.Customs;
|
||||
}
|
||||
}
|
||||
}
|
||||
//All other files
|
||||
else
|
||||
{
|
||||
entry.ExtractToFile(JOB_OPENING_PATH + entry.Name, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(job));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.SetReturnValue(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Save all job
|
||||
public void saveJob(object sender, CfrV8HandlerExecuteEventArgs e)
|
||||
{
|
||||
MetadataToFile metafile = new MetadataToFile();
|
||||
|
||||
//check the arguments
|
||||
if (e.Arguments.Count() == 0)
|
||||
return;
|
||||
|
||||
//Call Save Dialog
|
||||
SaveFileDialog jobSaveFileDialog = new SaveFileDialog();
|
||||
jobSaveFileDialog.Filter = "CMS Job Files(*.JOB)|*.job|Zip Files(*.ZIP)|*.zip";
|
||||
if(jobSaveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
// Job deserialize
|
||||
JobToStep job = JsonConvert.DeserializeObject<JobToStep>(e.Arguments[0].StringValue);
|
||||
|
||||
//Metadata
|
||||
metafile.Description = job.Metadata.Generics.Description;
|
||||
metafile.ExecutionTime = job.Metadata.Generics.ExecutionTime;
|
||||
metafile.Tools = job.Metadata.Tools;
|
||||
metafile.Customs = job.Metadata.Customs;
|
||||
using (StreamWriter file = System.IO.File.CreateText(JOB_OPENING_PATH + JOB_METADATA_FILENAME))
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
serializer.Formatting = Formatting.Indented;
|
||||
serializer.Serialize(file, metafile);
|
||||
}
|
||||
|
||||
//Main Program
|
||||
System.IO.File.WriteAllText(JOB_OPENING_PATH + JOB_MAIN_FILENAME, job.IsoMainProgram);
|
||||
|
||||
//images
|
||||
int id = 1;
|
||||
foreach(string imgs in job.Metadata.Generics.Images)
|
||||
{
|
||||
System.IO.File.WriteAllBytes(JOB_OPENING_PATH + "image_"+ id + "." + GetExtensionFromBase64(imgs), Convert.FromBase64String(GetContentFromBase64(imgs)));
|
||||
id++;
|
||||
}
|
||||
|
||||
//delete Zip File if exists
|
||||
if (System.IO.File.Exists(jobSaveFileDialog.FileName))
|
||||
System.IO.File.Delete(jobSaveFileDialog.FileName);
|
||||
|
||||
//Create Zip File
|
||||
ZipFile.CreateFromDirectory(JOB_OPENING_PATH, jobSaveFileDialog.FileName);
|
||||
|
||||
}
|
||||
|
||||
e.SetReturnValue(null);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Clear the temp folder files
|
||||
private void ClearTempPath()
|
||||
{
|
||||
DirectoryInfo di = new DirectoryInfo(JOB_OPENING_PATH);
|
||||
foreach (FileInfo file in di.GetFiles())
|
||||
file.Delete();
|
||||
foreach (DirectoryInfo dir in di.GetDirectories())
|
||||
dir.Delete(true);
|
||||
}
|
||||
|
||||
|
||||
//Clear the temp folder files
|
||||
private string GetExtensionFromBase64(string base64img)
|
||||
{
|
||||
base64img = base64img.Remove(0,"data:image/".Length);
|
||||
return base64img.Substring(0, base64img.IndexOf(";base64,"));
|
||||
}
|
||||
|
||||
|
||||
//Clear the temp folder files
|
||||
private string GetContentFromBase64(string base64img)
|
||||
{
|
||||
return base64img.Substring(base64img.IndexOf(";base64,") + ";base64,".Length);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using CMS_Client.Browser_Tools.Models.Metadata;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CMS_Client.Browser_Tools.Models
|
||||
{
|
||||
public class JobToStep
|
||||
{
|
||||
public string Name;
|
||||
public DateTime LastEditTimestamp;
|
||||
public string IsoMainProgram;
|
||||
public Metas Metadata;
|
||||
|
||||
public JobToStep()
|
||||
{
|
||||
Metadata = new Metas();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CMS_Client.Browser_Tools.Models.Metadata
|
||||
{
|
||||
public class Custom_Param
|
||||
{
|
||||
public string Name;
|
||||
public string Type;
|
||||
public List<string> SelectionList;
|
||||
|
||||
public Custom_Param()
|
||||
{
|
||||
SelectionList = new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CMS_Client.Browser_Tools.Models.Metadata
|
||||
{
|
||||
public class Generic_Params
|
||||
{
|
||||
public List<string> Images;
|
||||
public string Description;
|
||||
public TimeSpan ExecutionTime;
|
||||
|
||||
public Generic_Params()
|
||||
{
|
||||
Images = new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CMS_Client.Browser_Tools.Models.Metadata
|
||||
{
|
||||
public class Metas
|
||||
{
|
||||
public Generic_Params Generics;
|
||||
public List<int> Tools;
|
||||
public List<Custom_Param> Customs;
|
||||
|
||||
public Metas()
|
||||
{
|
||||
Generics = new Generic_Params();
|
||||
Tools = new List<int>();
|
||||
Customs = new List<Custom_Param>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using CMS_Client.Browser_Tools.Models.Metadata;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CMS_Client.Browser_Tools.Models
|
||||
{
|
||||
public class MetadataToFile
|
||||
{
|
||||
public string Description;
|
||||
public TimeSpan ExecutionTime;
|
||||
public List<int> Tools;
|
||||
public List<Custom_Param> Customs;
|
||||
|
||||
public MetadataToFile()
|
||||
{
|
||||
Tools = new List<int>();
|
||||
Customs = new List<Custom_Param>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,6 +135,8 @@
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
@@ -153,6 +155,11 @@
|
||||
<Compile Include="Browser_Tools\Models\Drive.cs" />
|
||||
<Compile Include="Browser_Tools\Models\File.cs" />
|
||||
<Compile Include="Browser_Tools\Models\InfoFile.cs" />
|
||||
<Compile Include="Browser_Tools\Models\MetadataToFile.cs" />
|
||||
<Compile Include="Browser_Tools\Models\JobToStep.cs" />
|
||||
<Compile Include="Browser_Tools\Models\Metadata\Custom_Param.cs" />
|
||||
<Compile Include="Browser_Tools\Models\Metadata\Generic_Params.cs" />
|
||||
<Compile Include="Browser_Tools\Models\Metadata\Metas.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="View\LoadingForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
||||
Reference in New Issue
Block a user