Using client objects |
The client-side classes of the .NET SDK are used to simplify some programming tasks. The classes ensure that interface extensions, VBScript events, and property pages are invoked when external code is executed. For that purpose, most client classes provide overloaded constructors with a BCServiceProvider object as a parameter. The BCServiceProvider class is analogous to the AMServiceProvider COM class. It represents a context to encapsulate additional information about the calling environment.
For a stand-alone application, a context must be created and initialized manually by the developer. This is demonstrated by the following example code for a BCFolderUI client-side class.
Private Sub DoIt(ByVal repository As BCRepository) ' Create context for client object. Using sp As BCServiceProvider = New BCServiceProvider(repository) Using folderUI As BCFolderUI = New BCFolderUI(repository.Root, sp) Dim doc As BCDocument = folderUI.NewDocument(Me, "NewDocument") MessageBox.Show("New document path: " + doc.Path) End Using End Using repository.Commit() End Sub
For an interface extension, a context is provided by the host application. You can access the context via the ExtensionHost.Services property (it replaces the Visual Basic 6 IAMUIExtensionDesigner.GetHostService method).
The following example demonstrates how to use a BCDocumentUI client-side class in an interface extension.
Private Sub UIExtensionComposer_BeforeDelete(ByVal sender As Object, _ ByVal e As CancelCurrentObjectEventArgs) Handles MyBase.BeforeDelete Using docUI As BCDocumentUI = New BCDocumentUI(e.CurrentObject, ExtensionHost.Services) MessageBox.Show("Location: " + docUI.Location) End Using End Sub