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 1: Line 1:
{{Template:API}}
{{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 Tutorials|Back to API Tutorials]]


'''Basics'''
==Tutorial: Connect and Disconnect from a Synthesis Repository==
#[[Connect or 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.
#[[Add New Synthesis Resources to a Repository]]
#[[Edit Existing Synthesis Resources]]
#[[Calculate Results from a Model]]
</div>


The Synthesis repositories store projects and analysis data. Before you can read or write data to a repository, you must first connect to it. In this tutorial, you will learn how to connect to a Synthesis repository and access one of its projects, and then disconnect from the repository when a task is done.
A VBA version of the code sample is available [[Connect_or_Disconnect_from_a_Synthesis_Repository/VBA|here]].  
 
 
 
 
 
 
 
 
==Connect to a Synthesis Repository==
The <code>Repository</code> class represents a Synthesis repository. It provides several methods for connecting to either a standard or enterprise repository. In this tutorial, we'll use the basic <code>ConnectToRepository</code> method to connect to a standard repository.
 
1. Create a new module and start with the following basic code.
{{APIComment|'Declare a new instance of the Repository class.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
{{APIComment|'Specify the full path to the Synthesis repository.}}
{{APIComment|'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.}}
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
 
2. Next, specify the current (or active) project to use. For this example, we'll access the first project in the repository. Use the <code>Project.GetAllProjects</code> method to get an array of all the projects in the repository, and then use the <code>Project.SetCurrentProject</code> method to select the first project in the array.
{{APIComment|'Declare a new instance of the NameIdPair class.}}
  {{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)
3. Use the following code to test the response. In this example, we've used the <code>GetCurrentProject</code> method to return the name and ID of the current project.
{{APIComment|'Display the name and ID number 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)
 
4. Disconnect from the current repository by using the <code>DisconnectFromRepository</code> method.
 
{{APIComment|'Disconnect from the Synthesis repository.}}
  MyRepository.DisconnectFromRepository
 
===Test the Code===
Below are the complete code lists for this example. To test them, run the application by clicking '''Start''' on the Debug menu. A message box will display the name and ID number of the active project in the repository.
 
'''VBA'''
 
Sub Main()
{{APIComment|'Declare a new instance of the Repository class.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
 
{{APIComment|'Specify the full path to the Synthesis repository.}}
{{APIComment|'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.}}
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
{{APIComment|'Declare a new instance of the NameIdPair class.}}
  {{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 ID number 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
End Sub


  '''VB.NET'''
  '''VB.NET'''
Line 97: Line 10:
  {{APIPrefix|Imports}} SynthesisAPI  
  {{APIPrefix|Imports}} SynthesisAPI  
   
   
  {{APIPrefix|Public Class}} Form1
  {{APIPrefix|Module}} Module1
     {{APIPrefix|Private Sub}} Button1_Click(sender {{APIPrefix|As}} System.Object, e {{APIPrefix|As}} System.EventArgs) {{APIPrefix|Handles}} Button1.Click
     {{APIPrefix|Sub}} Main()
   
   
   {{APIComment|'Declare a new instance of the Repository class.}}
   {{APIComment|'Declare a new Repository object.}}
     {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
     {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
    
    
   {{APIComment|'Specify the full path to the Synthesis repository.}}
   {{APIComment|'Specify the full path to the standard repository. Assume that}}
   {{APIComment|'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.}}
   {{APIComment|'a standard repository called "RSRepository1.rsr10" exists in the C drive.}}
     MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
     MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
   
   
   {{APIComment|'Declare a new instance of the NameIdPair class.}}
   {{APIComment|'Declare a new NameIdPair object.}}
     {{APIPrefix|Dim}} ListofProjects() {{APIPrefix|As}} NameIdPair
     {{APIPrefix|Dim}} ListofProjects() {{APIPrefix|As}} NameIdPair
   
   
Line 116: Line 29:
     MyRepository.Project.SetCurrentProject(ListofProjects(0).ID)
     MyRepository.Project.SetCurrentProject(ListofProjects(0).ID)
   
   
   {{APIComment|'Display the name and ID number of the current project.}}
   {{APIComment|'Display the name and object ID 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 128: Line 41:
   
   
     {{APIPrefix|End Sub}}
     {{APIPrefix|End Sub}}
  {{APIPrefix|End Class}}
  {{APIPrefix|End Module}}


===Notes===
===Discussion===  
Any time you wish to switch to another project in the current repository, use the <code>Project.SetCurrentProject</code> method to specify a new active project.
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. (To connect to an SQL repository, use the [[Repository.ConnectToSQLRepository|ConnectToSQLRepository]] method. To connect to an Oracle repository, use the [[Repository.ConnectToOracleRepository|ConnectToOracleRepository]] method.)


However, if you wish to access projects from another repository, you’ll first need to disconnect from the current repository, and then connect to the desired repository.  
Note that to connect successfully, you must at least have "read" permissions in the 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.rsr10" exists in the C drive.}}
  MyRepository.ConnectToRepository({{APIString|"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 [[Repository.Project.GetAllProjects|Project.GetAllProjects]] method to return an array of all the projects in the repository. The method returns a [[NameIdPair_Class|NameIDPair]] object that represents 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 the <code>Project.SetCurrentProject</code> method again to specify the new active project.
{{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)
In the following section, we've used the [[Repository.Project.GetCurrentProject|Project.GetCurrentProject]] method to return the name and ID pair of the current project.
{{APIComment|'Display the name and object ID number 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)
 
Finally, the following code disconnects the session from the current repository.
 
{{APIComment|'Disconnect from the Synthesis repository.}}
  MyRepository.DisconnectFromRepository


===References===
===References===
To learn more, see the reference documentation for the classes and methods discussed in this tutorial:
*[[Repository Class]]
*[[Repository Class]]
*[[NameIdPair Class]]
*[[NameIdPair Class]]
Line 151: Line 99:




'''<span style="color:#808080;">Next: [[Add New Synthesis Resources to a Repository|Add New Synthesis Resources to a Repository >>]]</span>'''
'''<span style="color:#808080;">Next Tutorial: [[Add New Synthesis Resources to a Repository|Add New Synthesis Resources to a Repository >>]]</span>'''

Revision as of 23:47, 26 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 step-by-step walkthrough 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 >>