VB.NET Support - AquaticInformatics/aquarius-sdk-net GitHub Wiki
Your code can consume the Aquarius.SDK
package from a VB.NET project just as easily as from a C# project. The two languages are very similar in functionality, so it is really just a change in syntax.
Make sure to target the .NET 4.7.2 framework (or higher)
Your VB.NET project should target the .NET 4.7.2 framework, or newer, in order to consume the Aquarius.SDK
package from NuGet.
The target framework dropdown list can be found in the Project => Properties => Application settings tab within Visual Studio.
Quick Example - Find the point count of the first Stage time-series
This example will use the SDK to connect to an AQTS app server and use the Publish API operations to find the number of points after 2018 in the first Stage series it discovers.
This example highlights a few key ideas:
- All the API calls are wrapped in an outer exception handler, with specific support for
WebServiceException
error handling from any failing API. - The connection to the app server is wrapped in a
Using
block to automatically clean up connection resources - Individual request properties are set using VB's fluent
With {.PropertyName = Value}
syntax
Imports Aquarius.TimeSeries.Client
Imports Aquarius.TimeSeries.Client.ServiceModels.Publish
Imports ServiceStack
Module Module1
Sub Main()
' Wrap the entire operation in a try/catch block. Any API failures will be WebServiceException objects
Try
ConnectAndMakeRequests()
Catch ex As WebServiceException
' A REST API failed, so show the message from the server
Console.WriteLine($"AQTS ERROR: {ex.ErrorCode} {ex.ErrorMessage}")
Catch ex As Exception
' Something else went wrong
Console.WriteLine($"ERROR: {ex.Message}\n{ex.StackTrace}")
End Try
End Sub
Sub ConnectAndMakeRequests()
' Wrap all the calls to AQTS in a using block so that the connection gets automatically deleted no matter how the code exits
Using connectedClient = AquariusClient.CreateConnectedClient("doug-vm2019", "admin", "admin")
Client = connectedClient
FindPointCountOfFirstStageTimeSeries()
End Using
End Sub
Private Property Client As IAquariusClient
Sub FindPointCountOfFirstStageTimeSeries()
Console.WriteLine($"Connected to {Client.ServerVersion}")
Dim locationDescriptions = Client.Publish.Get(New LocationDescriptionListServiceRequest()).LocationDescriptions
Console.WriteLine($"There are {locationDescriptions.Count} locations")
' You can set request properties fluently using VB's "With {.PropertyName = Value}" syntax
Dim timeSeriesDescriptions = Client.Publish.Get(New TimeSeriesDescriptionServiceRequest With {.Parameter = "Stage"}).TimeSeriesDescriptions
Console.WriteLine($"There are {timeSeriesDescriptions.Count} stage time-series.")
If timeSeriesDescriptions.Any() Then
Dim ts = timeSeriesDescriptions.First()
Dim queryFrom = New DateTimeOffset(2018, 1, 1, 7, 0, 0, TimeSpan.Zero)
Dim data = Client.Publish.Get(New TimeSeriesDataCorrectedServiceRequest With
{
.TimeSeriesUniqueId = ts.UniqueId,
.QueryFrom = queryFrom,
.QueryTo = queryFrom.AddDays(1)
})
Console.WriteLine($"There are {data.NumPoints} points in '{ts.Identifier}'.")
End If
End Sub
End Module