From 9c2913d709ca81442a6181017039b8165f4e32f1 Mon Sep 17 00:00:00 2001 From: luevard Date: Thu, 20 Oct 2022 08:37:23 +0200 Subject: [PATCH 1/8] nouvelle branche connexion --- Code/IHM/App.xaml.cs | 2 +- Code/IHM/MainWindow.xaml.cs | 25 +++-------------- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 42 +++++++---------------------- Code/Model/IPersistanceManager.cs | 2 +- Code/Model/Manager.cs | 21 +-------------- 5 files changed, 15 insertions(+), 77 deletions(-) diff --git a/Code/IHM/App.xaml.cs b/Code/IHM/App.xaml.cs index c799256..87723ac 100644 --- a/Code/IHM/App.xaml.cs +++ b/Code/IHM/App.xaml.cs @@ -15,7 +15,7 @@ namespace IHM /// public partial class App : Application { - public Manager AllInscrits { get; private set; } = new Manager(new LinqToPgSQL.PersLinqToPgSQL()); + public Manager Manager { get; private set; } = new Manager(new LinqToPgSQL.PersLinqToPgSQL()); //public Manager AllInscrits { get; private set; } = new Manager(new Stub()); } diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index 09786c4..0de7bd9 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -22,40 +22,21 @@ namespace IHM /// public partial class MainWindow : Window { - public Manager ListedesInscrits => ((App)Application.Current).AllInscrits; + public Manager Manager => ((App)Application.Current).Manager; public MainWindow() { InitializeComponent(); - - ListedesInscrits.LoadInscrit(); - DataContext = ListedesInscrits; - + DataContext = Manager.SelectedInscrits; } public void testSelect() { - foreach (Inscrit i in ListedesInscrits.ListedesInscrits) - { - - - MessageBox.Show($"{i.Id} + {i.Nom} + {i.Prenom} + {i.Mail} + {i.Mdp}"); - - - } - + MessageBox.Show($"{Manager.SelectedInscrits.Id} + {Manager.SelectedInscrits.Nom} + {Manager.SelectedInscrits.Prenom} + {Manager.SelectedInscrits.Mail} + {Manager.SelectedInscrits.Mdp}"); } public void testSuppression() { - foreach (Inscrit i in ListedesInscrits.ListedesInscrits) - { - if (i.Nom == "YOUVOI") - { - ListedesInscrits.supprimerInscritBdd(i); - } - - } MessageBox.Show("Suppression ok"); } diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index 1eb575d..1d6b0ba 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -18,21 +18,12 @@ namespace LinqToPgSQL private static string Password = "lulu"; private static string Port = "5432"; - string connString = - String.Format( - "Server={0};Username={1};Database={2};Port={3};Password={4};SSLMode=Prefer", - Host, - User, - DBname, - Port, - Password); - - public PersLinqToPgSQL() { } - public IEnumerable LoadInscrit() + string connexionBDD = String.Format("Server={0};Username{1};Database{2};Port{3};Password{4};SSLMode=Prefer",Host,User,DBname,Port,Password); + public Inscrit LoadInscrit() { - List ListeInscrits = new List(); - - var conn = new NpgsqlConnection(connString); + int t = 0; + Inscrit i=null; + var conn = new NpgsqlConnection(connexionBDD); Console.Out.WriteLine("Ouverture de la connection"); try { conn.Open(); @@ -41,23 +32,15 @@ namespace LinqToPgSQL { conn.Close(); Environment.Exit(0); - } - - NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Inscrit", conn).ExecuteReader(); - while (dbReader.Read()) { - - ListeInscrits.Add(new Inscrit(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4))); - + t++; + i=new Inscrit(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4)); } - - dbReader.Close(); - - return ListeInscrits; + return i; } @@ -66,28 +49,21 @@ namespace LinqToPgSQL { /*List ListeInscrits = new List(LoadInscrit());*/ - var conn = new NpgsqlConnection(connString); + var conn = new NpgsqlConnection(connexionBDD); Console.Out.WriteLine("Ouverture de la connection"); conn.Open(); - - string requete = $"DELETE FROM INSCRIT WHERE id=(@p)"; string requeteFKey = $"DELETE FROM DEVISEINSCRIT WHERE idInscrit=(@p2)"; - using (var command1 = new NpgsqlCommand(requeteFKey, conn)) { command1.Parameters.AddWithValue("p2", i.Id); await command1.ExecuteNonQueryAsync(); } - using (var command = new NpgsqlCommand(requete, conn)) { command.Parameters.AddWithValue("p", i.Id); await command.ExecuteNonQueryAsync(); } - - - } } } diff --git a/Code/Model/IPersistanceManager.cs b/Code/Model/IPersistanceManager.cs index fe3121c..05e222f 100644 --- a/Code/Model/IPersistanceManager.cs +++ b/Code/Model/IPersistanceManager.cs @@ -8,7 +8,7 @@ namespace Model { public interface IPersistanceManager { - IEnumerable LoadInscrit(); + Inscrit LoadInscrit(); void SupprimerInscritBdd(Inscrit inscrit); } } diff --git a/Code/Model/Manager.cs b/Code/Model/Manager.cs index 7e86094..442672e 100644 --- a/Code/Model/Manager.cs +++ b/Code/Model/Manager.cs @@ -10,16 +10,8 @@ namespace Model { public class Manager : INotifyPropertyChanged { - public Manager() { } - public event PropertyChangedEventHandler? PropertyChanged; - - public IReadOnlyCollection ListedesInscrits { get; private set; } - private List TousLesInscrits { get; set; } = new List(); - public IPersistanceManager Pers { get; private set; } - - public Inscrit SelectedInscrits { get => selectedInscrits; @@ -33,22 +25,11 @@ namespace Model } } private Inscrit selectedInscrits; - void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - - public void LoadInscrit() - { - TousLesInscrits.Clear(); - TousLesInscrits.AddRange(Pers.LoadInscrit()); - if (TousLesInscrits.Count > 0) - SelectedInscrits = TousLesInscrits.First(); - - } - public Manager(IPersistanceManager persistance) { - ListedesInscrits = new ReadOnlyCollection(TousLesInscrits); + SelectedInscrits = persistance.LoadInscrit(); Pers = persistance; } From 8ed4a57ef19e4758f5685bf621133db34fe4f2e5 Mon Sep 17 00:00:00 2001 From: Hugo LIVET Date: Thu, 20 Oct 2022 11:49:45 +0200 Subject: [PATCH 2/8] Ajout de Sonnar --- .drone.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index f2bfbc5..dc9711e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -20,4 +20,24 @@ steps: - cd Code - dotnet restore CI_CONSECO.sln - dotnet test CI_CONSECO.sln --no-restore - depends_on: [build] \ No newline at end of file + depends_on: [build] + - name: code-analysis + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6 + commands: + - cd Code/ + - dotnet restore CI_CONSECO.sln + - dotnet sonarscanner begin /k:ConsEco /d:sonar.host.url=$${PLUGIN_SONAR_HOST} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.login=$${PLUGIN_SONAR_TOKEN} + - dotnet build CI_CONSECO.sln -c Release --no-restore + - dotnet test CI_CONSECO.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" + - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" + - dotnet publish CI_CONSECO.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release + - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} + secrets: [ SECRET_SONAR_LOGIN ] + settings: + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + sonar_host: https://codefirst.iut.uca.fr/sonar/ + # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} + sonar_token: + from_secret: SECRET_SONAR_LOGIN + depends_on: [tests] + \ No newline at end of file From 98c88e43bf82c1127045bb4d92f0e45ac6167ec6 Mon Sep 17 00:00:00 2001 From: luevard Date: Fri, 21 Oct 2022 14:01:06 +0200 Subject: [PATCH 3/8] modification loadInsrit --- Code/IHM/MainWindow.xaml.cs | 2 +- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 44 +++++++++++------------------ Code/Model/IPersistanceManager.cs | 2 +- Code/Model/Manager.cs | 27 ++++++------------ Code/Model/Model.csproj | 4 +++ 5 files changed, 30 insertions(+), 49 deletions(-) diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index 0de7bd9..3597942 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -32,7 +32,7 @@ namespace IHM public void testSelect() { - MessageBox.Show($"{Manager.SelectedInscrits.Id} + {Manager.SelectedInscrits.Nom} + {Manager.SelectedInscrits.Prenom} + {Manager.SelectedInscrits.Mail} + {Manager.SelectedInscrits.Mdp}"); + MessageBox.Show($"{Manager.SelectedInscrits}"); } public void testSuppression() diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index 1d6b0ba..41ed0a2 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -12,43 +12,30 @@ namespace LinqToPgSQL { public class PersLinqToPgSQL : IPersistanceManager { - private static string Host = "90.114.135.116"; - private static string User = "postgres"; - private static string DBname = "conseco"; - private static string Password = "lulu"; - private static string Port = "5432"; - - string connexionBDD = String.Format("Server={0};Username{1};Database{2};Port{3};Password{4};SSLMode=Prefer",Host,User,DBname,Port,Password); - public Inscrit LoadInscrit() + string connexionBDD = String.Format("Server=90.114.135.116; Username=postgres; Database=conseco; Port=5432; Password=lulu; SSLMode=Prefer"); + public string LoadInscrit(string id, string mdp) { - int t = 0; - Inscrit i=null; var conn = new NpgsqlConnection(connexionBDD); - Console.Out.WriteLine("Ouverture de la connection"); try - { - conn.Open(); - } - catch - { - conn.Close(); - Environment.Exit(0); - } - NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Inscrit", conn).ExecuteReader(); - while (dbReader.Read()) + Console.Out.WriteLine("Ouverture de la connection"); + conn.Open(); + using var cmd = new NpgsqlCommand("SELECT id FROM INSCRIT WHERE (nom=(@p) OR mail=(@p)) AND mdp=@p2",conn) { - t++; - i=new Inscrit(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4)); - } - dbReader.Close(); - return i; + Parameters = + { + new("p", id), + new("p2", mdp) + } + }; + return cmd.ExecuteNonQuery().ToString(); } + /*Revoir la BDD, probleme de clé étrangère de devise*/ public async void SupprimerInscritBdd(Inscrit i) { /*List ListeInscrits = new List(LoadInscrit());*/ - + var conn = new NpgsqlConnection(connexionBDD); Console.Out.WriteLine("Ouverture de la connection"); conn.Open(); @@ -65,5 +52,6 @@ namespace LinqToPgSQL await command.ExecuteNonQueryAsync(); } } + } -} +} \ No newline at end of file diff --git a/Code/Model/IPersistanceManager.cs b/Code/Model/IPersistanceManager.cs index 05e222f..f273ff1 100644 --- a/Code/Model/IPersistanceManager.cs +++ b/Code/Model/IPersistanceManager.cs @@ -8,7 +8,7 @@ namespace Model { public interface IPersistanceManager { - Inscrit LoadInscrit(); + string LoadInscrit(string id,string mdp); void SupprimerInscritBdd(Inscrit inscrit); } } diff --git a/Code/Model/Manager.cs b/Code/Model/Manager.cs index 442672e..aaa2a9b 100644 --- a/Code/Model/Manager.cs +++ b/Code/Model/Manager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; +using Npgsql; using System.Text; using System.Threading.Tasks; @@ -12,37 +13,25 @@ namespace Model { public event PropertyChangedEventHandler? PropertyChanged; public IPersistanceManager Pers { get; private set; } - public Inscrit SelectedInscrits - { - get => selectedInscrits; - set - { - if (selectedInscrits != value) - { - selectedInscrits = value; - OnPropertyChanged(nameof(SelectedInscrits)); - } - } - } - private Inscrit selectedInscrits; + public string SelectedInscrits; + void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); public Manager(IPersistanceManager persistance) { - SelectedInscrits = persistance.LoadInscrit(); Pers = persistance; } - public void supprimerInscritBdd(Inscrit i) + public void SupprimerInscritBdd(Inscrit i) { Pers.SupprimerInscritBdd(i); } - /* public void supprimerInscritBdd(Inscrit i) - { - + public void LoadInscrit(string id, string mdp) + { + SelectedInscrits = Pers.LoadInscrit(id, mdp); + } - }*/ } diff --git a/Code/Model/Model.csproj b/Code/Model/Model.csproj index bafd05b..1fb252d 100644 --- a/Code/Model/Model.csproj +++ b/Code/Model/Model.csproj @@ -6,4 +6,8 @@ enable + + + + From 75b6c7a2fdb6a2b7babfd88d3d3d927d6ad1715b Mon Sep 17 00:00:00 2001 From: Lucas EVARD Date: Fri, 21 Oct 2022 15:18:55 +0200 Subject: [PATCH 4/8] Connexion par ID et MDP fonctionnelle --- Code/IHM/MainWindow.xaml.cs | 1 + Code/LinqToPgSQL/PersLinqToPgSQL.cs | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index 3597942..9b2e41f 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -42,6 +42,7 @@ namespace IHM private void test_Click(object sender, RoutedEventArgs e) { + Manager.LoadInscrit("",""); testSelect(); /* testSuppression();*/ } diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index 41ed0a2..8e045b1 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Data; +using System.Configuration; using Npgsql; using Model; using System.IO; @@ -15,20 +17,26 @@ namespace LinqToPgSQL string connexionBDD = String.Format("Server=90.114.135.116; Username=postgres; Database=conseco; Port=5432; Password=lulu; SSLMode=Prefer"); public string LoadInscrit(string id, string mdp) { + string resultat=""; var conn = new NpgsqlConnection(connexionBDD); Console.Out.WriteLine("Ouverture de la connection"); conn.Open(); - using var cmd = new NpgsqlCommand("SELECT id FROM INSCRIT WHERE (nom=(@p) OR mail=(@p)) AND mdp=@p2",conn) + NpgsqlParameter p1 = new NpgsqlParameter { ParameterName = "p", Value = id }; + NpgsqlParameter p2 = new NpgsqlParameter { ParameterName = "p2", Value = mdp }; + NpgsqlCommand cmd = new NpgsqlCommand($"SELECT id FROM INSCRIT WHERE (nom=(@p) OR mail=(@p)) AND mdp=@p2", conn); + cmd.Parameters.Add(p1); + cmd.Parameters.Add(p2); + NpgsqlDataReader dr = cmd.ExecuteReader(); + try { - Parameters = - { - new("p", id), - new("p2", mdp) - } - }; - return cmd.ExecuteNonQuery().ToString(); + dr.Read(); + } + catch (Exception ex) + { Console.Out.WriteLine("A GERER"); } + dr.Close(); + return null; } - + /*Revoir la BDD, probleme de clé étrangère de devise*/ From 1c4ec437f59a873c5a5018654de9ae680765dc89 Mon Sep 17 00:00:00 2001 From: Lucas EVARD Date: Fri, 21 Oct 2022 15:24:40 +0200 Subject: [PATCH 5/8] Modification connexion --- Code/IHM/MainWindow.xaml.cs | 2 +- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index 9b2e41f..f776a43 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -42,7 +42,7 @@ namespace IHM private void test_Click(object sender, RoutedEventArgs e) { - Manager.LoadInscrit("",""); + Manager.LoadInscrit("stef@.com", "teststef"); testSelect(); /* testSuppression();*/ } diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index 8e045b1..ed0d0d6 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -30,11 +30,16 @@ namespace LinqToPgSQL try { dr.Read(); + resultat = dr.GetString(0); + dr.Close(); + return resultat; } catch (Exception ex) - { Console.Out.WriteLine("A GERER"); } - dr.Close(); + { Console.Out.WriteLine("A GERER"); return null; + } + dr.Close(); + } From 474726bbd48ae1d2413d108ee64bf9b1efa03b73 Mon Sep 17 00:00:00 2001 From: Lucas EVARD Date: Fri, 21 Oct 2022 19:31:11 +0200 Subject: [PATCH 6/8] Modification encapsulation --- Code/IHM/MainWindow.xaml | 7 ++++++- Code/IHM/MainWindow.xaml.cs | 10 +++++++--- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 10 +++++----- Code/Model/Banque.cs | 2 +- Code/Model/Inscrit.cs | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Code/IHM/MainWindow.xaml b/Code/IHM/MainWindow.xaml index 4a745ad..ecdd3d5 100644 --- a/Code/IHM/MainWindow.xaml +++ b/Code/IHM/MainWindow.xaml @@ -7,7 +7,12 @@ mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> -