public static List <MetricViewModel> GetDeltaMetricsBox(IConfigurationRoot configuration, string choice = "") { DbDataReader reader = null; List <TmpObject> Objects = new List <TmpObject>(); List <MetricViewModel> ListToReturn = new List <MetricViewModel>(); MySqlConnection myConnectionServices = new MySqlConnection(configuration["connectionString"]); MySqlConnection myConnectionReferenceMetrics = new MySqlConnection(configuration["connectionString"]); MySqlConnection myConnectionReferenceTests = new MySqlConnection(configuration["connectionString"]); MySqlConnection myConnectionMetrics = new MySqlConnection(configuration["connectionString"]); MySqlConnection myConnectionTests = new MySqlConnection(configuration["connectionString"]); myConnectionServices.Open(); myConnectionMetrics.Open(); myConnectionTests.Open(); myConnectionReferenceMetrics.Open(); myConnectionReferenceTests.Open(); string queryServices = "SELECT ServiceID, ServiceName, DirectionName, DirectionteamName FROM serviceinformation se, teamdirection te, direction di where se.DirectionTeamID = te.DirectionTeamID and te.DirectionID = di.DirectionID"; MySqlCommand commandServices = new MySqlCommand(queryServices, myConnectionServices); string queryMetrics = null; string queryTests = null; reader = commandServices.ExecuteReader(); while (reader.Read()) { string referenceMetrics = "select * from servicemetrics where ServiceID = @ServiceID order by InterrogationDate DESC limit 1"; string referenceTests = "SELECT * FROM servicebuild where ServiceID=@ServiceID and (result = 'succeeded' or result = 'partiallySucceeded') and BuildName LIKE 'Sonar_%' order by FinishTime DESC limit 1"; TmpObject Object = new TmpObject(); switch (choice) { case "une semaine": queryMetrics = "select * from servicemetrics where ServiceID = @ServiceID order by InterrogationDate DESC limit 1,1"; queryTests = "SELECT * FROM servicebuild where ServiceID=@ServiceID and (result = 'succeeded' or result = 'partiallySucceeded') and BuildName LIKE 'Sonar_%' order by FinishTime DESC limit 1,1"; break; case "deux semaines": queryMetrics = "select * from servicemetrics where ServiceID = @ServiceID order by InterrogationDate DESC limit 2,1"; queryTests = "SELECT * FROM servicebuild where ServiceID=@ServiceID and (result = 'succeeded' or result = 'partiallySucceeded') and BuildName LIKE 'Sonar_%' order by FinishTime DESC limit 2,1"; break; case "un mois": queryMetrics = "select * from servicemetrics where ServiceID = @ServiceID order by InterrogationDate DESC limit 4,1"; queryTests = "SELECT * FROM servicebuild where ServiceID=@ServiceID and (result = 'succeeded' or result = 'partiallySucceeded') and BuildName LIKE 'Sonar_%' order by FinishTime DESC limit 4,1"; break; case "un trimestre": queryMetrics = "select * from servicemetrics where ServiceID = @ServiceID order by InterrogationDate DESC limit 12,1"; queryTests = "SELECT * FROM servicebuild where ServiceID=@ServiceID and (result = 'succeeded' or result = 'partiallySucceeded') and BuildName LIKE 'Sonar_%' order by FinishTime DESC limit 12,1"; break; default: queryMetrics = "select * from servicemetrics where ServiceID = @ServiceID order by InterrogationDate DESC limit 1,1"; queryTests = "SELECT * FROM servicebuild where ServiceID=@ServiceID and (result = 'succeeded' or result = 'partiallySucceeded') and BuildName LIKE 'Sonar_%' order by FinishTime DESC limit 1,1"; break; } MySqlCommand commandMetrics = new MySqlCommand(queryMetrics, myConnectionMetrics); MySqlCommand commandTests = new MySqlCommand(queryTests, myConnectionTests); MySqlCommand commandReferenceMetrics = new MySqlCommand(referenceMetrics, myConnectionReferenceMetrics); MySqlCommand commandReferenceTests = new MySqlCommand(referenceTests, myConnectionReferenceTests); commandMetrics.Parameters.AddWithValue("@ServiceID", reader.GetInt32(0)); commandReferenceMetrics.Parameters.AddWithValue("@ServiceID", reader.GetInt32(0)); commandReferenceTests.Parameters.AddWithValue("@ServiceID", reader.GetInt32(0)); commandTests.Parameters.AddWithValue("@ServiceID", reader.GetInt32(0)); DbDataReader readerMetrics = commandMetrics.ExecuteReader(); DbDataReader readerReferenceMetrics = commandReferenceMetrics.ExecuteReader(); DbDataReader readerReferenceTests = commandReferenceTests.ExecuteReader(); DbDataReader readerTests = commandTests.ExecuteReader(); if (readerMetrics.Read() && readerReferenceMetrics.Read()) { Object.Metrics.Add(FillObject(readerReferenceMetrics, readerReferenceTests, reader)); Object.Metrics.Add(FillObject(readerMetrics, readerTests, reader)); } readerMetrics.Dispose(); readerTests.Dispose(); readerReferenceMetrics.Dispose(); readerReferenceTests.Dispose(); if (Object.Metrics.Count != 0) { Objects.Add(Object); } } foreach (TmpObject ob in Objects) { ob.MetricsToShow.ServiceProfile = ob.Metrics[0].ServiceProfile; ob.MetricsToShow.ServiceName = ob.Metrics[0].ServiceName; ob.MetricsToShow.DirectionName = ob.Metrics[0].DirectionName; ob.MetricsToShow.TeamName = ob.Metrics[0].TeamName; ob.MetricsToShow.NumberBugs = ob.Metrics[0].NumberBugs - ob.Metrics[1].NumberBugs; ob.MetricsToShow.NumberVulnerabilities = ob.Metrics[0].NumberVulnerabilities - ob.Metrics[1].NumberVulnerabilities; ob.MetricsToShow.NumberCodeSmells = ob.Metrics[0].NumberCodeSmells - ob.Metrics[1].NumberCodeSmells; ob.MetricsToShow.Coverage = ob.Metrics[0].Coverage - ob.Metrics[1].Coverage; ob.MetricsToShow.Duplication = ob.Metrics[0].Duplication - ob.Metrics[1].Duplication; ob.MetricsToShow.Size = ob.Metrics[0].Size - ob.Metrics[1].Size; ob.MetricsToShow.Complexity = ob.Metrics[0].Complexity - ob.Metrics[1].Complexity; ob.MetricsToShow.Documentation = ob.Metrics[0].Documentation - ob.Metrics[1].Documentation; ob.MetricsToShow.PassedTests = ob.Metrics[0].PassedTests - ob.Metrics[1].PassedTests; ob.MetricsToShow.TotalTests = ob.Metrics[0].TotalTests - ob.Metrics[1].TotalTests; ListToReturn.Add(ob.MetricsToShow); } return(ListToReturn); }
public static List <MetricViewModel> GetDeltaMetrics(IConfigurationRoot configuration) { DbDataReader reader = null; List <TmpObject> Objects = new List <TmpObject>(); List <MetricViewModel> ListToReturn = new List <MetricViewModel>(); MySqlConnection myConnectionServices = new MySqlConnection(configuration["connectionString"]); MySqlConnection myConnectionLastDate = new MySqlConnection(configuration["connectionString"]); MySqlConnection myConnectionMetrics = new MySqlConnection(configuration["connectionString"]); MySqlConnection myConnectionTests = new MySqlConnection(configuration["connectionString"]); myConnectionServices.Open(); myConnectionLastDate.Open(); myConnectionMetrics.Open(); myConnectionTests.Open(); //string queryServices = "select ServiceID, serviceName from serviceinformation"; string queryServices = "SELECT ServiceID, ServiceName, DirectionName, DirectionteamName FROM serviceinformation se, teamdirection te, direction di where se.DirectionTeamID = te.DirectionTeamID and te.DirectionID = di.DirectionID"; MySqlCommand commandServices = new MySqlCommand(queryServices, myConnectionServices); reader = commandServices.ExecuteReader(); while (reader.Read()) { TmpObject Object = new TmpObject(); string queryMetrics = "select * from servicemetrics where ServiceID = @ServiceID order by InterrogationDate DESC limit 2"; MySqlCommand commandMetrics = new MySqlCommand(queryMetrics, myConnectionMetrics); commandMetrics.Parameters.AddWithValue("@ServiceID", reader.GetInt32(0)); DbDataReader readerMetrics = commandMetrics.ExecuteReader(); string queryTests = "SELECT * FROM servicebuild where ServiceID=@ServiceID and (result = 'succeeded' or result = 'partiallySucceeded') and BuildName LIKE 'Sonar_%' order by FinishTime DESC limit 2"; MySqlCommand commandTests = new MySqlCommand(queryTests, myConnectionTests); commandTests.Parameters.AddWithValue("@ServiceID", reader.GetInt32(0)); DbDataReader readerTests = commandTests.ExecuteReader(); while (readerMetrics.Read()) { MetricViewModel Servicemetrics = new MetricViewModel(); Servicemetrics.ServiceProfile = readerMetrics.GetString(2); Servicemetrics.NumberBugs = readerMetrics.GetInt32(3); Servicemetrics.NumberVulnerabilities = readerMetrics.GetInt32(4); Servicemetrics.NumberCodeSmells = readerMetrics.GetInt32(5); Servicemetrics.Coverage = readerMetrics.GetDecimal(6); Servicemetrics.Duplication = readerMetrics.GetDecimal(7); Servicemetrics.Size = readerMetrics.GetInt32(8); Servicemetrics.Complexity = readerMetrics.GetInt32(9); Servicemetrics.Documentation = readerMetrics.GetDecimal(10); Servicemetrics.ServiceName = reader.GetString(1); Servicemetrics.DirectionName = reader.GetString(2); Servicemetrics.TeamName = reader.GetString(3); if (readerTests.Read()) { //Servicemetrics.PassedTests = readerTests.GetInt32(8); //Servicemetrics.TotalTests = readerTests.GetInt32(6); if (!readerTests.IsDBNull(8)) { Servicemetrics.PassedTests = readerTests.GetInt32(8); } if (!readerTests.IsDBNull(6)) { Servicemetrics.TotalTests = readerTests.GetInt32(6); } } Object.Metrics.Add(Servicemetrics); } readerMetrics.Dispose(); readerTests.Dispose(); Objects.Add(Object); } foreach (TmpObject ob in Objects) { ob.MetricsToShow.ServiceProfile = ob.Metrics[0].ServiceProfile; ob.MetricsToShow.ServiceName = ob.Metrics[0].ServiceName; ob.MetricsToShow.DirectionName = ob.Metrics[0].DirectionName; ob.MetricsToShow.TeamName = ob.Metrics[0].TeamName; ob.MetricsToShow.NumberBugs = ob.Metrics[0].NumberBugs - ob.Metrics[1].NumberBugs; ob.MetricsToShow.NumberVulnerabilities = ob.Metrics[0].NumberVulnerabilities - ob.Metrics[1].NumberVulnerabilities; ob.MetricsToShow.NumberCodeSmells = ob.Metrics[0].NumberCodeSmells - ob.Metrics[1].NumberCodeSmells; ob.MetricsToShow.Coverage = ob.Metrics[0].Coverage - ob.Metrics[1].Coverage; ob.MetricsToShow.Duplication = ob.Metrics[0].Duplication - ob.Metrics[1].Duplication; ob.MetricsToShow.Size = ob.Metrics[0].Size - ob.Metrics[1].Size; ob.MetricsToShow.Complexity = ob.Metrics[0].Complexity - ob.Metrics[1].Complexity; ob.MetricsToShow.Documentation = ob.Metrics[0].Documentation - ob.Metrics[1].Documentation; ListToReturn.Add(ob.MetricsToShow); } return(ListToReturn); }