Пример #1
0
        internal static List<WorkItem> GetLeadTasks(
			string tfsUrl,
			string areaPath,
			string iterarion,
			Action<int> progressReportHandler)
        {
            var strBuilder = new StringBuilder();
            strBuilder.Append("SELECT * FROM WorkItems");
            strBuilder.Append(" WHERE [System.WorkItemType] = 'LeadTask'");
            strBuilder.Append(" AND [Microsoft.VSTS.Common.Discipline] = 'Development'");
            strBuilder.Append(" AND [System.AreaPath] UNDER '" + areaPath + "'");
            strBuilder.Append(" AND [System.IterationPath] UNDER '" + iterarion + "'");
            strBuilder.Append(" AND [System.Reason] <> 'Canceled'");
            strBuilder.Append(" AND [Children Completed Work] > 0");

            List<WorkItem> result;
            using (var wiqlAccessor = new TfsWiqlAccessor(tfsUrl))
            {
                result = wiqlAccessor.QueryWorkItems(
                    strBuilder.ToString(),
                    null,
                    null,
                    progressReportHandler);
            }
            return result;
        }
Пример #2
0
        internal static void FixBugsAreaPaths(
			string tfsUrl,
			Dictionary<int, int> bugsWithLinks,
			Action<int> progressReportHandler)
        {
            using (var wiqlAccessor = new TfsWiqlAccessor(tfsUrl))
            {
                var ids = bugsWithLinks.Values.Concat(bugsWithLinks.Keys).ToList();
                var items = wiqlAccessor.QueryWorkItemsByIds(
                    ids,
                    null,
                    progressReportHandler == null
                        ? null
                        : new Action<int>(x => progressReportHandler(x * LoadingPart / 100)));
                var dict = items.ToDictionary(i => i.Id);
                int ind = 0;
                foreach (var pair in bugsWithLinks)
                {
                    string areaPath = dict[pair.Value].AreaPath;

                    var bug = dict[pair.Key];
                    bug.AreaPath = areaPath;

                    bug.Save();

                    if (progressReportHandler != null)
                        progressReportHandler(LoadingPart + ind * (100 - LoadingPart) / bugsWithLinks.Count);
                    ++ind;
                }
            }
        }
Пример #3
0
        internal static List<WorkItem> GetNoShipBugs(
			string tfsUrl,
			string areaPath,
			string iterarion,
			Action<int> progressReportHandler)
        {
            var strBuilder = new StringBuilder();
            strBuilder.Append("SELECT [System.Id] FROM WorkItemLinks");
            strBuilder.Append(" WHERE Source.[System.WorkItemType] = 'Bug'");
            strBuilder.Append(" AND Source.[System.AreaPath] UNDER '" + areaPath + "'");
            strBuilder.Append(" AND Source.[System.IterationPath] UNDER '" + iterarion + "'");
            strBuilder.Append(" AND Source.[System.State] <> 'Proposed'");
            strBuilder.Append(" AND Source.[System.State] <> 'Active'");
            strBuilder.Append(" AND Source.[System.Reason] <> 'Converted to Requirement'");
            strBuilder.Append(" AND Source.[Completed Work] > 0");
            strBuilder.Append(" AND Target.[System.WorkItemType] = 'Ship'");
            strBuilder.Append(" MODE (DoesNotContain)");

            List<WorkItem> result;
            using (var wiqlAccessor = new TfsWiqlAccessor(tfsUrl))
            {
                var ids = wiqlAccessor.QueryIdsFromLinks(
                    strBuilder.ToString(),
                    null,
                    null,
                    null);

                if (ids.Count == 0)
                    return new List<WorkItem>(0);

                strBuilder.Clear();
                strBuilder.Append("SELECT [System.Id] FROM WorkItemLinks");
                strBuilder.Append(" WHERE Source.[System.Id] IN (" + string.Join(",", ids.Keys) + ")");
                strBuilder.Append(" AND [System.Links.LinkType] = 'Child'");
                strBuilder.Append(" AND Target.[System.WorkItemType] = 'LeadTask'");
                strBuilder.Append(" AND Target.[Microsoft.VSTS.Common.Discipline] = 'Development'");
                strBuilder.Append(" MODE (DoesNotContain)");

                ids = wiqlAccessor.QueryIdsFromLinks(
                    strBuilder.ToString(),
                    null,
                    null,
                    null);

                if (ids.Count == 0)
                    return new List<WorkItem>(0);

                result = wiqlAccessor.QueryWorkItemsByIds(
                    ids.Keys,
                    "ORDER BY [Completed Work] DESC",
                    progressReportHandler);
            }
            return result;
        }
