Ejemplo n.º 1
0
        public List <WorkItem> GetListOfWorkItemRevisionsPaged()
        {
            int id = 1;

            VssConnection connection = Context.Connection;
            WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>();

            //skip revision 1 and give me the next 2
            List <WorkItem> revisions = workItemTrackingClient.GetRevisionsAsync(id, 2, 1).Result;

            Console.WriteLine("Work Item Revisions...");

            foreach (var item in revisions)
            {
                Console.WriteLine("Id:           {0}", item.Id);
                Console.WriteLine("Revision:     {0}", item.Rev);
                Console.WriteLine("Fields");

                foreach (var field in item.Fields)
                {
                    Console.WriteLine("{0} : {1}", field.Key, field.Value);
                }

                Console.WriteLine();
            }

            return(revisions);
        }
        public async Task <IEnumerable <WorkItem> > GetWorkItemRevisionsAsync(WorkItem workItem)
        {
            if (workItem == null)
            {
                throw new ArgumentNullException(nameof(workItem));
            }

            if (workItem.Id == null)
            {
                throw new ArgumentException("It's not possible to retrive revisions of a work item that does not have an id.",
                                            nameof(workItem));
            }

            return(await _witClient.GetRevisionsAsync(workItem.Id.Value));
        }
Ejemplo n.º 3
0
        public static async Task <IList <WorkItem> > QueryWorkItemRevisionsById(string organization, int id)
        {
            var uri         = new Uri($"https://dev.azure.com/{organization}");
            var credentials = GetVssCredentials();

            //var project = "VNC Agile";

            var wiql = new Wiql()
            {
                // NOTE: Even if other columns are specified, only the ID & URL are available in the WorkItemReference
                Query = "Select [Id] " +
                        "From WorkItems " +
                        "Where Id = " + id
            };

            using (var witHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                // execute the query to get the list of work item revisions

                var revisions = await witHttpClient.GetRevisionsAsync(id, expand : WorkItemExpand.All);

                //var result = await witHttpClient.QueryByWiqlAsync(wiql).ConfigureAwait(false);

                var ids = revisions.Select(item => item.Id);

                // some error handling
                if (ids.Count() == 0)
                {
                    return(Array.Empty <WorkItem>());
                }

                // TODO(crhodes)
                // How can we efficiently get more details depending on WorkItem Type

                string[] fields = GetFieldList();

                //Get WorkItem details(fields) for the ids found in query
                //return await witHttpClient.GetWorkItemsAsync(ids, fields, null, null, null, null);

                //var foo = await witHttpClient.GetWorkItemsAsync(ids, fields).ConfigureAwait(false);
                ////return await witHttpClient.GetWorkItemsAsync((IEnumerable<int>)ids, fields).ConfigureAwait(false);

                //return foo;
                return(revisions);
            }
        }
