-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogOnDB.cs
86 lines (71 loc) · 2.61 KB
/
LogOnDB.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/// <summary>
/// A highly-reusable class for logging in database, both in single mode and and bulk mode.
/// It takes advantage of singleton design pattern for preventing waste of memory
/// It also has the ability to log the PowerDetector::instance().* classes
///
/// Created and maintained By Jalal Derakhshani
/// drakhshani.aram@hotmail.com
/// 2020
/// </summary>
///
class LogOnDB implements IWritable
{
}
private void new()
{
}
/// <summary>
/// This method has the ability to log the entries through a unique connection instance to the AX transactional database in an intact way,
/// so the wrapper transaction getting failed cannot intercept this entries from getting logged.
/// This ensures the user that logging will take place.
/// </summary>
///
public void write(Notes text, str context="", boolean status=0, Notes title= funcName())
{
LogOnDBTable logOnDBTable;
utcdatetime dateTime;
// Error handling
str finalMsg = "";
SysInfologEnumerator infoLogEnum;
SysInfologMessageStruct infoMessageStruct;
UserConnection connection = new UserConnection();
dateTime = DateTimeUtil::utcNow();
appl.dbSynchronize(tableName2id("LogOnDBTable"), true); // Ensures that the imported table has been synchronized and ready to use.
try{
ttsBegin;
logOnDBTable.setConnection(connection);
logOnDBTable.ttsbegin();
logOnDBTable.clear();
logOnDBTable.Title = title;
logOnDBTable.StatusOfOp = status;
logOnDBTable.ErrorMessageText = text;
logOnDBTable.ErrorType = context;
logOnDBTable.doInsert();
logOnDBTable.ttscommit();
ttsCommit;
}catch(Exception::Error){
infoLogEnum = SysInfologEnumerator::newData(infolog.infologData());
while(infoLogEnum.moveNext())
{
infoMessageStruct = SysInfologMessageStruct::construct(infoLogEnum.currentMessage());
finalMsg+=infoMessageStruct.message();
}
logOnDBTable.ttsabort();
ttsabort;
}
}
public static LogOnDB instance()
{
LogOnDB singleton;
SysGlobalCache globalCache = infolog.objectOnServer() ? appl.globalCache() : infolog.globalCache();
;
if (globalCache.isSet(classStr(LogOnDB), 0))
singleton = globalCache.get(classStr(LogOnDB), 0);
else
{
singleton = new LogOnDB();
infoLog.globalCache().set(classStr(LogOnDB), 0, singleton);
appl.globalCache().set(classStr(LogOnDB), 0, singleton);
}
return singleton;
}