Пример #4
0
        internal DataContainer ProcessLeadTasks(
			string tfsUrl,
			List<WorkItem> leadTasks,
			Action<int> progressReportHandler)
        {
            var result = new DataContainer
            {
                WiDict = new Dictionary<int, WorkItem>(),
                BlockersDict = new Dictionary<int, List<int>>(),
                LeadTaskChildrenDict = new Dictionary<int, List<int>>(),
            };

            AppendLeadTasks(result, leadTasks);

            using (var wiqlAccessor = new TfsWiqlAccessor(tfsUrl))
            {
                List<int> ltChildrenIds = result.LeadTaskChildrenDict.Values.SelectMany(i => i).ToList();
                AppendTasks(
                    ltChildrenIds,
                    null,
                    result,
                    wiqlAccessor,
                    progressReportHandler);

                CleanDict(
                    result.LeadTaskChildrenDict,
                    result.WiDict,
                    false,
                    true,
                    wiqlAccessor);
                CleanDict(
                    result.BlockersDict,
                    result.WiDict,
                    true,
                    false,
                    wiqlAccessor);

                InitExternalBlockers(result, wiqlAccessor);
            }

            return result;
        }
Пример #5
0
        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
0
        private void AppendTasks(
			List<int> childrenIds,
			int? rootLeadTasskId,
			DataContainer dataContainer,
			TfsWiqlAccessor wiqlAccessor,
			Action<int> progressReportHandler)
        {
            if (childrenIds.Count == 0)
                return;

            var childrenTasks = wiqlAccessor.QueryWorkItemsByIds(
                childrenIds,
                progressReportHandler == null
                    ? null
                    : new Action<int>(x => progressReportHandler(LoadingPart * x / 100)));
            for (int i = 0; i < childrenTasks.Count; i++)
            {
                WorkItem task = childrenTasks[i];
                if (!dataContainer.WiDict.ContainsKey(task.Id))
                    dataContainer.WiDict.Add(task.Id, task);
                if (task.IsClosed())
                    continue;
                if (task.Type.Name != WorkItemType.Task)
                    continue;
                List<int> taskBlockersIds = WorkItemParser.GetRelationsByType(task, WorkItemLinkType.BlockedBy);
                if (taskBlockersIds.Count > 0)
                    dataContainer.BlockersDict.Add(task.Id, taskBlockersIds);

                var taskLinkDict = WorkItemParser.ParseLinks(task);
                int? currentParentLtId = rootLeadTasskId;
                if (currentParentLtId == null
                    && taskLinkDict.ContainsKey(WorkItemLinkType.Parent))
                {
                    int ltId = taskLinkDict[WorkItemLinkType.Parent][0];
                    if (dataContainer.LeadTaskChildrenDict.ContainsKey(ltId))
                        currentParentLtId = ltId;
                }
                if (currentParentLtId != null)
                {
                    var ltChildren = dataContainer.LeadTaskChildrenDict[currentParentLtId.Value];
                    if (!ltChildren.Contains(task.Id))
                        ltChildren.Add(task.Id);
                }
                if (taskLinkDict.ContainsKey(WorkItemLinkType.Child))
                    AppendTasks(
                        taskLinkDict[WorkItemLinkType.Child],
                        currentParentLtId,
                        dataContainer,
                        wiqlAccessor,
                        null);
                if (progressReportHandler != null)
                    progressReportHandler(LoadingPart + (100 - LoadingPart) * i / childrenTasks.Count);
            }
        }
