- Create a Data Collector Class;

- 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 ...
This commit is contained in:
2025-06-05 05:35:47 +03:30
parent 4e941f3a65
commit e46cac2ab1
12 changed files with 2107 additions and 927 deletions
+73 -215
View File
@@ -22,6 +22,7 @@
//
// Imports ...
#include "../Classes/x-saherelm.base.class.mq5"
#include "../Classes/x-saherelm.x-data.collector.class.mq5"
//
// Class Definition ...
@@ -42,7 +43,8 @@ class XCAlert : public XCBase
bool logAlerts = true, // Log Alerts
bool terminalAlerts = false, // Terminal Alerts
bool mailAlerts = false, // Mail Alerts
bool pushAlerts = false // Push Alerts
bool pushAlerts = false, // Push Alerts
bool saveAlerts = false // Save Alerts
)
{
//
@@ -50,6 +52,7 @@ class XCAlert : public XCBase
mLogAlerts = logAlerts;
mMailAlerts = mailAlerts;
mPushAlerts = pushAlerts;
mSaveAlerts = saveAlerts;
mEnableAlerts = enableAlerts;
mTerminalAlerts = terminalAlerts;
@@ -59,12 +62,21 @@ class XCAlert : public XCBase
{
mPrefix = GetTag();
}
//
// Initialize Collector ...
collector = new XCDataCollector();
collector.Path(mPrefix);
}
//
// Deconstructor ...
~XCAlert()
{
//
// Cleanup Resources ...
delete collector;
ZeroMemory(collector);
}
//
@@ -86,7 +98,9 @@ class XCAlert : public XCBase
//
void SetPrefix(string value)
{
//
mPrefix = value;
collector.Path(mPrefix);
}
//
@@ -113,6 +127,18 @@ class XCAlert : public XCBase
mEnableAlerts = value;
}
//
bool GetSaveAlerts()
{
return mSaveAlerts;
}
//
void SetSaveAlerts(bool value)
{
mSaveAlerts = value;
}
//
bool GetPushAlerts()
{
@@ -166,8 +192,12 @@ class XCAlert : public XCBase
return;
}
//
message = PrepareMessage(message);
//
Log(message);
Save(message);
}
//
@@ -187,6 +217,7 @@ class XCAlert : public XCBase
// Send Terminal Alert ...
Alert(message);
Save(message);
}
//
@@ -203,6 +234,7 @@ class XCAlert : public XCBase
//
// Send Mail Alert ...
SendMail(GetPrefix(), message);
Save(message);
}
//
@@ -223,6 +255,7 @@ class XCAlert : public XCBase
//
// Send Push Notification Alert ...
SendNotification(message);
Save(message);
}
//
@@ -1334,16 +1367,55 @@ class XCAlert : public XCBase
return result;
}
//
void Save(string message)
{
//
if (!mSaveAlerts ||
!IsValid(message) ||
message == mLastSavedMessage ||
PrepareMessage(message) == mLastSavedMessage)
{
return;
}
//
string filePath = collector.GetFilePath("XLogs");
if (!IsValid(filePath))
{
return;
}
//
// Attach Time ...
string savedMessage = ToString(TimeCurrent()) + " " + message;
//
bool has = collector.Append(
filePath,
savedMessage //
);
if (has)
{
mLastSavedMessage = message;
}
}
private:
//
// Props ...
string mPrefix; // Alerts Prefixe
bool mEnableAlerts; // Enable Alerts
bool mSaveAlerts; // Save Alerts
bool mLogAlerts; // Log Alerts
bool mTerminalAlerts; // Terminal Alerts
bool mMailAlerts; // Mail Alerts
bool mPushAlerts; // Push Alerts
//
string mLastSavedMessage; // For Prevent Multiple Saving Same Mesage ...
XCDataCollector *collector;
//
// Tools ...
@@ -1363,218 +1435,4 @@ class XCAlert : public XCBase
}
};
//
// a Base Class by Support Alert ...
class XCBaseAlert : public XCBase
{
//
// Public ...
public:
//
// Props ...
//
// Constructor(s) ...
void XCBaseAlert()
{
//
// Instance Alert ...
mAlert = new XCAlert();
}
//
// Deconstructors ...
void ~XCBaseAlert()
{
//
delete mAlert;
//
ZeroMemory(mAlert);
}
//
// Alert Handler Functions ...
//
// Alert Functions Getter(s) / Setters(s) ...
//
string GetAlertPrefix()
{
return mAlert.GetPrefix();
}
//
void SetAlertPrefix(string value)
{
mAlert.SetPrefix(value);
}
//
bool GetAlertLogAlerts()
{
return mAlert.GetLogAlerts();
}
//
void SetAlertLogAlerts(bool value)
{
mAlert.SetLogAlerts(value);
}
//
bool GetAlertEnableAlerts()
{
return mAlert.GetEnableAlerts();
}
//
void SetAlertEnableAlerts(bool value)
{
mAlert.SetEnableAlerts(value);
}
//
bool GetAlertPushAlerts()
{
return mAlert.GetPushAlerts();
}
//
void SetAlertPushAlerts(bool value)
{
mAlert.SetPushAlerts(value);
}
//
bool GetAlertMailAlerts()
{
return mAlert.GetMailAlerts();
}
//
void SetAlertMailAlerts(bool value)
{
mAlert.SetMailAlerts(value);
}
//
bool GetAlertTerminalAlerts()
{
return mAlert.GetTerminalAlerts();
}
//
void SetAlertTerminalAlerts(bool value)
{
mAlert.SetTerminalAlerts(value);
}
//
// Alert Actions ...
//
// Logging an Alert ...
void LogAlert(string message)
{
mAlert.LogAlert(message);
}
//
// Terminal Alert ...
void TerminalAlert(string message)
{
mAlert.TerminalAlert(message);
}
//
// Mail Alert ...
void MailAlert(string message)
{
mAlert.MailAlert(message);
}
//
// Send Push Notification ...
void PushAlert(string message)
{
mAlert.PushAlert(message);
}
//
// Send an Alert by Handling all Different Specified
// type's of Alert's if they are Enabled ...
void SendAlert(string message)
{
mAlert.SendAlert(message);
}
//
// Logs ...
//
// Log a Message ...
void Log(string message)
{
mAlert.Log(message);
}
void Log(string tag, string message)
{
mAlert.Log(tag, message);
}
void LogEmpty()
{
mAlert.LogEmpty();
}
//
// Log Specific Array ...
template <typename T>
void LogArray(
T &array[], // Array to Log
string label = NULL // Array Label
)
{
mAlert.LogArray(array, label);
}
//
// Error ...
//
// Log an Error ...
void LogError(
int error = -1 // Specific Error, if it's equal to -1, use Last Error ...
)
{
mAlert.LogError(error);
}
//
// Retrieve Specified Error Code Description ...
string GetErrorDescription(int err_code)
{
return mAlert.GetErrorDescription(err_code);
}
//
// Retrieve Specified Error Code Description ...
string GetTradeServerReturnCodeDescription(int return_code)
{
return mAlert.GetTradeServerReturnCodeDescription(return_code);
}
//
// Protected ...
protected:
//
// Alert ...
XCAlert *mAlert;
//
// Private ...
private:
};
//