//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CDatabaseFileSystemManager { private: //--- FolderCreate/FolderClean/FileDelete all shared the same 5-attempt/1s-sleep retry shape, //--- differing only in which op ran and the noun in the log line. One loop, dispatched by an //--- enum rather than a function pointer (MQL5 function pointers cannot bind a built-in call //--- with default parameters with any more certainty than a compile can confirm - not worth the //--- risk for 3 one-line bodies). enum ENUM_FS_RETRY_OP { FS_RETRY_CREATE_DIR, FS_RETRY_CLEAN_DIR, FS_RETRY_DELETE_FILE }; bool RetryFileSystemOp(ENUM_FS_RETRY_OP op, string target, string verb, string caller) { int attempts = 0; while(attempts < 5) { bool ok = false; switch(op) { case FS_RETRY_CREATE_DIR: ok = FolderCreate(target, FILE_COMMON); break; case FS_RETRY_CLEAN_DIR: ok = FolderClean(target, FILE_COMMON); break; case FS_RETRY_DELETE_FILE: ok = FileDelete(target, FILE_COMMON); break; } if(ok) return true; Print(caller + ": Retry " + IntegerToString(attempts + 1) + " failed to " + verb + ": " + target); Sleep(1000); // Wait for a second before retrying attempts++; } Print(caller + ": Failed to " + verb + " after retries: " + target); return false; } public: bool CreateDirectory(string folderName) { return RetryFileSystemOp(FS_RETRY_CREATE_DIR, folderName, "create directory", __FUNCTION__); } bool CleanDirectory(string folderName) { return RetryFileSystemOp(FS_RETRY_CLEAN_DIR, folderName, "clean folder", __FUNCTION__); } bool DeleteFile(string fileName) { return RetryFileSystemOp(FS_RETRY_DELETE_FILE, fileName, "delete file", __FUNCTION__); } }; //+------------------------------------------------------------------+