Пример #7
0
        private void InitExternalBlockers(DataContainer dataContainer, TfsWiqlAccessor wiqlAccessor)
        {
            if (dataContainer.BlockersDict.Count == 0)
                return;

            var notFound = new HashSet<int>();
            foreach (var pair in dataContainer.BlockersDict)
            {
                foreach (int blockerId in pair.Value.Where(i => !dataContainer.WiDict.ContainsKey(i)))
                {
                    notFound.Add(blockerId);
                }
            }

            if (notFound.Count == 0)
                return;

            var workItems = wiqlAccessor.QueryWorkItemsByIds(notFound, null);
            for (int i = 0; i < workItems.Count; i++)
            {
                WorkItem workItem = workItems[i];
                dataContainer.WiDict[workItem.Id] = workItem;
            }
        }
Пример #8
0
        private void CleanDict(
			Dictionary<int, List<int>> dict,
			Dictionary<int, WorkItem> wiDict,
			bool deleteEmpty,
			bool useResolvedLinkedfWorkItems,
			TfsWiqlAccessor wiqlAccessor)
        {
            var notFoundIdsDict = new Dictionary<int, List<List<int>>>(dict.Keys.Count);
            foreach (var dictKey in dict.Keys)
            {
                var idsToRemove = new HashSet<int>();
                var values = dict[dictKey];
                foreach (int id in values)
                {
                    if (wiDict.ContainsKey(id))
                    {
                        if (wiDict[id].IsClosed())
                            idsToRemove.Add(id);
                    }
                    else
                    {
                        if (notFoundIdsDict.ContainsKey(id))
                            notFoundIdsDict[id].Add(values);
                        else
                            notFoundIdsDict.Add(id, new List<List<int>>(1) { values });
                    }
                }
                foreach (int id in idsToRemove)
                {
                    values.Remove(id);
                }
            }
            if (notFoundIdsDict.Keys.Count > 0)
            {
                var workItems = wiqlAccessor.QueryWorkItemsByIds(notFoundIdsDict.Keys.ToList(), null);
                for (int i = 0; i < workItems.Count; i++)
                {
                    WorkItem workItem = workItems[i];
                    if (!workItem.IsClosed() && (useResolvedLinkedfWorkItems || !workItem.IsResolved()))
                        continue;
                    foreach (List<int> ids in notFoundIdsDict[workItem.Id])
                    {
                        ids.Remove(workItem.Id);
                    }
                }
            }
            if (deleteEmpty)
            {
                var emptyKeys = dict.Keys.Where(k => dict[k].Count == 0).ToList();
                emptyKeys.ForEach(k => dict.Remove(k));
            }
        }
