Ejemplo n.º 1
0
        public IEnumerable <ITfsWorkItem> GetResults()
        {
            var variables = new Dictionary <string, string>();

            variables["project"] = Project.Name;
            var query = new Query(WorkItemStore, QueryDefinition.QueryText, variables);

            if (query.IsLinkQuery)
            {
                var sourceIds = String.Join(", ", query.RunLinkQuery().Select(link => (link.SourceId != 0) ? link.SourceId : link.TargetId));
                foreach (WorkItem item in _workItemStore.Query(
                             "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.Description], [System.State] FROM WorkItems WHERE [System.Id] IN (" + sourceIds + ") ORDER BY [System.Id]", variables))
                {
                    yield return(new TfsWorkItem(item));
                }
            }
            else
            {
                foreach (WorkItem item in _workItemStore.Query(
                             query.QueryString, variables))
                {
                    yield return(new TfsWorkItem(item));
                }
            }
        }
        private WorkItemCollection GetWorkItemsByState(string state = "New")
        {
            WorkItemType       workItemType = project.WorkItemTypes["Bug"];
            WorkItemCollection collection   = store.Query("SELECT [System.Id],[System.Title],[System.State],[System.CreatedDate] FROM WorkItems WHERE [System.State] = '" + state + "'");

            return(collection);
        }
Ejemplo n.º 3
0
        private async Task RefreshAsyncWorkitems()
        {
            try
            {
                // Set our busy flag and clear the previous data
                this.IsBusy = true;
                this.WorkItems.Clear();

                ObservableCollection <WorkItem> lworkItems = new ObservableCollection <WorkItem>();

                // Make the server call asynchronously to avoid blocking the UI
                await Task.Run(() =>
                {
                    ITeamFoundationContext context = this.CurrentContext;
                    if (context != null && context.HasCollection && context.HasTeamProject)
                    {
                        WorkItemStore wis = context.TeamProjectCollection.GetService <WorkItemStore>();
                        if (wis != null)
                        {
                            WorkItemCollection wic;
                            if (!string.IsNullOrWhiteSpace(this.UserAccountName))
                            {
                                string user = "******" + this.UserDisplayName + "'";
                                wic         = wis.Query("SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.WorkItemType] <> ''  AND  [System.State] <> ''  AND  [System.AssignedTo] EVER " + user + " ORDER BY [System.ChangedDate] desc");
                            }
                            else
                            {
                                wic = wis.Query("SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.WorkItemType] <> ''  AND  [System.State] <> '' AND [System.TeamProject] = '" + context.TeamProjectName + "'ORDER BY [System.ChangedDate] desc");
                            }

                            int i = 0;
                            foreach (WorkItem wi in wic)
                            {
                                lworkItems.Add(wi);
                                i++;
                                if (i >= 12)
                                {
                                    break;
                                }
                            }
                        }
                    }
                });

                // Now back on the UI thread, update the bound collection and section title
                this.WorkItems = lworkItems;
            }
            catch (Exception ex)
            {
                this.ShowNotification(ex.Message, NotificationType.Error);
            }
            finally
            {
                // Always clear our busy flag when done
                this.IsBusy = false;
            }
        }
        public WorkItem GetWorkItem(string type, string title, string project)
        {
            var workItems = _workItemStore.Query(
                string.Format(
                    "SELECT * FROM workitems WHERE [Work Item Type]='{0}' and [Team Project]='{1}' and [Title]='{2}'",
                    type,
                    project,
                    title));
            var workItem = workItems.Cast <WorkItem>().FirstOrDefault(x => x.Title == title && x.Project.Name == project);

            return(workItem);
        }
Ejemplo n.º 5
0
        public ICollection <WorkItem> GetWorkItemsUnderIterationPath(string iterationPath)
        {
            ICollection <WorkItem> result = new Collection <WorkItem>();
            string query = GetWorkItemQuery(iterationPath, true);

            //string query = string.Format(CultureInfo.CurrentCulture,
            //                             "SELECT [System.Id], [System.IterationId], [System.IterationPath], [System.State], [System.Title] " +
            //                             "FROM WorkItems WHERE [Work Item Type] = 'User Story' AND [System.IterationPath] UNDER '{0}'",
            //                             iterationPath);
            foreach (WorkItem item in store.Query(query))
            {
                result.Add(item);
            }

            return(result);
        }
