Beispiel #1
0
        public JsonResult <ResponseModel> Count(RequestModel requestModel)
        {
            ResponseModel responseModel = new ResponseModel();

            try
            {
                using (var client = new HttpClient())
                {
                    string projName     = requestModel.Project_Name;
                    string workitemType = requestModel.WI_Type;
                    if (requestModel.WI_Type != "ALL")
                    {
                        string          queryString  = @"select [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] from workitems WHERE [System.TeamProject] = '" + projName + "' AND [System.WorkItemType] = '" + workitemType + "'";
                        var             wiql         = new { query = queryString };
                        var             content      = Newtonsoft.Json.JsonConvert.SerializeObject(wiql);
                        string          url          = "https://dev.azure.com/" + org + "/_apis/wit/wiql?api-version=5.1";
                        CountvalueModel wiqlResponse = Store.GetApi <CountvalueModel>(url, pat, "POST", content);
                        if (wiqlResponse != null)
                        {
                            responseModel.Request_ID = requestModel.Request_ID;
                            responseModel.Status     = "Success";
                            responseModel.Details    = new Detail {
                                Count = wiqlResponse.workItems.Count
                            };
                            responseModel.WI_Details = null;
                            return(Json(responseModel));
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        string          queryString  = @"select [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] from workitems WHERE [System.TeamProject] = '" + projName + "'";
                        var             wiql         = new { query = queryString };
                        var             content      = Newtonsoft.Json.JsonConvert.SerializeObject(wiql);
                        string          url          = "https://dev.azure.com/" + org + "/_apis/wit/wiql?api-version=5.1";
                        CountvalueModel wiqlResponse = Store.GetApi <CountvalueModel>(url, pat, "POST", content);
                        if (wiqlResponse != null)
                        {
                            responseModel.Request_ID = requestModel.Request_ID;
                            responseModel.Status     = "Success";
                            responseModel.Details    = new Detail {
                                Count = wiqlResponse.workItems.Count
                            };
                            responseModel.WI_Details = null;
                            return(Json(responseModel));
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Beispiel #2
0
        public JsonResult <ResponseModel> Sum(RequestModel requestModel)
        {
            ResponseModel responseModel = new ResponseModel();

            try
            {
                using (var client = new HttpClient())
                {
                    string projName     = requestModel.Project_Name;
                    string workitemType = requestModel.WI_Type;
                    string fieldName    = requestModel.Field_Name;

                    if (fieldName == null)
                    {
                        responseModel.Request_ID      = requestModel.Request_ID;
                        responseModel.Status          = "Failure";
                        responseModel.Failure_Message = "Field Name not entered";
                        return(Json(responseModel));
                    }
                    else if (fieldName != null && workitemType != null && projName != null)
                    {
                        string          queryString  = @"select  " + fieldName + " from workitems WHERE [System.TeamProject] = '" + projName + "' AND [System.WorkItemType] = '" + workitemType + "'";
                        var             wiql         = new { query = queryString };
                        var             content      = Newtonsoft.Json.JsonConvert.SerializeObject(wiql);
                        string          url          = "https://dev.azure.com/" + org + "/_apis/wit/wiql?api-version=5.1";
                        CountvalueModel wiqlResponse = Store.GetApi <CountvalueModel>(url, pat, "POST", content);
                        string          defaultUrl   = "https://dev.azure.com/" + org + "/_apis/wit/workitems?ids=";
                        url = defaultUrl;
                        WorkItemReponseModel workItemReponse = new WorkItemReponseModel();
                        workItemReponse.value = new List <WIDetail>();
                        string endUrl = "&$expand=all&api-version=5.1";

                        //QueryValue testData = JsonConvert.DeserializeObject<QueryValue>(wiqlResponse);
                        for (int j = 0; j < wiqlResponse.workItems.Count(); j++)
                        {
                            if (j % 200 == 0 && j != 0)
                            {
                                var batchResponse = Store.GetApi <WorkItemReponseModel>(url + endUrl, pat);
                                workItemReponse.count += batchResponse.count;
                                foreach (var item in batchResponse.value)
                                {
                                    workItemReponse.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 <WorkItemReponseModel>(url, pat);
                        workItemReponse.count   += lastBatchResponse.count;
                        responseModel.Request_ID = requestModel.Request_ID;
                        responseModel.Status     = "Success";
                        foreach (var items in lastBatchResponse.value)
                        {
                            workItemReponse.value.Add(items);
                        }
                        Double summation = 0;
                        for (int i = 0; i < lastBatchResponse.value.Count; i++)
                        {
                            summation += double.Parse(lastBatchResponse.value[i].fields["Microsoft.VSTS.Scheduling.Effort"].ToString());
                        }
                        responseModel.Details = new Detail {
                            Sum = summation
                        };

                        responseModel.WI_Details = new List <WIDetail>();

                        responseModel.WI_Details.AddRange(workItemReponse.value);

                        return(Json(responseModel));
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(null);
        }