Advanced programming


You can declare methods in iPlus in two ways:

  • either in the source code in your assembly
  • or as a script method in the iPlus development environment.

To announce methods in the iPlus framework, you must use the attribute class ACMethodInfo or one of the derivatives and insert it before the method signature. These assembly methods should be as public as possible.

Depending on their purpose, various signatures are available in derivatives of the ACMethodInfo attribute class.

The following purposes are intended:

  • Server-side or local use
  • Command method
  • Client side use only
  • Method for context menus
  • Attached method (extension method)
  • Status-Dependent Method

 

 


Use the attribute class ACMethodInfo for classic methods that use:

  • Can have parameters and / or return values
  • and can be called locally or over the network.
[ACMethodInfo("ExGroup", "en{'Example serverside'}de{'Beispiel serverseitig'}", 202, false)]
public Boolean MyServersideMethod(string stringParam)
{... return false}

If the method is called on a proxy component (client-side) using the ACUrlCommand, the framework delegates the call in the background through the network to the server-side instance. The method is then executed on the server side (on the real instance) and the return value is sent back through the network. During this time, the thread that called the method on the client side is blocked (synchronous call).

Note that both the parameter list types and the return value must be serializable and known to the DataContractSerializer if you want to execute remote calls. If the method is only called in the local application domain, the types do not have to be serializable.


You use the attribute class ACMethodCommand for parameterless void methods mainly in connection with buttons on the interface.

[ACMethodCommand("ExGroup", "en{'Example command'}de{'Beispiel Kommando'}", 202, false)]
public void MyCommand() }

Command methods have a special feature compared to the classic use of the ACMethodInfo: Before the command method is called, the IsEnabled method first checks whether the command method can be called. To do this, declare another method with the prefix "IsEnabled" followed by the method name of the command method:

public bool IsEnabledMyCommand() { return true/false; }

Note: The method must have a boolean return value.

The CanExecute event handler of the CommandBindings of UIElementen calls the IsEnabled method. This CanExecute event handler is automatically set in iPlus controls (e.g. buttons, MenuItems, Ribbon). Therefore, all you have to do during GUI programming is enter the method name of the command method in the VBContent property. The complex CanExecute event handling of the WPF framework remains hidden for you.

#IsEnabled

Remote calls (delegation of method calls via the network) load the network layer and may cause computing power on the server side. Methods that do not change the object state (change the property values of an instance) therefore do not necessarily have to be executed on the server side. Here, so-called client-side methods are used.

Use the attribute ACMethodClient class whenever:

  • all data (object state) in the proxy component is available that is required for the method algorithm,
  • if the method is called often and has only client-side relevance (e.g. for the GUI: calculation of a signal color, conversion of units...)
  • database operations can or should be made on the client side.

Client-side methods with the attribute class ACMethodClient can only be static. Similar to the concept of .NET-Extension Methods, the algorithm of the static method must know the this pointer. Therefore, the signature of the method must always be structured in such a way that the first parameter is always an IACComponent acComponent:

[ACMethodClient ("ExGroup", "en{'Example clientside'}de{'Beispiel clientseitig'}", 202, false)]
public static Boolean MyClientsideMethod(IACComponent acComponent, string stringParam)
{... return false; }

When calling client-side methods using ACUrlCommand, the first parameter (this pointer) is automatically set by the iPlus framework and must therefore not be passed explicitly!

Parameters do not have to be serializable for client-side methods.

The "IsEnabled"-method must also be static and requires the IACComponent acComponent parameter:

public static bool IsEnabledMyClientsideMethod(IACComponent acComponent) 
{... return true;  }

Use the attribute class ACMethodInteraction to call parameterless void methods from the context menu. ACMethodInteraction is a derivation of the ACMethodCommand-class.

[ACMethodInteraction("ExGroup", "en{'Example contextmenu command'}de{'Beispiel Kontextmenü-Kommando'}", 200, true, "", Global.ACKinds.MSMethod, false, Global.ContextMenuCategory.ProcessCommands)]
public virtual void MyCtxMenuMethod()

As with the ACMethodCommand attribute class, you can define an IsEnabled method. The iPlus framework calls the IsEnabled method as soon as the context menu is to be displayed on the interface. If the method returns "false", no context menu entry is displayed for this method.

With the parameter contextMenuCategory you can define in which submenu (category) your method shall be displayed.

