HOWTO use .Net or Java data structures in the OutSystems apps (Hastable, etc)

HOWTO use .Net or Java data structures in the OutSystems apps (Hastable, etc)

  

In some situations there is the need to reuse functionality that is already implemented in .Net or Java in an OutSystems application. A common situation is the need to use an advanced data structure (like a HashTable, Stack, Queue, Cirular Array, StringBuilder, Graph, Tree, XML Document, Etc.) or even a business spefic object that is already available in the .Net or Java frameworks or in a custom library (an external existing .dll or .jar library).

The goal of this HOWTO is to explain how a specific data structure already available in .Net can be used in an OutSystems application. The HOWTO will be based on a specific example in .Net (the Queue data structure), but the exact same pricinciples can be used in the Java stack and any other data structure.

In the screenshot below you can get and high-level picture of how a Queue class that is availalble at the .Net (or Java) framework can be wrapped in an OutSystems extension and then used in your OutSystems Service Studio visual flows.

Contents

1. Overview

In this HOWTO our goal is to use the functionality provided by the Queue class available in the .Net Framwork in our OutSystems application to manage strings. 

Click here to download the StringQueue.zip file that contains the StringQueue.xif extension that will be created throughout the HOWTO and the StringQueue_Sample.oml file that uses and tests the StringQueue extension.

The Queue class is availlable in the System.Collections namespace (see the Queue class documention here). We want to be able to use the following members of the Queue class:

  1. Enqueue - Adds an object to the end of the Queue.
  2. Dequeue - Removes and returns the object at the beginning of the Queue.
  3. Contains - Determines whether an element is in the Queue.
  4. Peek - Returns the object at the beginning of the Queue without removing it.
  5. Clear - Removes all objects from the Queue.
  6. Count- A property of the queue object that indicates the number of objects in the queue. 
  7. ToArray - Copies the Queue elements to a new array.

From a high-level perspective, we will have to do the following:

  1. Create a new OutSystems extension named StringQueue;
  2. In the StringQueue extension define an action that that creates the Queue object (invoking its constructor);
  3. In the StringQueue extension define all the Queue behavior actions  (Enqueue, Dequeue, etc.);
  4. Implement all the StringQueue actions in C# using the System.Collections.Queue class;

2. Creating a StringQueue OutSystems extension

In this section I will show you the step by step instructions to create the QueueString OutSystems extension that makes use of the System.Collections.Queue class. In the attached StringQueue.zip file you have the StringQueue_Sample.xif extension that will be created in this section.

2.1 Create a new StringQueue OutSystems extension in Integration Studio

To create an OutSytems extension, start by opening the OutSystems Integration Studio at Start > Programs > OutSystems > Integration Studio. Name your extension StringQueue.

2.2 Define an action that creates the Queue object (CreateQueue)

The CreateQueue action that will instantiate a Queue object. The CreateQueue action returns the reference to the created Queue object with the OutSystems object data type.

2.3 Implement the action that creates the Queue object  C#

To edit the source code implementation of the CreateQueue action, press the Edit Source Code button in Integration Studio - this will open Microsoft Visual Studio. By opening the StringQueue.cs file, you can see that Integration Studio automatically generates the signature of your integration actions.

The C# implementation of your CreateQueue is extremely simple. All you have to do is find the MssQueueAction that was generate for you and write the C# line that invokes the System.Collections.Queue class constructor and assigns the result to the ssQueue output variable.

2.4 Define the Queue behavior actions (Enqueue, Dequeue, etc.)

For each of the Queue class member that you want to use, create a corresponding OutSystems action. Each of these actions will receive the Queue object as an input parameter and the remaining necessary parameters.

2.5 Implement the Queue behavior actions in C#

 

To implement the Queue behavior actions, Edit the Source Code of your extension again. You can see that in the StringQueue.cs file the new methods were automatically generated. For each method, all you have to do is invoke the corresponding class member in the System.Collections.Queue and do the necessary type conversions.

2.6 Publish the StringQueue extension in your OutSystems server

In order to be able to use the actions that you just created in the StringQueue extension, you only have to push the 1-click-publish button. This will automatically compile you extension source code and make it available for OutSystems applications to use it.

3. Using the StringQueue in your OutSystems application

To use the StringQueue extension in your application, you simply have to do the following. In the attached StringQueue.zip file you have the StringQueue_Sample.oml eSpace that uses and tests the StringQueue extension.

3.1 In your eSpace, add a reference to the StringQueue extension

In your eSpace, press Add/Remove References import all the actions made available by the StringQueue extension.

3.2 In your Service Studio visual flows, create the Queue object with CreateQueue. Use the returned reference to invoke the Queue behavior actions (Enqueue, Dequeue, etc.)

Whenever you use the StringQueue object, you have to first invoke the CreateQueue action that creates the Queue object - the output of the action is a reference to the object.

Whenever you invoke one of the Queue behavior actions (Enqueue, Dequeue, etc.), use the reference returned by the CreateQueueaction.



Kind Regards,

Daniel Lourenço
OutSystems
Wow.  Fantastic article, and it's great to know this path is available.
Thank you for your positive feedback, Frank :) .
very clear : thank you