APISynthesisResourcesTutorial

From ReliaWiki
Revision as of 16:18, 22 October 2015 by Kate Racaza (talk | contribs)
Jump to navigation Jump to search

Template:InProgress

APIWiki.png


<< Back to Quick Start Guide

Synthesis Resources Tutorial

  1. Connect to a Synthesis Repository and Project
  2. Create a New Synthesis Resource
  3. Update an Existing Resource
  4. Calculate Results from a Model

This four-part tutorial introduces you to the basic functionalities of the Synthesis API. You will learn how to use the API to connect to a Synthesis repository, create a new resource, update an existing resource and obtain calculated results from a model.


The Synthesis Platform uses repositories to store projects and analysis data. Projects, in turn, hold resources that contain various types of information that can be shared between analyses. Therefore, to create or update a resource in a Synthesis repository, we must begin by first connecting to the repository and then accessing the project that holds that resource.


Part 1: Connect to a Synthesis Repository and Project

1. We'll start with the Repository class, which provides several methods for connecting to standard or enterprise repositories. In this example, we will use the basic ConnectToRepository method to create a simple application.

Create a new module and start with the following basic code for connecting to a standard Synthesis repository.

VBA|VB.NET

 '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, use the Project.SetCurrentProject method to specify the current (or active) project by using the project's ID number. In this example, we'll first use the Project.GetAllProjects method to get an array of all projects in the repository, and then use the ID number of the first project in the array to set it as the current project.

VBA|VB.NET

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

Any time you wish to switch to another project in the repository, you can always 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 by using the DisconnectFromRepository method, and then use the ConnectToRepository method again to connect to the desired repository.

VBA|VB.NET

 'Disconnect from the Synthesis repository. 
  MyRepository.DisconnectFromRepository

Test the Code

Let’s verify that our connections to the repository and project work.

Below is the code list for this example. On the Debug menu, click Start to run the application. A message box displays the name and ID number of the current project in the repository.

VBA|VB.NET
 
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

References

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



Next: Create a New Synthesis Resource >>