diff --git a/Client.Config/Config.cs b/Client.Config/Config.cs index 7a40da5b..4ba4f35d 100644 --- a/Client.Config/Config.cs +++ b/Client.Config/Config.cs @@ -14,6 +14,7 @@ namespace Client.Config public static SubModels.Connection ConnectionConfig; public static SubModels.VendorHmi VendorHmiConfig; public static SubModels.ProdSoftware ProdSoftwareConfig { get; set; } + public static string TextEditorPath { get; set; } public static SubModels.Software[] ExtSoftwaresConfig { get; set; } } diff --git a/Client.Config/SubModels/ServerConfigModel.cs b/Client.Config/SubModels/ServerConfigModel.cs index 09b28e2f..b95597e2 100644 --- a/Client.Config/SubModels/ServerConfigModel.cs +++ b/Client.Config/SubModels/ServerConfigModel.cs @@ -15,6 +15,8 @@ namespace Client.Config.SubModels public string ProdEnabled { get; set; } public string ProdPath { get; set; } public string Autorun { get; set; } + public string EditorPath { get; set; } + public List ExtSoftwares { get; set; } } } diff --git a/Client.Utils/Constants.cs b/Client.Utils/Constants.cs index 34a00d1b..2706c541 100644 --- a/Client.Utils/Constants.cs +++ b/Client.Utils/Constants.cs @@ -10,17 +10,17 @@ namespace Client.Utils { //Folders - public static String BASE_PATH = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\"; - public static String BROWSER_CACHE_FOLDER = BASE_PATH + "LocalStorage"; - public static String STARTUP_CONFIG_SCHEMA_PATH = BASE_PATH + "ClientValidator.xsd"; - public static String STARTUP_CONFIG_PATH = BASE_PATH + "Config.xml"; - public static String CEF_PATH = BASE_PATH + "CEF"; - public static String CEF_X86_PATH = BASE_PATH + "CEF\\Release_X86"; - public static String CEF_X64_PATH = BASE_PATH + "CEF\\Release_X64"; - 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"; - public static String JOB_OPENING_PATH = "C:\\CMS\\ACTIVE\\TMP\\clientTmpJob\\"; + public static string BASE_PATH = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\"; + public static string BROWSER_CACHE_FOLDER = BASE_PATH + "LocalStorage"; + public static string STARTUP_CONFIG_SCHEMA_PATH = BASE_PATH + "ClientValidator.xsd"; + public static string STARTUP_CONFIG_PATH = BASE_PATH + "Config.xml"; + public static string CEF_PATH = BASE_PATH + "CEF"; + public static string CEF_X86_PATH = BASE_PATH + "CEF\\Release_X86"; + public static string CEF_X64_PATH = BASE_PATH + "CEF\\Release_X64"; + 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"; + public static string JOB_OPENING_PATH = "C:\\CMS\\ACTIVE\\TMP\\clientTmpJob\\"; public static string PART_PRG_FOLDER = "C:\\PartPrg"; //Config Names @@ -37,7 +37,7 @@ namespace Client.Utils //BROWSER OBJECT NAME -> The first letter must be Lower-Case (CEF Settings) - public const String BROWSER_JS_OBJ_NAME = "cmsClient"; + public const string BROWSER_JS_OBJ_NAME = "cmsClient"; //Nc States public enum NcState { HIDE = 0, SHOW = 1, SHOWPROD = 2 }; diff --git a/Client/Browser_Tools/BrowserJSObject.cs b/Client/Browser_Tools/BrowserJSObject.cs index a48146b0..97a9ad90 100644 --- a/Client/Browser_Tools/BrowserJSObject.cs +++ b/Client/Browser_Tools/BrowserJSObject.cs @@ -20,17 +20,32 @@ using System.Threading; using System.Windows.Forms; using static Client.Utils.Constants; using System.Management; +using Chromium.Remote; +using System.Text; namespace Active_Client.Browser_Tools { public class BrowserJSObject : JSObject { + private struct EditorVar + { + public CfrV8Value func; + public CfrV8Context context; + public string file; + } // The first letter of All PUBLIC Variables and Methods must be Lower-Case (CEF Settings) private MainForm mainForm; - private static readonly string[] _validExtensions = { "", ".txt", ".cnc", ".cn", ".cno", ".ini", ".mpf", ".spf", ".iso" /*".job", ".zip"*/ }; + + private static readonly string[] _validExtensions = { "", ".txt", ".cnc", ".cn", ".cno", ".ini", ".mpf", ".spf", ".tap", ".anc", ".iso", /*".job", ".zip"*/ }; private static readonly string[] _validImages = { ".jpg", ".jpeg", ".png" }; private static string jobPath = ""; + private static Dictionary _editorOpened = new Dictionary(); + private static EditorVar _currentEditorObject = new EditorVar(); + public static string RECENT_FOLDER_KEY = "RECENT"; + + public static FileSystemWatcher watcher = null; + public static DateTime _lastTimeFileWatcherEventRaised = DateTime.Now; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -41,11 +56,13 @@ namespace Active_Client.Browser_Tools { mainForm = f; + AddDynamicProperty("RECENT_FOLDER_KEY").PropertyGet += getProp; + AddFunction("minimizeForm").Execute += minimizeForm; AddFunction("maximizeForm").Execute += maximizeForm; AddFunction("closeForm").Execute += closeForm; AddFunction("forceStepFocus").Execute += forceStepFocus; - AddFunction("forceNcFocus").Execute += forceNcFocus; + AddFunction("forceNcFocus").Execute += forceNcFocus; AddFunction("reloadBrokenPage").Execute += reloadBrokenPage; AddFunction("setNcWindowState").Execute += setNcWindowState; @@ -61,6 +78,7 @@ namespace Active_Client.Browser_Tools AddFunction("getOSdriveList").Execute += getOSdriveList; AddFunction("getFileList").Execute += getFileList; AddFunction("getProgramInfo").Execute += getProgramInfo; + AddFunction("editProgram").Execute += editProgram; AddFunction("uploadAndActivateProgram").Execute += uploadAndActivateProgram; AddFunction("uploadAndAddToQueue").Execute += uploadAndAddToQueue; @@ -74,15 +92,22 @@ namespace Active_Client.Browser_Tools AddFunction("delImageFromJob").Execute += delImageFromJob; AddFunction("addPPToJob").Execute += addPPToJob; AddFunction("delPPFromJob").Execute += delPPFromJob; - AddFunction("readJobMetadata").Execute += readJobMetadata; + AddFunction("readJobMetadata").Execute += readJobMetadata; AddFunction("updateJobMetadata").Execute += updateJobMetadata; AddFunction("isHMIenabled").Execute += isHMIenabled; AddFunction("isPRODenabled").Execute += isPRODenabled; AddFunction("isSCMVisualStyle").Execute += isSCMVisualStyle; + AddFunction("cleanFileWatcher").Execute += cleanFileWatcher; } #endregion CONSTRUCTOR_METHOD + public void getProp(object sender, CfrV8AccessorGetEventArgs e) + { + e.Retval = RECENT_FOLDER_KEY; + e.SetReturnValue(true); + } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region FORM_BEHAVIOUR_METHODS @@ -123,7 +148,7 @@ namespace Active_Client.Browser_Tools //If the mainform is disposed do nothing if (mainForm.IsDisposed) return; - + //Invoke method if is needed or call the method in STD mode if (mainForm.InvokeRequired) mainForm.Invoke((MethodInvoker)delegate () @@ -158,7 +183,7 @@ namespace Active_Client.Browser_Tools if (NcWindow.State == NcState.SHOW) mainForm.ShowNCWindow(); - else if(NcWindow.State == NcState.SHOWPROD) + else if (NcWindow.State == NcState.SHOWPROD) mainForm.ShowProdWindow(); else mainForm.HideAUXWindow(); @@ -221,28 +246,28 @@ namespace Active_Client.Browser_Tools // Get the option of virtual Keyb configured private void isVirtualKeybConfigured(object sender, CfrV8HandlerExecuteEventArgs e) { - e.SetReturnValue((Boolean)Config.ClientConfig.ShowVirtualKeyboard); + e.SetReturnValue((bool)Config.ClientConfig.ShowVirtualKeyboard); } // Get the option of virtual Keyb configured private void isHMIenabled(object sender, CfrV8HandlerExecuteEventArgs e) { - e.SetReturnValue((Boolean)Config.VendorHmiConfig.Enabled); + e.SetReturnValue((bool)Config.VendorHmiConfig.Enabled); } // Get the option of PROD Enabled private void isPRODenabled(object sender, CfrV8HandlerExecuteEventArgs e) { - e.SetReturnValue((Boolean)Config.ProdSoftwareConfig.Enabled); + e.SetReturnValue((bool)Config.ProdSoftwareConfig.Enabled); } // Get the SCM option private void isSCMVisualStyle(object sender, CfrV8HandlerExecuteEventArgs e) { - e.SetReturnValue((Boolean)Config.ClientConfig.IsSCM); + e.SetReturnValue((bool)Config.ClientConfig.IsSCM); } - + #endregion STEP_METHODS /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -266,7 +291,7 @@ namespace Active_Client.Browser_Tools { if (e.Arguments.Count() == 0) return; - + Thread t = new Thread(new ParameterizedThreadStart(OpenNew)); t.Start(e.Arguments[0].StringValue); } @@ -286,12 +311,12 @@ namespace Active_Client.Browser_Tools { Software sft = Config.ExtSoftwaresConfig.FirstOrDefault(X => X.id == (string)id); - if (sft != null && System.IO.File.Exists(sft.path)) + if (sft != null && File.Exists(sft.path)) { Process[] p = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(sft.path)).OrderByDescending(X => X.StartTime).ToArray(); if (p.Count() > 0 && p[0].MainWindowHandle != IntPtr.Zero) - NcWindow.ForceExtFocus(p[0].MainWindowHandle); + NcWindow.ForceExtFocus(p[0].MainWindowHandle, 0, 0, 0, 0); else { ProcessStartInfo PS = new ProcessStartInfo(sft.path, sft.arguments); @@ -324,13 +349,13 @@ namespace Active_Client.Browser_Tools { List drivelist = new List(); - //USB & HD Drives + // USB & HD Drives foreach (var drive in DriveInfo.GetDrives()) { if (drive.IsReady) { //Filter NC Address - if(drive.DriveType != DriveType.Network) + if (drive.DriveType != DriveType.Network) { drivelist.Add(new Drive() { @@ -342,26 +367,15 @@ namespace Active_Client.Browser_Tools } } - //Desktop folder + // Desktop folder drivelist.Add(new Drive() { Name = ElaborateName("Desktop", "", DriveType.Unknown), Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\", Type = "SPFO" }); - - //PartPRG Folder - if (Directory.Exists(PART_PRG_FOLDER)) - { - drivelist.Add(new Drive() - { - Name = ElaborateName("PartPrg", "", DriveType.Unknown), - Path = PART_PRG_FOLDER + "\\", - Type = "SPFO" - }); - } - - //Network Folders + + // Network Folders var searcher = new ManagementObjectSearcher("select * from Win32_MappedLogicalDisk"); foreach (ManagementObject queryObj in searcher.Get()) { @@ -374,7 +388,7 @@ namespace Active_Client.Browser_Tools Path = queryObj["Name"].ToString(), Type = ElaborateType(DriveType.Network) }); - } + } } e.SetReturnValue(JsonConvert.SerializeObject(drivelist)); @@ -383,57 +397,63 @@ namespace Active_Client.Browser_Tools // Read all files in directory public void getFileList(object sender, CfrV8HandlerExecuteEventArgs e) { - List filelist = new List(); + List filelist = new List(); if (e.Arguments.Count() == 0) { - e.SetReturnValue(JsonConvert.SerializeObject(new List())); + e.SetReturnValue(JsonConvert.SerializeObject(new List())); return; } - String p = e.Arguments[0].StringValue; - if (!Directory.Exists(p)) + string p = e.Arguments[0].StringValue; + if (p != RECENT_FOLDER_KEY && !Directory.Exists(p)) { - e.SetReturnValue(JsonConvert.SerializeObject(new List())); + e.SetReturnValue(JsonConvert.SerializeObject(new List())); return; } try { - foreach (String item in Directory.GetDirectories(p)) + if(p == RECENT_FOLDER_KEY) { - filelist.Add(new Models.File - { - Name = Path.GetFileName(item), - AbsolutePath = Path.GetFullPath(item), - Path = Path.GetFullPath(item), - IsDirectory = true - }); + filelist = GetLastUploadedFiles(); } - } - catch (Exception ex) - { - } - try - { - foreach (String item in Directory.GetFiles(p)) + else { - if (_validExtensions.Contains(Path.GetExtension(item).ToLower())) + // Add directories + foreach (string item in Directory.GetDirectories(p)) { - bool isJob = JOB_EXTENSIONS.Contains(Path.GetExtension(item)); - filelist.Add(new Models.File + filelist.Add(new FileModel { Name = Path.GetFileName(item), AbsolutePath = Path.GetFullPath(item), Path = Path.GetFullPath(item), - IsDirectory = false, - IsJob = isJob + IsDirectory = true, + FileExist = true, + IsMain = false }); } + + // Add files + foreach (string item in Directory.GetFiles(p)) + { + if (_validExtensions.Contains(Path.GetExtension(item).ToLower())) + { + bool isJob = JOB_EXTENSIONS.Contains(Path.GetExtension(item)); + filelist.Add(new FileModel + { + Name = Path.GetFileName(item), + AbsolutePath = Path.GetFullPath(item), + Path = Path.GetFullPath(item), + IsDirectory = false, + IsJob = isJob, + IsMain = false, + FileExist = true + }); + } + } } } - catch (Exception ex) - { - } + catch { } e.SetReturnValue(JsonConvert.SerializeObject(filelist)); } @@ -441,79 +461,102 @@ namespace Active_Client.Browser_Tools // Upload and activate the program public async void uploadAndActivateProgram(object sender, CfrV8HandlerExecuteEventArgs e) { - String fileToUpload = ""; - Boolean uploadAllFiles = false; - Byte[] filecontent = null, imagecontent = null; - String fileNameNoExt; - String imageName = ""; - String fileName; - String imageDirectory; - String dirName; + string fileToUpload = ""; + byte[] filecontent = null, imagecontent = null; + string fileNameNoExt; + string imageName = ""; + string fileName; + string imageDirectory; + string dirName; - //Check the arguments numbers + // Check the arguments numbers if (e.Arguments.Length < 2 || e.Arguments[0] == null || e.Arguments[1] == null) { e.SetReturnValue(UPLOAD_PAGE + ";INVALID_ARGUMENTS"); return; } - //Check if the file exists + // Check if the file exists fileToUpload = e.Arguments[0].StringValue; - if (!System.IO.File.Exists(fileToUpload)) + if (!File.Exists(fileToUpload)) { e.SetReturnValue(UPLOAD_PAGE + ";FILE_NOT_FOUND"); return; } - //Check if must be uploaded all files - uploadAllFiles = e.Arguments[1].BoolValue; + // Check if must be uploaded all files + bool uploadAllFiles = e.Arguments[1].BoolValue; + // Check if recent files are selected + bool recentDriveSelected = e.Arguments[2].BoolValue; - //Get names and content of the file + // Get names and content of the file fileNameNoExt = Path.GetFileNameWithoutExtension(fileToUpload); fileName = Path.GetFileName(fileToUpload); - filecontent = System.IO.File.ReadAllBytes(fileToUpload); + filecontent = File.ReadAllBytes(fileToUpload); - //Get all bytes of the image (if exists) + // Get all bytes of the image (if exists) imageDirectory = Path.GetDirectoryName(fileToUpload); foreach (string ext in _validImages) { - if (System.IO.File.Exists(imageDirectory + "/" + fileNameNoExt + ext)) + if (File.Exists(imageDirectory + "/" + fileNameNoExt + ext)) { imageName = fileNameNoExt + ext; - imagecontent = System.IO.File.ReadAllBytes(imageDirectory + "/" + fileNameNoExt + ext); + imagecontent = File.ReadAllBytes(imageDirectory + "/" + fileNameNoExt + ext); break; } } - //Send all to the server + // Send all to the server using (HttpClient httpClient = new HttpClient()) { - //Create the new FORM + // Create the new FORM MultipartFormDataContent form = new MultipartFormDataContent { - //Add the content to the form + // Add the main program to the form { new ByteArrayContent(filecontent), "main", fileName } }; - if (uploadAllFiles) + + List files = GetFileToUpload(fileToUpload, uploadAllFiles, recentDriveSelected); + + //if (recentDriveSelected) + //{ + // List files = GetLastUploadedFiles(); + + // foreach(FileModel file in files) + // { + // if(file.FileExist && !file.IsMain) + // form.Add(new ByteArrayContent(File.ReadAllBytes(file.AbsolutePath)), "file", file.Name); + // } + //} + //else if (uploadAllFiles) + //{ + // // Load all the programs in the selected folder + // dirName = Path.GetDirectoryName(fileToUpload); + // string[] fileEntries = Directory.GetFiles(dirName); + // foreach (string subfileName in fileEntries) + // { + // if (fileToUpload.ToLower() != subfileName.ToLower() && _validExtensions.Contains(Path.GetExtension(subfileName).ToLower())) + // form.Add(new ByteArrayContent(File.ReadAllBytes(subfileName)), "file", Path.GetFileName(subfileName)); + // } + //} + + foreach(FileModel file in files) { - dirName = Path.GetDirectoryName(fileToUpload); - string[] fileEntries = Directory.GetFiles(dirName); - foreach (string subfileName in fileEntries) - { - if(fileToUpload.ToLower() != subfileName.ToLower() && _validExtensions.Contains(Path.GetExtension(subfileName).ToLower())) - { - form.Add(new ByteArrayContent(System.IO.File.ReadAllBytes(subfileName)), "file", Path.GetFileName(subfileName)); - } - } + if(!file.IsMain) + form.Add(new ByteArrayContent(File.ReadAllBytes(file.AbsolutePath)), "file", Path.GetFileName(file.AbsolutePath)); } + if (imagecontent != null) form.Add(new ByteArrayContent(imagecontent), "image", imageName); - //Send them - HttpResponseMessage response = httpClient.PostAsync( - "http://" + Config.ConnectionConfig.ServerUrl + ":" + Config.ConnectionConfig.ServerPort + "/" + Constants.UPLOAD_PAGE, - form).Result; - //Wait the answer + // Send them + HttpResponseMessage response = httpClient + .PostAsync("http://" + Config.ConnectionConfig.ServerUrl + ":" + Config.ConnectionConfig.ServerPort + "/" + UPLOAD_PAGE, form) + .Result; + + WriteLastUploadedFile(files); + + // Wait the answer if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) e.SetReturnValue(UPLOAD_PAGE + ";" + await response.Content.ReadAsStringAsync()); else if (response.StatusCode != System.Net.HttpStatusCode.OK) @@ -527,14 +570,14 @@ namespace Active_Client.Browser_Tools public async void uploadAndAddToQueue(object sender, CfrV8HandlerExecuteEventArgs e) { string fileToUpload = ""; - Byte[] filecontent = null, imagecontent = null; + byte[] filecontent = null, imagecontent = null; string fileNameNoExt; string imageName = ""; string fileName; string imageDirectory; int reps = 0; - //Check the arguments numbers + // Check the arguments numbers if (e.Arguments.Length < 1 || e.Arguments[0] == null) { e.SetReturnValue(UPLOAD_ADD_QUEUE + "INVALID_ARGUMENTS"); @@ -545,37 +588,39 @@ namespace Active_Client.Browser_Tools fileToUpload = e.Arguments[0].StringValue; reps = e.Arguments[1].IntValue; - if (!System.IO.File.Exists(fileToUpload)) + if (!File.Exists(fileToUpload)) { e.SetReturnValue(UPLOAD_ADD_QUEUE + ";FILE_NOT_FOUND"); return; } - //Get names and content of the file + // Get names and content of the file fileNameNoExt = Path.GetFileNameWithoutExtension(fileToUpload); fileName = Path.GetFileName(fileToUpload); ; - filecontent = System.IO.File.ReadAllBytes(fileToUpload); + filecontent = File.ReadAllBytes(fileToUpload); - //Get all bytes of the image (if exists) + // Get all bytes of the image (if exists) imageDirectory = Path.GetDirectoryName(fileToUpload); foreach (string ext in _validImages) { - if (System.IO.File.Exists(imageDirectory + "/" + fileNameNoExt + ext)) + if (File.Exists(imageDirectory + "/" + fileNameNoExt + ext)) { imageName = fileNameNoExt + ext; - imagecontent = System.IO.File.ReadAllBytes(imageDirectory + "/" + fileNameNoExt + ext); + imagecontent = File.ReadAllBytes(imageDirectory + "/" + fileNameNoExt + ext); break; } } - //Send all to the server + // Send all to the server using (HttpClient httpClient = new HttpClient()) { //Create the new FORM - MultipartFormDataContent form = new MultipartFormDataContent(); + MultipartFormDataContent form = new MultipartFormDataContent + { - //Add the content to the form - form.Add(new ByteArrayContent(filecontent), "file", fileName); + //Add the content to the form + { new ByteArrayContent(filecontent), "file", fileName } + }; if (imagecontent != null) form.Add(new ByteArrayContent(imagecontent), "image", imageName); // Add reps to the form-data @@ -599,7 +644,6 @@ namespace Active_Client.Browser_Tools // Read info of a file public void getProgramInfo(object sender, CfrV8HandlerExecuteEventArgs e) { - InfoFile file = new InfoFile(); string line, imagePath, imageDirectory; int counter = 0; @@ -609,18 +653,23 @@ namespace Active_Client.Browser_Tools return; } - String p = e.Arguments[0].StringValue; - if (!System.IO.File.Exists(p)) + string p = e.Arguments[0].StringValue; + if (!File.Exists(p)) { e.SetReturnValue(JsonConvert.SerializeObject(new InfoFile())); return; } FileInfo f = new FileInfo(p); - file.Name = f.Name; - file.CreationDate = f.CreationTime; - file.LastModDate = f.LastAccessTime; - file.AbsolutePath = p; + InfoFile file = new InfoFile + { + Name = f.Name, + CreationDate = f.CreationTime, + LastModDate = f.LastAccessTime, + AbsolutePath = p, + CanEdit = !f.IsReadOnly + }; + imagePath = Path.GetFileNameWithoutExtension(p); imageDirectory = Path.GetDirectoryName(p); @@ -637,9 +686,9 @@ namespace Active_Client.Browser_Tools foreach (string ext in _validImages) { - if (System.IO.File.Exists(imageDirectory + "/" + imagePath + ext)) + if (File.Exists(imageDirectory + "/" + imagePath + ext)) { - file.PreviewBase64 = "data:image/" + ext + ";base64," + Convert.ToBase64String(System.IO.File.ReadAllBytes(imageDirectory + "/" + imagePath + ext)); + file.PreviewBase64 = "data:image/" + ext + ";base64," + Convert.ToBase64String(File.ReadAllBytes(imageDirectory + "/" + imagePath + ext)); break; } } @@ -651,32 +700,210 @@ namespace Active_Client.Browser_Tools e.SetReturnValue(JsonConvert.SerializeObject(file)); } - // Private functions - private String ElaborateName(String name, String letter, DriveType type) + // Launch file editor + public void editProgram(object sender, CfrV8HandlerExecuteEventArgs e) { - var retName = ""; - - if (!String.IsNullOrWhiteSpace(name)) - retName = name; - else + if (e.Arguments.Count() < 2) { - switch (type) + e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_arguments_not_ok"))); + return; + } + // Get path + string p = e.Arguments[0].StringValue; + if (!File.Exists(p)) + { + e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("file_not_found"))); + return; + } + + // Check if editor exist + if (!File.Exists(Config.TextEditorPath)) + { + e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("editor_not_configured"))); + return; + } + + _currentEditorObject = new EditorVar + { + context = CfrV8Context.GetCurrentContext(), + func = e.Arguments[1], + file = p + }; + + Thread t = new Thread(startNewEditor); + t.Start(); + } + + public void startNewEditor() + { + Process proc = new Process + { + StartInfo = new ProcessStartInfo() { - case DriveType.Fixed: retName = "Hard_Disk";break; - case DriveType.Removable: retName = "Usb_Disk"; break; - case DriveType.Network: retName = "Netword_Disk"; break; - default: retName = "Undefined"; break; + FileName = Config.TextEditorPath, + Arguments = _currentEditorObject.file + } + }; + + // Start editor process + proc.Start(); + // Start watcher + WatchFile(); + } + + public void cleanFileWatcher(object sender, CfrV8HandlerExecuteEventArgs e) + { + if(watcher != null) + { + watcher.EnableRaisingEvents = false; + + watcher = null; + } + } + + public static void WatchFile() + { + if (watcher == null) + { + watcher = new FileSystemWatcher + { + // Watch for changes in LastWrite times + NotifyFilter = NotifyFilters.LastWrite + }; + // Set event handler + watcher.Changed += OnChanged; + } + + // Set filter in order to watch only selected files + watcher.Filter = Path.GetFileName(_currentEditorObject.file); + // Set directory path + watcher.Path = Path.GetDirectoryName(_currentEditorObject.file); + + // Add event handlers + if (!watcher.EnableRaisingEvents) + watcher.EnableRaisingEvents = true; + } + + // Define the event handlers. + private static void OnChanged(object source, FileSystemEventArgs e) + { + // FileSystemWatcher has a bug which fires twice the onChange event + // Avoid duplicated events + if (DateTime.Now.Subtract(_lastTimeFileWatcherEventRaised).TotalMilliseconds < 500) + return; + // Update last event time + _lastTimeFileWatcherEventRaised = DateTime.Now; + + //// Call JS return function + CallJSFunction(_currentEditorObject.func, null, _currentEditorObject.context); + } + + private void WriteLastUploadedFile(List files) + { + StringBuilder stringBuilder = new StringBuilder(); + + bool isFirst = true; + foreach (FileModel file in files) + { + string stringVal = ""; + if (!file.IsMain) + stringVal = file.AbsolutePath + ";false"; + else + stringVal = file.AbsolutePath + ";true"; + + if (!isFirst) + stringVal = Environment.NewLine + stringVal; + else + isFirst = false; + + stringBuilder.Append(stringVal); + } + + File.WriteAllLines(".active.list", stringBuilder.ToString() + .Split( + new[] { Environment.NewLine }, + StringSplitOptions.None + )); + } + + private List GetFileToUpload(string main, bool uploadAllFiles, bool recentDriveSelected) + { + // Add main to list + List files = new List() + { + new FileModel(){ + AbsolutePath = main, + Name = Path.GetFileName(main), + Path = main, FileExist = File.Exists(main), + IsDirectory = false, + IsMain = true + } + }; + + // Check recent files + if (recentDriveSelected) + { + List recentFiles = GetLastUploadedFiles(); + + foreach (FileModel file in recentFiles) + { + if (file.FileExist && !file.IsMain) + files.Add(file); + + } + } + // Check if software need to upload all the files + else if (uploadAllFiles) + { + string dirName = Path.GetDirectoryName(main); + string[] fileEntries = Directory.GetFiles(dirName); + foreach (string subfileName in fileEntries) + { + if (main.ToLower() != subfileName.ToLower() && _validExtensions.Contains(Path.GetExtension(subfileName).ToLower())) + { + // Add file + files.Add(new FileModel() + { + AbsolutePath = subfileName, + FileExist = true, + IsDirectory = false, + IsMain = false, + Name = Path.GetFileName(subfileName), + Path = subfileName + }); + } } } - - if (!String.IsNullOrWhiteSpace(letter)) - retName = retName + " (" + letter + ")"; - - return retName; + return files; } - private String ElaborateType(DriveType type) + private List GetLastUploadedFiles() + { + if (!File.Exists(".active.list")) + return new List(); + + string[] fileEntries = File.ReadAllLines(".active.list"); + + List files = new List(); + foreach (string row in fileEntries) + { + string[] rowData = row.Split(';'); + files.Add(new FileModel + { + Name = Path.GetFileName(rowData[0]), + AbsolutePath = Path.GetFullPath(rowData[0]), + Path = Path.GetFullPath(rowData[0]), + IsDirectory = false, + IsMain = Convert.ToBoolean(rowData[1]), + FileExist = File.Exists(rowData[0]) + }); + } + + return files; + } + + private string ElaborateType(DriveType type) { switch (type) { @@ -687,8 +914,59 @@ namespace Active_Client.Browser_Tools return "SPFO"; } - #endregion FILESYSTEM_METHODS + // Private functions + private string ElaborateName(string name, string letter, DriveType type) + { + var retName = ""; + if (!string.IsNullOrWhiteSpace(name)) + retName = name; + else + { + switch (type) + { + case DriveType.Fixed: retName = "Hard_Disk"; break; + case DriveType.Removable: retName = "Usb_Disk"; break; + case DriveType.Network: retName = "Netword_Disk"; break; + default: retName = "Undefined"; break; + } + } + + + if (!string.IsNullOrWhiteSpace(letter)) + retName = retName + " (" + letter + ")"; + + return retName; + } + + #endregion FILESYSTEM_METHODS + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region RECALL_METHOD + + private static void CallJSFunction(CfrV8Value functionIstance, string arguments, CfrV8Context context) + { + //Create & enter function context + var rpcContext = functionIstance.CreateRemoteCallContext(); + rpcContext.Enter(); + + //Task to execute + var task = new CfrTask(); + task.Execute += (s, e) => + { + context.Enter(); + var args = new CfrV8Value[] { arguments }; + functionIstance.ExecuteFunction(null, args); //execute callback, nothing happens here + context.Exit(); + }; + //Start it + CfrTaskRunner.GetForThread(CfxThreadId.Renderer).PostTask(task); + + //Exit + rpcContext.Exit(); + } + + #endregion RECALL_METHOD /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region JOB_METHODS @@ -958,7 +1236,7 @@ namespace Active_Client.Browser_Tools metafile.tools = job.metadata.tools; metafile.customs = job.metadata.customs; - using (StreamWriter file = System.IO.File.CreateText(JOB_OPENING_PATH + JOB_METADATA_FILENAME)) + using (StreamWriter file = File.CreateText(JOB_OPENING_PATH + JOB_METADATA_FILENAME)) { JsonSerializer serializer = new JsonSerializer { @@ -968,11 +1246,11 @@ namespace Active_Client.Browser_Tools } //Main Program - System.IO.File.WriteAllText(JOB_OPENING_PATH + JOB_MAIN_FILENAME, job.isoMainProgram); + File.WriteAllText(JOB_OPENING_PATH + JOB_MAIN_FILENAME, job.isoMainProgram); //delete Zip File if exists - if (System.IO.File.Exists(jobSaveFileDialog.FileName)) - System.IO.File.Delete(jobSaveFileDialog.FileName); + if (File.Exists(jobSaveFileDialog.FileName)) + File.Delete(jobSaveFileDialog.FileName); //Create Zip File ZipFile.CreateFromDirectory(JOB_OPENING_PATH, jobSaveFileDialog.FileName); @@ -1005,7 +1283,7 @@ namespace Active_Client.Browser_Tools //check the arguments if (e.Arguments.Count() == 0) return; - if (String.IsNullOrEmpty(jobPath)) + if (string.IsNullOrEmpty(jobPath)) { jobSaveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); jobSaveFileDialog.FileName = job.name; @@ -1020,14 +1298,14 @@ namespace Active_Client.Browser_Tools } } - if (!String.IsNullOrEmpty(jobPath)) + if (!string.IsNullOrEmpty(jobPath)) { //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)) + using (StreamWriter file = File.CreateText(JOB_OPENING_PATH + JOB_METADATA_FILENAME)) { JsonSerializer serializer = new JsonSerializer { @@ -1037,11 +1315,11 @@ namespace Active_Client.Browser_Tools } //Main Program - System.IO.File.WriteAllText(JOB_OPENING_PATH + JOB_MAIN_FILENAME, job.isoMainProgram); + File.WriteAllText(JOB_OPENING_PATH + JOB_MAIN_FILENAME, job.isoMainProgram); //delete Zip File if exists - if (System.IO.File.Exists(jobPath)) - System.IO.File.Delete(jobPath); + if (File.Exists(jobPath)) + File.Delete(jobPath); //Create Zip File try @@ -1070,23 +1348,23 @@ namespace Active_Client.Browser_Tools imageOpenFileDialog.Multiselect = false; if (imageOpenFileDialog.ShowDialog() == DialogResult.OK) { - String newImagePath = JOB_OPENING_PATH + Path.GetFileName(imageOpenFileDialog.FileName); + string newImagePath = JOB_OPENING_PATH + Path.GetFileName(imageOpenFileDialog.FileName); //If exixts send error - if (System.IO.File.Exists(newImagePath)) + if (File.Exists(newImagePath)) { e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("file_esists"))); return; } //Copy the file - System.IO.File.Copy(imageOpenFileDialog.FileName, newImagePath); + File.Copy(imageOpenFileDialog.FileName, newImagePath); //Send to Step e.SetReturnValue(JsonConvert.SerializeObject(new ImageParam() { name = Path.GetFileName(imageOpenFileDialog.FileName), - base64 = "data:image/" + Path.GetExtension(newImagePath).ToLower().TrimStart('.') + ";base64," + Convert.ToBase64String(System.IO.File.ReadAllBytes(newImagePath)) + base64 = "data:image/" + Path.GetExtension(newImagePath).ToLower().TrimStart('.') + ";base64," + Convert.ToBase64String(File.ReadAllBytes(newImagePath)) })); return; } @@ -1102,17 +1380,17 @@ namespace Active_Client.Browser_Tools return; //Get the file Path - String imagePath = JOB_OPENING_PATH + e.Arguments[0].StringValue; + string imagePath = JOB_OPENING_PATH + e.Arguments[0].StringValue; //If not exixts Error! - if (!System.IO.File.Exists(imagePath)) + if (!File.Exists(imagePath)) { e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("file_not_esists"))); return; } //delete it - System.IO.File.Delete(imagePath); + File.Delete(imagePath); e.SetReturnValue(null); return; @@ -1132,17 +1410,17 @@ namespace Active_Client.Browser_Tools return; } - String newPPPath = JOB_OPENING_PATH + Path.GetFileName(PPOpenFileDialog.FileName); + string newPPPath = JOB_OPENING_PATH + Path.GetFileName(PPOpenFileDialog.FileName); //If exixts delete old file and save the new one - if (System.IO.File.Exists(newPPPath)) + if (File.Exists(newPPPath)) { e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("file_esists"))); return; } //Copy the file - System.IO.File.Copy(PPOpenFileDialog.FileName, newPPPath); + File.Copy(PPOpenFileDialog.FileName, newPPPath); //Send to Step e.SetReturnValue(JsonConvert.SerializeObject(new PPContainer(Path.GetFileName(PPOpenFileDialog.FileName)))); @@ -1160,17 +1438,17 @@ namespace Active_Client.Browser_Tools return; //Get the file Path - String ppPath = JOB_OPENING_PATH + e.Arguments[0].StringValue; + string ppPath = JOB_OPENING_PATH + e.Arguments[0].StringValue; //If not exixts Error! - if (!System.IO.File.Exists(ppPath)) + if (!File.Exists(ppPath)) { e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("file_not_esists"))); return; } //delete it - System.IO.File.Delete(ppPath); + File.Delete(ppPath); e.SetReturnValue(null); return; @@ -1203,7 +1481,7 @@ namespace Active_Client.Browser_Tools private static ErrorContainer ValidateZip(string filePath) { ErrorContainer result = null; - if (!System.IO.File.Exists(filePath)) + if (!File.Exists(filePath)) return new ErrorContainer("error_file_not_found"); try diff --git a/Client/Browser_Tools/Models/File.cs b/Client/Browser_Tools/Models/File.cs index 234c2bce..82a16433 100644 --- a/Client/Browser_Tools/Models/File.cs +++ b/Client/Browser_Tools/Models/File.cs @@ -6,12 +6,14 @@ using System.Threading.Tasks; namespace Active_Client.Browser_Tools.Models { - public class File + public class FileModel { public string Name; public string AbsolutePath; public string Path; public bool IsDirectory; public bool IsJob; + public bool IsMain; + public bool FileExist; } } diff --git a/Client/Browser_Tools/Models/InfoFile.cs b/Client/Browser_Tools/Models/InfoFile.cs index 0f4e30ac..c1503813 100644 --- a/Client/Browser_Tools/Models/InfoFile.cs +++ b/Client/Browser_Tools/Models/InfoFile.cs @@ -12,7 +12,8 @@ namespace Active_Client.Browser_Tools.Models public String AbsolutePath; public DateTime CreationDate; public DateTime LastModDate; - public List Content; + public List Content; + public Boolean CanEdit; public string PreviewBase64; } } diff --git a/Client/View/NcWindow.cs b/Client/View/NcWindow.cs index 79783b15..753edd93 100644 --- a/Client/View/NcWindow.cs +++ b/Client/View/NcWindow.cs @@ -572,11 +572,13 @@ namespace Active_Client.View //Force Focus External app - public static void ForceExtFocus(IntPtr Handle) + public static void ForceExtFocus(IntPtr Handle, int X, int Y, int width, int height) { if (Handle != IntPtr.Zero) ForceFocus(Handle); + if (width > 0 && height > 0) + MoveWindow(Handle, X, Y, width, height, true); } diff --git a/Client/View/OpeningForm.cs b/Client/View/OpeningForm.cs index a609e501..9fa1a0f3 100644 --- a/Client/View/OpeningForm.cs +++ b/Client/View/OpeningForm.cs @@ -283,11 +283,13 @@ namespace Active_Client.View else Config.ProdSoftwareConfig.Enabled = false; + // Paths Config.ProdSoftwareConfig.Path = ProdPath; + Config.TextEditorPath = ConfigResponse.EditorPath; - if(ConfigResponse.ExtSoftwares != null) + if (ConfigResponse.ExtSoftwares != null) Config.ExtSoftwaresConfig = ConfigResponse.ExtSoftwares.ToArray(); - + return true; } diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 10fe9abb..3507730d 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Config/Config/headsConfig.xml b/Step.Config/Config/headsConfig.xml index 75f5f3e1..7339e09d 100644 --- a/Step.Config/Config/headsConfig.xml +++ b/Step.Config/Config/headsConfig.xml @@ -20,14 +20,4 @@ 55 80 - - - Testa WJ C - Head WJ C - - WJ - false - 55 - 80 - \ No newline at end of file diff --git a/Step.Config/Config/serverConfig.xml b/Step.Config/Config/serverConfig.xml index 2ae275c9..ba99af4a 100644 --- a/Step.Config/Config/serverConfig.xml +++ b/Step.Config/Config/serverConfig.xml @@ -22,6 +22,7 @@ true localhost false + C:\Windows\System32\notepad.exe C:\CMS\MTC\ADAPTER\ SCMA true diff --git a/Step.Config/Config/serverConfigValidator.xsd b/Step.Config/Config/serverConfigValidator.xsd index bb2e14ef..ad613015 100644 --- a/Step.Config/Config/serverConfigValidator.xsd +++ b/Step.Config/Config/serverConfigValidator.xsd @@ -35,6 +35,7 @@ + diff --git a/Step.Config/Config/toolManagerConfig.xml b/Step.Config/Config/toolManagerConfig.xml index c4e87e65..0e7cddc2 100644 --- a/Step.Config/Config/toolManagerConfig.xml +++ b/Step.Config/Config/toolManagerConfig.xml @@ -1,11 +1,11 @@  - RADIUS + DIAMETER true false true - false + true true true true @@ -61,7 +61,7 @@ 2 - true + false Magazine 2 Magazzino 2 @@ -69,7 +69,7 @@ 3 - true + false Magazine 3 Magazzino 3 diff --git a/Step.Config/ServerConfigController.cs b/Step.Config/ServerConfigController.cs index 3021db0d..bd071ea4 100644 --- a/Step.Config/ServerConfigController.cs +++ b/Step.Config/ServerConfigController.cs @@ -287,7 +287,7 @@ namespace Step.Config .Descendants(PROD_SFT_CONFIG_KEY) .Select(x => new SoftwareProdConfigModel() { - Enabled = Convert.ToBoolean(x.Element("enabled").Value), + Enabled = Convert.ToBoolean(x.Element("enabled").Value), Path = x.Element("path").Value }).FirstOrDefault(); @@ -303,6 +303,7 @@ namespace Step.Config EnableDirectoryBrowsing = Convert.ToBoolean(x.Element("enableDirectoryBrowsing").Value), DatabaseAddress = x.Element("databaseAddress").Value, AutoOpenCmsClient = Convert.ToBoolean(x.Element("autoOpenCmsClient").Value), + TextEditorPath = x.Element("textEditorPath").Value, MTCFolderPath = x.Element("MTCFolderPath").Value, MTCApplicationName = x.Element("MTCApplicationName").Value, MaxAlarmsRows = Convert.ToInt32(x.Element("maxAlarmsRows").Value), diff --git a/Step.Model/ConfigModels/ServerConfigModel.cs b/Step.Model/ConfigModels/ServerConfigModel.cs index a2f5dbb7..9a567482 100644 --- a/Step.Model/ConfigModels/ServerConfigModel.cs +++ b/Step.Model/ConfigModels/ServerConfigModel.cs @@ -15,12 +15,12 @@ namespace Step.Model.ConfigModels public bool EnableDirectoryBrowsing { get; set; } public string DatabaseAddress { get; set; } public bool AutoOpenCmsClient { get; set; } + public string TextEditorPath { get; set; } public string MTCFolderPath { get; set; } public string MTCApplicationName { get; set; } - public Boolean CMSConnectReady { get; set; } + public bool CMSConnectReady { get; set; } public int MaxAlarmsRows { get; set; } public int AlarmToDelete { get; set; } - } } \ No newline at end of file diff --git a/Step.Model/DTOModels/DTOClientConfigurationModel.cs b/Step.Model/DTOModels/DTOClientConfigurationModel.cs index ec11a196..7fddd062 100644 --- a/Step.Model/DTOModels/DTOClientConfigurationModel.cs +++ b/Step.Model/DTOModels/DTOClientConfigurationModel.cs @@ -13,6 +13,7 @@ namespace Step.Model.DTOModels public ushort NcPort { get; set; } public bool ProdEnabled { get; set; } public string ProdPath { get; set; } + public string EditorPath { get; set; } public bool Autorun { get; set; } public bool MgiOption { get; set; } public List ExtSoftwares { get; set; } diff --git a/Step.Utils/Step.Utils.csproj b/Step.Utils/Step.Utils.csproj index 15ec31a2..9d543c60 100644 --- a/Step.Utils/Step.Utils.csproj +++ b/Step.Utils/Step.Utils.csproj @@ -100,7 +100,7 @@ PreserveNewest - + PreserveNewest diff --git a/Step/Controllers/WebApi/ConfigurationController.cs b/Step/Controllers/WebApi/ConfigurationController.cs index 84644f68..473065b8 100644 --- a/Step/Controllers/WebApi/ConfigurationController.cs +++ b/Step/Controllers/WebApi/ConfigurationController.cs @@ -46,6 +46,7 @@ namespace Step.Controllers.WebApi ProdPath = SoftwareProdConfig.Path, ExtSoftwares = ExtSoftwaresConfig, Autorun = ServerStartupConfig.AutoOpenCmsClient, + EditorPath = ServerStartupConfig.TextEditorPath, MgiOption = NcConfig.MgiOption }; diff --git a/Step/Controllers/WebApi/NcFileController.cs b/Step/Controllers/WebApi/NcFileController.cs index 2b2a6eb8..562f4fb4 100644 --- a/Step/Controllers/WebApi/NcFileController.cs +++ b/Step/Controllers/WebApi/NcFileController.cs @@ -1,6 +1,7 @@ using CMS_CORE_Library.Models; using Step.Model.DTOModels; using Step.NC; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -98,6 +99,7 @@ namespace Step.Controllers.WebApi bool imageUploaded = false; string mainPPName = ""; + List programs = new List(); if (!Request.Content.IsMimeMultipartContent()) { @@ -109,13 +111,14 @@ namespace Step.Controllers.WebApi { ncFileHandler.Connect(); - if(NcConfig.NcVendor == NC_VENDOR.OSAI) + if (NcConfig.NcVendor == NC_VENDOR.OSAI) { // Clean upload folder only OSAI CmsError cmsError = ncFileHandler.CleanUploadFolder(); - if (cmsError.IsError() && cmsError.errorCode != CMS_ERROR_CODES.FILE_NOT_FOUND) + if (cmsError.IsError() && cmsError.errorCode != CMS_ERROR_CODES.FILE_NOT_FOUND) return BadRequest(cmsError.localizationKey); } + ActiveProgramDataModel programData = new ActiveProgramDataModel(); foreach (FormItem item in formItems) { @@ -123,8 +126,9 @@ namespace Step.Controllers.WebApi { if (item.ParameterName == "main") { - File.WriteAllBytes(TEMP_PP_FOLDER + item.FileName, item.Data); + File.WriteAllBytes(TEMP_PP_FOLDER + item.FileName, item.Data); mainPPName = item.FileName; + programs.Add(item.FileName); // Upload main program CmsError cmsError = ncFileHandler.UploadPartProgramAndActivate(TEMP_PP_FOLDER, item.FileName, out programData); @@ -134,6 +138,8 @@ namespace Step.Controllers.WebApi else if (item.ParameterName == "file") { File.WriteAllBytes(TEMP_PP_FOLDER + item.FileName, item.Data); + programs.Add(item.FileName); + // Upload files CmsError cmsError = ncFileHandler.UploadPartProgram(TEMP_PP_FOLDER, item.FileName, out string programPath); if (cmsError.IsError()) @@ -151,23 +157,124 @@ namespace Step.Controllers.WebApi if (!imageUploaded) { mainPPName = Path.GetFileNameWithoutExtension(mainPPName); - string [] imgFiles = Directory.GetFiles(PART_PRG_IMAGES); - foreach(string f in imgFiles) + string[] imgFiles = Directory.GetFiles(PART_PRG_IMAGES); + foreach (string f in imgFiles) { - if(Path.GetFileNameWithoutExtension(f) == mainPPName) + if (Path.GetFileNameWithoutExtension(f) == mainPPName) File.Delete(f); } - } + + if (NcConfig.NcVendor != NC_VENDOR.OSAI) { + + List lines = new List(); + string outputFileName = NcConfig.SharedPath + "activePP.list"; + + foreach (string prog in programs) + { + FileInfo fi = new FileInfo(NcConfig.SharedPath + prog); + if (fi.Exists) + { + lines.Add(prog + "|" + fi.CreationTime + "|" + fi.LastWriteTime); + } + } + // Write file + File.WriteAllLines(outputFileName, lines.ToArray()); + } + + } return Ok(); } + [Route("shared_folder_ok"), HttpGet] + public IHttpActionResult IsSharedFolderOK() + { + if (NcConfig.NcVendor == NC_VENDOR.OSAI) + return Ok(true); + else + { + string fileName = NcConfig.SharedPath + "activePP.list"; + int count = Directory.GetFiles(NcConfig.SharedPath).Length; + + if (!File.Exists(fileName) && count == 0) + return Ok(true); + + if (File.Exists(fileName) && count == 1) + return Ok(false); + + if (File.Exists(fileName) && count > 1) + { + // Write file + string[] lines = File.ReadAllLines(fileName); + foreach (string line in lines) + { + if (!string.IsNullOrWhiteSpace(line)) + { + string[] linesplitted = line.Split('|'); + if (linesplitted.Length != 3) + return Ok(false); + FileInfo fi = new FileInfo(NcConfig.SharedPath + linesplitted[0]); + if (!fi.Exists) + return Ok(false); + if (fi.CreationTime.ToString() != linesplitted[1]) + return Ok(false); + if (fi.LastWriteTime.ToString() != linesplitted[2]) + return Ok(false); + } + } + return Ok(true); + } + return Ok(false); + } + } + + [Route("clean_shared_folder"), HttpPut] + public IHttpActionResult cleanSharedFolder() + { + if (NcConfig.NcVendor == NC_VENDOR.OSAI) + return Ok(true); + else + { + foreach(string filename in Directory.GetFiles(NcConfig.SharedPath)) + { + File.Delete(filename); + } + } + return Ok(false); + } + + [Route("backup_shared_folder"), HttpPut] + public IHttpActionResult BackupSharedFolder() + { + if (NcConfig.NcVendor == NC_VENDOR.OSAI) + return Ok(true); + else + { + string newFolder = "C:\\Backup_" + new DirectoryInfo(NcConfig.SharedPath).Name + "\\" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss") + "\\"; + + File.Delete(NcConfig.SharedPath + "activePP.list"); + Directory.CreateDirectory(newFolder); + foreach (string filename in Directory.GetFiles(NcConfig.SharedPath)) + { + try + { + File.Move(filename, newFolder + Path.GetFileName(filename)); + } + catch + { + return InternalServerError(); + } + } + return Ok(true); + } + } + [Route("shared_files"), HttpGet] public IHttpActionResult GetSharedFolderFileList(string sharedPath) - { + { List filelist = new List(); // NC - PC shared folder path string sharedFullPath = NcConfig.SharedPath + sharedPath; diff --git a/Step/wwwroot/assets/styles/base/card.less b/Step/wwwroot/assets/styles/base/card.less index c7324507..ca281a3a 100644 --- a/Step/wwwroot/assets/styles/base/card.less +++ b/Step/wwwroot/assets/styles/base/card.less @@ -1916,13 +1916,16 @@ background-color: @color-clear-blue-30; color: #002680; - // color: @color-white; + .not-exist{ + color: #d0021b !important; + } + &.dark { background-color: rgba(23, 145, 255, 0.75); color: #fff; * { - color: #fff !important; + color: #fff; } } } diff --git a/Step/wwwroot/assets/styles/base/modals.less b/Step/wwwroot/assets/styles/base/modals.less index fbcfa4ff..54b1f933 100644 --- a/Step/wwwroot/assets/styles/base/modals.less +++ b/Step/wwwroot/assets/styles/base/modals.less @@ -1317,7 +1317,7 @@ } } .modal-load-program-header, .modal-add-element-queue-header { - height: 80px; + height: 70px; width: 100%; display: flex; flex-flow: column; @@ -1328,7 +1328,7 @@ // } .box-search { width: 100%; - height: 80px; + height: 70px; display: flex; flex-flow: row; align-items: center; @@ -1370,6 +1370,40 @@ display: flex; position: relative; flex-flow: row; + + .ask-confirm, + .cleanTempFolder { + top: 0; + left: 0; + position: absolute; + width: 100%; + height: 100%; + display: flex; + align-items: center; + justify-content: center; + font-weight: bold; + font-size: 2em; + line-height: 3em; + flex-flow: column; + background-color: rgba(217, 217, 217, 0.5); + } + + .fileIsChanged { + top: 0; + left: 1112px; + position: absolute; + width: 696px; + height: 100%; + display: flex; + align-items: center; + justify-content: center; + font-weight: bold; + font-size: 2em; + line-height: 3em; + flex-flow: column; + background-color: rgba(217, 217, 217, 0.5); + } + hr { width: 5%; } @@ -1488,13 +1522,19 @@ } } } + + .selected-item-blur { + filter: blur(10px); + padding: 10px !important; + } + .selected-item { width: 660px; height: 100%; display: flex; flex-flow: column; justify-content: flex-end; - padding: 0 16px 0 22px; + padding: 0 16px 0 22px; .selected-item-header { height: 78px; width: 100%; @@ -1551,7 +1591,7 @@ width: 100%; // margin: auto margin-top: 10px; - height: 336px; + height: 331px; align-items: center; .container{ margin: auto; @@ -1560,7 +1600,7 @@ cursor: pointer; img { display: block; - max-height: 336px; + max-height: 331px; max-width: 567px; box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.4); } @@ -1589,12 +1629,13 @@ .selected-item-body-description { display: flex; width: 100%; - margin-top: 10px; + margin-top: 8px; overflow-x: hidden; - height: calc(~"100% - 380px"); + height: calc(~"100% - 360px"); flex-flow: column; .row{ + width: 99%; font-family: monospace; white-space:pre; height: 32px; @@ -1617,7 +1658,6 @@ .row:nth-child(even){ background-color: @color-white4; } - } } .notselecteditem { diff --git a/Step/wwwroot/assets/styles/style.css b/Step/wwwroot/assets/styles/style.css index 76d34eef..de0deb09 100644 --- a/Step/wwwroot/assets/styles/style.css +++ b/Step/wwwroot/assets/styles/style.css @@ -1240,7 +1240,7 @@ .modal.modal-add-element-queue .modal-load-program-header, .modal.modal-load-program .modal-add-element-queue-header, .modal.modal-add-element-queue .modal-add-element-queue-header { - height: 80px; + height: 70px; width: 100%; display: flex; flex-flow: column; @@ -1250,7 +1250,7 @@ .modal.modal-load-program .modal-add-element-queue-header .box-search, .modal.modal-add-element-queue .modal-add-element-queue-header .box-search { width: 100%; - height: 80px; + height: 70px; display: flex; flex-flow: row; align-items: center; @@ -1313,6 +1313,46 @@ position: relative; flex-flow: row; } +.modal.modal-load-program .modal-load-program-body .ask-confirm, +.modal.modal-add-element-queue .modal-load-program-body .ask-confirm, +.modal.modal-load-program .modal-add-element-queue-body .ask-confirm, +.modal.modal-add-element-queue .modal-add-element-queue-body .ask-confirm, +.modal.modal-load-program .modal-load-program-body .cleanTempFolder, +.modal.modal-add-element-queue .modal-load-program-body .cleanTempFolder, +.modal.modal-load-program .modal-add-element-queue-body .cleanTempFolder, +.modal.modal-add-element-queue .modal-add-element-queue-body .cleanTempFolder { + top: 0; + left: 0; + position: absolute; + width: 100%; + height: 100%; + display: flex; + align-items: center; + justify-content: center; + font-weight: bold; + font-size: 2em; + line-height: 3em; + flex-flow: column; + background-color: rgba(217, 217, 217, 0.5); +} +.modal.modal-load-program .modal-load-program-body .fileIsChanged, +.modal.modal-add-element-queue .modal-load-program-body .fileIsChanged, +.modal.modal-load-program .modal-add-element-queue-body .fileIsChanged, +.modal.modal-add-element-queue .modal-add-element-queue-body .fileIsChanged { + top: 0; + left: 1112px; + position: absolute; + width: 696px; + height: 100%; + display: flex; + align-items: center; + justify-content: center; + font-weight: bold; + font-size: 2em; + line-height: 3em; + flex-flow: column; + background-color: rgba(217, 217, 217, 0.5); +} .modal.modal-load-program .modal-load-program-body hr, .modal.modal-add-element-queue .modal-load-program-body hr, .modal.modal-load-program .modal-add-element-queue-body hr, @@ -1491,6 +1531,13 @@ margin-top: 4px; color: #002680; } +.modal.modal-load-program .modal-load-program-body .selected-item-blur, +.modal.modal-add-element-queue .modal-load-program-body .selected-item-blur, +.modal.modal-load-program .modal-add-element-queue-body .selected-item-blur, +.modal.modal-add-element-queue .modal-add-element-queue-body .selected-item-blur { + filter: blur(10px); + padding: 10px !important; +} .modal.modal-load-program .modal-load-program-body .selected-item, .modal.modal-add-element-queue .modal-load-program-body .selected-item, .modal.modal-load-program .modal-add-element-queue-body .selected-item, @@ -1584,7 +1631,7 @@ display: flex; width: 100%; margin-top: 10px; - height: 336px; + height: 331px; align-items: center; } .modal.modal-load-program .modal-load-program-body .selected-item .selected-item-body .selected-item-body-image .container, @@ -1601,7 +1648,7 @@ .modal.modal-load-program .modal-add-element-queue-body .selected-item .selected-item-body .selected-item-body-image .container img, .modal.modal-add-element-queue .modal-add-element-queue-body .selected-item .selected-item-body .selected-item-body-image .container img { display: block; - max-height: 336px; + max-height: 331px; max-width: 567px; box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.4); } @@ -1636,15 +1683,16 @@ .modal.modal-add-element-queue .modal-add-element-queue-body .selected-item .selected-item-body .selected-item-body-description { display: flex; width: 100%; - margin-top: 10px; + margin-top: 8px; overflow-x: hidden; - height: calc(100% - 380px); + height: calc(100% - 360px); flex-flow: column; } .modal.modal-load-program .modal-load-program-body .selected-item .selected-item-body .selected-item-body-description .row, .modal.modal-add-element-queue .modal-load-program-body .selected-item .selected-item-body .selected-item-body-description .row, .modal.modal-load-program .modal-add-element-queue-body .selected-item .selected-item-body .selected-item-body-description .row, .modal.modal-add-element-queue .modal-add-element-queue-body .selected-item .selected-item-body .selected-item-body-description .row { + width: 99%; font-family: monospace; white-space: pre; height: 32px; @@ -8804,12 +8852,15 @@ footer .container button.big:before { background-color: rgba(23, 145, 255, 0.3); color: #002680; } +.selected-path-drive .not-exist { + color: #d0021b !important; +} .selected-path-drive.dark { background-color: rgba(23, 145, 255, 0.75); color: #fff; } .selected-path-drive.dark * { - color: #fff !important; + color: #fff; } .objects-job { margin: 8px; diff --git a/Step/wwwroot/src/app_modules/production/components/card-production-cms.ts b/Step/wwwroot/src/app_modules/production/components/card-production-cms.ts index 3e0ce780..56cf0275 100644 --- a/Step/wwwroot/src/app_modules/production/components/card-production-cms.ts +++ b/Step/wwwroot/src/app_modules/production/components/card-production-cms.ts @@ -31,6 +31,7 @@ export default class CardProductionCms extends Vue { get currentProgram() { return this.$store.state.process.currentProgram; } + get loadPrgVisible() { if ( !this.queue && @@ -41,6 +42,7 @@ export default class CardProductionCms extends Vue { return true; else return false; } + get infoPrgVisible() { if ( (this.currentProgram && @@ -52,6 +54,10 @@ export default class CardProductionCms extends Vue { else return false; } + get canLoadProgram() { + return this.$store.state.process.canLoadProgram; + } + openModal() { ModalHelper.ShowModal(modalLoadProgram); } diff --git a/Step/wwwroot/src/app_modules/production/components/card-production-cms.vue b/Step/wwwroot/src/app_modules/production/components/card-production-cms.vue index 6f6e30cc..e7dfc8e6 100644 --- a/Step/wwwroot/src/app_modules/production/components/card-production-cms.vue +++ b/Step/wwwroot/src/app_modules/production/components/card-production-cms.vue @@ -10,10 +10,9 @@
{{'production_label_select_prg' | localize('Seleziona un programma')}}
- +
-
diff --git a/Step/wwwroot/src/modules/base-components/cards/card-folder-path.vue b/Step/wwwroot/src/modules/base-components/cards/card-folder-path.vue index ffc0bcb8..725678f0 100644 --- a/Step/wwwroot/src/modules/base-components/cards/card-folder-path.vue +++ b/Step/wwwroot/src/modules/base-components/cards/card-folder-path.vue @@ -1,6 +1,6 @@