.NET Customisation
User Guide
.NET Customisation
:
Database Interface
:
Events
: Adding Pseudo Attribute Code
Adding Pseudo Attribute Code
Code can be plugged in to calculate the value of pseudo attributes. The code to do this must be registered in the AVEVA module by passing in a C# delegate.
Code can be registered in two ways:
1.
Against a specific UDA. The code will then be invoked for all elements having this UDA.
2.
Against a specific UDA and a specific element type. The code will only be invoked for all elements of that type.
The same UDA may have multiple delegates registered for different element types.
There is a different delegate for each attribute type, for example: for integer attributes the delegate is:
public
delegate
double GetDoubleDelegate(DbElement ele, DbAttribute att, int qualifier);
These are defined in the DbPseudoAttribute class.
The user must write a method that matches the method signature of the delegate, for example: to write pseudo attribute code for a 'double' attribute, the user must write a method that has the signature defined by '
GetDoubleDelegate
'. i.e. a method that takes a
DbElement
, a
DbAttribute
, int and returns a double.
For example: the following method would be valid:
// Double delegate for UDA
static
private
double
VolumeCalculation(DbElement ele,DbAttribute
att,
int
qualifier)
{
// calculate the volume by multiplying the lengths along each side
double
x=ele.GetDouble(ATT.XLEN);
double
y=ele.GetDouble(ATT.YLEN);
double
z=ele.GetDouble(ATT.ZLEN);
// Result of UDA must be returned
return
(x * y * z);
}
An instance of the delegate containing the method must then be created and registered with the AVEVA module.
There are separate methods to register the different types of delegates. There are also separate methods to add a plugger for a particular element type, for example: the two methods to add a
GetDoubleDelegate
are:
public
static
void
AddGetDoubleAttribute(DbAttribute att,GetIntDelegate plug)
public
static
void
AddGetDoubleAttribute(DbAttribute att, DbElementType type, GetIntDelegate plug)
An example of registering a delegate is:
using
System;
using
NOUN=Aveva.Core.Database.DbElementTypeInstance;
using
Ps=Aveva.Core.Database.DbPseudoAttribute;
namespace
Aveva.Core.Shared.Tests
{
static
public
void
RegisterDelegate()
{
// get uda attribute
DbAttribute uda=DbAttribute.GetDbAttribute(":VOLUME");
// Create instance of delegate containing "VolumeCalculation" method
Ps.GetDoubleDelegate dele=
new
Ps.GetDoubleDelegate(VolumeCalculation);
// Pass delegate instance to core PDMS. This will be invoked later
// when :VOLUME is queried.
// In this case registry for all valid element types.
Ps.AddGetDoubleAttribute(uda,dele);
}
}
Code may be plugged by UDET as well as the base type. The following criteria are used to locate the right plugged code:
1.
If a UDET, look for a delegate plugged by UDET and attribute.
2.
Look for a delegate plugged by base type and attribute
3.
Look for a delegate plugged by matching attribute only.
for example: you could add three delegates to calculate :WEIGHT. You could add one that calculates the :WEIGHT on a :MYELE, one that calculates the :WEIGHT of SCTN and one that calculates WEIGHT for any other element for which :WEIGHT is valid.
A delegate only needs adding once at start up.
The events do not allow for errors. Thus if the value can not be calculated then the pseudo attribute code should return a sensible default.
1974 to current year.
AVEVA Solutions Limited and its subsidiaries. All rights reserved.