Пример #9
0
        private static Dictionary<int, int> GetWrongAreaPathBugs(
			TfsWiqlAccessor wiqlAccessor,
			string areaPath,
			string iterarion,
			bool ourBugs,
			Action<int> progressReportHandler)
        {
            var strBuilder = new StringBuilder();
            strBuilder.Append("SELECT [System.Id] FROM WorkItemLinks");
            strBuilder.Append(" WHERE Source.[System.WorkItemType] = 'Bug'");
            strBuilder.Append(" AND Source.[System.AreaPath] "
                + (ourBugs ? "NOT UNDER '" : "UNDER '")
                + areaPath
                + "'");
            strBuilder.Append(" AND Source.[System.IterationPath] UNDER '" + iterarion + "'");
            strBuilder.Append(" AND Target.[System.WorkItemType] = 'Ship'");
            strBuilder.Append(" AND Target.[System.AreaPath] "
                + (ourBugs ? "UNDER '" : "NOT UNDER '")
                + areaPath
                + "'");
            strBuilder.Append(" AND Target.[System.IterationPath] UNDER '" + iterarion + "'");
            strBuilder.Append(" MODE (MustContain)");

            var bugsWithOtherShips = wiqlAccessor.QueryIdsFromLinks(
                strBuilder.ToString(),
                null,
                null,
                progressReportHandler);

            if (bugsWithOtherShips.Count == 0)
                return new Dictionary<int, int>();

            strBuilder.Clear();
            strBuilder.Append("SELECT [System.Id] FROM WorkItemLinks");
            strBuilder.Append(" WHERE Source.[System.Id] IN (" + string.Join(",", bugsWithOtherShips.Keys) + ")");
            strBuilder.Append(" AND Target.[System.WorkItemType] = 'Ship'");
            strBuilder.Append(" AND Target.[System.AreaPath] "
                + (ourBugs ? "NOT UNDER '" : "UNDER '")
                + areaPath
                + "'");
            strBuilder.Append(" AND Target.[System.IterationPath] UNDER '" + iterarion + "'");
            strBuilder.Append(" MODE (DoesNotContain)");

            var result = wiqlAccessor.QueryIdsFromLinks(
                strBuilder.ToString(),
                null,
                null,
                null);

            return result.ToDictionary(i => i.Key, i => bugsWithOtherShips[i.Key].First());
        }
Пример #10
0
        private static List<WorkItem> GetBugs(
			string tfsUrl,
			string areaPath,
			string iterarion,
			bool newFunc,
			bool sd,
			Action<int> progressReportHandler)
        {
            var strBuilder = new StringBuilder();
            strBuilder.Append("SELECT [System.Id] FROM WorkItemLinks");
            strBuilder.Append(" WHERE Source.[System.WorkItemType] = 'Bug'");
            strBuilder.Append(" AND Source.[System.AreaPath] UNDER '" + areaPath + "'");
            strBuilder.Append(" AND Source.[System.IterationPath] UNDER '" + iterarion + "'");
            strBuilder.Append(" AND Source.[System.State] <> 'Proposed'");
            strBuilder.Append(" AND Source.[System.State] <> 'Active'");
            if (!sd)
            {
                strBuilder.Append(" AND Source.[Found On Level] <> '6 Product Testing'");
                strBuilder.Append(" AND Source.[Regress] = '" + (newFunc ? "No" : "Yes") + "'");
            }
            strBuilder.Append(" AND Source.[Service Desk] "+ (sd ? "=" : "<>") + " 'Yes'");
            strBuilder.Append(" AND Source.[System.Reason] NOT IN ('Rejected', 'Deferred', 'Duplicate', 'Cannot Reproduce', 'Converted to Requirement')");
            strBuilder.Append(" AND Target.[System.WorkItemType] = 'LeadTask'");
            strBuilder.Append(" AND Target.[Microsoft.VSTS.Common.Discipline] = 'Development'");
            strBuilder.Append(" AND [System.Links.LinkType] = 'Child'");
            strBuilder.Append(" MODE (DoesNotContain)");

            List<WorkItem> result;
            using (var wiqlAccessor = new TfsWiqlAccessor(tfsUrl))
            {
                var ids = wiqlAccessor.QueryIdsFromLinks(
                    strBuilder.ToString(),
                    null,
                    null,
                    null);

                if (ids.Count == 0)
                    return new List<WorkItem>(0);

                strBuilder.Clear();
                strBuilder.Append("SELECT [System.Id] FROM WorkItemLinks");
                strBuilder.Append(" WHERE Source.[System.Id] IN (" + string.Join(",", ids.Keys) + ")");
                strBuilder.Append(" AND Target.[System.WorkItemType] = 'Ship'");
                strBuilder.Append(" AND Target.[System.AreaPath] UNDER '" + areaPath + "'");
                strBuilder.Append(" AND Target.[System.IterationPath] UNDER '" + iterarion + "'");
                strBuilder.Append(" MODE (MustContain)");

                ids = wiqlAccessor.QueryIdsFromLinks(
                    strBuilder.ToString(),
                    null,
                    null,
                    null);

                if (ids.Count == 0)
                    return new List<WorkItem>(0);

                result = wiqlAccessor.QueryWorkItemsByIds(
                    ids.Keys,
                    "ORDER BY [Completed Work] DESC",
                    progressReportHandler);
            }
            return result;
        }
