/// <summary> /// Removes all files and directories in a folder, keeping the folder. /// From: https://www.techiedelight.com/delete-all-files-sub-directories-csharp/ /// </summary> /// <param name="folderPath"></param> /// <returns></returns> internal static bool EmptyDirectory(string folderPath, RobotLogger logger) { DirectoryInfo di = new DirectoryInfo(folderPath); try { foreach (FileInfo file in di.GetFiles()) { file.Delete(); } foreach (DirectoryInfo dir in di.GetDirectories()) { dir.Delete(true); } } catch (Exception ex) { logger.Error($"Could not delete files in \"{folderPath}\""); logger.Debug(ex); return(false); } return(true); }
// ██████╗ ██╗ ██╗██████╗ ██╗ ██╗ ██████╗ // ██╔══██╗██║ ██║██╔══██╗██║ ██║██╔════╝ // ██████╔╝██║ ██║██████╔╝██║ ██║██║ // ██╔═══╝ ██║ ██║██╔══██╗██║ ██║██║ // ██║ ╚██████╔╝██████╔╝███████╗██║╚██████╗ // ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═════╝ // /// <summary> /// Main constructor /// </summary> public DriverABB(Control ctrl) : base(ctrl) { if (this.parentControl.connectionMode == ConnectionType.Machina) { _rsBridge = new RobotStudioManager(this); } logger = this.parentControl.logger; }
internal TCPCommunicationManagerUR(Driver driver, RobotCursor writeCursor, RobotCursor motionCursor, string robotIP, int robotPort) { this._parentDriver = driver; this.logger = driver.parentControl.logger; this._issueCursor = writeCursor; this._motionCursor = motionCursor; this._robotIP = robotIP; //this._robotPort = robotPort; // It will always be 30003, user need not care about this this._translator = Protocols.Factory.GetTranslator(this._parentDriver); }
internal TCPCommunicationManagerABB(Driver driver, RobotCursor releaseCursor, RobotCursor executionCursor, string ip, int port) { this._parentDriver = driver; this.logger = driver.parentControl.logger; this._releaseCursor = releaseCursor; this._executionCursor = executionCursor; this._motionCursor = driver.parentControl.MotionCursor; // @TODO: homogeinize how the driver picks cursors from parent control: as constructor arguments or directly from the object this._ip = ip; this._port = port; this._monitorIP = ip; this._monitorPort = port + 1; // these should be configurable... this._translator = Protocols.Factory.GetTranslator(this._parentDriver); }
/// <summary> /// Saves the files in this program to a folder in the system. /// </summary> /// <param name="folderPath"></param> /// <param name="logger"></param> /// <returns></returns> internal bool SaveToFolder(string folderPath, RobotLogger logger) { return(Utilities.FileIO.SaveProgramToFolder(this, folderPath, logger)); }
public DriverOffline(Control ctrl) : base(ctrl) { logger = ctrl.logger; }
public RobotStudioManager(Driver parent) { _parentDriver = parent; logger = _parentDriver.parentControl.logger; }
/// <summary> /// Saves a List of program Files to a folder (creates the folder if needed). /// </summary> /// <param name="program"></param> /// <param name="folderPath"></param> /// <param name="encoding"></param> /// <param name="logger"></param> /// <returns></returns> internal static bool SaveProgramToFolder(RobotProgram program, string folderPath, RobotLogger logger) { // Create a subfolder within folderPath string programFolderPath = ""; try { programFolderPath = Path.Combine(folderPath, Utilities.Strings.SafeProgramName(program.Name + "_Program")); } catch (Exception ex) { logger.Error("Badly formatted folder path: " + folderPath); logger.Debug(ex); return(false); } // Check if directory exists, and create it otherwise try { if (Directory.Exists(programFolderPath)) { logger.Debug("Found existing folder on " + programFolderPath + ", deleting it..."); EmptyDirectory(programFolderPath, logger); } else { DirectoryInfo di = Directory.CreateDirectory(programFolderPath); logger.Debug("Created folder " + programFolderPath); } } catch (Exception ex) { logger.Error("Could not create folder " + programFolderPath); logger.Debug(ex); return(false); } // More sanity if (!IsDirectoryWritable(programFolderPath)) { logger.Error("Cannot write to folder " + programFolderPath); return(false); } // Write each file bool success = true; foreach (var file in program.Files) { string fullPath = Path.Combine(programFolderPath, file.Name + "." + file.Extension); success = success && SaveStringListToFile(file.Lines, fullPath, file.Encoding, logger); } return(success); }
/// <summary> /// Saves a List of strings to a file. /// </summary> /// <param name="lines"></param> /// <param name="filepath"></param> /// <param name="encoding"></param> /// <param name="logger"></param> /// <returns></returns> internal static bool SaveStringListToFile(List <string> lines, string filepath, Encoding encoding, RobotLogger logger) { try { System.IO.File.WriteAllLines(filepath, lines, encoding); logger.Debug($"Saved content to file \"{filepath}\""); return(true); } catch (Exception ex) { logger.Error("Could not save content to file \"{filepath}\""); logger.Debug(ex); } return(false); }
protected virtual void Awake() { _robotLogger = GetComponent <RobotLogger>(); }