APISynthesisResourcesTutorial: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
(Redirected page to API Tutorials)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:Synthesis Resources Tutorial}}{{Template:API}}
#REDIRECT [[API_Tutorials]]
<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
<nowiki><<</nowiki> [[APIQuickStartGuide|Back to Quick Start Guide]]
 
'''Synthesis Resources Tutorial'''
#Connect to a Synthesis Repository and Project
#[[APISynthesisResourcesTutorial2|Create a New Synthesis Resource]]
#[[APISynthesisResourcesTutorial3|Update an Existing Resource]]
#[[APISynthesisResourcesTutorial4|Calculate Results from a Model]]
</div>
 
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.
 
Note that this tutorial makes use of object IDs to help you test responses from the API. We recommend reading [[Using Item IDs|this short topic]] on object IDs before you begin.
 
 
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. Let's start with the <code>Repository</code> class, which represents a Synthesis repository. This class provides several methods for connecting to either a standard or enterprise repository. In this example, we'll use the basic <code>ConnectToRepository</code> method.
 
Create a new module and start with the following basic code for connecting to a standard Synthesis repository.
 
'''VBA|VB.NET'''
{{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, we'll specify the current (or active) project to use.
 
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 ID number of the first project in the array.
 
'''VBA|VB.NET'''
{{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)
 
Any time you wish to switch to another project in the repository, you can always use the <code>Project.SetCurrentProject</code> 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 <code>DisconnectFromRepository</code> method, and then use the <code>ConnectToRepository</code> method again to connect to the desired repository.
 
'''VBA|VB.NET'''
{{APIComment|'Disconnect from the Synthesis repository.}}
  MyRepository.DisconnectFromRepository
===Test the Code===
Let’s verify that our connections to the repository and project work.
 
Below are the VBA and VB.NET code lists 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'''
 
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'''
 
{{APIPrefix|Imports}} SynthesisAPI
{{APIPrefix|Public Class}} Form1
    {{APIPrefix|Private Sub}} Button1_Click(sender {{APIPrefix|As}} System.Object, e {{APIPrefix|As}} System.EventArgs) {{APIPrefix|Handles}} Button1.Click
  {{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
    {{APIPrefix|End Sub}}
{{APIPrefix|End Class}}
 
===References===
To learn more, see the reference documentation for the classes and methods discussed in this section:
 
*[[Repository Class]]
*[[NameIdPair 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]]
 
 
 
 
 
 
'''<span style="color:#808080;">Next: [[APISynthesisResourcesTutorial2|Create a New Synthesis Resource >>]]</span>'''

Latest revision as of 22:14, 9 February 2016

Redirect to: