Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can I list all Requirements Types and their Requirements for a selected Project Baseline with C# .NET

How can I list all Requirements Types and their Requirements for a selected Project Baseline with C# .NET

Problem:

How can I list all Requirements Types and their Requirements for a selected Project Baseline with C# .NET

Resolution:


  • Product Name: CaliberRM
  • Product Version: 8.1.534.000 ? CaliberRM R2 SP1
  • Product Component: CaliberRM SDK

First you will need to set up a new project and add a reference to the CaliberRM .NET dll as described in the following article:

How can I access CaliberRM using the SDK with C# .NET in Microsoft Visual Studio .NET 2003?

The following code will list all Requirement Types & Requirements for a Selected Project Baseline:

using System;
using System.Windows.Forms;
using Starbase.CaliberRM.Interop;
namespace SDKCode_VS2005
{

public partial class Form1 : Form
{
//Set up objects
CaliberServerFactory myFactory = new CaliberServerFactory();
CaliberServer myServer;
Project myProject;
Session mySession;
Boolean loggedIn;
Baseline myBaseline;
RequirementTree tree;
RequirementTreeNode treeNode, treeNode2;

public void doLogin(String host, String username, String password)
{
try
{
//get server info
myServer = myFactory.Create(host);
//get username and password and attempt to login
mySession = myServer.login(username,password);
loggedIn = true;
txtHost.Enabled = false;
txtPassword.Enabled = false;
txtUsername.Enabled = false;
cmdLogin.Text = "Logged In";
cmdLogin.Enabled = false;

}
catch
{
loggedIn = false;
}

}

public Form1()
{
InitializeComponent();
}

private void cmdLogin_Click(object sender, EventArgs e)
{
doLogin(txtHost.Text, txtUsername.Text, txtPassword.Text);

if (loggedIn == true)
{
System.Console.WriteLine("Logged in");
//when logged in show form items
lblProjects.Visible = true;
lblBaselines.Visible = true;
cmbProjects.Visible = true;
cmbBaselines.Visible = true;
lstRequirements.Visible = true;
cmdListReq.Visible = true;
cmdClear.Visible = true;
int no_projects;
//count number of Projects
no_projects = mySession.Projects.Count;
//populate project combobox
for (int i = 0; i
{
myProject = (Project)mySession.Projects;
System.Console.WriteLine("Project: " + myProject.Name);
cmbProjects.Items.Add(myProject.Name);
}
}
else
{
MessageBox.Show("Incorrect Username or password","Login Failed");
}
}

private void cmbProjects_SelectedIndexChanged(object sender, EventArgs e)
{
cmbBaselines.Items.Clear();
cmbBaselines.Text = (" ");
//get selected project
myProject = (Project)mySession.Projects[cmbProjects.SelectedIndex];
System.Console.WriteLine("Project Selected: " + myProject.Name);

int no_baselines;
//count number of baselines
no_baselines = myProject.Baselines.Count;
//populate baseline combobox for (int i = 0; i
{
myBaseline = (Baseline)myProject.Baselines;
cmbBaselines.Items.Add(myBaseline.Name);
if (myBaseline.Name == "Deleted View")
{
cmbBaselines.Items.Remove("Deleted View");
}
}
}

private void cmdListReq_Click(object sender, EventArgs e)
{

//clear listbox
lstRequirements.Items.Clear();
//get selected baseline
myBaseline = (Baseline)myProject.Baselines[cmbBaselines.SelectedIndex];
tree = (RequirementTree)myBaseline.RequirementTree;
treeNode = (RequirementTreeNode)tree.Root;
TraverseTree(treeNode);

}

public void TraverseTree(RequirementTreeNode treeNode)
{
int no_children;
no_children = treeNode.Children.Count;
for (int i = 0; i
{
treeNode2 = (RequirementTreeNode)treeNode.Children;

//Format Output
String formatting = "";
for (int j = 1; j
{
formatting = formatting + " ";
}
if (treeNode2.Level == 1 && i > 0)
{
System.Console.WriteLine(" ");
lstRequirements.Items.Add(" ");
}

System.Console.WriteLine(formatting + treeNode2.HierarchyNumber + " " + treeNode2.Name);
lstRequirements.Items.Add(formatting + treeNode2.HierarchyNumber + " " + treeNode2.Name);

//recursion
TraverseTree((RequirementTreeNode)treeNode2);
}
}

private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
if (loggedIn != true)
{
Application.Exit();
}
else
{
mySession.logout();
Application.Exit();
}
}
private void cmdClear_Click(object sender, EventArgs e)
{
//clear listbox
lstRequirements.Items.Clear();
}
}
}

Please see Sample Project Attached


Related documents:


Old KB# 15815

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 18:26
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.