Beispiel #1
0
        public static async Task <DataTable> ReadHistory(Config c)
        {
            var tasks     = new List <Task <ConcurrentDictionary <Guid, Dictionary <string, string> > > >();
            var fieldList = new List <FieldWithLabel>();

            fieldList.Add(new FieldWithLabel()
            {
                Id = "System.TeamProject", Label = "Project"
            });
            fieldList.Add(new FieldWithLabel()
            {
                Id = "ParentParentTitle", Label = "Feature"
            });
            fieldList.Add(new FieldWithLabel()
            {
                Id = "ParentTitle", Label = "User Story"
            });
            fieldList.Add(new FieldWithLabel()
            {
                Id = "System.Title", Label = "Task"
            });
            fieldList.Add(new FieldWithLabel()
            {
                Id = "TimeChangedAt", Label = "Change happened at"
            });
            fieldList.Add(new FieldWithLabel()
            {
                Id = "TimeChange", Label = "'Completed Work' increased by"
            });
            var table = new DataTable();

            table.Columns.Add("URL", typeof(string));
            table.Columns.Add("ParentURL", typeof(string));
            table.Columns.Add("ParentParentURL", typeof(string));
            table.Columns.Add("Organization", typeof(string));
            foreach (var field in fieldList)
            {
                table.Columns.Add(field.Label, typeof(string));
            }

            foreach (var orgWithPAT in c.OrgsWithPATs)
            {
                foreach (var org in orgWithPAT.Orgs)
                {
                    var or = new OrgReader(org, orgWithPAT.Pat, c.Query, fieldList, c.LinkType);
                    tasks.Add(or.ReadWIsWithTimeChange());
                }
            }

            ConcurrentDictionary <Guid, Dictionary <string, string> >[] results = await Task.WhenAll(tasks);

            foreach (var wiDict in results)
            {
                foreach (var wiKVP in wiDict)
                {
                    var row = table.NewRow();
                    //row["ID"] = wiKVP.Key;
                    row["Organization"] = wiKVP.Value["Organization"];
                    if (wiKVP.Value == null)
                    {
                        Console.WriteLine($"Details for Workitem {wiKVP.Key} are missing");
                    }
                    else
                    {
                        foreach (var field in fieldList)
                        {
                            row[field.Label] = wiKVP.Value.ContainsKey(field.Id) ? wiKVP.Value[field.Id] : "";
                            if (field.Id == "System.Title" && wiKVP.Value.ContainsKey("URL"))
                            {
                                row["URL"] = wiKVP.Value["URL"];
                            }
                            else if (field.Id == "ParentTitle" && wiKVP.Value.ContainsKey("ParentURL"))
                            {
                                row["ParentURL"] = wiKVP.Value["ParentURL"];
                            }
                            else if (field.Id == "ParentParentTitle" && wiKVP.Value.ContainsKey("ParentParentURL"))
                            {
                                row["ParentParentURL"] = wiKVP.Value["ParentParentURL"];
                            }
                        }
                    }
                    table.Rows.Add(row);
                }
            }

            table.DefaultView.Sort = "Change happened at desc";
            return(table.DefaultView.ToTable());
        }
Beispiel #2
0
        private const double AzureExchangeEuro = 0.843; // https://azureprice.net/Exchange

        public static async Task <DataTable> ReadWIs(Config c)
        {
            var fieldList = new List <FieldWithLabel>(c.Fields);

            if (!fieldList.Any(f => f.Id == "System.Title"))
            {
                fieldList.Add(new FieldWithLabel()
                {
                    Id = "System.Title", Label = "Title"
                });
            }

            var tasks         = new List <Task <ConcurrentDictionary <long, Dictionary <string, string> > > >();
            var tasksEntities = new List <Task <KeyValuePair <string, string> > >();

            foreach (var orgWithPAT in c.OrgsWithPATs)
            {
                foreach (var org in orgWithPAT.Orgs)
                {
                    var or = new OrgReader(org, orgWithPAT.Pat, c.Query, fieldList, c.LinkType);
                    tasks.Add(or.ReadWIs());
                    var ur = new UserReader(org, orgWithPAT.Pat);
                    tasksEntities.Add(ur.ReadEntity());
                }
            }

            ConcurrentDictionary <long, Dictionary <string, string> >[] results = await Task.WhenAll(tasks);

            KeyValuePair <string, string>[] resultsEntitiesKVP = await Task.WhenAll(tasksEntities);

            var resultsEntities = resultsEntitiesKVP.ToDictionary(x => x.Key, x => x.Value);

            if (fieldList.Any(f => f.Id == "System.AssignedTo"))
            {
                fieldList.RemoveAll(f => f.Id == "System.AssignedTo");
                fieldList.Add(new FieldWithLabel()
                {
                    Id = "System.AssignedTo.DisplayName", Label = "Name"
                });
                fieldList.Add(new FieldWithLabel()
                {
                    Id = "System.AssignedTo.UniqueName", Label = "eMail"
                });
            }
            fieldList.Add(new FieldWithLabel()
            {
                Id = "ParentTitle", Label = "Parent"
            });

            var table = new DataTable();

            table.Columns.Add("ID", System.Type.GetType("System.Int32"));
            table.Columns.Add("URL", typeof(string));
            table.Columns.Add("Entity", typeof(string));
            table.Columns.Add("Organization", typeof(string));
            table.Columns.Add("ParentURL", typeof(string));
            foreach (var field in fieldList)
            {
                table.Columns.Add(field.Label, typeof(string));
            }

            foreach (var wiDict in results)
            {
                foreach (var wiKVP in wiDict)
                {
                    var row = table.NewRow();
                    row["ID"]           = wiKVP.Key;
                    row["Organization"] = wiKVP.Value["Organization"];
                    row["Entity"]       = resultsEntities[wiKVP.Value["Organization"]];
                    if (wiKVP.Value == null)
                    {
                        Console.WriteLine($"Details for Workitem {wiKVP.Key} are missing");
                    }
                    else
                    {
                        foreach (var field in fieldList)
                        {
                            row[field.Label] = wiKVP.Value.ContainsKey(field.Id) ? wiKVP.Value[field.Id] : "";
                            if (field.Id == "System.Title" && wiKVP.Value.ContainsKey("URL"))
                            {
                                row["URL"] = wiKVP.Value["URL"];
                            }
                            else if (field.Id == "ParentTitle" && wiKVP.Value.ContainsKey("ParentURL"))
                            {
                                row["ParentURL"] = wiKVP.Value["ParentURL"];
                            }
                        }
                    }
                    table.Rows.Add(row);
                }
            }

            return(table);
        }