Click or drag to resize

Programming guidelines for Visual Basic .NET

The .NET interop library is a wrapped version of the Visual Basic interfaces that has been optimized for .NET and, therefore, the interface details for Visual Basic .NET are very similar to Visual Basic 6. For example, instead of using the Visual Basic 6 objects named AM*, use the equivalent objects named BC*. For example, instead of the AMDocumentRepository object, use BCRepository.

Following are some recommendations for working with Meridian Enterprise API objects and the code that manipulates them.

Instead of a cast of a document object to an interface such as IAMVersionable, use the Versionable property of the BCDocument object.

Many of the .NET SDK methods return their results in a one dimension array. Most of the .NET SDK methods accept a collection of strings as an argument of the IEnumerable(Of String) interface. To convert array results to collection arguments, you can use several methods, depending on the .NET version that is installed on the client computer. The following examples demonstrate these methods using the members of a Meridian user group named Managers.

Dim Managers = ExtensionHost.ScriptObjects.Vault.GetUsers(BlueCieloECM.InnoCielo.Meridian.Scripting.SUserColumnFlags.AS_UCOL_NAME, "Managers") 
Dim ManagerNames = New ArrayList(Managers).ToArray(GetType(String)) ' Supported by .NET Framework: 1.1 and higher 
Dim ManagerNames = Managers.Cast(Of String)() ' Supported by .NET Framework: 3.5 and higher 
Dim ManagerNames = Managers.OfType(Of String)() ' Supported by .NET Framework: 3.5 and higher

You could pass such a collection to the ExecuteTransition method as in the following example.

doc.Workflow.ExecuteTransition(Transition, Comment, UserNames, ManagerNames)

Like all objects in .NET, the lifetime of Meridian Enterprise objects should be defined with Using statements to guarantee that the objects are disposed of when the code block is exited either gracefully or as the result of an exception. The lifetime of Meridian Enterprise objects that are not defined by Using statements conforms to the general rules of .NET with a simple exception – all of them are disposed of upon closing the transaction to which they are tied.

Just as we do not recommend using a collection indexer and For Each statements to enumerate TableView collections in Visual Basic 6, we do not recommend enumerating BCCollection objects with a BCCollection indexer and For Each statements in Visual Basic .NET. Doing so will instantiate live objects on the server and keep them all alive until the transaction is committed or revoked. Instead, we recommend using the GetRowAMID method to retrieve the ID of the object and then instantiate the object of the proper type by the ID.

For example:

Wrong
Using tv As BCReadOnlyCollection(Of BCDocument) = doc.IncomingDocuments 
  For Each d As BCDocument In tv 
    ' The Using statement DOES NOT release the object on server. 
    Using d 
      Dim S As String = d.DisplayName 
    End Using 
  Next 
End Using
Wrong
Using tv As BCReadOnlyCollection(Of BCDocument) = doc.IncomingDocuments 
  For i As Integer = 0 To tv.Count - 1 
    ' The Using statement DOES NOT release the object on server. 
    Using d As BCDocument = tv.Item(i) 
      Dim S As String = d.DisplayName 
    End Using 
  Next i 
End Using
Right
Using tv As BCReadOnlyCollection(Of BCDocument) = doc.IncomingDocuments
  For i As Integer= 0 To tv.Count – 1
    Dim id As String = tv.GetRowAMID(i)
    ' The Using statement DOES release the object on server. 
    Using d As BCDocument = repository.GetFSObject(id)
      S = d.DisplayName
    End Using
  Next i
End Using
See Also