Ejemplo n.º 6
0
        public IEnumerable <TimeSheetItem> GetWorkItems(DateTime iterationDay, string userName)
        {
            if (!IsAuthenticated)
            {
                throw new InvalidOperationException("User not authenticated.");
            }

            var result = new List <TimeSheetItem>();

            var parameters = new Hashtable {
                { "project", _project }, { "me", userName }
            };
            var wiCollection = _workItemStore.Query(_workitemQueryText, parameters);

            // Add only workitems from an iteration that has the given iterationDay
            result.AddRange(from WorkItem workItem in wiCollection
                            let fullPath                       = workItem.IterationPath.Replace(_project, _project + @"\Iteration")
                                                      let node = _commonStructureService.GetNodeFromPath(fullPath)
                                                                 where node.StartDate <= iterationDay && node.FinishDate >= iterationDay
                                                                 select new TimeSheetItem
            {
                WorkItemId    = workItem.Id,
                Name          = workItem.Title,
                WorkRemaining = Convert.ToDateTime(TimeSpan.FromHours(Convert.ToDouble(workItem["Remaining work"])).ToString()),
                Project       = _project,
                ServerUrl     = _url
            });

            return(result);
        }
Ejemplo n.º 7
0
        private IEnumerable <WorkItem> QueryWorkItems(WorkItemStore workItemStore)
        {
            WIQLQueryBuilder queryBuilder = new WIQLQueryBuilder();

            queryBuilder.Ids                = Id;
            queryBuilder.WorkItemTypes      = Type;
            queryBuilder.States             = State;
            queryBuilder.AssignedTo         = TfsWorkCmdletArgumentParser.ParseUserIdentities("Assigned To", workItemStore.TeamProjectCollection, AssignedTo).Select(x => x.UniqueName).ToList();
            queryBuilder.Title              = Title;
            queryBuilder.Priority           = Priority;
            queryBuilder.AreaPath           = AreaPath;
            queryBuilder.UnderAreaPath      = UnderAreaPath;
            queryBuilder.IterationPath      = IterationPath;
            queryBuilder.UnderIterationPath = UnderIterationPath;
            queryBuilder.ExtraFilters       = Filter;

            string wiqlQuery = queryBuilder.Build();

            WriteVerbose(string.Format("Query workitems with WIQL query: {0}.", wiqlQuery));

            var workItemCollection = workItemStore.Query(wiqlQuery);

            foreach (WorkItem workItem in workItemCollection)
            {
                yield return(workItem);
            }
        }
Ejemplo n.º 8
0
        public IEnumerable <WorkItem> PullWorkItemsThatChanged(Uri tfsConnectionstring, string projectName, DateTime startDate, DateTime endDate)
        {
            WorkItemStore workItemStore = GetWorkItemStore(tfsConnectionstring);

            const string queryTemplate    = @"
                SELECT ID, Title, [Team Project], [Microsoft.VSTS.Common.Priority], System.ChangedDate, [System.AssignedTo], [System.IterationPath], [System.AreaPath], [System.State], [CodeBox.UserVotes]
                FROM Issue 
                WHERE 
                    [System.TeamProject] = @projectName                    
                    and System.ChangedDate > @startDate 
                    and System.ChangedDate < @endDate
                ";
            IDictionary  paramsDictionary = new Dictionary <string, object>();

            paramsDictionary["projectName"] = projectName;

            //TFS will throw an error if you use the time in query and it defaults to midnight on the day sent in so we
            //have to use the previous day's date.
            paramsDictionary["startDate"] = startDate.Date.AddDays(-1);
            paramsDictionary["endDate"]   = endDate.Date.AddDays(1);

            WorkItemCollection tfsWorkItemCollection = workItemStore.Query(queryTemplate, paramsDictionary);

            return(tfsWorkItemCollection.Cast <WorkItem>().ToList());
        }
        /// <summary>
        /// Search all work items
        /// </summary>
        /// <param name="store"></param>
        /// <param name="iterationPath"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        public WorkItemTimeCollection(WorkItemStore store, string iterationPath, DateTime startDate, DateTime endDate)
        {
            this.IterationPath = iterationPath;
            this.Data          = new ObservableCollection <WorkItemTime>();

            // Sets a list of dates to compute
            _trackDates.Add(startDate.Date);
            for (DateTime date = startDate.Date; date <= endDate.Date; date = date.AddDays(1))
            {
                _trackDates.Add(date.AddHours(23).AddMinutes(59));
            }

            // Gets all work items for each dates
            foreach (DateTime asOfDate in _trackDates)
            {
                // Execute the query
                var wiCollection = store.Query(this.GetQueryString(asOfDate));

                // Iterate through all work items
                foreach (WorkItem wi in wiCollection)
                {
                    WorkItemTime time = new WorkItemTime(asOfDate, wi);
                    this.Data.Add(time);
                }
            }
        }
