/// <summary> /// Add or Update Rating to a project /// </summary> /// <param name="ProjectId"></param> /// <param name="Rating"></param> /// <returns></returns> public string AddRating(int ProjectId, string Rating, string ratingtype) { string returnStatus = "Success"; try { ProjectRating rating = (from rate in context.ProjectRatings where rate.projectId == ProjectId select rate).FirstOrDefault(); if (rating != null) { if (ratingtype == "P") { rating.rating = Rating;//1 for high, 2 for Optimum and 3 for Expensive. } if (ratingtype == "Q") { rating.QualityRating = Rating; } if (ratingtype == "R") { rating.UserRating = Rating; } } else { ProjectRating projRating = new ProjectRating(); if (ratingtype == "i4irating") { projRating.projectId = ProjectId; projRating.rating = Rating; context.ProjectRatings.Add(projRating); } if (ratingtype == "Qualityrating") { projRating.projectId = ProjectId; projRating.QualityRating = Rating; context.ProjectRatings.Add(projRating); } if (ratingtype == "userrating") { projRating.projectId = ProjectId; projRating.UserRating = Rating; context.ProjectRatings.Add(projRating); } } ProjectRatingHistory projHis = new ProjectRatingHistory(); projHis.ProjectId = ProjectId; projHis.rating = Rating; projHis.date = DateTime.Now; context.ProjectRatingHistories.Add(projHis); context.SaveChanges(); } catch { returnStatus = "Fail"; } return(returnStatus); }
public void SendMetricMailsToProjectHeads() { var personRepository = new PersonRepository(); var sonarAPI = new SonarAPI(); var sonarProjects = sonarAPI.GetAllProjects(); var chart = new SonarSerieChart(); List <Task> AllTasksFromAllProjects = new List <Task>(); sonarProjects.Wait(); if (sonarProjects.Exception == null && sonarProjects.Result != null) { var projects = sonarProjects.Result; foreach (var project in projects) { if (!string.IsNullOrEmpty(project.Key)) { var issuesMetricsTask = sonarAPI.GetProjectThreeIssuesMetricsAsync(project.Key); var severityProjectMetricsTask = sonarAPI.GetSeverityProjectMetricsAsync(project.Key); var complexityProjectMetricsTask = sonarAPI.GetComplexityAndLineNumberAndCodeQualityProjectMetricsAsync(project.Key); var ratingTask = sonarAPI.GetProjectRatings(project.Key); AllTasksFromAllProjects.Add(Task.WhenAll(issuesMetricsTask, severityProjectMetricsTask, complexityProjectMetricsTask, ratingTask).ContinueWith( tasksResults => { string typeChartPath = chart.CreateChartsGrouped(issuesMetricsTask.Result, project.Name, "Ocorrências por Tipo"); string severityChartPath = chart.CreateChartsGrouped(severityProjectMetricsTask.Result, project.Name, "Ocorrências por Severidade"); string complexityChartPath = chart.CreateChartsGrouped(complexityProjectMetricsTask.Result, project.Name, "Número de linhas x Complexidade"); ProjectRating rating = ratingTask.Result; var projectMembers = personRepository.FindAllByProjectKey(project.Key); string managerName = projectMembers.SingleOrDefault(m => m.Role == Role.Manager)?.Name ?? "Não cadastrado"; string headName = projectMembers.SingleOrDefault(m => m.Role == Role.Head)?.Name ?? "Não cadastrado"; IEnumerable <string> projecMemberEmails = projectMembers.Select(m => m.Email); double codeHealthPercentage = new CodeHealthService(complexityProjectMetricsTask.Result, issuesMetricsTask.Result).Calculate(); List <CodeQualityMeasurement> calculatedCodeQuality = new CodeQualityService(complexityProjectMetricsTask.Result).Calculate(); EmailInfo email = new EmailInfo(project.Name, project.Key, managerName, headName, projecMemberEmails, complexityChartPath, typeChartPath, severityChartPath, codeHealthPercentage, calculatedCodeQuality, rating); var emailService = new EmailService(email); emailService.SendReportEmail(); })); } } // Aguarda todas as atividades assincronas terminarem para seguir Task.WaitAll(AllTasksFromAllProjects.ToArray()); } }
public async Task <ProjectRating> GetProjectRatings(string projectKey) { ProjectRating projectRatings = null; string apiURLWithProjectParameter = string.Format(ConfigurationManager.AppSettings["ratingsApiTemplateURL"], projectKey); using (var serviceClient = this.ConfigureClient()) { HttpResponseMessage response = await serviceClient.GetAsync(apiURLWithProjectParameter); if (response.IsSuccessStatusCode) { var stringResult = await response.Content.ReadAsStringAsync(); var projectRatingsJson = JsonConvert.DeserializeObject <SonarRatingJson>(stringResult, GetDeserializationSettings()); projectRatings = CreateProjectRatingPopulated(projectRatingsJson); } } return(projectRatings); }
/// <summary> /// Add or Update Rating to a project /// </summary> /// <param name="ProjectId"></param> /// <param name="Rating"></param> /// <returns></returns> public string AddRating(int ProjectId, string Rating, string ratingtype) { string returnStatus = "Success"; try { ProjectRating rating = (from rate in context.ProjectRatings where rate.projectId == ProjectId select rate).FirstOrDefault(); if (rating != null) { if (ratingtype == "P") { rating.rating = Rating;//1 for high, 2 for Optimum and 3 for Expensive. } if (ratingtype == "Q") { rating.QualityRating = Rating; } if (ratingtype == "R") { rating.UserRating = Rating; } } else { ProjectRating projRating = new ProjectRating(); if (ratingtype == "i4irating") { projRating.projectId = ProjectId; projRating.rating = Rating; context.ProjectRatings.Add(projRating); } if (ratingtype == "Qualityrating") { projRating.projectId = ProjectId; projRating.QualityRating = Rating; context.ProjectRatings.Add(projRating); } if (ratingtype == "userrating") { projRating.projectId = ProjectId; projRating.UserRating = Rating; context.ProjectRatings.Add(projRating); } } ProjectRatingHistory projHis = new ProjectRatingHistory(); projHis.ProjectId = ProjectId; projHis.rating = Rating; projHis.date = DateTime.Now; context.ProjectRatingHistories.Add(projHis); context.SaveChanges(); } catch { returnStatus = "Fail"; } return returnStatus; }