- Add Support for Save Logs in Alert Class; - Add Propper inputs for Handle Saving Logs in EA and Expert Class; - remove x-trade.manager Class Data Collector and use General Developed Data Collector; - Add Support for Reading Fles in Data Collector Class for Support Configuration Parsing; - Remove XCBaseAlert class and add Support for get XCAlert instance reference pointer as Dependency Injection in all used classed and Refactor all Changes; - Apply Fix some UnImplemented Event Handlers on Ea Expert Class of XCATBEA and also change Event Handler Binding to Collection Based Model; - Test all Functionalities ... - Apply Some Fixes on Prevent Double Saing Same Log Messages ...
372 lines
6.7 KiB
Plaintext
372 lines
6.7 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Indicator
|
|
// -------------------------------------------------
|
|
// Name: XCDataCollector ...
|
|
// Description: Class for Handling Data Read or Write ...
|
|
//
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property library
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://saherelm.ir"
|
|
#property version "1.00"
|
|
#property description "SaherElm Class for Handling Data Read or Write"
|
|
#property strict
|
|
|
|
//
|
|
// Imports ...
|
|
#include "../Classes/x-saherelm.base.class.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
// Implementation ...
|
|
class XCDataCollector : public XCBase
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Constructors ...
|
|
XCDataCollector()
|
|
{
|
|
mPath = "XDataCollector";
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCDataCollector()
|
|
{
|
|
}
|
|
|
|
//
|
|
// Properties ...
|
|
|
|
//
|
|
string Path()
|
|
{
|
|
return mPath;
|
|
}
|
|
|
|
//
|
|
void Path(string value)
|
|
{
|
|
//
|
|
// Normalizing Collector Path ...
|
|
if (IsValid(value))
|
|
{
|
|
mPath = value;
|
|
}
|
|
else
|
|
{
|
|
mPath = "XDataCollector";
|
|
}
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
string GetFilePath(string fileName)
|
|
{
|
|
//
|
|
string result = "";
|
|
|
|
//
|
|
result =
|
|
//
|
|
mPath + "\\" + fileName + ".x121.log"
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int GetFileHandlerForWrite(string filePath)
|
|
{
|
|
//
|
|
int result = INVALID_HANDLE;
|
|
|
|
//
|
|
if (!IsValid(filePath))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = FileOpen(
|
|
filePath,
|
|
FILE_READ | FILE_WRITE | FILE_TXT //
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int GetFileHandlerForRead(string filePath)
|
|
{
|
|
//
|
|
int result = INVALID_HANDLE;
|
|
|
|
//
|
|
if (!IsValid(filePath))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = FileOpen(
|
|
filePath,
|
|
FILE_READ | FILE_TXT //
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Save Specified Content into Specified File Name ...
|
|
*
|
|
* @param fileName: string, file name ...
|
|
* @param content: string, content ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool Save(
|
|
string fileName,
|
|
string content //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = IsValid(fileName) &&
|
|
IsValid(content);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int mHandler = GetFileHandlerForWrite(fileName);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
FileWrite(mHandler, content);
|
|
FileFlush(mHandler);
|
|
FileClose(mHandler);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Append Specified Content into Specified File Name ...
|
|
*
|
|
* @param fileName: string, file name ...
|
|
* @param content: string, content ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool Append(
|
|
string fileName,
|
|
string content //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = IsValid(fileName) &&
|
|
IsValid(content);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int mHandler = GetFileHandlerForWrite(fileName);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
FileSeek(mHandler, 0, SEEK_END);
|
|
FileWrite(mHandler, content);
|
|
FileFlush(mHandler);
|
|
FileClose(mHandler);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Read Specified File Content ...
|
|
*
|
|
* @param fileName: string, file name ...
|
|
* @param content: string reference, hold's reading content ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool Read(
|
|
string fileName,
|
|
string &content //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Args ...
|
|
content = NULL;
|
|
|
|
//
|
|
// Validate Args ...
|
|
result = IsValid(fileName);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int mHandler = GetFileHandlerForRead(fileName);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Reading File ...
|
|
while (!FileIsEnding(mHandler))
|
|
{
|
|
//
|
|
string iLine = FileReadString(mHandler);
|
|
content += iLine;
|
|
}
|
|
|
|
//
|
|
// Close File ...
|
|
FileClose(mHandler);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Read Specified File Content ...
|
|
*
|
|
* @param fileName: string, file name ...
|
|
* @param content: string reference collection, hold's reading content lines ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool Read(
|
|
string fileName,
|
|
string &content[] //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Args ...
|
|
Clean(content);
|
|
|
|
//
|
|
// Validate Args ...
|
|
result = IsValid(fileName);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int mHandler = GetFileHandlerForRead(fileName);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Reading File ...
|
|
while (!FileIsEnding(mHandler))
|
|
{
|
|
//
|
|
string iLine = FileReadString(mHandler);
|
|
Add(
|
|
iLine,
|
|
content //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Close File ...
|
|
FileClose(mHandler);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check Specified File Exists or not ...
|
|
*
|
|
* @param fileName: string, Full Path of File to Check ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsExists(string fileName)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Args ...
|
|
result = IsValid(fileName);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check File Exists or not ...
|
|
int mHandler = GetFileHandlerForRead(fileName);
|
|
result = mHandler != INVALID_HANDLE;
|
|
FileClose(mHandler);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string mPath; // Base Collector Path ...
|
|
};
|