本文整理汇总了C#中Query.RunLinkQuery方法的典型用法代码示例。如果您正苦于以下问题:C# Query.RunLinkQuery方法的具体用法?C# Query.RunLinkQuery怎么用?C# Query.RunLinkQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Query
的用法示例。
在下文中一共展示了Query.RunLinkQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryIdsFromLinks
public Dictionary<int, List<int>> QueryIdsFromLinks(
string wiqlString,
Dictionary<string, object> paramValues,
Dictionary<string, List<object>> complexParamValues,
Action<int> progressReportHandler)
{
if (complexParamValues != null && complexParamValues.Count > 0)
wiqlString = UpdateParams(wiqlString, paramValues, complexParamValues);
var query = new Query(m_workItemStore, wiqlString, paramValues);
var queryResult = query.RunLinkQuery();
var result = new Dictionary<int, List<int>>();
for (int i = 0; i < queryResult.Length; i++)
{
var link = queryResult[i];
if (link.SourceId == 0)
result.Add(link.TargetId, new List<int>());
else
result[link.SourceId].Add(link.TargetId);
if (progressReportHandler != null)
progressReportHandler(i * 100 / queryResult.Length);
}
return result;
}
示例2: GetLinks
public WorkItemLinkInfo[] GetLinks()
{
var store = GetWorkItemStore();
var query = new Query(store, _wiql, _defaultParameters);
return query.RunLinkQuery();
}
示例3: GetChildWorkItems
private static List<WorkItem> GetChildWorkItems(WorkItemStore store, WorkItem workitem, string queryText)
{
//Ref. http://blogs.msdn.com/b/jsocha/archive/2012/02/22/retrieving-tfs-results-from-a-tree-query.aspx and
//http://blogs.msdn.com/b/team_foundation/archive/2010/07/02/wiql-syntax-for-link-query.aspx
//https://msdn.microsoft.com/en-us/library/bb130306%28v=vs.120%29.aspx
List<WorkItem> details = null;
try
{
int id = workitem.Id;
var treeQuery = new Query(store, queryText);
WorkItemLinkInfo[] links = treeQuery.RunLinkQuery();
List<int> except = new List<int>();
except.Add(id);
//
// Build the list of work items for which we want to retrieve more information
//
int[] ids = (from WorkItemLinkInfo info in links
select info.TargetId).Except(except.AsEnumerable()).ToArray();
if (ids.Length > 0)
{
//
// Next we want to create a new query that will retrieve all the column values from the original query, for
// each of the work item IDs returned by the original query.
//
var detailsWiql = new StringBuilder();
detailsWiql.AppendLine("SELECT");
bool first = true;
foreach (FieldDefinition field in treeQuery.DisplayFieldList)
{
detailsWiql.Append(" ");
if (!first)
detailsWiql.Append(",");
detailsWiql.AppendLine("[" + field.ReferenceName + "]");
first = false;
}
detailsWiql.AppendLine("FROM WorkItems");
//
// Get the work item details
//
var flatQuery = new Query(store, detailsWiql.ToString(), ids);
details = flatQuery.RunQuery().OfType<WorkItem>().ToList();
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return details;
}
示例4: Process
public void Process()
{
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(TpcUrl));
var store = tpc.GetService<WorkItemStore>();
var testSvc = tpc.GetService<ITestManagementService>();
Matrix = new RequirementMatrix();
var wiql = string.Format(
@"SELECT [System.Id]
FROM WorkItemLinks
WHERE
Source.[System.TeamProject] = @project AND {0}
Source.[System.WorkItemType] IN GROUP 'Microsoft.RequirementCategory' AND
Target.[System.WorkItemType] IN GROUP 'Microsoft.TestCaseCategory'
MODE(MAYCONTAIN)", GetIDClause(store));
var hQyery = new Query(store, wiql, new Dictionary<string, object>() { { "project", ProjectName } });
var links = hQyery.RunLinkQuery();
// add items with children
Matrix.Requirements = (from link in links
where link.SourceId > 0
group link by link.SourceId into reqs
select new Requirement
{
Id = reqs.Key,
TestIds = reqs.Select(t => t.TargetId).ToList()
}).ToList();
// add items without children
var childLess = from link in links
where link.SourceId == 0 && !Matrix.Requirements.Any(t => t.Id == link.TargetId)
select new Requirement
{
Id = link.TargetId
};
Matrix.Requirements.AddRange(childLess);
var testIds = new List<int>();
Matrix.Requirements.ForEach(t => testIds = testIds.Union(t.TestIds).ToList());
Matrix.Tests = testIds.ConvertAll(i => new WorkItemInfo() { Id = i });
var plans = testSvc.GetTeamProject(ProjectName).TestPlans.Query("SELECT * FROM TestPlan");
foreach (var testId in testIds)
{
var mostRecent = GetLatestTestResult(testId, plans);
Matrix.Tests.First(t => t.Id == testId).MatrixState = mostRecent;
}
Matrix.Requirements.ForEach(r => GetItemInfo(r, store));
Matrix.Tests.ForEach(t => GetItemInfo(t, store, false));
}
示例5: QueryWorkItems
public List<WorkItem> QueryWorkItems(string queryPath, Action<int> progressReportHandler)
{
List<string> paths = queryPath.Split(Path.DirectorySeparatorChar).ToList();
if (paths.Count == 1)
paths = queryPath.Split(Path.AltDirectorySeparatorChar).ToList();
Project project = m_workItemStore.Projects[paths[0]];
paths.RemoveAt(0);
QueryItem item = project.QueryHierarchy;
foreach (string path in paths)
{
var queryFolder = item as QueryFolder;
item = queryFolder[path];
}
if (item == null)
throw new InvalidOperationException("Invalid Query Path.");
string queryText = m_workItemStore.GetQueryDefinition(item.Id).QueryText.Replace("@project", "'" + project.Name + "'");
var query = new Query(m_workItemStore, queryText);
if (query.IsLinkQuery)
{
var queryResults = query.RunLinkQuery();
var workItemIds = new List<int>();
foreach (var queryResult in queryResults)
{
workItemIds.Add(queryResult.SourceId);
workItemIds.Add(queryResult.TargetId);
}
using (var wiqlAccessor = new TfsWiqlAccessor(m_tfsAccessor))
{
return wiqlAccessor.QueryWorkItemsByIds(workItemIds, progressReportHandler);
}
}
var qResult = query.RunQuery();
var result = new List<WorkItem>(qResult.Count);
for (int i = 0; i < qResult.Count; i++)
{
result.Add(qResult[i]);
}
return result;
}
示例6: RunQuery
public IEnumerable<WorkItem> RunQuery(QueryDefinition queryDefinition)
{
QueryDefinition parsedQueryDefinition = macroParser.Replace(queryDefinition);
var query = new Query(currentContext.CurrentWorkItemStore, parsedQueryDefinition.QueryText);
if (query.IsLinkQuery)
{
var queryResults = query.RunLinkQuery();
return from l in queryResults.OfType<WorkItemLinkInfo>()
select currentContext.CurrentWorkItemStore.GetWorkItem(l.TargetId);
}
else
{
var queryResults = query.RunQuery();
return queryResults.OfType<WorkItem>();
}
}
示例7: GetWorkItemsFromLinkQuery
private static WorkItemCollection GetWorkItemsFromLinkQuery(WorkItemStore store, Query workItemQuery,
IEnumerable<FieldDefinition> fieldDefinitions)
{
var workItemInfo = workItemQuery.RunLinkQuery();
var allWorkItemIds = workItemInfo.Select(wi => wi.TargetId).Distinct().ToArray();
if (fieldDefinitions == null)
{
return store.Query(allWorkItemIds, "SELECT * FROM WorkItems");
}
else
{
IEnumerable<string> numericFieldDefinitionNames =
fieldDefinitions.Select(fd => "[" + fd.ReferenceName + "]");
string select = "SELECT " + string.Join(", ", numericFieldDefinitionNames) + " FROM WorkItems";
var actualWorkItemQuery = new Query(store, select, allWorkItemIds);
return actualWorkItemQuery.RunQuery();
}
}
示例8: BwDoWork
private void BwDoWork(object sender, DoWorkEventArgs e)
{
// Logger.Write("Entering BwDoWork method");
var newWorkItems = new ObservableCollection<WorkItem>();
if (!string.IsNullOrEmpty((string) e.Argument))
{
var queryString = string.Format("SELECT * FROM WorkItems WHERE [System.IterationPath] = '{0}'", e.Argument);
var q = new Query(workItemStoreService, queryString);
if (q.IsLinkQuery)
{
var queryResults = q.RunLinkQuery();
foreach (WorkItemLinkInfo i in queryResults)
{
var wi = workItemStoreService.GetWorkItem(i.TargetId);
newWorkItems.Add(wi);
}
}
else
{
var queryResults = q.RunQuery();
foreach (WorkItem workitem in queryResults)
{
newWorkItems.Add(workitem);
}
}
}
e.Result = newWorkItems;
}
示例9: ExecuteQueryLinkTypes
public static bool ExecuteQueryLinkTypes(QueryDefinition qdef, string ProjectName, out int[] qdata)
{
Hashtable context = new Hashtable();
StringBuilder strb = new StringBuilder();
List<int> lqdata = new List<int>();
context.Add("project", ProjectName); //@me, @today are filled automatically
var query = new Query(Utilities.wistore, qdef.QueryText, context);
if (query.IsLinkQuery)
{
foreach (var wilnk in query.RunLinkQuery())
{
lqdata.Add(wilnk.TargetId);
lqdata.Add(wilnk.SourceId);
Utilities.OutputCommandString(string.Format("ParentID={0}, WorkItemID={1}", wilnk.SourceId, wilnk.TargetId));
}
lqdata = lqdata.Distinct().ToList();
}
else
{
foreach (WorkItem wi in query.RunQuery())
{
lqdata.Add(wi.Id);
Utilities.OutputCommandString(string.Format("WorkItemID={0}, Title={1}", wi.Id, wi.Title));
}
}
qdata = lqdata.ToArray();
return false;
}
示例10: RunLinkQuery
private List<WorkItem> RunLinkQuery(WorkItemStore workItemStore, Query query)
{
var queryResults = query.RunLinkQuery();
return queryResults.Select(i => workItemStore.GetWorkItem(i.TargetId)).ToList();
}
示例11: GetTestCases
void GetTestCases(ITestCaseCollection testcases, ExcelWorksheet oSheet)
{
int i = 2;
foreach (ITestCase Testcase in testcases)
{
int j = 1;
string str1 = null;
string str2 = null;
foreach (ITestAction action in Testcase.Actions)
{
ISharedStep shared_step = null;
ISharedStepReference shared_ref = action as ISharedStepReference;
if (shared_ref != null)
{
shared_step = shared_ref.FindSharedStep();
foreach (ITestAction shr_action in shared_step.Actions)
{
var test_step = shr_action as ITestStep;
str1 = str1 + j.ToString() + "." + ((test_step.Title.ToString().Length ==0)? "<<Not Recorded>>" : test_step.Title.ToString()) + System.Environment.NewLine;
str2 = str2 + j.ToString() + "." + ((test_step.ExpectedResult.ToString().Length ==0) ? "<<Not Recorded>>" : test_step.ExpectedResult.ToString()) + System.Environment.NewLine;
j++;
}
}
else
{
var test_step = action as ITestStep;
str1 = str1 + j.ToString() + "." + ((test_step.Title.ToString().Length ==0) ? "<<Not Recorded>>" : test_step.Title.ToString()) + System.Environment.NewLine;
str2 = str2 + j.ToString() + "." + ((test_step.ExpectedResult.ToString().Length ==0) ? "<<Not Recorded>>" : test_step.ExpectedResult.ToString()) + System.Environment.NewLine;
j++;
}
}
string result = null;
string tot_result = null;
foreach (ITestPoint test_point in TP.QueryTestPoints(string.Format("Select * from TestPoint where TestCaseId = {0} ", Testcase.Id)))
{
ITestCaseResult tc_res = test_point.MostRecentResult;
if (tc_res != null)
{
if (tc_res.Outcome.ToString().Equals("None"))
result= tc_res.TestConfigurationName + " : In Progress" + System.Environment.NewLine;
else
result = tc_res.TestConfigurationName + " : " + tc_res.Outcome.ToString() + System.Environment.NewLine;
}
else
result = test_point.ConfigurationName + " : Active" + System.Environment.NewLine;
tot_result = tot_result + result;
}
Query query = new Query(_store,string.Format("SELECT [Target].[System.Id] FROM WorkItemLinks WHERE ([Source].[System.Id] = {0}) and ([Source].[System.WorkItemType] = 'Test Case') And ([Target].[System.WorkItemType] = 'Bug')mode(MustContain)", Testcase.Id));
WorkItemLinkInfo[] workItemLinkInfoArray = null;
if (query.IsLinkQuery)
{
workItemLinkInfoArray = query.RunLinkQuery();
}
else
{
throw new Exception("Run link query fail. Query passed is not a link query");
}
string bug_list = null;
for (int k = 0; k < workItemLinkInfoArray.Length; k++)
{
if (workItemLinkInfoArray[k].LinkTypeId != 0)
bug_list = bug_list + workItemLinkInfoArray[k].TargetId.ToString() + System.Environment.NewLine;
}
oSheet.Cells[i, 1].Value = Testcase.Id.ToString();
oSheet.Cells[i, 2].Value = Testcase.Title.ToString();
oSheet.Cells[i, 3].Value = str1;
oSheet.Cells[i, 4].Value = str2;
oSheet.Cells[i, 8].Value = Testcase.WorkItem.CreatedBy.ToString();
oSheet.Cells[i, 5].Value = Testcase.Description.ToString() + " ";
oSheet.Cells[i, 9].Value = tot_result;
oSheet.Cells[i, 10].Value = bug_list;
i++;
}
}
示例12: FlatLinkQuery
/// <summary>
/// Flats the link query.
/// </summary>
/// <param name="query">The query.</param>
/// <returns></returns>
private IEnumerable<WorkItem> FlatLinkQuery(Query query)
{
var workItemLinks = query.RunLinkQuery();
// Build the list of work items for which we want to retrieve more information
int[] ids = (from WorkItemLinkInfo info in workItemLinks
select info.TargetId).ToArray();
// Next we want to create a new query that will retrieve all the column values from the original query, for
// each of the work item IDs returned by the original query.
var detailsWiql = new StringBuilder();
detailsWiql.AppendLine("SELECT");
bool first = true;
foreach (FieldDefinition field in query.DisplayFieldList)
{
detailsWiql.Append(" ");
if (!first)
detailsWiql.Append(",");
detailsWiql.AppendLine("[" + field.ReferenceName + "]");
first = false;
}
detailsWiql.AppendLine("FROM WorkItems");
// Get the work item details
var flatQuery = new Query(TeamProject.Store, detailsWiql.ToString(), ids);
WorkItemCollection details = flatQuery.RunQuery();
return details.Cast<WorkItem>();
}
示例13: ItemOnSelected
public void ItemOnSelected(object sender, RoutedEventArgs e)
{
try
{
var item = (TreeViewItem)sender;
if (Query != null)
{
var queryDef = (QueryDefinition)project.QueryHierarchy.Find((Guid)item.Tag);
queryDef.QueryText = queryDef.QueryText.Replace("@project", "'" + project.Name + "'");
Query(queryDef);
var query = new Query(ItemStore, queryDef.QueryText);
Int32 count = 0;
if (query.IsLinkQuery)
{
var queryResults = query.RunLinkQuery();
count = queryResults.Count();
}
else
{
var queryResults = query.RunQuery();
count = queryResults.Count;
}
QueryTypes type;
switch (queryDef.QueryType)
{
case QueryType.List: type = QueryTypes.FView; break;
case QueryType.OneHop: type = QueryTypes.DView; break;
case QueryType.Tree: type = QueryTypes.HView; break;
default: type = QueryTypes.None; break;
}
item.Header = CreateTreeItem(queryDef.Name + " [" + count + "]", type);
QueryReport.correctQuery = true;
}
}
catch (InvalidQueryTextException ex)
{
MessageBox.Show(ex.Message, ResourceHelper.GetResourceString("ERROR_TEXT"), MessageBoxButton.OK, MessageBoxImage.Error);
QueryReport.correctQuery = false;
}
}
示例14: ExecuteTreeQuery
/// <summary>
/// The execute tree query.
/// </summary>
/// <param name="query">
/// The query.
/// </param>
/// <returns>
/// The <see cref="List"/>.
/// </returns>
public List<WorkItemLinkInfo> ExecuteTreeQuery(string query)
{
var treeQuery = new Query(ItemsStore, query);
return treeQuery.RunLinkQuery().ToList();
}
示例15: GetWorkItemLinkInfos
/// <summary>
/// 从一个work项中获取WorkItemLinkInfoDetails。
/// </summary>
public IEnumerable<WorkItemLinkInfoDetails> GetWorkItemLinkInfos(int workitemID)
{
// 构造WIQL。
string queryStr = string.Format(queryFormat, workitemID);
Query linkQuery = new Query(this.WorkItemStore, queryStr);
// 获取所有的WorkItemLinkInfo对象。
WorkItemLinkInfo[] linkinfos = linkQuery.RunLinkQuery();
// 定义一个WorkItemLinkInfoDetails类型的泛型变量。从WorkItemLinkInfo对象中获取WorkItemLinkInfoDetails。
List<WorkItemLinkInfoDetails> detailsList = new List<WorkItemLinkInfoDetails>();
foreach (var linkinfo in linkinfos)
{
if (linkinfo.LinkTypeId != 0)
{
WorkItemLinkInfoDetails details = GetDetailsFromWorkItemLinkInfo(linkinfo);
Console.WriteLine(details.ToString());
}
}
return detailsList;
}