コード例 #1
0
        //Author:Ravivarma (12/03/2020) -To get the count of all Workitems by types in the organisation

        public int GetWorkitemCountByType(string organisation, string workitemtype, string projectName)
        {
            APIRequest req;
            string     url;

            try
            {
                string       queryString = "Select  [Id] From WorkItems Where [System.WorkItemType] = '" + workitemtype + "' ";
                object       Wiql        = new { query = queryString };
                ProjectModel model       = new ProjectModel();
                url = "https://dev.azure.com/" + organisation + "/_apis/wit/wiql?api-version=5.1";
                req = new APIRequest(Session["PAT"].ToString());
                string response = req.ApiRequest(url, "POST", JsonConvert.SerializeObject(Wiql));
                model         = JsonConvert.DeserializeObject <ProjectModel>(response);
                c.WIcountType = model.WorkItems.Count;
                if (projectName != "0")
                {
                    queryString         = "Select  [Id] From WorkItems Where [System.WorkItemType] = '" + workitemtype + "' AND   [System.TeamProject] ='" + projectName + "'";
                    Wiql                = new { query = queryString };
                    url                 = "https://dev.azure.com/" + organisation + "/_apis/wit/wiql?api-version=5.1";
                    response            = req.ApiRequest(url, "POST", JsonConvert.SerializeObject(Wiql));
                    model               = JsonConvert.DeserializeObject <ProjectModel>(response);
                    c.ProjWIcountByType = model.WorkItems.Count;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(c.WIcountType);
        }
コード例 #2
0
        public void AllUsersCount(string organisation)
        {
            bool         added     = false;
            HttpClient   client    = new HttpClient();
            ProjectModel projModel = new ProjectModel();

            req = new APIRequest(Session["PAT"].ToString());
            string url;
            string response;

            /*   url = BaseURL + "/" + organisation + "/_apis/projects?api-version=" + version1;
             * string response = req.ApiRequest(url);
             * org = JsonConvert.DeserializeObject<OrgModel>(response);*/
            //org.Value = projModel.Value;
            //org.counts = new orgCounts();
            List <string> MemberCount;

            foreach (var projeId in org.Value)
            {
                url      = "https://vssps.dev.azure.com/" + organisation + "/_apis/graph/descriptors/" + projeId.Id + "?api-version=" + version1 + ".1";
                response = req.ApiRequest(url);
                JObject jobj = JObject.Parse(response);


                url      = "https://vssps.dev.azure.com/" + organisation + "/_apis/graph/groups?scopeDescriptor=" + jobj["value"] + "&api-version=" + version1;
                response = req.ApiRequest(url);
                ProjectModel Grp = JsonConvert.DeserializeObject <ProjectModel>(response);
                //projeId.counts = new orgCounts();

                MemberCount = new List <string>();
                foreach (var group in Grp.Value)
                {
                    url      = "https://vsaex.dev.azure.com/" + organisation + "/_apis/GroupEntitlements/" + group.originId + "/members?api-version=" + version1 + ".1";
                    response = req.ApiRequest(url);
                    MembersMod Model = JsonConvert.DeserializeObject <MembersMod>(response);

                    foreach (var mem in Model.members)
                    {
                        if (!MemberCount.Contains(mem.id))
                        {
                            added = true;
                            MemberCount.Add(mem.id);
                        }
                        if (added == true)
                        {
                            projeId.counts.UserCount = MemberCount.Count;

                            added = false;
                        }
                    }
                }

                //org.counts.UserCount = MemberCount.Count;
                c.UserCount = MemberCount.Count;
            }

            //return org;
        }
コード例 #3
0
        public JsonResult report(string organisation, string workitemtype = "0", string projectName = "0")
        {
            if (workitemtype != "0")
            {
                c.WIcountType = GetWorkitemCountByType(organisation, workitemtype, projectName);
                org.counts    = c;
                return(Json(org, JsonRequestBehavior.AllowGet));
            }
            req = new APIRequest(Session["PAT"].ToString());
            string url;

            url = BaseURL + "/" + organisation + "/_apis/projects?api-version=" + version;
            string response = req.ApiRequest(url);

            org = JsonConvert.DeserializeObject <OrgModel>(response);
            countGen count = new countGen();

            org.counts     = new orgCounts();
            url            = BaseURL + "/" + organisation + "/_apis/process/processes?api-version=" + version;
            response       = req.ApiRequest(url);
            count          = JsonConvert.DeserializeObject <countGen>(response);
            c.processCount = count.Count;
            foreach (var project in org.Value)
            {
                url            = BaseURL + organisation + "/" + project.Name + "/_apis/build/definitions?api-version=" + version;
                response       = req.ApiRequest(url);
                project.counts = new orgCounts();
                count          = JsonConvert.DeserializeObject <countGen>(response);
                project.counts.buildDefCount = count.Count;
                c.buildDefCount += count.Count;
                url              = BaseURLvsrm + organisation + "/" + project.Name + "/_apis/release/definitions?api-version=" + version;
                response         = req.ApiRequest(url);
                count            = JsonConvert.DeserializeObject <countGen>(response);
                project.counts.releaseDefCount = count.Count;
                c.releaseDefCount += count.Count;
                url      = BaseURL + organisation + "/" + project.Name + "/_apis/git/repositories?api-version=" + version;
                response = req.ApiRequest(url);
                count    = JsonConvert.DeserializeObject <countGen>(response);
                project.counts.repoCount = count.Count;
                //c.repoCount += count.Count;
            }

            // Calling Repos Count
            AllReposCount(organisation);
            // Calling Users Count
            AllUsersCount(organisation);
            // Calling WorkitemsCount Count
            AllWorKitemsCount(organisation);
            WITypes(organisation);
            //Calling WorkItemCountByType
            org.counts = c;
            return(Json(org, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public ActionResult ReadExcelFile(HttpPostedFileBase Excel, string Organisation, string PAT, string SourceProj, string DestionationProj)
        {
            try
            {
                var          excelStream = Excel.InputStream;
                ExcelPackage excel       = new ExcelPackage(excelStream);

                ReadExcel(excel);
            }
            catch (IndexOutOfRangeException)
            {
                ViewBag.message = "No Work Sheets Found";
            }
            catch (Exception ex)
            {
                ViewBag.message = "Something Went Wrong, Please Download Excel/Attachments From 'Export Attachments'";
                throw (ex);
            }
            //BaseUrl += Organisation;

            ProjectName    = DestionationProj;
            OldTeamProject = SourceProj;
            UserPAT        = PAT;
            WIOps.ConnectWithPAT(BaseUrl + Organisation, UserPAT);
            APIRequest req        = new APIRequest(UserPAT);
            string     response   = req.ApiRequest("https://dev.azure.com/" + Organisation + "/" + DestionationProj + "/_apis/wit/fields?api-version=5.1");
            Fields     fieldsList = JsonConvert.DeserializeObject <Fields>(response);

            /*var model = new sheetList()
             * {
             *  Sheets = sheets,
             *  fields=fieldsList.value
             * };
             * string data = JsonConvert.SerializeObject(model);
             * ViewBag.model = data;*/
            List <SelectListItem> list = new List <SelectListItem>();

            foreach (var key in sheets.Keys)
            {
                list.Add(new SelectListItem()
                {
                    Text = key, Value = JsonConvert.SerializeObject(sheets[key])
                });
            }
            List <SelectListItem> flist = new List <SelectListItem>();

            foreach (var field in fieldsList.value)
            {
                flist.Add(new SelectListItem()
                {
                    Text = field.name, Value = field.name
                });
            }
            ViewBag.fields     = flist;
            ViewBag.Selectlist = list;
            return(View("SheetsDrop"));
        }
コード例 #5
0
        public JsonResult GetUserDetails(string organisation)
        {
            try
            {
                APIRequest Req            = new APIRequest(Session["PAT"].ToString());
                DateTime   Today          = DateTime.Now.Date;
                string     RequestUrl     = null;
                string     ResponseString = null;
                UserModel  UsersList      = new UserModel();

                RequestUrl     = "https://vsaex.dev.azure.com/" + organisation + "/_apis/userentitlements?api-version=4.1-preview.1";
                ResponseString = Req.ApiRequest(RequestUrl);
                if (!string.IsNullOrEmpty(ResponseString))
                {
                    UsersList = JsonConvert.DeserializeObject <UserModel>(ResponseString);
                }
                UsersList.AccessLevels = new Dictionary <string, int>();
                foreach (var user in UsersList.value)
                {
                    user.LastAccessDate = user.lastAccessedDate.ToShortDateString();
                    user.DateCreated    = user.dateCreated.ToShortDateString();
                    TimeSpan Diff = Today.Subtract(user.lastAccessedDate);
                    if ((int)Diff.TotalDays <= 30)
                    {
                        user.AccesedRecently = true;
                    }
                    else
                    {
                        user.AccesedRecently = false;
                    }
                    if (!UsersList.AccessLevels.ContainsKey(user.accessLevel.licenseDisplayName))
                    {
                        UsersList.AccessLevels.Add(user.accessLevel.licenseDisplayName, 1);
                    }
                    else
                    {
                        UsersList.AccessLevels[user.accessLevel.licenseDisplayName] += 1;
                    }
                }
                /*UsersList.AccessLevels.OrderBy(x => x.Key);*/
                return(Json(UsersList, JsonRequestBehavior.AllowGet));
            }
            catch (Exception E)
            {
                return(null);
            }
        }
コード例 #6
0
        public void AllReposCount(string organisation)
        {
            APIRequest req;
            //OrgModel org = new OrgModel();
            string url;

            try
            {
                url = BaseURL + "/" + organisation + "/_apis/git/repositories?api-version=" + version;
                req = new APIRequest(Session["PAT"].ToString());
                string   response = req.ApiRequest(url);
                countGen count    = JsonConvert.DeserializeObject <countGen>(response);
                c.repoCount = count.Count;
            }
            catch (Exception)
            {
            }

            //return org;
        }
コード例 #7
0
        public void AllWorKitemsCount(string organisation)
        {
            APIRequest req;
            OrgModel   org = new OrgModel();
            string     url;

            try
            {
                object       Wiql  = new { query = "Select  [Id] From WorkItems" };
                ProjectModel model = new ProjectModel();
                url = "https://dev.azure.com/" + organisation + "/_apis/wit/wiql?api-version=5.1";
                req = new APIRequest(Session["PAT"].ToString());
                string response = req.ApiRequest(url, "POST", JsonConvert.SerializeObject(Wiql));
                model        = JsonConvert.DeserializeObject <ProjectModel>(response);
                c.WIcountOrg = model.WorkItems.Count;
            }
            catch (Exception)
            {
            }

            //return org;
        }