Connect or Disconnect from a Synthesis Repository: Difference between revisions
Kate Racaza (talk | contribs) (Created page with '{{Template:API}} <div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;"> <nowiki><<</nowiki> [[API …') |
Kate Racaza (talk | contribs) No edit summary |
||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Template:API}} | {{Template:API}} | ||
{{Template:BacktoPrevPage}} | |||
==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 [[Connect_or_Disconnect_from_a_Synthesis_Repository/VBA|here]]. | |||
'''VB.NET''' | |||
{{APIPrefix|Imports}} SynthesisAPI | |||
{{APIPrefix|Module}} Module1 | |||
{{APIPrefix|Sub}} Main() | |||
{{APIComment|'Declare a new Repository object.}} | |||
{{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | |||
{{APIComment|'Specify the full path to the standard repository. Assume that}} | |||
{{APIComment|'a standard repository called "RSRepository1.rsr11" exists in the C drive.}} | |||
MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr11"}}) | |||
{{APIComment|'Declare a new NameIdPair object.}} | |||
{{APIPrefix|Dim}} ListofProjects() {{APIPrefix|As}} NameIdPair | |||
{{APIComment|'Get a list of all projects in the repository.}} | |||
ListOfProjects = MyRepository.Project.GetAllProjects | |||
{{APIComment|'Set the first available project as the current project.}} | |||
MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) | |||
{{APIComment|'Display the name and object ID of the current project.}} | |||
{{APIPrefix|Dim}} ProjectName {{APIPrefix|As}} String | |||
{{APIPrefix|Dim}} ProjectID {{APIPrefix|As}} Integer | |||
ProjectName = MyRepository.Project.GetCurrentProject.Name | |||
ProjectID = MyRepository.Project.GetCurrentProject.ID | |||
MsgBox ({{APIString|"You are currently connected to: "}} & ProjectName & {{APIString|", ID#"}} & ProjectID) | |||
{{APIComment|'Disconnect from the Synthesis repository.}} | |||
MyRepository.DisconnectFromRepository | |||
{{APIPrefix|End Sub}} | |||
{{APIPrefix|End Module}} | |||
===Discussion=== | |||
The [[Repository Class|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 [[Repository.ConnectToRepository|ConnectToRepository]] method to connect to a standard repository. | |||
{{APIComment|'Declare a new Repository object.}} | |||
{{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | |||
{{APIComment|'Specify the full path to the Synthesis repository. Assume that}} | |||
{{APIComment|'a standard repository called "RSRepository1.rsr11" exists in the C drive.}} | |||
MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr11"}}) | |||
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 [[Repository.Project.GetAllProjects|Project.GetAllProjects]] method to get an array of all the projects in the repository. The method returns an array of [[NameIdPair_Class|NameIDPair]] objects that represent the name and ID pair of each project. | |||
The [[Repository.Project.SetCurrentProject|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. | |||
{{APIComment|'Declare a new | {{APIComment|'Declare a new NameIdPair object.}} | ||
{{APIPrefix|Dim}} ListofProjects() {{APIPrefix|As}} NameIdPair | {{APIPrefix|Dim}} ListofProjects() {{APIPrefix|As}} NameIdPair | ||
Line 42: | Line 72: | ||
MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) | MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) | ||
To show the name and ID of the current project in an output, use the [[Repository.Project.GetCurrentProject|Project.GetCurrentProject]] method. The following example displays the current project's name and ID in a message box. | |||
{{APIComment|'Display the name and ID number of the current project.}} | {{APIComment|'Display the name and object ID number of the current project.}} | ||
{{APIPrefix|Dim}} ProjectName {{APIPrefix|As}} String | {{APIPrefix|Dim}} ProjectName {{APIPrefix|As}} String | ||
{{APIPrefix|Dim}} ProjectID {{APIPrefix|As}} Integer | {{APIPrefix|Dim}} ProjectID {{APIPrefix|As}} Integer | ||
Line 52: | Line 82: | ||
MsgBox ({{APIString|"You are currently connected to: "}} & ProjectName & {{APIString|", ID#"}} & ProjectID) | MsgBox ({{APIString|"You are currently connected to: "}} & ProjectName & {{APIString|", ID#"}} & ProjectID) | ||
Finally, the following code disconnects the session from the current repository. | |||
{{APIComment|'Disconnect from the Synthesis repository.}} | {{APIComment|'Disconnect from the Synthesis repository.}} | ||
MyRepository.DisconnectFromRepository | MyRepository.DisconnectFromRepository | ||
==Notes== | |||
To connect to an SQL repository, use the [[Repository.ConnectToSQLRepository|ConnectToSQLRepository]] method. | |||
To connect to an Oracle repository, use the [[Repository.ConnectToOracleRepository|ConnectToOracleRepository]] method. | |||
Note that in a secure database, you must at least have "read" permissions in the repository in order to connect successfully. | |||
===References=== | ===References=== | ||
*[[Repository Class]] | *[[Repository Class]] | ||
**[[Repository.ConnectToRepository|Repository.ConnectToRepository Method]] | |||
**[[Repository.DisconnectFromRepository|Repository.DisconnectFromRepository Method]] | |||
**[[Repository.Project.GetAllProjects|Repository.Project.GetAllProjects Method]] | |||
**[[Repository.Project.SetCurrentProject|Repository.Project.SetCurrentProject Method]] | |||
**[[Repository.Project.GetCurrentProject|Repository.Project.GetCurrentProject Method]] | |||
*[[NameIdPair Class]] | *[[NameIdPair Class]] | ||
'''<span style="color:#808080;">Next: [[ | '''<span style="color:#808080;">Next Tutorial: [[Add New Synthesis Resources to a Repository|Add New Synthesis Resources to a Repository >>]]</span>''' |
Latest revision as of 18:00, 3 April 2017
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.rsr11" exists in the C drive. MyRepository.ConnectToRepository("C:\RSRepository1.rsr11") '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.
'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.rsr11" exists in the C drive. MyRepository.ConnectToRepository("C:\RSRepository1.rsr11")
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.
'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)
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.
'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
Notes
To connect to an SQL repository, use the ConnectToSQLRepository method.
To connect to an Oracle repository, use the ConnectToOracleRepository method.
Note that in a secure database, you must at least have "read" permissions in the repository in order to connect successfully.
References
Next Tutorial: Add New Synthesis Resources to a Repository >>