Ejemplo n.º 1
0
        public HttpResponseMessage GetCount([FromBody] vsts_project vsts_project)
        {
            SOAmodel            soamodel  = new SOAmodel();
            HttpResponseMessage response  = new HttpResponseMessage();;
            Result              objResult = new Result();
            SOABAL              soabal    = new SOABAL();
            HttpClient          client    = new HttpClient();
            HttpResponseMessage response1 = new HttpResponseMessage();
            string              str_guid  = Guid.NewGuid().ToString();

            try
            {
                soamodel = soabal.GetCount(vsts_project.vsts_projectname);

                if (soamodel != null)
                {
                    objResult.Results = soamodel;
                    objResult.Message = "true";
                    objResult.Status  = "true";
                    response          = Request.CreateResponse(HttpStatusCode.OK, objResult);
                }
                else
                {
                    objResult.Results = null;
                    objResult.Message = "false";
                    objResult.Status  = "false";
                    response          = Request.CreateResponse(HttpStatusCode.NotFound, "Data Empty!");
                }
                return(response);
            }
            catch (Exception ex)
            {
                response.StatusCode = HttpStatusCode.BadRequest;
                return(response);
            }
        }
Ejemplo n.º 2
0
        // Bug -  Approved,Committed,Done,New   // task - Done, In Progress,Removed,To Do
        #region Count
        /// <summary>
        /// Gives total number of bugs and task
        /// </summary>
        /// <returns>int</returns>
        public SOAmodel GetCount(string projectname)
        {
            SOAmodel soamodel            = new SOAmodel();
            Uri      uri                 = new Uri(ConfigurationManager.AppSettings["uri"]);
            string   personalAccessToken = ConfigurationManager.AppSettings["personalAccessToken"];
            // string project = ConfigurationManager.AppSettings["project"];

            VssBasicCredential credentials = new VssBasicCredential("", ConfigurationManager.AppSettings["personalAccessToken"]);

            // Bug -  Approved,Committed,Done,New   // task - Done, In Progress,Removed,To Do
            #region Bugs
            #region Approved_Bug_count
            //create a wiql object and build our query
            Wiql wiql = new Wiql()
            {
                Query = "Select [State], [Title] " +
                        "From WorkItems " +
                        " Where [Work Item Type] = 'Bug' " +
                        " And [System.TeamProject] = '" + projectname + "' " +
                        " And [System.State] = 'Approved'  " +
                        " Order By [State] Asc, [Changed Date] Desc"
            };

            //create instance of work item tracking http client
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                //execute the query to get the list of work items in the results
                WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;
                soamodel.approved_bugs = workItemQueryResult.WorkItems.Count();
            }
            #endregion

            #region Committed_Bug_count
            //create a wiql object and build our query
            Wiql wiql_commited = new Wiql()
            {
                Query = "Select [State], [Title] " +
                        "From WorkItems " +
                        " Where [Work Item Type] = 'Bug' " +
                        " And [System.TeamProject] = '" + projectname + "' " +
                        " And [System.State] = 'Committed'  " +
                        " Order By [State] Asc, [Changed Date] Desc"
            };

            //create instance of work item tracking http client
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                //execute the query to get the list of work items in the results
                WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql_commited).Result;
                soamodel.committed_bugs = workItemQueryResult.WorkItems.Count();
            }
            #endregion

            #region Done_Bug_count
            //create a wiql object and build our query
            Wiql wiql_done = new Wiql()
            {
                Query = "Select [State], [Title] " +
                        "From WorkItems " +
                        " Where [Work Item Type] = 'Bug' " +
                        " And [System.TeamProject] = '" + projectname + "' " +
                        " And [System.State] = 'Done'  " +
                        " Order By [State] Asc, [Changed Date] Desc"
            };

            //create instance of work item tracking http client
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                //execute the query to get the list of work items in the results
                WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql_done).Result;
                soamodel.done_bugs = workItemQueryResult.WorkItems.Count();
            }
            #endregion

            #region Approved_Bug_count
            //create a wiql object and build our query
            Wiql wiql_new = new Wiql()
            {
                Query = "Select [State], [Title] " +
                        "From WorkItems " +
                        " Where [Work Item Type] = 'Bug' " +
                        " And [System.TeamProject] = '" + projectname + "' " +
                        " And [System.State] = 'New'  " +
                        " Order By [State] Asc, [Changed Date] Desc"
            };

            //create instance of work item tracking http client
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                //execute the query to get the list of work items in the results
                WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql_new).Result;
                soamodel.new_bugs = workItemQueryResult.WorkItems.Count();
            }
            #endregion

            #endregion

            #region Task

            #region Done_Task_count
            //create a wiql object and build our query
            Wiql wiql_task_done = new Wiql()
            {
                Query = "Select [State], [Title] " +
                        "From WorkItems " +
                        " Where [Work Item Type] = 'Task' " +
                        " And [System.TeamProject] = '" + projectname + "' " +
                        " And [System.State] = 'Done'" +
                        " Order By [State] Asc, [Changed Date] Desc"
            };

            //create instance of work item tracking http client
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                //execute the query to get the list of work items in the results
                WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql_task_done).Result;
                soamodel.done_tasks = workItemQueryResult.WorkItems.Count();
            }
            #endregion

            #region In_Progress_Task_count
            //create a wiql object and build our query
            Wiql wiql_task_inprogress = new Wiql()
            {
                Query = "Select [State], [Title] " +
                        "From WorkItems " +
                        " Where [Work Item Type] = 'Task' " +
                        " And [System.TeamProject] = '" + projectname + "' " +
                        " And [System.State] = 'In Progress'" +
                        " Order By [State] Asc, [Changed Date] Desc"
            };

            //create instance of work item tracking http client
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                //execute the query to get the list of work items in the results
                WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql_task_inprogress).Result;
                soamodel.in_progress_tasks = workItemQueryResult.WorkItems.Count();
            }
            #endregion

            #region Removed_Task_count
            //create a wiql object and build our query
            Wiql wiql_task_removed = new Wiql()
            {
                Query = "Select [State], [Title] " +
                        "From WorkItems " +
                        " Where [Work Item Type] = 'Task' " +
                        " And [System.TeamProject] = '" + projectname + "' " +
                        " And [System.State] = 'Removed'" +
                        " Order By [State] Asc, [Changed Date] Desc"
            };

            //create instance of work item tracking http client
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                //execute the query to get the list of work items in the results
                WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql_task_removed).Result;
                soamodel.removed_tasks = workItemQueryResult.WorkItems.Count();
            }
            #endregion

            #region To_Do_Task_count
            //create a wiql object and build our query
            Wiql wiql_task_ToDo = new Wiql()
            {
                Query = "Select [State], [Title] " +
                        "From WorkItems " +
                        " Where [Work Item Type] = 'Task' " +
                        " And [System.TeamProject] = '" + projectname + "' " +
                        " And [System.State] = 'To Do'" +
                        " Order By [State] Asc, [Changed Date] Desc"
            };

            //create instance of work item tracking http client
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
            {
                //execute the query to get the list of work items in the results
                WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql_task_ToDo).Result;
                soamodel.to_do_tasks = workItemQueryResult.WorkItems.Count();
            }
            #endregion

            #endregion
            return(soamodel);
        }