Ejemplo n.º 4
0
        public async static Task <AzureWorkItem> GetWorkItem(AzureDevOpsConnectionInfo connInfo, WorkItemTrackingHttpClient witClient, int id)
        {
            var workItem = await witClient.GetWorkItemAsync(id, expand : WorkItemExpand.All);

            var azureWit  = workItem.Map(connInfo);
            var tasks     = workItem.Relations.Where(t => t.Rel == "System.LinkTypes.Hierarchy-Forward").Select(x => GetWorkItem(connInfo, witClient, x.GetItemId()));
            var parentRel = workItem.Relations.FirstOrDefault(t => t.Rel == "System.LinkTypes.Hierarchy-Reverse");

            /*if (parentRel != null)
             * {
             *  azureWit.Parent = await GetWorkItem(connInfo, witClient, parentRel.GetItemId());
             * }*/
            var histories = await witClient.GetRevisionsAsync(id);

            var history = histories.Where(h => h.Fields.ContainsKey("System.AssignedTo")).OrderByDescending(h => h.Fields["System.ChangedDate"]).FirstOrDefault();

            azureWit.AssignedOn = history != null ? (DateTime)history.Fields["System.ChangedDate"] : DateTime.MinValue;
            azureWit.Children   = (await Task.WhenAll(tasks)).OrderBy(x => x.BacklogPriority).ToList();
            return(azureWit);
        }
 //Fill list with hours for each date and task
 private static void FillReportList(Dictionary <int, int> pDctTasksFT, List <FTTaskComleted> pLstReport, DateTime pStartDate, DateTime pFinishtDate)
 {
     foreach (int _taskId in pDctTasksFT.Keys)
     {
         List <WorkItem> _revs      = WiClient.GetRevisionsAsync(_taskId).Result;
         DateTime        _lastDate  = DateTime.MinValue; //last processed date for revisions of work item
         int             _lastHours = int.MinValue;      //last processed value of compteted work for revisions of work item
         foreach (WorkItem _rev in _revs)
         {
             if (!_rev.Fields.Keys.Contains(CompletedWorkFieldRef) || !_rev.Fields.Keys.Contains(ChangedDateFieldRef))
             {
                 continue;
             }
             DateTime _changedDate;
             if (!DateTime.TryParse(_rev.Fields[ChangedDateFieldRef].ToString(), out _changedDate))
             {
                 continue;
             }
             bool _inscope = false;
             // calculate hours based on previous revision
             int _completedValue, _completedDiff;
             if (!int.TryParse(_rev.Fields[CompletedWorkFieldRef].ToString(), out _completedValue))
             {
                 continue;
             }
             if (_lastHours == int.MinValue)
             {
                 _completedDiff = _completedValue;
             }
             else
             {
                 _completedDiff = _completedValue - _lastHours;
             }
             _lastHours = _completedValue;
             // check for date of revision between needed dates
             if (pFinishtDate == DateTime.MinValue)
             {
                 if (_changedDate.Date == pStartDate.Date)
                 {
                     _inscope = true;
                 }
             }
             else if (_changedDate.Date >= pStartDate.Date && _changedDate.Date <= pFinishtDate.Date)
             {
                 _inscope = true;
             }
             if (_inscope && _completedDiff != 0)
             {
                 if (_lastDate.Date == _changedDate.Date && pLstReport.Count > 0)
                 {
                     //update existing item if several changes in one day
                     pLstReport[pLstReport.Count - 1].CompletedOnDate    += _completedDiff;
                     pLstReport[pLstReport.Count - 1].CompletedFieldValue = _completedValue;
                 }
                 else     // add new report item
                 {
                     pLstReport.Add(
                         new FTTaskComleted
                     {
                         FTID                = pDctTasksFT[_taskId],
                         TaskID              = _taskId, ReportDT = _changedDate,
                         CompletedOnDate     = _completedDiff,
                         CompletedFieldValue = _completedValue
                     }
                         );
                 }
                 _lastDate = _changedDate;
             }
         }
     }
 }
Ejemplo n.º 6
0
        public static async Task RunGetBugsQueryUsingClientLib()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            var configuration = builder.Build();

            var projetoDesejado = configuration.GetSection("ProjetoDesejado").Value;

            var sources = configuration.GetSection("Projetos:" + projetoDesejado).GetChildren().ToList();

            var uri = new Uri(sources.FirstOrDefault(x => x.Key == "UriString").Value);
            var personalAccessToken = sources.FirstOrDefault(x => x.Key == "PersonalAccessToken").Value;
            var project             = sources.FirstOrDefault(x => x.Key == "Project").Value;

            var credentials = new VssBasicCredential("", personalAccessToken);

            var wiqlQuery = configuration.GetSection("WiqlQuery").Value;

            var wiql = new Wiql()
            {
                Query = wiqlQuery
            };

            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                WorkItemQueryResult workItemQueryResult = await workItemTrackingHttpClient.QueryByWiqlAsync(wiql);

                if (workItemQueryResult.WorkItems.Count() > 0)
                {
                    List <int> list           = new List <int>();
                    string     itemIdAnterior = null;
                    string     itemId;
                    string     boardColumn;
                    string     boardColumnAnterior = null;

                    bool preencher = true;

                    using (var writer = new StreamWriter("./output.csv"))
                        foreach (var item in workItemQueryResult.WorkItems)
                        {
                            var Revions = await workItemTrackingHttpClient.GetRevisionsAsync(item.Id);

                            foreach (var r in Revions)
                            {
                                preencher = true;
                                var Type        = r.Fields.Where(p => p.Key == "System.WorkItemType").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var Title       = r.Fields.Where(p => p.Key == "System.Title").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var CreatedDate = r.Fields.Where(p => p.Key == "System.CreatedDate").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var Interation  = r.Fields.Where(p => p.Key == "System.IterationPath").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var BoardColumn = r.Fields.Where(p => p.Key == "System.BoardColumn").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var ChangedDate = r.Fields.Where(p => p.Key == "System.ChangedDate").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();

                                itemId      = item.Id.ToString();
                                boardColumn = BoardColumn.Value == null ? "-1" : BoardColumn.Value?.ToString();

                                if (itemId.Equals(itemIdAnterior) && boardColumn.Equals(boardColumnAnterior))
                                {
                                    preencher = false;
                                }

                                var linha = string.Join(";", new string[] {
                                    item.Id.ToString()
                                    , Type.Value.ToString()
                                    , Title.Value.ToString()
                                    , CreatedDate.Value.ToString()
                                    , Interation.Value?.ToString()
                                    , BoardColumn.Value?.ToString()
                                    , ChangedDate.Value?.ToString()
                                });

                                itemIdAnterior      = itemId;
                                boardColumnAnterior = BoardColumn.Value == null ? "-1" : BoardColumn.Value?.ToString();;

                                //if (preencher) Console.WriteLine(linha);
                                if (preencher)
                                {
                                    writer.WriteLine(linha);
                                }
                            }
                        }
                }
            }
        }
