DOT NET Interface Library/en: Unterschied zwischen den Versionen
Cg (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „== Overview == The .NET Interface Library (".NET Bridge") contains a mechanism to access Microsoft .NET (CLR) objects of a local or remote .NET application (a…“) |
Cg (Diskussion | Beiträge) |
||
Zeile 105: | Zeile 105: | ||
<hr> |
<hr> |
||
Back to [[Plugins]]<br> |
|||
Back to [[OnlineDocumentation#Library and Plugin Overview|Online Documentation]]. |
Back to [[OnlineDocumentation#Library and Plugin Overview|Online Documentation]]. |
Version vom 10. April 2014, 23:29 Uhr
Inhaltsverzeichnis
Overview[Bearbeiten]
The .NET Interface Library (".NET Bridge") contains a mechanism to access Microsoft .NET (CLR) objects of a local or remote .NET application (a so-called .NET bridge), and an API for elementary blocks and a library of blocks to interact with these objects.
Programmatic Interface[Bearbeiten]
Access to .NET objects, classes and programs is done via a framework called "dotNET-Bridge". This framework implements transparent forwarding of expecco messages (virtual function calls) from either Smalltalk or JavaScript code to .NET objects as existent in a local or remote .NET virtual machine. Also, return values, callBacks and exception information are passed back from the .NET program to expecco. A proxy-object mechanism which catches all function calls, wraps the arguments and sends a datagram to the other bridge side is used for this to be almost completely transparent to the Smalltalk/JavaScript code inside expecco.
In addition to existing blocks of the .NET Interface Library, programmatic access to dotNET objects is sometimes useful or required. So the following information is useful if you want to write your own elementary .NET-blocks, or if you have to enhance the existing library by adding application-specific interface blocks.
Initializing / Releasing the Bridge[Bearbeiten]
Before any communication can take place between expecco and any dotNet object, the .NET side of the bridge has to be started, and a communication path to be setup.
All of the bridges classes are in the DOTNET
namespace; the main interface class is DotNet
, in this namespace:
dotNetHandle := DOTNET::DotNet startNew.
or (in JavaScript):
dotNetHandle = DOTNET::DotNet.startNew();
This starts the .NET-side of the bridge (the executable named "DotNetBridge.Server.exe"), and waits for a connection request from this program.
When finished, release the bridge with:
dotNetHandle.exitDotNet();
which shuts down the connection and terminates the executable.
Loading Assemblies[Bearbeiten]
Using the "loadLibrary"-function, wellknown assemblies can be loaded:
dotNetHandle.loadLibrary("System.Windows.Forms");
or:
dotNetHandle.loadLibrary("user32.dll");
Arbitrary files which contain assemblies are loaded with:
dotNetHandle.loadFile(pathToDLL);
Accessing Globals[Bearbeiten]
Globals, nameSpaces and members of a namespace are accessed using message sends to the dotNet handle, where the message name is the name of the global, namespace or interface. These messages can be chained, to access a hierarchy of namespaces. For example:
dotNetHandle.System.Reflection.Assembly.LoadFile("c:\foo\bar\myAssembly.dll");
Instantiating a Class[Bearbeiten]
Object instances are created via the "new"-message, sent to a global:
b = dotNetHandle.Button.new();
f = dotNetHandle.Form.new();
once instanciated, any message can be sent transparently to such an .NET object, as if it was an expecco object:
b.text("Hello World");
f.controls.add(b);
f.showDialog();
Callbacks[Bearbeiten]
Callbacks from .NET back into expecco are implemented via Smalltalk blocks (JavaScript anonymous functions). The bridge automatically installs an appropriate callback, whenever a block/function is given to a .NET component as a callback or hook.
Here is a complete example for creating a .NET form with a callback into expecco. This code could be put into an EB (Elementary Block) of an expecco activity diagram:
var dotNet, form, button;
// called when the .NET button is clicked
function callBack() {
dotNet.MessageBox.show("Hello from expecco");
};
dotNet = DOTNET::DotNet.startNew();
dotNet.loadLibrary("System.Windows.Forms");
button = dotNet.Button.new();
button.text("Hello");
button.click.add( callBack );
form = dotNet.Form.new();
button.dock( dotNet.DockStyle.fill );
form.controls.add( button );
form.showDialog();
dotNet.exitDotNet();
to be continued
See Also[Bearbeiten]
The Java Interface Plugin & Library, which implements a likewise interface for Java applications/libraries.
Back to Plugins
Back to Online Documentation.