private async Task <string> GetPriorityFieldName(string projectName)
        {
            var types = await WorkItemsClient.GetWorkItemTypesAsync(projectName);

            var xmlForms = types.Where(t => _workItemTypes.Contains(t.Name)).Select(t => t.XmlForm);
            var xmlForm  = string.Join(string.Empty, xmlForms);

            return(GetPriorityFieldNameFromXml(xmlForm));
        }
        public async Task <IEnumerable <Card> > GetCards(string projectName, int depth = 0)
        {
            var wiql =
                string.Format(@"SELECT * FROM WorkItemLinks WHERE 
                                [Source].[System.TeamProject] = '{0}' AND
                                [System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' AND
                                [Target].[System.State] NOT IN('Done', 'Closed', 'Resolved') AND
                                [Target].[System.WorkItemType] IN('Feature', 'User Story', 'Product Backlog Item') AND 
                                [Source].[System.WorkItemType] IN('Feature', 'User Story', 'Product Backlog Item')
                                ORDER BY [Source].[System.WorkItemType], [{1}]
                                mode(recursive)", projectName, PriorityFieldNameFor(projectName));
            var result = await WorkItemsClient.QueryByWiqlAsync(new Wiql { Query = wiql });

            var workItems = await GetWorkItems(result);

            var cards = workItems.Select(AsCard).ToList();

            AssignFeatures(result.WorkItemRelations, cards);
            FlattenFeatures(cards, depth);
            return(cards);
        }
 private async Task Update(Card card)
 {
     var doc = CreateUpdateDocument(card);
     await WorkItemsClient.UpdateWorkItemAsync(doc, card.Id);
 }