Ejemplo n.º 7
0
        public static async Task RunGetBugsQueryUsingClientLib()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            var configuration = builder.Build();

            var projetoDesejado = configuration.GetSection("ProjetoDesejado").Value;

            var sources = configuration.GetSection("Projetos:" + projetoDesejado).GetChildren().ToList();

            var uri = new Uri(sources.FirstOrDefault(x => x.Key == "UriString").Value);
            var personalAccessToken = sources.FirstOrDefault(x => x.Key == "PersonalAccessToken").Value;
            var project             = sources.FirstOrDefault(x => x.Key == "Project").Value;
            var area = sources.FirstOrDefault(x => x.Key == "Area").Value;

            var credentials = new VssBasicCredential("", personalAccessToken);

            //var wiqlQuery = configuration.GetSection("WiqlQuery").Value;

            Wiql wiql = new Wiql()
            {
                Query = "SELECT [State], [Title] " +
                        "FROM WorkItems " +
                        "Where [Work Item Type] <> 'Task' " +
                        "And [System.TeamProject] = '" + project + "' " +
                        "And [System.AreaPath] = '" + area + "' "
            };

            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                WorkItemQueryResult workItemQueryResult = await workItemTrackingHttpClient.QueryByWiqlAsync(wiql);

                if (workItemQueryResult.WorkItems.Count() > 0)
                {
                    List <int> list           = new List <int>();
                    string     itemIdAnterior = null;
                    string     itemId;
                    string     boardColumn;
                    string     boardColumnAnterior = null;

                    bool preencher = true;

                    string     fileName = "output.csv";
                    FileStream fs       = null;
                    fs = new FileStream(fileName, FileMode.OpenOrCreate);

                    using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8)) {
                        string[] header = { "id", "type", "title", "createdDate", "area", "Interation", "changedDate", "boardColumn" };
                        writer.WriteLine(string.Join(";", header));

                        foreach (var item in workItemQueryResult.WorkItems)
                        {
                            var Revions = await workItemTrackingHttpClient.GetRevisionsAsync(item.Id);

                            foreach (var r in Revions)
                            {
                                preencher = true;
                                var Type        = r.Fields.Where(p => p.Key == "System.WorkItemType").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var Title       = r.Fields.Where(p => p.Key == "System.Title").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var CreatedDate = r.Fields.Where(p => p.Key == "System.CreatedDate").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var Interation  = r.Fields.Where(p => p.Key == "System.IterationPath").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var BoardColumn = r.Fields.Where(p => p.Key == "System.BoardColumn").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var ChangedDate = r.Fields.Where(p => p.Key == "System.ChangedDate").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();
                                var Area        = r.Fields.Where(p => p.Key == "System.AreaPath").ToDictionary(p => p.Key, p => p.Value).FirstOrDefault();

                                itemId      = item.Id.ToString();
                                boardColumn = BoardColumn.Value == null ? "-1" : BoardColumn.Value?.ToString();

                                if (itemId.Equals(itemIdAnterior) && boardColumn.Equals(boardColumnAnterior))
                                {
                                    preencher = false;
                                }

                                var linha = string.Join(";", new string[] {
                                    item.Id.ToString()
                                    , Type.Value.ToString()
                                    , Title.Value.ToString()
                                    , CreatedDate.Value.ToString()
                                    , Area.Value?.ToString()
                                    , Interation.Value?.ToString()
                                    , ChangedDate.Value?.ToString()
                                    , BoardColumn.Value?.ToString()
                                });

                                itemIdAnterior      = itemId;
                                boardColumnAnterior = BoardColumn.Value == null ? "-1" : BoardColumn.Value?.ToString();;

                                //if (preencher) Console.WriteLine(linha);
                                if (preencher)
                                {
                                    writer.WriteLine(linha);
                                }
                            }
                        }
                    }
                }
            }
        }