The following function creates a new AEScreen internal DP with the current UI number as index (so each user has a different and customized AEScreen); it also creates a new AESProperty internal DP, and makes the relative association between AEScreen and AESProperty; it sets the filters and removes the cache.
I don't know if there are different ways to accomplish this goal, but the approach seems quite neat to me.
Code: Select all
void openCustomAES(dyn_string dps, int FILTER_PRIO = 0, int FILTER_STATE = 0) {
/*
1. Search in the AESScreens' DPs if there is a DP with name = _AEScreen_UI_ + nrUI
2. If it doesn't exist, create it (copy from another AEScreen DP)
3. Search in AESProperties if there is a DP with name = AESProperty + nrUI (starting from 9000)
4. If it doesn't exist, create it (copy from another AESProperty DP)
5. Set in the AEScreen DP the corresponding property name+nrUI
6. Modify the filters of the property name+nrUI
7. Launch AEScreen with the previous configuration
*/
// 1.
int NrUi = myUiNumber();
dyn_string _other_dps = dpNames("*","_AEScreen");
string AESDP = "_AEScreen_UI_" + NrUi;
bool aesdp_exist = false;
for(int y= 1; y <= _other_dps.count(); y++) {
if(_other_dps[y] == AESDP) {
aesdp_exist = true;
break;
}
}
//2.
int err;
if(!aesdp_exist) {
if( !dpExists( AESDP ) )
{
dpCopy( "_AEScreen_0000", AESDP, err ); //copy dp structure
dpCopyOriginal( "_AEScreen_0000", AESDP, err ); //copy dp config
if( err != 0 )
{
DebugN("Errore nella copia", err);
}
}
DebugN("DP copied", AESDP);
}
string aes_name = "aes_ui_" + NrUi;
dpSetWait(AESDP + ".Name" + AES_ORIVAL, aes_name);
dpSetWait(AESDP + ".Bot.Active" + AES_ORIVAL, FALSE);
//3.
dyn_string _other_property_dps = dpNames("*","_AESProperties");
string AESDP_PROPERTY = "_AESProperties_" + (9000+NrUi);
bool aesdp_property_exist = false;
for(int x= 1; x <= _other_property_dps.count(); x++) {
if(_other_property_dps[x] == AESDP_PROPERTY) {
aesdp_property_exist = true;
break;
}
}
//4.
int err_property;
if(!aesdp_property_exist) {
if( !dpExists( AESDP_PROPERTY ) )
{
dpCopy( "_AESProperties_0002", AESDP_PROPERTY, err_property ); //copy dp property structure
dpCopyOriginal( "_AESProperties_0002", AESDP_PROPERTY, err_property ); //copy dp property config
if( err_property != 0 )
{
DebugN("Copy error", err_property);
}
}
DebugN("DP PROPERTY copied", AESDP_PROPERTY);
}
//update property name with NrUi index
string p_name = "aes_dyndp_ui_" + NrUi;
dpSetWait(AESDP_PROPERTY + ".Name" + AES_ORIVAL, p_name);
//5.
dpSetWait(AESDP + ".Top.Config" + AES_ORIVAL, p_name);
//6.
//set DP list
dyn_string _dps2 = dps;
_dps2.append("_Config");
dpSetWait(AESDP_PROPERTY + ".Alerts.Filter.DpList" + AES_ORIVAL, _dps2 );
//set filter priority
// 0 = no priority filter
dpSetWait(AESDP_PROPERTY + ".Alerts.Filter.Prio" + AES_ORIVAL, FILTER_PRIO );
/*
ShowOnly pending = FALSE
0 = All
1 = Unacknowledge
5 = Acknowledge
7 = Non-acknowledgeable
8 = Oldest acknowledgeable
ShowOnly pending = TRUE
2 = All
3 = Unacknowledge
4 = Acknowledge
6 = Non-acknowledgeable
*/
dpSetWait(AESDP_PROPERTY + ".Alerts.FilterState.State" + AES_ORIVAL, FILTER_STATE );
//remove cache
dpRemoveCache(AESDP);
dpRemoveCache(AESDP_PROPERTY);
// 7.
//open AES Screen with previous config
openAES(aes_name, TRUE, AES_ACTION_AUTORUN );
}