Using A NuGet Package
Using A NuGet Package
Using A NuGet Package
Extending Logic with C# Code:
Using a NuGet Package
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 1
Table of Contents
Table of Contents 2
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 2
Introduction
The power of the OutSystems platform comes from the combination of rapid development and
change using the visual low-code paradigm and the uncompromising capability to integrate and
be extended with other technologies.
Probably the best example of this is the capability to develop specific functionalities in the .NET
C# language. This is beneficial when the need to integrate with a legacy external system arises
or when we must invoke a specialized third-party executable.
In this lab we will be implementing an Action in C#, using OutSystems Integration Studio and
Microsoft Visual Studio, that will then be seamlessly callable from Service Studio modules, just
as any other Server Action would be.
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 3
We will start by creating an extension in Integration Studio containing a single Action that
requires no specialized types for its parameters. This action will allow the conversion of
Markdown1 text to HTML, which could be used to build a CMS2 in OutSystems.
1) Open Integration Studio and login in your OutSystems server (likely your personal
environment).
a) Launch I ntegration Studio f rom a Desktop shortcut or the Windows Start Menu
or
b) Connect Integration Studio to your OutSystems server using the icon on the top
toolbar
c) In the Connect to Environment dialog, enter the environment address,
username and password you will be using to carry out the exercises, and click
1
https://en.wikipedia.org/wiki/Markdown
2
https://en.wikipedia.org/wiki/Content_management_system
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 4
Connect.
NOTE: This login information is exactly the same as you use to connect Service
Studio to the OutSystems platform server.
b) Integration Studio will change to display a newly created extension, change its
name from the default “ Extension” to MarkdownToHTML and press Return
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 5
a) Right-click the A
ctions folder and select A
dd Action.
d) Below the M
arkdown parameter, type in H
TML for the Name o
f the second
parameter. Change its kind to Output Parameter by clicking on its icon. Leave its
Data Type as “Text”.
NOTE: Unticking the “Mandatory” c heckbox will allow an Input Parameter to be
made optional. The mandatory concept is not applicable to Output Parameters so
the checkbox in these parameters is non functional.
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 6
b) Integration Studio will automatically generate the C# source to match our
Extension definitions...
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 7
c) … and Microsoft Visual Studio will launch and load in the MarkdownToHTML
project, ready for editing
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 8
NOTE: Upon opening a source C# file, you may be notified that the file has
inconsistent line endings. This is not a problem so, on that dialog, simply leave
the Line ending to the suggested “Windows (CR LF)”, untick the “Always show this
dialog” and click Yes.
3
https://docs.microsoft.com/en-us/nuget/what-is-nuget
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 9
NOTE: The Solution, Project and “main” C# source filename will always match the
name given to the Extension.
2) Import the CommonMark4 assembly into the extension project, using NuGet
a) Right-click the M
arkdownToHTML element in Solution Explorer tree, and select
the Manage NuGet Packages… option
b) On the main window, a NuGet management tab for the solution will appear.
Select the Browse tab and type in CommonMark in the search input
d) Locate and select CommonMark.NET from the result list on the left. The right
panel will show details about this assembly. Ensure the “0.15.1” version is
selected and press Install.
4
https://github.com/Knagis/CommonMark.NET#commonmarknet
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 10
e) After acknowledging that this operation will make changes to your solution, the
Output Window will show the steps of the assembly installation.
f) Upon completion, expand the R
eferences node in the Solution Explorer panel:
CommonMark should be visible there. Select it and ensure its C
opy Local
property is set to “True”.
NOTE: Due to the way Integration Studio packs extensions, any external
assemblies or resources that are required for the extension to function will need
to reside inside the extension folder, on the appropriate subdirectory. The C
opy
Local property ensures this (i.e. that C
ommonMark.dll is inside the bin/ folder).
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 11
b) Move to the M
ssMarkdown_ConvertToHTML function definition
a) Replace the body of the function (i.e. between { and }) with the following C# code
f) The output window should show no errors
g) Close Microsoft Visual Studio using menu File, option Exit.
NOTE: Building the solution inside Visual Studio i s not strictly needed, as the
code will be rebuilt inside Integration Studio. We do so simply to speed up error
detection before leaving the Microsoft IDE.
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 12
NOTE: This view shows the filesystem tree based on where the Extension was
expanded in the developer’s machine. Files displayed comprise both included
(dark) and excluded (greyed-out) from the Extension package.
By default, Integration Studio already selects for inclusion file types it knows are
important for the functioning and future developments of the Extension (such as
.dll and .cs files). In this case we decided to override the default (of ignore) for
packages.config. We do this so Microsoft Visual Studio can keep track of the
CommonMark version we are currently using in the project.
b) Locate the packages.config file in the tree, right-click it and select I nclude in
Extension
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 13
b) Integration Studio should detect the inclusion of C
ommonMark into the project
and add the necessary resources to the Extension. It will then compile it and
publish it to the server.
NOTE: During the process, your extension will also be saved locally to your hard
drive. If you haven’t explicitly saved it before, you may be prompted for a path
halfway through this publication.
3) Publish the sample M
icro_CMS a
pplication into your server
a) Open Service Studio from the Start Menu or by double clicking the icon.
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 14
c) In the Environment t op menu, select O
pen Files...
d) Change the the bottom-right file type Combo filter to show “ OutSystems
Application Pack (*.oap)”. Navigate to and select the M
icro CMS.oap s ample
application, and then press Open.
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 15
NOTE: After the installation completes, the application will be moved further
down in the list to be sorted alphabetically. Depending on how many applications
you have already installed, it may therefore move out of view (you can use search
to find it).
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 16
b) Click the MicroCMS module inside the Micro CMS application view to open it
c) Click the Manage Dependencies i con on the top toolbar
d) In the Manage Dependencies d ialog, type in “ markdown” in the Producers filter
to narrow down the list. Then select the MarkdownToHTML E xtension on the
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 17
NOTE: Like any public action in Service Studio modules, C# actions created in an
extension and consumed from the dependencies dialog become - in practical
terms - indistinguishable from every other action in our (consuming) module.
2) Add the M
arkdown_ConvertToHTML functionality to the CMSEntryDetail s creen
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 18
b) Drag a Run Server Action from the toolbox and drop it on the Action flow just
before the “ Save Edited Content” Assign statement.
c) On the S
elect Action p
opup, type in ”markdown” in the filter area, and
double-click the M
arkdown_ConvertToHTML action, to select it
CMSEntryForm.Record.CMS_Entry.ContentEditable
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 19
e) Click on the “ Save Edited Content” Assign s tatement below, and change the
expression-side of the assignment to “Markdown_ConvertToHTML.HTML”
NOTE: The steps above are sufficient to use the extension functionality previously
implemented. However, if you press the S
ave button too rapidly after typing
things into the Content multi-line input, the latest changes may not be saved.
With this in mind, you may want to carry the following (multiple) step
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 20
a) Click the 1-Click Publish button to publish the module to the server.
b) After it’s done, press the Open in Browser button to open your application in
your default browser.
NOTE: If you are not yet logged into any application on your environment, you
will be taken to the login screen. Simply login with any Registered user and you’ll
be able to enter the application.
a) Press the “Create a new CMS Entry” link at the top-right corner of the application
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 21
b) In the New CME Entry screen, set the entry Title t o “Sample” and set the entry
Content to
Heading
=======
## Sub-heading
Horizontal rule:
---
Bullet list:
* apples
* oranges
* pears
Numbered list:
1. wash
2. rinse
3. repeat
A [link][example].
[example]: http://www.outsystems.com
![Image](https://foundation.outsystems.net/resource/get/neo-mascot.pn
g "NEO")
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 22
c) When you stop typing, the right Preview panel will flash to show the HTML
version of the markdown content above. You should see something like this
d) Press the “Save” button to go back to the CMS Entries screen. Press the “Eye” icon
on the line of the Sample we just created
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 23
e) This will open a dedicated page to display just your HTML content!
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 24
End of Lab
In this exercise lab, we created an Extension module that adds new functionality to be used by
regular OutSystems Service Studio modules: adding a converter from Markdown to HTML.
We used Integration Studio to define an action prototype, and then Microsoft Visual Studio to
first import an external assembly into our C# project and then flesh out the action’s code.
We then extended that application to call the action from our Extension, and use the converter
every time we create new content in the CMS application, thus showing the seamless
integration of .NET C# into the OutSystems platform.
OutSystems Inc. 5
901 Peachtree Dunwoody Road, N.E. Building C, Suite 495, Atlanta, GA 30328 25