Connect or Disconnect from a Synthesis Repository: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 2: Line 2:


==Tutorial: Connect and 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 step-by-step walkthrough of the example follows.
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 [[Connect_or_Disconnect_from_a_Synthesis_Repository/VBA|here]].  
A VBA version of the code sample is available [[Connect_or_Disconnect_from_a_Synthesis_Repository/VBA|here]].  
Line 42: Line 42:
     {{APIPrefix|End Sub}}
     {{APIPrefix|End Sub}}
  {{APIPrefix|End Module}}
  {{APIPrefix|End Module}}


===Discussion===  
===Discussion===  
Line 84: Line 85:
  {{APIComment|'Disconnect from the Synthesis repository.}}
  {{APIComment|'Disconnect from the Synthesis repository.}}
   MyRepository.DisconnectFromRepository
   MyRepository.DisconnectFromRepository


===References===
===References===
Line 93: Line 95:
*[[Repository.Project.SetCurrentProject|Repository.Project.SetCurrentProject Method]]
*[[Repository.Project.SetCurrentProject|Repository.Project.SetCurrentProject Method]]
*[[Repository.Project.GetCurrentProject|Repository.Project.GetCurrentProject Method]]
*[[Repository.Project.GetCurrentProject|Repository.Project.GetCurrentProject Method]]





Revision as of 18:42, 27 April 2016

APIWiki.png



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
 
Imports SynthesisAPI 

Module Module1
   Sub Main()

  'Declare a new Repository object. 
   Dim MyRepository As New Repository
 
  'Specify the full path to the standard repository. Assume that 
  'a standard repository called "RSRepository1.rsr10" exists in the C drive. 
   MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")

  'Declare a new NameIdPair object. 
   Dim ListofProjects() As NameIdPair

  'Get a list of all projects in the repository. 
   ListOfProjects = MyRepository.Project.GetAllProjects

  'Set the first available project as the current project. 
   MyRepository.Project.SetCurrentProject(ListofProjects(0).ID)

  'Display the name and object ID of the current project. 
   Dim ProjectName As String
   Dim ProjectID As Integer 

   ProjectName = MyRepository.Project.GetCurrentProject.Name
   ProjectID = MyRepository.Project.GetCurrentProject.ID
   MsgBox ("You are currently connected to: " & ProjectName & ", ID#" & ProjectID)

  'Disconnect from the Synthesis repository. 
   MyRepository.DisconnectFromRepository

   End Sub
End Module


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. (To connect to an SQL repository, use the ConnectToSQLRepository method. To connect to an Oracle repository, use the ConnectToOracleRepository method.)

Note that to connect successfully, you must at least have "read" permissions in the repository.

 'Declare a new Repository object. 
  Dim MyRepository As New Repository

 'Specify the full path to the Synthesis repository. Assume that 
 'a standard repository called "RSRepository1.rsr10" exists in the C drive. 
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")

Once you are connected to a repository, you must specify which of its projects is the current (or active) project. Here, we used the Project.GetAllProjects method to return an array of all the projects in the repository. The method returns a NameIDPair object that represents 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 the Project.SetCurrentProject method again to specify the new active project.

 'Declare a new NameIdPair object. 
  Dim ListofProjects() As NameIdPair

 'Get a list of all projects in the repository. 
  ListOfProjects = MyRepository.Project.GetAllProjects

 'Set the first available project as the current project. 
  MyRepository.Project.SetCurrentProject(ListofProjects(0).ID)

In the following section, we've used the Project.GetCurrentProject method to return the name and ID pair of the current project.

 'Display the name and object ID number of the current project. 
  Dim ProjectName As String
  Dim ProjectID As Integer
 
  ProjectName = MyRepository.Project.GetCurrentProject.Name
  ProjectID = MyRepository.Project.GetCurrentProject.ID
  MsgBox ("You are currently connected to: " & ProjectName & ", ID#" & ProjectID)

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

 'Disconnect from the Synthesis repository. 
  MyRepository.DisconnectFromRepository


References



Next Tutorial: Add New Synthesis Resources to a Repository >>