private MemberCapacity GetMemberCapacity(CapacityDetails capacityDetails, DateTime iterationStartDate, DateTime currentDate)
        {
            var capacityPerDay       = capacityDetails.Activities.Sum(x => x.CapacityPerDay);
            var daysInIterationSoFar = GetBusinessDays(iterationStartDate, currentDate) - 1; //Run process in the morning, so subtract the current day since people haven't filled in the current day's completed hours yet
            var daysOffSoFar         = 0;

            if (_config.CountDaysOff)
            {
                daysOffSoFar = capacityDetails.DaysOff.Sum(x => GetBusinessDaysToCurrent(x.Start, x.End, currentDate.AddDays(-1)));
            }

            return(new MemberCapacity
            {
                CorrectCapacity = capacityPerDay * (daysInIterationSoFar - daysOffSoFar),
                DisplayName = capacityDetails.TeamMember.DisplayName,
                Email = capacityDetails.TeamMember.UniqueName,
                MemberId = capacityDetails.TeamMember.Id
            });
        }
示例#2
0
        public TeamCapacity GetTeamCapacityDetails(string org, string project, List <Iterations> iterations)
        {
            string       responseBody = "";
            TeamCapacity capacity     = new TeamCapacity();

            capacity.currentTeamCapacities = new List <CurrentTeamCapacity>();
            capacity.totalTeamCapacities   = new List <TotalTeamCapacity>();
            capacity.capacitybyTeamMembers = new List <CapacitybyTeamMember>();
            capacity.leavesbyTeamMembers   = new List <LeavesbyTeamMember>();
            List <CapacityDetails> capacityList = new List <CapacityDetails>();

            foreach (var item in iterations)
            {
                CapacityDetails capacitydetails = new CapacityDetails();
                string          teamname        = item.team;
                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Add(
                        new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(
                                                                                                   System.Text.ASCIIEncoding.ASCII.GetBytes(
                                                                                                       string.Format("{0}:{1}", "", Session["PAT"] == null ? Request.QueryString["code"] : Session["PAT"].ToString()))));
                    string url = "https://dev.azure.com/" + org + "/" + project + "/" + teamname + "/_apis/work/teamsettings/iterations/" + item.id + "/capacities?api-version=5.1";
                    using (HttpResponseMessage response = client.GetAsync(url).Result)
                    {
                        response.EnsureSuccessStatusCode();
                        responseBody                  = response.Content.ReadAsStringAsync().Result;
                        capacitydetails               = JsonConvert.DeserializeObject <CapacityDetails>(responseBody);
                        capacitydetails.teamName      = item.team;
                        capacitydetails.IterationPath = item.path;
                        capacityList.Add(capacitydetails);
                    }
                }
            }
            foreach (var item in capacityList)
            {
                try
                {
                    var teamiteration = iterations.FirstOrDefault(x => x.path == item.IterationPath && x.team == item.teamName);
                    CurrentTeamCapacity currentTeamCapacity = new CurrentTeamCapacity();
                    TotalTeamCapacity   totalTeamCapacity   = new TotalTeamCapacity();
                    double currentCapacity = 0;
                    double TotalCapacity   = 0;
                    if (teamiteration != null)
                    {
                        currentTeamCapacity.iterationPath = teamiteration.path;
                        currentTeamCapacity.teamName      = teamiteration.team;
                        double currDays = Convert.ToDouble(DateTime.Now.ToString().GetBusinessDays(teamiteration.attributes.finishDate));
                        if (currDays > 0 && currDays < 1)
                        {
                            currDays = 1;
                        }
                        currentTeamCapacity.currentWorkingDays = currDays < 0 ? "0" :Convert.ToInt32(currDays).ToString();
                        totalTeamCapacity.iterationPath        = teamiteration.path;
                        totalTeamCapacity.teamName             = teamiteration.team;
                        totalTeamCapacity.iterationStart       = Convert.ToDateTime(teamiteration.attributes.startDate).ToString("MM/dd/yyyy");
                        totalTeamCapacity.iterationEnd         = Convert.ToDateTime(teamiteration.attributes.finishDate).ToString("MM/dd/yyyy");
                        totalTeamCapacity.totalWorkingDays     = teamiteration.attributes.startDate.GetBusinessDays(teamiteration.attributes.finishDate);

                        foreach (var member in item.value)
                        {
                            CapacitybyTeamMember capacitybyTeamMember = new CapacitybyTeamMember();
                            LeavesbyTeamMember   leavesbyTeamMember   = new LeavesbyTeamMember();
                            currentCapacity += (Convert.ToDouble(member.activities[0].capacityPerDay));

                            capacitybyTeamMember.teamMember     = member.teamMember.displayName;
                            capacitybyTeamMember.iterationPath  = teamiteration.path;
                            capacitybyTeamMember.iterationStart = Convert.ToDateTime(teamiteration.attributes.startDate).ToString("MM/dd/yyyy");
                            capacitybyTeamMember.iterationEnd   = Convert.ToDateTime(teamiteration.attributes.finishDate).ToString("MM/dd/yyyy");
                            capacitybyTeamMember.capacityPerDay = member.activities[0].capacityPerDay;
                            capacitybyTeamMember.teamName       = teamiteration.team;
                            capacity.capacitybyTeamMembers.Add(capacitybyTeamMember);

                            leavesbyTeamMember.teamMember = member.teamMember.displayName;
                            leavesbyTeamMember.teamName   = teamiteration.team;
                            leavesbyTeamMember.LeaveFrom  = "";
                            leavesbyTeamMember.LeaveTo    = "";
                            if (member.daysOff.Count > 0)
                            {
                                string fromleave = string.Empty;
                                string toleave   = string.Empty;
                                foreach (var val in member.daysOff)
                                {
                                    fromleave = val.start;
                                    toleave   = val.end;
                                    leavesbyTeamMember.LeaveFrom = Convert.ToDateTime(fromleave).ToString("MM/dd/yyyy");
                                    leavesbyTeamMember.LeaveTo   = Convert.ToDateTime(toleave).ToString("MM/dd/yyyy");
                                }
                                string diff = fromleave.DateDifference(toleave);
                                leavesbyTeamMember.NoOfdaysLeave = diff == "0" ? "1" : diff;
                            }
                            else
                            {
                                leavesbyTeamMember.LeaveFrom     = "";
                                leavesbyTeamMember.LeaveTo       = "";
                                leavesbyTeamMember.NoOfdaysLeave = "";
                            }
                            leavesbyTeamMember.iterationPath = teamiteration.path;
                            capacity.leavesbyTeamMembers.Add(leavesbyTeamMember);
                        }
                        currentTeamCapacity.currentCapacity = (currentCapacity * Convert.ToDouble(currentTeamCapacity.currentWorkingDays)).ToString();
                        totalTeamCapacity.totalCapacity     = (currentCapacity * Convert.ToDouble(totalTeamCapacity.totalWorkingDays)).ToString();
                        capacity.currentTeamCapacities.Add(currentTeamCapacity);
                        capacity.totalTeamCapacities.Add(totalTeamCapacity);
                    }
                }
                catch (Exception ex)
                {
                }
            }
            return(capacity);
        }