MS .NET
To integrate your applications using Microsoft .NET with edinn through the API, you will need a working environment in your preferred programming language.
In this example we will use VB.NET to connect to the edinn platform, obtain the tree of areas and processes and disconnect from the platform.
This example needs the NuGet package Newtonsoft.Json package, which you can install from the Microsoft Visual Studio IDE.
We can explain the example in three steps:
1st Create a UWP Application:
Open Visual Studio .Net.
Select "Create a new project" in Get Started section.
Type "uwp basic" in the search box.
Select Blank App (Universal Windows). Note that there must have the labels "Visual Basic" and "UWP".
Choose the project name, location and solution name you prefer.
2nd Paste the example code:
In the solution explorer, make double click on MainPage.xaml.
We can see now the preview of thr window and the corresponding xml code of the interface.
Paste the following code inside the grid section.
<StackPanel x:Name="frmLogin" HorizontalAlignment="Stretch"> <TextBlock Text="edinn API tester" FontSize="14" FontWeight="Bold" /> <TextBox x:Name="txtCompany" PlaceholderText="company" /> <TextBox x:Name="txtUser" PlaceholderText="user" /> <TextBox x:Name="txtPass" PlaceholderText="password" /> <Button x:Name="cmdLogin" Content="Login" Click="cmdLogin_Click" HorizontalAlignment="Stretch" /> <TextBox x:Name="txtSession" Text="" TextWrapping="Wrap" PlaceholderText="session"/> <Button x:Name="cmdTree" Content="Get Tree" HorizontalAlignment="Stretch" Click="cmdTree_Click"/> <Button x:Name="cmdLogout" Content="Logout" HorizontalAlignment="Stretch" Click="cmdLogout_Click"/> <TextBox x:Name="txtResponse" Text="" TextWrapping="Wrap" IsReadOnly="True" Height="180" PlaceholderText="response"/> </StackPanel> |
Open de VB code belongin to the inteface in MainPage.xaml.vb
' The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 ''' <summary> ''' An empty page that can be used on its own or navigated to within a Frame. ''' </summary> Public NotInheritable Class MainPage Inherits Page End Class |
Import the Http library at the top of the code.
' The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 |
Imports System.Net.Http |
''' <summary> ''' An empty page that can be used on its own or navigated to within a Frame. ''' </summary> Public NotInheritable Class MainPage Inherits Page End Class |
Paste the following code after the class declaration.
' The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 Imports System.Net.Http ''' <summary> ''' An empty page that can be used on its own or navigated to within a Frame. ''' </summary> Public NotInheritable Class MainPage Inherits Page |
Private Sub cmdLogin_Click(sender As Object, e As RoutedEventArgs) Handles cmdLogin.Click txtResponse.Text = "" Dim lStr = session_post() txtResponse.Text = lStr End Sub Private Sub cmdTree_Click(sender As Object, e As RoutedEventArgs) txtResponse.Text = "" Dim lStr = tree_get() txtResponse.Text = lStr End Sub Private Sub cmdLogout_Click(sender As Object, e As RoutedEventArgs) txtResponse.Text = "" txtResponse.Text = session_delete() End Sub Private Function session_post() As String Dim client As New HttpClient ''' IMPORTANT! Change the url according to your server IP ad PORT ''' Dim url As String = "http://localhost:8080/sessions" Dim values As New Dictionary(Of String, String) values("company") = txtCompany.Text values("user") = txtUser.Text values("password") = txtPass.Text Try Dim content As New FormUrlEncodedContent(values) Dim response As New HttpResponseMessage response = client.PostAsync(url, content).Result Return response.Content.ReadAsStringAsync().Result Catch ex As Exception Return ex.Message End Try End Function Private Function session_delete() As String Dim client As New HttpClient ''' IMPORTANT! Change the url according to your server IP ad PORT ''' Dim url As String = "http://localhost:8080/sessions/" & txtSession.Text & "?company=" & txtCompany.Text Try Dim request As New HttpRequestMessage(HttpMethod.Delete, New Uri(url)) Dim response As New HttpResponseMessage response = client.SendAsync(request).Result Return response.Content.ReadAsStringAsync().Result Catch ex As Exception Return ex.Message End Try End Function Private Function tree_get() As String Dim client As New HttpClient ''' IMPORTANT! Change the url according to your server IP ad PORT ''' Dim url As String = "http://localhost:8080/tree?company=" & txtCompany.Text & "&session=" & txtSession.Text Try Dim response As New HttpResponseMessage response = client.GetAsync(New Uri(url)).Result Return response.Content.ReadAsStringAsync().Result Catch ex As Exception Return ex.Message End Try End Function |
End Class |
3rd Customize and test it
If we have our own server, a company and a user in edinn, we can test the application inmediatly.
We should only change the url adress that in the example code begins wthit "http://localhost:8080/" with the adress of our own server.
How to use the test application
To do login: Fill in the "company", "user" and "password" field and click "Login". In the “response” box you will see the session code.
Get the tree of areas and processes: To get the tree of areas and processes, fill in the field "company", paste the session code in the "session" box and click "Get Tree". In the “response” box you will see the tree of areas and processes.
To logout: To end a session, fill in the "company" field, paste the session code in the "session" box and press Logout. In the “response” box you will see the response.
From this point on, you can implement the calls to the available functions, by reading the API help topics.