Ejemplo n.º 10
0
        private List <WorkItem> GetWorkItems()
        {
            var workItemCollection = WorkItemStore.Query(BugsQuery());

            Logger.WriteInfo(p => p.JMessage(Site.Tfs, Operation.Reading, Artifact.WorkItem, BugsQuery()));
            return(workItemCollection.Cast <WorkItem>().ToList());
        }
        public void Sprint1Forecast()
        {
            TfsTeamProjectCollection tpc = TfsConnect();

            // Get work items

            WorkItemStore      store      = new WorkItemStore(tpc);
            Project            project    = store.Projects[TeamProject];
            string             wiql       = "SELECT [System.Id] FROM WorkItems " + "WHERE [System.TeamProject] = '" + TeamProject + "' AND [System.WorkItemType] ='Product Backlog Item'";
            WorkItemCollection collection = store.Query(wiql);

            // Get list of work items to put into Sprint 1

            int count = 0;

            for (int i = 0; i < collection.Count; i++)
            {
                WorkItem wi = collection[i];

                // Set Iteration Path and State

                wi.Open();
                wi.IterationPath = @"Fabrikam\Release 1\Sprint 1";
                wi.State         = "Committed";
                wi.Save();
                Console.Write(".");
                count++;
            }

            // Done

            Console.WriteLine(string.Format(" ({0} PBIs added)", count));
        }
        public HttpResponseMessage SearchItem([FromUri] string requestedCollectionUri, [FromUri] string requestedProject, [FromUri] int count, [FromBody] BasicQuery query)
        {
            string type   = Utils.GetTFSType(query.type);
            string filter = query.query;

            Uri collectionUri                      = new Uri(requestedCollectionUri);
            TfsTeamProjectCollection tpc           = new TfsTeamProjectCollection(collectionUri, new NetworkCredential(username, password, domain));
            WorkItemStore            workItemStore = tpc.GetService <WorkItemStore>();
            WorkItemCollection       queryResults  = workItemStore.Query(
                "Select [Title], [State], [Id], [Stack Rank] " +
                "From Workitems " +
                "Where [Work Item Type] = '" + type + "' and [State] != 'Removed' and [State] != 'Closed' and " +
                "[State] != 'Resolved' and [Area Path] under 'RD\\Azure App Plat\\Logic Apps' and [Title] contains '" + filter + "' " +
                "Order By [Stack Rank] Asc"
                );
            var response = (from WorkItem r in queryResults select new SimpleWorkItem {
                Title = r.Title,
                State = r.State,
                id = r.Id,
                AreaPath = r.AreaPath,
                IterationPath = r.IterationPath,
                Type = r.Type.Name
            }).Take(count);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Ejemplo n.º 13
0
        protected IEnumerable <WorkItem> QueryFromWorkItems(WorkItemStore workItemStore)
        {
            if (WorkItemId != null && WorkItemId.Count > 0)
            {
                WIQLQueryBuilder queryBuilder = new WIQLQueryBuilder();
                queryBuilder.Ids = WorkItemId;

                string wiqlQuery = queryBuilder.Build();
                WriteVerbose(string.Format("Query workitems with WIQL query: {0}.", wiqlQuery));

                var workItemCollection = workItemStore.Query(wiqlQuery);
                foreach (WorkItem workItem in workItemCollection)
                {
                    yield return(workItem);
                }
            }

            if (WorkItem != null)
            {
                WriteVerbose(string.Format("Get workitems from command line argument: Count = {0}.", WorkItem.Count));

                foreach (WorkItem workItem in WorkItem)
                {
                    yield return(workItem);
                }
            }
        }
Ejemplo n.º 14
0
        public WorkItemCollection GetChildTasks(int id)
        {
            try
            {
                WorkItemStore store       = GetTFS().GetService <WorkItemStore>();
                var           queryString = string.Format(@"SELECT [Target].[Id] FROM WorkItemLinks WHERE " +
                                                          "[System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' AND " +
                                                          "Target.[System.WorkItemType] = 'Task' AND " +
                                                          "Source.[System.Id] = '{0}'", id);
                var query = new Query(store, queryString);

                queryString = @"SELECT [Id], [Title] FROM WorkItems WHERE [System.AssignedTo]= @me AND ([ID]='0'";
                foreach (WorkItemLinkInfo link in query.RunLinkQuery())
                {
                    if (link.TargetId != 0)
                    {
                        queryString += string.Format(@" OR [Id] = '{0}'", link.TargetId);
                    }
                }
                return(store.Query(queryString + ")"));
            }
            catch (Exception ex)
            {
                Helpers.DebugInfo("GetChildTasks exception: " + ex.Message);
                tfs = null;
                throw;
            }
        }
Ejemplo n.º 15
0
        public List <WI> GetInitialWorkItens()
        {
            string s = "SELECT [System.TeamProject], [System.Id],  [System.AssignedTo], [System.Title], [System.CreatedBy], [System.CreatedDate] FROM WorkItems WHERE [System.TeamProject]='" + teamProjectName + "'  ORDER BY [System.Id]";

            WorkItemCollection existingWI = wiStore.Query(s);
            DateTime           dtCreated  = existingWI[0].CreatedDate;
            string             sCreatedBy = existingWI[0].CreatedBy;

            List <WI> lst = new List <WI>();

            foreach (WorkItem itm in existingWI)
            {
                if (itm.CreatedBy == sCreatedBy && itm.CreatedDate == dtCreated)
                {
                    WI wi = new WI {
                        Title = itm.Title, Description = itm.Description, Type = itm.Type.Name, AreaPath = itm.AreaPath, IterationPath = itm.IterationPath
                    };
                    foreach (Field fld in itm.Fields)
                    {
                        if (fld.ReferenceName.IndexOf("System.") < 0 && fld.ReferenceName.IndexOf("Microsoft.") < 0)
                        {
                            wi.customFields.Add(fld.ReferenceName, fld.Value);
                        }
                    }

                    lst.Add(wi);
                }
                else
                {
                    break;
                }
            }

            return(lst);
        }
        public WorkItemCollection GetWorkItemsFromId(string workItemName, string workItemId)
        {
            string queryString =
                string.Format("SELECT [タイトル] FROM WorkItems WHERE [作業項目の種類]='{0}' AND [ID]={1}", workItemName, workItemId);

            return(_workItemStore.Query(queryString));
        }
Ejemplo n.º 17
0
        private static bool ReassignWorkitems(string sourceUserName, string targetUserName)
        {
            // Retrieve all Work Items where the sourceUserName is in the Assigned To field
            string             wiql    = string.Format("SELECT System.Id, System.AssignedTo FROM WorkItems WHERE System.AssignedTo = '{0}'", sourceUserName);
            WorkItemCollection results = _wistore.Query(wiql);

            WriteLog(string.Format("Reassigning Work Items from {0} to {1} ({2} Work Item(s) found)", sourceUserName, targetUserName, results.Count));
            try
            {
                foreach (WorkItem workitem in results)
                {
                    // Update Work Item
                    workitem.Open();
                    workitem.Fields["System.AssignedTo"].Value = targetUserName;
                    workitem.Fields["System.History"].Value    = "Updated by the VSTSPermCopy tool";
                    workitem.Save();
                }
            }
            catch (Exception ex)
            {
                WriteLog(LogLevel.Error, string.Format("An error occurred while updating a Work Item: {0}\n\nUpdates for the current user are aborted.\nDo you want to continue with the next user (y/n)?", ex.ToString()));
                if (Console.ReadKey().Key != ConsoleKey.Y)
                {
                    return(false);
                }
            }
            return(true);
        }
        public void Sprint1Plan()
        {
            TfsTeamProjectCollection tpc = TfsConnect();

            // Load tasks from config file

            XmlDocument xmlInput = new XmlDocument();

            xmlInput.Load(InputFile);
            XmlNodeList tasks = xmlInput.SelectNodes("//plan/task");

            // Get PBI work items

            WorkItemStore      store      = new WorkItemStore(tpc);
            Project            project    = store.Projects[TeamProject];
            string             wiql       = "SELECT [System.Id] FROM WorkItems " + "WHERE [System.TeamProject] = '" + TeamProject + "' AND [System.WorkItemType] ='Product Backlog Item'";
            WorkItemCollection collection = store.Query(wiql);

            // Loop through each PBI

            int count = 0;

            for (int i = 0; i < collection.Count; i++)
            {
                WorkItem PBI = collection[i];

                // Loop through each Task

                foreach (XmlNode task in tasks)
                {
                    WorkItem wi = new WorkItem(project.WorkItemTypes["task"]);
                    wi.Title         = task["title"].InnerText;
                    wi.IterationPath = @"Fabrikam\Release 1\Sprint 1";
                    wi.Fields["Microsoft.VSTS.Scheduling.RemainingWork"].Value = Convert.ToInt32(task["remainingwork"].InnerText);

                    ArrayList ValidationResult = wi.Validate();
                    if (ValidationResult.Count > 0)
                    {
                        Microsoft.TeamFoundation.WorkItemTracking.Client.Field badField = (Microsoft.TeamFoundation.WorkItemTracking.Client.Field)ValidationResult[0];
                        Console.WriteLine();
                        Console.WriteLine("  Invalid \"{0}\" value \"{1}\" ({2})", badField.Name, badField.Value, badField.Status);
                        return;
                    }
                    Console.Write(".");
                    wi.Save();

                    // Save link to parent PBI

                    WorkItemLinkTypeEnd childLink = store.WorkItemLinkTypes.LinkTypeEnds["Parent"];
                    wi.WorkItemLinks.Add(new WorkItemLink(childLink, PBI.Id));
                    wi.Save();
                    count++;
                }
            }

            // Done

            Console.WriteLine(string.Format(" ({0} tasks added)", count));
        }
        public override IEnumerable <WorkItemData> GetWorkItems(QueryOptions query)
        {
            Log.LogDebug("TfsWorkItemEndPoint::GetWorkItems(query)");
            EnsureConnection();
            var wis = _Store.Query(query.Query, query.Paramiters);

            return(ToWorkItemDataList(wis));
        }
Ejemplo n.º 20
0
        private static void taskQuery(string sprintNum)
        {
            WorkItemCollection wc = workItemStore.Query(
                "SELECT * FROM WorkItems WHERE [System.TeamProject] = 'Prism' AND [System.AreaPath] UNDER 'Prism\\Core' AND  [System.IterationPath] = 'Prism\\Sprint " + sprintNum + "'" +
                "AND [System.WorkItemType] = 'Task' AND  [System.State] != 'Removed'");

            memEffort  = new Dictionary <string, double[]>();
            actiEffort = new Dictionary <string, double[]>();
            actiEffort.Add("Grand Total", new double[2]);

            foreach (WorkItem wi in wc)
            {
                Revision rev = getWorkItemRevision(wi);
                activityEffort(wi, rev);
                memberEffort(wi, rev);
            }
        }
Ejemplo n.º 21
0
        private static WorkItem GetWorkItem(TfsTeamProjectCollection teamProjectCollection, string project, int id)
        {
            var workItemStore = new WorkItemStore(teamProjectCollection);
            WorkItemCollection workItemCollection = workItemStore.Query
                (
                    "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] " +
                    "FROM WorkItems WHERE [System.TeamProject] = '" + project + "'  AND  [System.Id] = " + id
                );

            return workItemCollection.Count > 0 ? workItemCollection[0] : null;
        }