public ActionResult Export(InputModel inp)
        {
            //var data = .Data;
            ResponseWI response = new ResponseWI();

            response.value = new List <Value>();
            response       = (ResponseWI)Filter(inp, 1);
            //response.value = JsonConvert.DeserializeObject<List<Value>>(new JavaScriptSerializer().Serialize(Filter(inp,1).Data));
            generateExcel(response, inp);
            return(RedirectToAction("../WIReport/Index"));
        }
        public JsonResult getWorkItembyType(InputModel inp)
        {
            ResponseWI Witems = new ResponseWI();

            if (Session["WorkItems"] == null)
            {
                WITypes(inp);
            }
            Witems = (ResponseWI)Session["WorkItems"];
            var result = Json(Witems.value.Where(x => x.fields.WorkItemType == inp.WorkItemType.Trim()), JsonRequestBehavior.AllowGet);

            return(result);
        }
Ejemplo n.º 3
0
        public JsonResult WITypesCount(string orgName)
        {
            Dictionary <string, Dictionary <string, int> > CountByProject = new Dictionary <string, Dictionary <string, int> >();
            Dictionary <string, int> CountByOrg = new Dictionary <string, int>();
            var pm = service.GetApi <ProjectModel>("https://dev.azure.com/" + orgName + "/_apis/projects?api-version=5.1");

            foreach (var project in pm.Value)
            {
                var        response            = service.GetApi <distribution_copy.Models.WorkItemType.WorkItemType>("https://dev.azure.com/" + orgName + "/" + project.Name + "/_apis/wit/workitemtypes?api-version=5.1");
                ResponseWI responseType        = new ResponseWI();
                Dictionary <string, int> types = new Dictionary <string, int>();
                foreach (var TypeName in response.Value)
                {
                    string       queryString = "Select [Id] From WorkItems Where [System.WorkItemType] = '" + TypeName.Name + "' And [System.TeamProject]='" + project.Name + "'";
                    ProjectModel model       = new ProjectModel();
                    string       url         = "https://dev.azure.com/" + orgName + "/_apis/wit/wiql?api-version=5.1";
                    var          wiql        = new
                    {
                        query = queryString
                    };
                    var content = JsonConvert.SerializeObject(wiql);

                    responseType = service.GetApi <ResponseWI>(url, "POST", content);
                    if (responseType.workItems.Count != 0)
                    {
                        types.Add(TypeName.Name, responseType.workItems.Count);
                    }
                }
                CountByProject.Add(project.Name, types);
            }
            foreach (var proj in CountByProject.Keys)
            {
                foreach (var Type in CountByProject[proj].Keys)
                {
                    if (CountByOrg.ContainsKey(Type))
                    {
                        CountByOrg[Type] += CountByProject[proj][Type];
                    }
                    else
                    {
                        CountByOrg.Add(Type, CountByProject[proj][Type]);
                    }
                }
            }
            ChartCountModel chartCount = new ChartCountModel();

            chartCount.CountByOrg     = CountByOrg;
            chartCount.CountByProject = CountByProject;
            return(Json(chartCount));
        }
        public JsonResult WITypes(InputModel inp)
        {
            ResponseWI wiqlResponse = new ResponseWI();

            ResponseWI urlResponse  = new ResponseWI();
            string     responseBody = "";
            string     queryString  = @"Select [Work Item Type],[State], [Title],[Created By] From WorkItems ";

            queryString += "Order By [Stack Rank] Desc, [Backlog Priority] Desc";
            var wiql = new
            {
                query = queryString
            };

            using (var client = new HttpClient())
            {
                var content = new StringContent(JsonConvert.SerializeObject(wiql), Encoding.UTF8, "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()))));
                var request = new HttpRequestMessage(
                    new HttpMethod("POST"),
                    "https://dev.azure.com/" + inp.OrganizationName + "/_apis/wit/wiql?api-version=5.1"
                    )
                {
                    Content = content
                };
                var response = client.SendAsync(request).Result;
                if (response.IsSuccessStatusCode)
                {
                    responseBody = response.Content.ReadAsStringAsync().Result;
                }
                wiqlResponse = JsonConvert.DeserializeObject <ResponseWI>(responseBody);
            }

            if (wiqlResponse.workItems == null || wiqlResponse.workItems.Count == 0)
            {
                return(null);
            }
            string defaultUrl = "https://dev.azure.com/" + inp.OrganizationName + "/_apis/wit/workitems?ids=";

            url = defaultUrl;
            urlResponse.value = new List <Value>();
            string b = "&api-version=5.1";

            for (int j = 0; j < wiqlResponse.workItems.Count; j++)
            {
                if (j % 200 == 0 && j != 0)
                {
                    var batchResponse = getWorkItems(inp);
                    urlResponse.count += batchResponse.count;
                    foreach (var item in batchResponse.value)
                    {
                        urlResponse.value.Add(item);
                    }
                    url = defaultUrl;
                }
                if (j % 200 == 0)
                {
                    url += wiqlResponse.workItems[j].id;
                }
                else
                {
                    url += "," + wiqlResponse.workItems[j].id;
                }
            }
            url += b;

            var lastBatchResponse = getWorkItems(inp);

            urlResponse.count += lastBatchResponse.count;
            foreach (var item in lastBatchResponse.value)
            {
                urlResponse.value.Add(item);
            }
            Session["WorkItems"] = urlResponse;
            List <string> Types = new List <string>();

            foreach (var i in urlResponse.value)
            {
                if (!Types.Contains(i.fields.WorkItemType))
                {
                    Types.Add(i.fields.WorkItemType);
                }
            }
            return(Json(Types, JsonRequestBehavior.AllowGet));
        }
        public void generateExcel(ResponseWI wi, InputModel inp)
        {
            ExcelPackage excel     = new ExcelPackage();
            var          workSheet = excel.Workbook.Worksheets.Add("WorkItems");

            workSheet.TabColor         = System.Drawing.Color.White;
            workSheet.DefaultRowHeight = 12;
            workSheet.Row(1).Height    = 20;
            workSheet.Row(1).Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
            workSheet.Row(1).Style.Font.Bold           = true;
            workSheet.Cells[1, 1].Value  = "ID";
            workSheet.Cells[1, 2].Value  = "Work Item Type";
            workSheet.Cells[1, 3].Value  = "Title";
            workSheet.Cells[1, 4].Value  = "Team Project";
            workSheet.Cells[1, 5].Value  = "Assigned To";
            workSheet.Cells[1, 6].Value  = "State";
            workSheet.Cells[1, 7].Value  = "Url";
            workSheet.Cells[1, 8].Value  = "PlannedHours";
            workSheet.Cells[1, 9].Value  = "ActualHours";
            workSheet.Cells[1, 10].Value = "Sprint";
            workSheet.Cells[1, 11].Value = "OriginalEstimate";
            workSheet.Cells[1, 12].Value = "CompletedWork";
            workSheet.Cells[1, 13].Value = "RemainingWork";
            workSheet.Cells[1, 14].Value = "CreatedDate";
            workSheet.Cells[1, 15].Value = "Description";
            workSheet.Cells[1, 16].Value = "CreatedBy";
            workSheet.Cells[1, 17].Value = "AssignedTo";
            workSheet.Cells[1, 18].Value = "ChangedBy";
            int recordIndex = 2;
            int columnNo    = 0;

            foreach (var WI in wi.value)
            {
                columnNo = 0;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.id;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.WorkItemType;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.Title;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.TeamProject;
                if (WI.fields.AssignedTo != null)
                {
                    workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.AssignedTo.displayName;
                }
                else
                {
                    workSheet.Cells[recordIndex, ++columnNo].Value = "Unassigned";
                }
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.State;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.url;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.PlannedHours;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.ActualHours;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.Sprint;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.OriginalEstimate;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.CompletedWork;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.RemainingWork;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.CreatedDate.ToShortDateString();
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.Description;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.CreatedBy == null ? "" : WI.fields.CreatedBy.displayName;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.AssignedTo == null ? "" : WI.fields.AssignedTo.displayName;
                workSheet.Cells[recordIndex, ++columnNo].Value = WI.fields.ChangedBy == null ? "" : WI.fields.ChangedBy.displayName;
                recordIndex++;
            }
            for (var i = 1; i <= columnNo; i++)
            {
                workSheet.Column(i).AutoFit();
            }
            string excelName = inp.OrganizationName + "-" + (inp.ProjectName != null ? inp.ProjectName : "") + "-" + (inp.WorkItemType != null ? inp.WorkItemType : "") + DateTime.Now.ToString();

            using (var memoryStream = new MemoryStream())
            {
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment; filename=" + excelName + ".xlsx");
                excel.SaveAs(memoryStream);
                memoryStream.WriteTo(Response.OutputStream);
                Response.Flush();
                Response.End();
            }
        }
        public object Filter(InputModel inp, int loc)
        {
            ResponseWI wI       = (ResponseWI)Session["WorkItems"];
            ResponseWI returnWI = new ResponseWI();

            if (inp.ProjectName != null && inp.ProjectName != "Empty List" && inp.ProjectName != "0")
            {
                returnWI.value = new List <Value>();
                foreach (var i in wI.value)
                {
                    if (i.fields.TeamProject == inp.ProjectName)
                    {
                        returnWI.value.Add(i);
                    }
                }
            }
            else
            {
                returnWI = wI;
            }

            ResponseWI returnWI2 = new ResponseWI();

            if (inp.WorkItemType != null && inp.WorkItemType != "Empty List" && inp.WorkItemType != "0")
            {
                returnWI2.value = new List <Value>();
                foreach (var i in returnWI.value)
                {
                    if (i.fields.WorkItemType == inp.WorkItemType)
                    {
                        returnWI2.value.Add(i);
                    }
                }
            }
            else
            {
                returnWI2 = returnWI;
            }

            ResponseWI returnWI3 = new ResponseWI();

            if (inp.AssignedTo != null && inp.AssignedTo != "Empty List" && inp.AssignedTo != "0")
            {
                returnWI3.value = new List <Value>();
                foreach (var i in returnWI2.value)
                {
                    if (i.fields.AssignedTo != null)
                    {
                        if (i.fields.AssignedTo.uniqueName == inp.AssignedTo || i.fields.AssignedTo.displayName == inp.AssignedTo)
                        {
                            returnWI3.value.Add(i);
                        }
                    }
                }
            }
            else
            {
                returnWI3 = returnWI2;
            }

            ResponseWI returnWI4 = new ResponseWI();

            if (inp.Sprint != null && inp.Sprint != "Empty List" && inp.Sprint != "0")
            {
                returnWI4.value = new List <Value>();
                foreach (var i in returnWI3.value)
                {
                    if (i.fields.Sprint == inp.Sprint)
                    {
                        returnWI4.value.Add(i);
                    }
                }
            }
            else
            {
                returnWI4 = returnWI3;
            }

            ResponseWI returnWI5 = new ResponseWI();

            if (inp.State != null && inp.State != "Empty List" && inp.State != "0")
            {
                returnWI5.value = new List <Value>();
                foreach (var i in returnWI4.value)
                {
                    if (i.fields.State == inp.State)
                    {
                        returnWI5.value.Add(i);
                    }
                }
            }
            else
            {
                returnWI5 = returnWI4;
            }

            ResponseWI FilteredWI = new ResponseWI();

            if (inp.CreatedDate != null && inp.CreatedDate != "")
            {
                FilteredWI.value = new List <Value>();
                foreach (var i in returnWI5.value)
                {
                    if (i.fields.CreatedDate.Date >= DateTime.Parse(inp.CreatedDate))
                    {
                        FilteredWI.value.Add(i);
                    }
                }
            }
            else
            {
                FilteredWI = returnWI5;
            }
            if (loc > 0)
            {
                return(FilteredWI);
            }
            else
            {
                string output = JsonConvert.SerializeObject(FilteredWI.value);
                //return Json(FilteredWI.value, JsonRequestBehavior.AllowGet);
                return(output);
            }
        }
        public JsonResult AllList(InputModel inp)
        {
            ResponseWI Witems = new ResponseWI();

            if (Session["WorkItems"] == null)
            {
                WITypes(inp);
            }

            List <string> WorkItemList   = new List <string>();
            List <string> AssignedToList = new List <string>();
            List <string> SprintList     = new List <string>();
            List <string> StateList      = new List <string>();

            foreach (var i in ((ResponseWI)Session["WorkItems"]).value.Where(x => x.fields.TeamProject == inp.ProjectName))
            {
                if (i.fields.AssignedTo != null)
                {
                    if (i.fields.AssignedTo.uniqueName != null)
                    {
                        if (!AssignedToList.Contains(i.fields.AssignedTo.uniqueName))
                        {
                            AssignedToList.Add(i.fields.AssignedTo.uniqueName);
                        }
                    }
                    else
                    {
                        if (!AssignedToList.Contains(i.fields.AssignedTo.displayName))
                        {
                            AssignedToList.Add(i.fields.AssignedTo.displayName);
                        }
                    }
                }
                if (i.fields.Sprint != null)
                {
                    if (!SprintList.Contains(i.fields.Sprint))
                    {
                        SprintList.Add(i.fields.Sprint);
                    }
                }
                if (i.fields.State != null)
                {
                    if (!StateList.Contains(i.fields.State))
                    {
                        StateList.Add(i.fields.State);
                    }
                }
                if (i.fields.WorkItemType != null)
                {
                    if (!WorkItemList.Contains(i.fields.WorkItemType))
                    {
                        WorkItemList.Add(i.fields.WorkItemType);
                    }
                }
            }
            List <List <string> > all = new List <List <string> >();

            all.Add(AssignedToList);
            all.Add(SprintList);
            all.Add(StateList);
            all.Add(WorkItemList);
            return(Json(all, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 8
0
        //
        public List <ValueNew> Workitemlist123(string projectName)
        {
            Session.Remove("WorkItemscount");
            WorkNew urlResponse = new WorkNew();
            //  string queryString = @"Select [Work Item Type]= 'Bug',[State], [Title],[Created By] From WorkItems ";
            //  if (Org.ProjectName != null)
            //      //WHERE[System.AssignedTo] = 'joselugo'  WHERE[Adatum.CustomMethodology.Severity] >= 2
            //      queryString += "where [System.TeamProject]='" + projectName + "' "; //+ Org.ProjectName + "' ";
            ////  queryString += "Order By [Stack Rank] Desc, [Backlog Priority] Desc";
            //  var wiql = new { query = queryString };
            //  var content = JsonConvert.SerializeObject(wiql);
            string url  = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/wiql?api-version=5.1";
            object wiql = new
            {
                query = "Select [Work Item Type],[State], [Title],[Created By] " +
                        "From WorkItems " +
                        // "Where [Work Item Type] = '" + workItemName + "' " +
                        "Where [Work Item Type] = 'Bug' " +
                        //"OR [Work Item Type]='Task'" +
                        //"OR [Work Item Type]='Feature'" +
                        //"And [Work Item Type] = 'Epic' " +
                        "And [System.TeamProject] = '" + projectName + "' " +
                        "Order By [Stack Rank] Desc, [Backlog Priority] Desc"
            };
            var postValue = new StringContent(JsonConvert.SerializeObject(wiql), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Org.pat);
                var response = client.PostAsync(url, postValue).Result;
            }

            var        content      = JsonConvert.SerializeObject(wiql);
            ResponseWI wiqlResponse = Store.GetApi <ResponseWI>(url, "POST", content);

            if (wiqlResponse.workItems == null || wiqlResponse.workItems.Count == 0)
            {
                return(null);
            }

            string defaultUrl = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/workitems?ids=";

            url = defaultUrl;
            urlResponse.value = new List <ValueNew>();
            string endUrl = "&$expand=all&api-version=5.1";

            for (int j = 0; j < wiqlResponse.workItems.Count; j++)
            {
                if (j % 200 == 0 && j != 0)
                {
                    var batchResponse = Store.GetApi <WorkNew>(url + endUrl);
                    urlResponse.count += batchResponse.count;
                    foreach (var item in batchResponse.value)
                    {
                        urlResponse.value.Add(item);
                    }
                    url = defaultUrl;
                }
                if (j % 200 == 0)
                {
                    url += wiqlResponse.workItems[j].id;
                }
                else
                {
                    url += "," + wiqlResponse.workItems[j].id;
                }
            }
            url += endUrl;
            var lastBatchResponse = Store.GetApi <WorkNew>(url);

            urlResponse.count += lastBatchResponse.count;
            foreach (var item in lastBatchResponse.value)
            {
                urlResponse.value.Add(item);
            }


            System.Web.HttpContext.Current.Session["EWorkItems"] = urlResponse;
            List <ValueNew>         Types               = new List <ValueNew>();
            List <ValueNew>         BugFind             = new List <ValueNew>();
            List <IterationDetails> iterationsListStore = new List <IterationDetails>();

            iterationsListStore       = IterationsList(Org.OrganizationName, projectName);//Org.ProjectName);
            Session["WorkItemscount"] = urlResponse.count;
            ViewBag.WorkItemscount    = urlResponse.count;
            foreach (var i in urlResponse.value)
            {
                if (i.fields.WorkItemType == "Bug" && i.fields.Severity == "1 - Critical")
                {
                    //BugDetails bugStore=BugDetails(i.id);
                    //if(bugStore.fields.Severity== "1 - Critical")
                    //{
                    Types.Add(i);
                    // }
                    //&& i.fields.Severity == "1 - Critical"
                    //  if (!Types.Contains(i.fields.__invalid_name__SystemWorkItemType))
                    //    Types.Add(i);//.__invalid_name__SystemWorkItemType);
                }
            }
            //string output = JsonConvert.SerializeObject(Types);
            //return Json(Types, JsonRequestBehavior.AllowGet);
            //Session["criticalBug"] = Types;
            return(Types);
        }
Ejemplo n.º 9
0
        //public JsonResult WorkitemDeadline()
        public List <ValueNew> WorkitemDeadlineGet(string projectName)
        {
            Session.Remove("WorkItemstotal");
            WorkNew urlResponse = new WorkNew();
            string  queryString = @"Select [Work Item Type],[State], [Title],[Created By] From WorkItems ";

            if (Org.ProjectName != null)
            {
                queryString += "where [System.TeamProject]='" + projectName + "' "; //+ Org.ProjectName + "' ";
            }
            queryString += "Order By [Stack Rank] Desc, [Backlog Priority] Desc";
            var        wiql         = new { query = queryString };
            var        content      = JsonConvert.SerializeObject(wiql);
            string     url          = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/wiql?api-version=5.1";
            ResponseWI wiqlResponse = Store.GetApi <ResponseWI>(url, "POST", content);

            if (wiqlResponse.workItems == null || wiqlResponse.workItems.Count == 0)
            {
                return(null);
            }

            //if (wiqlResponse.count >= 0)
            //{
            //    Session["WorkItemstotal"] = wiqlResponse.count;
            //}
            string defaultUrl = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/workitems?ids=";

            url = defaultUrl;
            urlResponse.value = new List <ValueNew>();
            string endUrl = "&$expand=all&api-version=5.1";

            for (int j = 0; j < wiqlResponse.workItems.Count; j++)
            {
                if (j % 200 == 0 && j != 0)
                {
                    var batchResponse = Store.GetApi <WorkNew>(url + endUrl);
                    urlResponse.count += batchResponse.count;
                    foreach (var item in batchResponse.value)
                    {
                        urlResponse.value.Add(item);
                    }
                    url = defaultUrl;
                }
                if (j % 200 == 0)
                {
                    url += wiqlResponse.workItems[j].id;
                }
                else
                {
                    url += "," + wiqlResponse.workItems[j].id;
                }
            }
            url += endUrl;
            var lastBatchResponse = Store.GetApi <WorkNew>(url);

            urlResponse.count += lastBatchResponse.count;
            foreach (var item in lastBatchResponse.value)
            {
                urlResponse.value.Add(item);
            }

            System.Web.HttpContext.Current.Session["EWorkItems"] = urlResponse;
            List <ValueNew>         Types               = new List <ValueNew>();
            List <ValueNew>         Types1              = new List <ValueNew>();
            List <ValueNew>         BugFind             = new List <ValueNew>();
            List <IterationDetails> iterationsListStore = new List <IterationDetails>();

            iterationsListStore       = IterationsList(Org.OrganizationName, projectName);//Org.ProjectName);
            Session["WorkItemstotal"] = urlResponse.count;
            ViewBag.WorkItemstotal    = urlResponse.count;
            int sessioncount = 0;

            foreach (var i in urlResponse.value)
            {
                i.totalworkItemCounts = urlResponse.count;
                //Types.Add(i);
                sessioncount += 1;
                if (i.fields.WorkItemType == "Bug" || i.fields.WorkItemType == "Task" || i.fields.WorkItemType == "UserStory")
                {
                    foreach (var iter in iterationsListStore)
                    {
                        foreach (var iter1 in iter.value)
                        {
                            if (i.fields.Sprint == iter1.path)
                            {
                                DateTime finishDate       = Convert.ToDateTime(iter1.attributes.finishDate);
                                string   fin              = finishDate.ToString(DateTime.Now.ToString("MM/dd/yyyy"));
                                string   toDate           = DateTime.Now.ToString("MM/dd/yyyy");
                                var      Today            = DateTime.Today;
                                string   finishDateSprint = iter1.attributes.finishDate;
                                // DateTime finishdateConvert=new DateTime();

                                int value = DateTime.Compare(finishDate, Today);

                                DateTime date = Convert.ToDateTime("01-01-0001 00:00:00");
                                // checking
                                if (finishDate != null && finishDate != date)
                                {
                                    if (value < 0)
                                    {
                                        Types.Add(i);
                                    }
                                }
                            }
                        }
                    }
                }
            }


            Session["WorkItemExtendedDate"] = Types;

            return(Types);//return output;
        }
Ejemplo n.º 10
0
        //public JsonResult Workitem()
        //{
        //    logic.GetWorkItem();
        //    return null;
        //}

        // public JsonResult Workitem()
        public List <ValueNew> Workitemlist(string projectName)
        {
            Session.Remove("WorkItemscount");
            WorkNew urlResponse = new WorkNew();
            string  queryString = @"Select [Work Item Type],[State], [Title],[Created By] From WorkItems ";

            if (Org.ProjectName != null)
            {
                queryString += "where [System.TeamProject]='" + projectName + "' "; //+ Org.ProjectName + "' ";
            }
            queryString += "Order By [Stack Rank] Desc, [Backlog Priority] Desc";
            var        wiql         = new { query = queryString };
            var        content      = JsonConvert.SerializeObject(wiql);
            string     url          = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/wiql?api-version=5.1";
            ResponseWI wiqlResponse = Store.GetApi <ResponseWI>(url, "POST", content);

            if (wiqlResponse.workItems == null || wiqlResponse.workItems.Count == 0)
            {
                return(null);
            }

            string defaultUrl = "https://dev.azure.com/" + Org.OrganizationName + "/_apis/wit/workitems?ids=";

            url = defaultUrl;
            urlResponse.value = new List <ValueNew>();
            string endUrl = "&$expand=all&api-version=5.1";

            for (int j = 0; j < wiqlResponse.workItems.Count; j++)
            {
                if (j % 200 == 0 && j != 0)
                {
                    var batchResponse = Store.GetApi <WorkNew>(url + endUrl);
                    urlResponse.count += batchResponse.count;
                    foreach (var item in batchResponse.value)
                    {
                        urlResponse.value.Add(item);
                    }
                    url = defaultUrl;
                }
                if (j % 200 == 0)
                {
                    url += wiqlResponse.workItems[j].id;
                }
                else
                {
                    url += "," + wiqlResponse.workItems[j].id;
                }
            }
            url += endUrl;
            var lastBatchResponse = Store.GetApi <WorkNew>(url);

            urlResponse.count += lastBatchResponse.count;
            foreach (var item in lastBatchResponse.value)
            {
                urlResponse.value.Add(item);
            }


            System.Web.HttpContext.Current.Session["EWorkItems"] = urlResponse;
            List <ValueNew>         Types               = new List <ValueNew>();
            List <ValueNew>         BugFind             = new List <ValueNew>();
            List <IterationDetails> iterationsListStore = new List <IterationDetails>();

            iterationsListStore       = IterationsList(Org.OrganizationName, projectName);//Org.ProjectName);
            Session["WorkItemscount"] = urlResponse.count;
            ViewBag.WorkItemscount    = urlResponse.count;
            foreach (var i in urlResponse.value)
            {
                if (i.fields.WorkItemType == "Bug" && i.fields.Severity == "1 - Critical")
                {
                    //BugDetails bugStore=BugDetails(i.id);
                    //if(bugStore.fields.Severity== "1 - Critical")
                    //{
                    Types.Add(i);
                    // }
                    //&& i.fields.Severity == "1 - Critical"
                    //  if (!Types.Contains(i.fields.__invalid_name__SystemWorkItemType))
                    //    Types.Add(i);//.__invalid_name__SystemWorkItemType);
                }
            }
            //string output = JsonConvert.SerializeObject(Types);
            //return Json(Types, JsonRequestBehavior.AllowGet);
            //Session["criticalBug"] = Types;
            return(Types);
        }
Ejemplo n.º 11
0
        public JsonResult WITypes(InputModel inp)
        {
            RootObject urlResponse = new RootObject();
            string     queryString = @"Select [Work Item Type],[State], [Title],[Created By] From WorkItems ";

            if (inp.ProjectName != null)
            {
                queryString += "where [System.TeamProject]='" + inp.ProjectName + "' ";
            }
            queryString += "Order By [Stack Rank] Desc, [Backlog Priority] Desc";
            var        wiql         = new{ query = queryString };
            var        content      = JsonConvert.SerializeObject(wiql);
            string     url          = "https://dev.azure.com/" + inp.OrganizationName + "/_apis/wit/wiql?api-version=5.1";
            ResponseWI wiqlResponse = Account.GetApi <ResponseWI>(url, "POST", content);

            if (wiqlResponse.workItems == null || wiqlResponse.workItems.Count == 0)
            {
                return(null);
            }
            string defaultUrl = "https://dev.azure.com/" + inp.OrganizationName + "/_apis/wit/workitems?ids=";

            url = defaultUrl;
            urlResponse.value = new List <Models.ExpandWI.Value>();
            string endUrl = "&$expand=all&api-version=5.1";

            for (int j = 0; j < wiqlResponse.workItems.Count; j++)
            {
                if (j % 200 == 0 && j != 0)
                {
                    var batchResponse = Account.GetApi <RootObject>(url + endUrl);
                    urlResponse.count += batchResponse.count;
                    foreach (var item in batchResponse.value)
                    {
                        urlResponse.value.Add(item);
                    }
                    url = defaultUrl;
                }
                if (j % 200 == 0)
                {
                    url += wiqlResponse.workItems[j].id;
                }
                else
                {
                    url += "," + wiqlResponse.workItems[j].id;
                }
            }
            url += endUrl;
            var lastBatchResponse = Account.GetApi <RootObject>(url);

            urlResponse.count += lastBatchResponse.count;
            foreach (var item in lastBatchResponse.value)
            {
                urlResponse.value.Add(item);
            }

            System.Web.HttpContext.Current.Session["EWorkItems"] = urlResponse;
            List <string> Types = new List <string>();

            foreach (var i in urlResponse.value)
            {
                if (!Types.Contains(i.fields.WorkItemType))
                {
                    Types.Add(i.fields.WorkItemType);
                }
            }
            return(Json(Types, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 12
0
        public JsonResult WITypes(InputModel inp)
        {
            ResponseWI urlResponse = new ResponseWI();
            string     queryString = @"Select [Work Item Type],[State], [Title],[Created By] From WorkItems ";

            queryString += "Order By [Stack Rank] Desc, [Backlog Priority] Desc";
            var wiql = new
            {
                query = queryString
            };
            var        content      = JsonConvert.SerializeObject(wiql);
            var        Uri          = "https://dev.azure.com/" + inp.OrganizationName + "/_apis/wit/wiql?api-version=5.1";
            ResponseWI wiqlResponse = service.GetApi <ResponseWI>(Uri, "POST", content);

            if (wiqlResponse == null)
            {
                return(null);
            }

            if (wiqlResponse.workItems == null || wiqlResponse.workItems.Count == 0)
            {
                return(null);
            }
            string defaultUrl = "https://dev.azure.com/" + inp.OrganizationName + "/_apis/wit/workitems?ids=";

            url = defaultUrl;
            urlResponse.value = new List <Value>();
            string b = "&api-version=5.1";

            for (int j = 0; j < wiqlResponse.workItems.Count; j++)
            {
                if (j % 200 == 0 && j != 0)
                {
                    var batchResponse = service.GetApi <ResponseWI>(url + b);
                    urlResponse.count += batchResponse.count;
                    foreach (var item in batchResponse.value)
                    {
                        urlResponse.value.Add(item);
                    }
                    url = defaultUrl;
                }
                if (j % 200 == 0)
                {
                    url += wiqlResponse.workItems[j].id;
                }
                else
                {
                    url += "," + wiqlResponse.workItems[j].id;
                }
            }
            url += b;

            var lastBatchResponse = service.GetApi <ResponseWI>(url);

            urlResponse.count += lastBatchResponse.count;
            foreach (var item in lastBatchResponse.value)
            {
                urlResponse.value.Add(item);
            }
            Session["WorkItems"] = urlResponse;
            List <string> Types = new List <string>();

            foreach (var i in urlResponse.value)
            {
                if (!Types.Contains(i.fields.WorkItemType))
                {
                    Types.Add(i.fields.WorkItemType);
                }
            }
            return(Json(Types, JsonRequestBehavior.AllowGet));
        }