Adding issues
The following example describes how to add an issue.
1. Localize external namespaces.
using System;
using System.Collections.Generic;
using System.Text;
2. Set up the namespace, provide the login information, and define the project name.
namespace AddDefect
{
class AddDefect
{
static void Main (string[] args)
{
long cookie = -1;
ttsoapcgi ttsdk = null;
try
{
string username = "username";
string password = "password";
string ProjectName = "ProjectName";
3. Create an instance of the ttsoapcgi class, which is generated from the ttsoapcgi.wsdl file.
ttsdk = new ttsoapcgi();
4. Set the URL that the ttsdk object connects to if you are not using the default URL from the WSDL file.
ttsdk.Url = "http://localhost:80/scripts/ttsoapcgi.exe";
5. Select the Helix ALM project to connect to and set proj to reference it.
CProject[] projects = ttsdk.getProjectList(username, password);
CProject proj = null;
foreach (CProject p in projects)
{
if (p.database.name.Equals(projectName))
{
proj = p;
break;
}
}
6. Log in to the project.
cookie = ttsdk.ProjectLogon(proj, username, password);
7. Create a CDefect object and enter the issue information.
You must provide data for all required fields to correctly initialize the object.
CDefect def = new CDefect();
def.summary = "Defect 1, With Formatted Text.";
def.enteredby = "LastName, FirstName MiddleInitial";
def.type = "Cosmetic";
def.product = "Test Product";
Note: You can use any valid issue type as the def.type.
8. Create any new objects that include an array or list for populating required fields.
In the following example, the CReportedByRecord object and reported by list are created.
def.reportedbylist = new CReportedByRecord[1];
def.reportedbylist[0] = new CReportedByRecord();
def.reportedbylist[0].foundby = "LastName, FirstName MiddleInitial";
9. If you want to use HTML-formatted text, set the Helix ALM SDK to store it.
SOAP expects plain text for multi-line fields by default. Use the following to enable HTML-formatted text support.
ttsdk.formattedTextSupport(cookie, true);
Add HTML-formatted text to the field. The following example adds list items to the SOAP message using inline HTML. In most cases, HTML is retrieved from files, templates, or a WYSIWYG editor.
Note: The SDK post-processes HTML and may return results that are slightly different than the HTML sent in the SOAP message.
def.reportedbylist[0].comments =
"<p align=\"center\"><span style=\" font-size:24pt; color:#3366ff;\">Welcome To Helix ALM SDK Development</span></p><hr /><p> </p>\r\n"
+ "<p>This is a paragraph of regular text. Here's a link to the <a href=\"https://www.perforce.com/products/helix-alm\"><span style=\" color:#0000ff;\"><u>Helix ALM page</u></span></a>.</p>\r\n"
+ "<p> </p>\r\n"
+ "<p>A Table:</p>\r\n"
+ "<p> </p>\r\n"
+ "<table border=\"1\" width=\"600\" cellspacing=\"0\" cellpadding=\"3\" bgcolor=\"#faebd7\"><tr><td><p>A list:</p>\r\n"
+ "<p> </p>\r\n"
+ "<ol><li>First item</li>\r\n"
+ "<li>Second Item</li>\r\n"
+ "<li>Third item</li>\r\n"
+ "<li>Link to <a href=\"https://www.perforce.com/products/helix-alm\"><span style=\" color:#0000ff;\"><u>Helix ALM Page</u></span></a> on perforce.com</li>\r\n"
+ "</ol></td> <td><p> Welcome to the SDK. The power of the SDK gives you the ability to create applications which can make almost any change to data that a human\r\n"
+ "using the full client can. This means you can create automated processes to update the database, based on input from a variety of sources, such as user submissions\r\n"
+ "in an application, or info in third-party databases.</p></td></tr>\r\n"
+ "</table><p>\r\n"
+ "<br /> </p>";
10. Optionally add attachments, such as screenshots, and create the attachment list array to add the file to the attachment list.
CFileAttachment file = new CFileAttachment();
file.mstrFileName = filename;
System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAcess.Read);
System.IO.BinaryReader reader = new.System.IO.BinaryReader (fs);
file.mpFileData = reader.ReadBytes((int) fs.Length);
reader.Close();
fs.Close();
def.reportedbylist[0].attachmentlist = new CFileAttachment [1];
def.reportedbylist[0].attachmentlist[0] = file;
11. Finish adding the issue and catch exceptions.
ttsdk.addDefect(cookie, def);
Console.WriteLine("Finished adding new defect");
}
catch (Exception e)
{
Console.WriteLine("An exception occurred:");
Console.WriteLine(e.Message);
}
12. End the session and log out of the Helix ALM SDK.
finally
{
if (ttsdk != null && cookie != -1)
{
ttsdk.DatabaseLogoff(cookie);
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services;
namespace AddDefect
{
class AddDefect
{
static void Main(string[] args)
{
long cookie = -1;
ttsoapcgi ttsdk = null;
try
{
string username = "username";
string password = "password";
string projectName = "ProjectName";
ttsdk = new ttsoapcgi();
ttsdk.Url = "http://localhost:80/scripts/ttsoapcgi.exe";
CProject[] projects = ttsdk.getProjectList(username, password);
CProject proj = null;
foreach (CProject p in projects)
{
if (p.database.name.Equals(projectName))
{
proj = p;
break;
}
}
cookie = ttsdk.ProjectLogon(proj, username, password);
CDefect def = new CDefect();
def.summary = "Example Defect 1, With Formatted Text.";
def.enteredby = "LastName, FirstName MiddleInitial";
def.type = "Cosmetic"
def.product = "Test Product";
def.reportedbylist = new CReportedByRecord[1];
def.reportedbylist[0] = new CReportedByRecord();
def.reportedbylist[0].foundby = "Lastname, Firstname I";
ttsdk.formattedTextSupport(cookie, true);
def.reportedbylist[0].comments =
"<p align=\"center\"><span style=\" font-size:24pt; color:#3366ff;\">Welcome To Helix ALM SDK Development</span></p><hr /><p> </p>\r\n"
+ "<p>This is a paragraph of regular text. Here's a link to the <a href=\"https://www.perforce.com/products/helix-alm\"><span style=\" color:#0000ff;\"><u>Helix ALM page</u></span></a>.</p>\r\n"
+ "<p> </p>\r\n"
+ "<p>A Table:</p>\r\n"
+ "<p> </p>\r\n"
+ "<table border=\"1\" width=\"600\" cellspacing=\"0\" cellpadding=\"3\" bgcolor=\"#faebd7\"><tr><td><p>A list:</p>\r\n"
+ "<p> </p>\r\n"
+ "<ol><li>First item</li>\r\n"
+ "<li>Second Item</li>\r\n"
+ "<li>Third item</li>\r\n"
+ "<li>Link to <a href=\"https://www.perforce.com/products/helix-alm\"><span style=\" color:#0000ff;\"><u>Helix ALM Page</u></span></a> on perforce.com</li>\r\n"
+ "</ol></td> <td><p> Welcome to the SDK. The power of the SDK gives you the ability to create applications which can make almost any change to data that a human\r\n"
+ "using the full client can. This means you can create automated processes to update the database, based on input from a variety of sources, such as user submissions\r\n"
+ "in an application, or info in third-party databases.</p></td></tr>\r\n"
+ "</table><p>\r\n"
+ "<br /> </p>";
string filename = "Example1.png";
CFileAttachment file = new CFileAttachment();
file.mstrFileName = filename;
System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader reader = new System.IO.BinaryReader(fs);
file.mpFileData = reader.ReadBytes((int)fs.Length); //will not work for huge files with Length > int.MaxValue;
reader.Close();
fs.Close();
def.reportedbylist[0].attachmentlist = new CFileAttachment[1];
def.reportedbylist[0].attachmentlist[0] = file;
ttsdk.addDefect(cookie, def);
Console.WriteLine("Finished adding new defect");
}
catch (Exception e)
{
Console.WriteLine("An exception occurred:");
Console.WriteLine(e.Message);
}
finally
{
if (ttsdk != null && cookie != -1)
{
ttsdk.DatabaseLogoff(cookie);
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}
}