Connect or Disconnect from a Synthesis Repository: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
(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 …')
 
No edit summary
Line 4: Line 4:


'''Basics'''
'''Basics'''
#Connect or Disconnect from a Synthesis Repository
#[[Connect or Disconnect from a Synthesis Repository]]
#[[APISynthesisResourcesTutorial2|Create a New Synthesis Resource]]
#[[Add New Synthesis Resources to a Repository]]
#[[APISynthesisResourcesTutorial3|Update an Existing Resource]]
#[[Edit Existing Synthesis Resources]]
#[[APISynthesisResourcesTutorial4|Calculate Results from a Model]]
#[[Calculate Results from a Model]]
</div>
</div>


Line 151: Line 151:




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

Revision as of 23:44, 9 February 2016

APIWiki.png


<< Back to API Tutorials

Basics

  1. Connect or Disconnect from a Synthesis Repository
  2. Add New Synthesis Resources to a Repository
  3. Edit Existing Synthesis Resources
  4. Calculate Results from a Model

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.





Connect to a Synthesis Repository

The Repository 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 ConnectToRepository method to connect to a standard repository.

1. Create a new module and start with the following basic code.

 'Declare a new instance of the Repository class. 
  Dim MyRepository As New Repository

 'Specify the full path to the Synthesis repository. 
 'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive. 
  MyRepository.ConnectToRepository("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 Project.GetAllProjects method to get an array of all the projects in the repository, and then use the Project.SetCurrentProject method to select the first project in the array.

 'Declare a new instance of the NameIdPair class. 
  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)

3. Use the following code to test the response. In this example, we've used the GetCurrentProject method to return the name and ID of the current project.

 'Display the name and 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)

4. Disconnect from the current repository by using the DisconnectFromRepository method.

 '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()

 'Declare a new instance of the Repository class. 
  Dim MyRepository As New Repository
 
 'Specify the full path to the Synthesis repository. 
 'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive. 
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")

 'Declare a new instance of the NameIdPair class. 
  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 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)

 'Disconnect from the Synthesis repository. 
  MyRepository.DisconnectFromRepository

End Sub
VB.NET
 
Imports SynthesisAPI 

Public Class Form1
   Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

  'Declare a new instance of the Repository class. 
   Dim MyRepository As New Repository
 
  'Specify the full path to the Synthesis repository. 
  'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive. 
   MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")

  'Declare a new instance of the NameIdPair class. 
   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 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)

  'Disconnect from the Synthesis repository. 
   MyRepository.DisconnectFromRepository

   End Sub
End Class

Notes

Any time you wish to switch to another project in the current repository, use the Project.SetCurrentProject method to specify a new active project.

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.

References

To learn more, see the reference documentation for the classes and methods discussed in this tutorial:




Next: Add New Synthesis Resources to a Repository >>