Connect or Disconnect from a Synthesis Repository

Tutorial: Connect and Disconnect from a Synthesis Repository
The following example demonstrates how to connect to a standard Synthesis repository, access one of its projects, and then disconnect from the repository. A discussion of the example follows.

A VBA version of the code sample is available here.

VB.NET SynthesisAPI Module1 Main MyRepository Repository MyRepository.ConnectToRepository ListofProjects NameIdPair ListOfProjects = MyRepository.Project.GetAllProjects MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) ProjectName String ProjectID Integer ProjectName = MyRepository.Project.GetCurrentProject.Name ProjectID = MyRepository.Project.GetCurrentProject.ID   MsgBox ( & ProjectName &  & ProjectID) MyRepository.DisconnectFromRepository

Discussion
The Repository class represents a Synthesis repository. It provides several methods for connecting to either a standard or enterprise repository. In this example, we used the basic ConnectToRepository method to connect to a standard repository.

MyRepository Repository MyRepository.ConnectToRepository

Once you are connected to a repository, you can specify which of its projects is the current (or active) project. Specifying the current project is required only if you plan to read/write data stored in projects (e.g., updating the properties of a URD resource, calculating metrics from a model resource, etc.).

Use the Project.GetAllProjects method to get an array of all the projects in the repository. The method returns an array of NameIDPair objects that represent the name and ID pair of each project.

The Project.SetCurrentProject method is then used to select the desired project. In this case, we've chosen the first project in the array. Any time you wish to switch to another project in the current repository, use this method again to specify the new active project. ListofProjects NameIdPair ListOfProjects = MyRepository.Project.GetAllProjects MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) To show the name and ID of the current project in an output, use the Project.GetCurrentProject method. The following example displays the current project's name and ID in a message box. ProjectName String ProjectID Integer ProjectName = MyRepository.Project.GetCurrentProject.Name ProjectID = MyRepository.Project.GetCurrentProject.ID  MsgBox ( & ProjectName &  & ProjectID)

Finally, the following code disconnects the session from the current repository.

MyRepository.DisconnectFromRepository