Пример #11
0
        internal static Dictionary<int, int> GetWrongAreaBugs(
			string tfsUrl,
			string areaPath,
			string iterarion,
			Action<int> progressReportHandler)
        {
            using (var wiqlAccessor = new TfsWiqlAccessor(tfsUrl))
            {
                var notOurBugs = GetWrongAreaPathBugs(
                    wiqlAccessor,
                    areaPath,
                    iterarion,
                    false,
                    progressReportHandler);

                var ourBugs = GetWrongAreaPathBugs(
                    wiqlAccessor,
                    areaPath,
                    iterarion,
                    true,
                    progressReportHandler);

                foreach (var pair in ourBugs)
                {
                    notOurBugs.Add(pair.Key, pair.Value);
                }

                return notOurBugs;
            }
        }
Пример #12
0
 internal static List<WorkItem> GetWorkItemsByIds(string tfsUrl, List<int> ids)
 {
     using (var wiqlAccessor = new TfsWiqlAccessor(tfsUrl))
     {
         return wiqlAccessor.QueryWorkItemsByIds(
             ids,
             null,
             null);
     }
 }
Пример #13
0
        private List<WorkItem> GetLeadTasks(
			string tfsUrl,
			List<string> values,
			bool withSubTrees,
			bool withSprint,
			string systemFieldName,
			string fieldAlias,
			string additionalOrderField)
        {
            var paramValues = new Dictionary<string, object>
            {
                {"project", @"FORIS_Mobile"},
            };

            var complexParamValues = new Dictionary<string, List<object>>
            {
                {"discipline", new List<object>{"Development"}},
                {"wiType", new List<object>{"LeadTask"}},
                {"wiState", new List<object>{"Proposed", "Active"}},
            };

            var strBuilder = new StringBuilder();
            strBuilder.Append("SELECT * FROM WorkItems");
            strBuilder.Append(" WHERE [System.TeamProject] = @project");
            strBuilder.Append(" AND [System.WorkItemType] IN (@wiType)");
            strBuilder.Append(" AND [System.State] IN (@wiState)");
            if (withSprint)
                strBuilder.Append(" AND [Sprint] <> ''");
            strBuilder.Append(" AND [Microsoft.VSTS.Common.Discipline] IN (@discipline)");
            if (withSubTrees)
            {
                strBuilder.Append(" AND (");
                for (int i = 0; i < values.Count; i++)
                {
                    string dataParam = fieldAlias + i;
                    if (i > 0)
                        strBuilder.Append(" OR ");
                    strBuilder.Append("[" + systemFieldName + "] UNDER @" + dataParam);
                    paramValues.Add(dataParam, values[i]);
                }
                strBuilder.Append(")");
            }
            else
            {
                strBuilder.Append(" AND [" + systemFieldName + "] IN (@" + fieldAlias + ")");
                complexParamValues.Add(fieldAlias, values.Cast<object>().ToList());
            }
            strBuilder.Append(" ORDER BY [Priority], [");
            strBuilder.Append(additionalOrderField + "]");

            List<WorkItem> result;
            using (var wiqlAccessor = new TfsWiqlAccessor(tfsUrl))
            {
                result = wiqlAccessor.QueryWorkItems(
                    strBuilder.ToString(),
                    paramValues,
                    complexParamValues,
                    null);
            }
            return result;
        }