The categories available for you to choose from are already predefined in the framework with the ContextMenuCategory enumeration and cannot be defined individually.

Use the attribute class ACMethodInteractionClient for client-side methods


Use the ACMethodAttached attribute class to display methods in the context menu.

The methods marked with this attribute class are appended to a class other than those defined. This means that the method is implemented in class A but "appended" to a class B.

[ACMethodAttached ("ExGroup", "en{'Example attached'}de{'Beispiel angehängt'}", 202, typeof(PAClassAlarmingBase), false)]
public static void MyAttachedMethod(IACComponent acComponent) { }

In the fourth parameter of the constructor, specify the type of class that you want to append to the method (e.g. typeof(ClassnameB) ).

Attached methods work like client-side methods or .NET-Extensionmethods. Therefore,

  • the signature of your Attached method must be static
  • and the first and only parameter of this method must be of type IACComponent.

 

The "IsEnabled"-Method must be static and requires the parameter IACComponent acComponent:

public static bool IsEnabledMyAttachedMethod(IACComponent acComponent)
{ return true;  }

The iPlus framework passes you an instance of the class to which your method is appended as this-pointer.


Use the ACMethodState attribute class to describe methods that are called when the state of an ACComponent changes.

"State" is the value of a property that is specifically used to describe a state. Components that derive from PABase (process functions or workflow classes) use the ACState property to describe their current state.

The type of the ACState-property is the ACStateEnum enumeration. The methods in these classes are named exactly like the possible values of the ACStateEnum. If the value of the ACState property changes, the corresponding method is called with the same name.

[ACMethodState("en{'Idle'}de{'Leerlauf'}", 10, true)]
public virtual void SMIdle() { }

These automated calls of the status methods are specifically programmed in the PABase class.

If you want to use your own status property + status methods, implement them using the following sample code:

 


In the previous code example ACMethodState the ExecuteACMethod method was used to call a method by name. Internally, Reflection is used to call the method. Since Reflection is an elaborate . NET process, this can be bypassed by calling the appropriate method itself when the ExecuteACMethod method is executed.

The ACComponent class provides the virtual method HandleExecuteACMethod for this purpose. Overwrite the method in your class as follows:

 

If the overridden method returns true, it tells the framework that the derived class itself called the method and that the framework no longer needs to make a Reflection call.

If the method has a return value, you must set the out variable "result" with this value. Parameter values are in the variable "acParameter" and are read by indexed array access.

The procedure described earlier only works with instance-related methods. Static methods, on the other hand, must be called using static handlers:

 

You cannot override static methods. As a result, acComponent cannot provide a virtual method that it is already aware of in advance. o announce these static handler methods to the iPlus framework, you must call the RegisterExecuteHandler method in the static class constructor and pass your handler method as a delegate:

static MyClass()
{
RegisterExecuteHandler(typeof(MyClass), HandleExecuteACMethod_MyClass);
}

 


The previous code example, "HandleExecuteACMethod_MyClass" calls the "AskUserExampleAskMethod" method. Methods with the prefix "AskUser" are called automatically by the framework, like "IsEnabled" methods. They serve to give the programmer the opportunity to intervene before calling the actual method, e.g. to ask the user something else.

"AskUser"-methods work like client-side methods or .NET-Extensionmethods. Therefore

  • the signature of your "AskUser" method must be static
  • and be the first and only parameter of type IACComponent:

 

An ACMethodInfo attribute class does not need to be used. Only the string after the "AskUser" prefix must match the name of the method to be called at the end.


All of the methods described above can also be defined as script methods. Script methods are stored in the database. At runtime, they are compiled as static methods and attached to the ACComponent instance. Since static methods do not know which class they belong to, like extension methods, they also need a reference to the instance on which they are to perform the operations. For this reason, the signature of a script method must always be such, that the first parameter is IACComponent (see "attached methods" or "client side methods" above):

 

After IACComponent, the remaining individual parameters then come. 

Please remember to transfer the same method name from the script code to the Method Name (ACIdentifier) ​​field on the "Method Info" tab.

The "<Precompiler>" section is a special directive for the iPlus system. Enter your using instructions here. If you need an assembly that was not automatically loaded into the application domain of the iPlus application at runtime, you must explicitly specify it with the keyword "refassembly" so that it is loaded by the iPlus runtime.