Hi All,
I am facing one issue in creating a graph of Open vs Severity using OTA api (C#).
Below is the code what i have tried.
I am calling retrieve bugs method to get the list of bugs.
Controller objController = new Controller();
IList<BugField> bfield = objController.retrieveFields();
IList<Bug> bugList = new IList<Bug>();
bugList = objController.retrieveBugs(bfield);
for (int i = 0; i < bugList.Count; i++)
{
if (bugList[i].Status == "Open")
{
Count_0 = Count_0 + 1;
}
}
The below method i have written in Common utility page.
///*** get a folder in QC ** @param string tsPath * @return TestSetFolder */
public IList<Bug> retrieveBugs(IList<BugField> fieldFilters)
{
BugFactory bugFactory = (BugFactory)tdConn.BugFactory;
TDFilter tdFilter = bugFactory.Filter;
try
{
tdFilter.Text = "";
foreach (BugField filterField in fieldFilters)
{
tdFilter["BG_STATUS"] = "Open";
}
if (fieldFilters.Count == 0)
{
tdFilter["BG_RESPONSIBLE"] = tdConn.UserName;
tdFilter["BG_STATUS"] = "not CLOSED";
}
string filterText = tdFilter.Text;
List BugList = bugFactory.NewList(filterText);
IList<Bug> bugList = new List<Bug>();
foreach (IBug Bug in BugList)
{
Bug bug = new Bug(Bug);
bugList.Add(bug);
}
return bugList;
}
catch (Exception e)
{
log.Warn("couldn't get TestSetFolder with path " + tdFilter.Text);
log.Warn(e.Message);
log.Warn(e.StackTrace);
throw e;
}
}
public IList<BugField> retrieveFields()
{
if (tdConn.Connected)
{
BugFactory bugFactory = (BugFactory)tdConn.BugFactory;
IList<BugField> fields = new List<BugField>();
foreach (TDField field in bugFactory.Fields)
{
fields.Add(new BugField(field));
}
return fields;
}
else
{
throw new Exception("Not connected");
}
}
Added a class file which refer to IBug interface.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TDAPIOLELib;
namespace SYFReportingToolFramework
{
[Serializable]
public class Bug
{
private IBug bug;
private string id;
private string status;
private string summary;
private string assignedTo;
private string detectedBy;
private string priority;
private string project;
private bool isLocked;
private bool modified;
private bool autoPost;
private bool hasAttachment;
private bool hasChange;
private bool isVirtual;
public Bug()
{
}
public Bug(IBug bug)
{
this.bug = bug;
Refresh();
}
public string ID
{
get { return id; }
}
public string Status
{
get { return status; }
set
{
if (bug != null)
{
this.status = value;
bug.Status = value;
}
else
{
throw new Exception("Unable to set a status, no bug selected");
}
}
}
public string Summary
{
get { return summary; }
}
public string AssignedTo
{
get { return assignedTo; }
set
{
if (bug != null)
{
this.assignedTo = value;
bug.AssignedTo = value;
}
else
{
throw new Exception("Unable to set a AssignedTo, no bug selected");
}
}
}
public string DetectedBy
{
get { return detectedBy; }
}
public string Priority
{
get { return priority; }
}
public string Project
{
get { return project; }
}
public bool IsLocked
{
get { return isLocked; }
}
public bool Modified
{
get { return modified; }
}
public bool AutoPost
{
get { return autoPost; }
}
public bool HasAttachment
{
get { return hasAttachment; }
}
public bool HasChange
{
get { return hasChange; }
}
public bool Virtual
{
get { return isVirtual; }
}
public string Severity
{
get { return severity; }
}
IList ChangeLinks
{
get { return bug.ChangeLinks; }
}
public IList<Attachment> Attachments
{
get
{
IList<Attachment> qcQttachment = new List<Attachment>();
AttachmentFactory factory = bug.Attachments as AttachmentFactory;
List attachments = factory.NewList(factory.Filter.Text);
foreach (IAttachment attachment in attachments)
{
qcQttachment.Add(new Attachment(attachment));
}
return qcQttachment;
}
}
public IList<IHistoryRecord> History
{
get
{
return (IList<IHistoryRecord>)bug.History;
}
}
public string this[string fieldName]
{
get { return bug != null ? bug[fieldName].ToString() : null; }
set
{
if (bug != null)
{
bug[fieldName] = value;
}
else
{
throw new Exception("Unable to set " + fieldName + ", no bug selected");
}
}
}
public IList<Bug> FindSimilarBugs(int SimilarityRatio = 10)
{
IList<Bug> bugs = new List<Bug>();
if (bug == null)
{
return bugs;
}
IList list = bug.FindSimilarBugs(SimilarityRatio);
foreach (Bug qcBug in list)
{
bugs.Add(new Bug());
}
return bugs;
}
public bool LockObject()
{
if (bug != null)
{
return bug.LockObject();
}
else
{
throw new Exception("Unable to LockObject, no bug selected");
}
}
public void Mail(string SendTo, string SendCc = "", int Option = 0, string Subject = "", string Comment = "")
{
bug.Mail(SendTo, SendCc, Option, Subject, Comment);
}
public void Post()
{
bug.Post();
}
public void Refresh()
{
if (bug != null)
{
id = bug.ID.ToString();
status = bug.Status;
summary = bug.Summary;
assignedTo = bug.AssignedTo;
detectedBy = bug.DetectedBy;
priority = bug.Priority;
project = bug.Project;
isLocked = bug.IsLocked;
modified = bug.Modified;
autoPost = bug.AutoPost;
hasAttachment = bug.HasAttachment;
hasChange = bug.HasChange;
isVirtual = bug.Virtual;
}
else
{
id = null;
status = null;
summary = null;
assignedTo = null;
detectedBy = null;
priority = null;
project = null;
isLocked = false;
modified = false;
autoPost = false;
hasAttachment = false;
hasChange = false;
isVirtual = false;
}
}
public void QCRefresh()
{
bug.Refresh();
Refresh();
}
public void Undo()
{
bug.Undo();
}
public void UnLockObject()
{
bug.UnLockObject();
}
public override string ToString()
{
return ID + "\t" + AssignedTo + "\t" + Summary + "\t";
}
}
}
But IBug inteface does not have
Severity as a property.
Can anybody let me know how do i get other fields and User fields added in HP QC.
Thanks,
Prashanth