From 222ec500649acfbef6bb7c39f568e113c4ac1bc1 Mon Sep 17 00:00:00 2001 From: Francesco Date: Tue, 21 Jul 2020 19:19:57 +0200 Subject: [PATCH 1/2] add Find Duplicate Functionality --- .../LoggingClient/LoggingClient.csproj | 3 + LoggingClient/LoggingClient/Model/LogModel.cs | 64 ++++++++++++------- .../LoggingClient/ViewModel/LogViewModel.cs | 43 +++++++++++-- .../LoggingClient/Views/LogView.xaml | 17 ++--- .../LoggingClient/Views/LogView.xaml.cs | 0 5 files changed, 93 insertions(+), 34 deletions(-) mode change 100644 => 100755 LoggingClient/LoggingClient/Model/LogModel.cs mode change 100644 => 100755 LoggingClient/LoggingClient/ViewModel/LogViewModel.cs mode change 100644 => 100755 LoggingClient/LoggingClient/Views/LogView.xaml mode change 100644 => 100755 LoggingClient/LoggingClient/Views/LogView.xaml.cs diff --git a/LoggingClient/LoggingClient/LoggingClient.csproj b/LoggingClient/LoggingClient/LoggingClient.csproj index 64bde42..ef12a5e 100644 --- a/LoggingClient/LoggingClient/LoggingClient.csproj +++ b/LoggingClient/LoggingClient/LoggingClient.csproj @@ -41,6 +41,9 @@ ..\packages\BouncyCastle.1.8.3.1\lib\BouncyCastle.Crypto.dll + + ..\..\Aufgaben\DuplicateCheckerLib\DuplicateCheckerLib.dll + ..\packages\Google.Protobuf.3.6.1\lib\net45\Google.Protobuf.dll diff --git a/LoggingClient/LoggingClient/Model/LogModel.cs b/LoggingClient/LoggingClient/Model/LogModel.cs old mode 100644 new mode 100755 index f2e67ed..59b0489 --- a/LoggingClient/LoggingClient/Model/LogModel.cs +++ b/LoggingClient/LoggingClient/Model/LogModel.cs @@ -1,32 +1,52 @@ using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using DuplicateCheckerLib; namespace LoggingClient.Model -{ - public class LogModel +{ + public class LogModel : IEntity { - public int id { get; set; } - public string pod { get; set; } - public string location { get; set; } - public string hostname { get; set; } - public int severity { get; set; } - public DateTime timestamp { get; set; } - public string message { get; set; } + public int Id { get; set; } + public string Pod { get; set; } + public string Location { get; set; } + public string Hostname { get; set; } + public int Severity { get; set; } + public DateTime Timestamp { get; set; } + public string Message { get; set; } public LogModel(int id, string pod, string location, string hostname, int severity, DateTime timestamp, string message) { - this.id = id; - this.pod = pod; - this.location = location; - this.hostname = hostname; - this.severity = severity; - this.timestamp = timestamp; - this.message = message; + this.Id = id; + this.Pod = pod; + this.Location = location; + this.Hostname = hostname; + this.Severity = severity; + this.Timestamp = timestamp; + this.Message = message; + } + public bool Equals(LogModel secondLogModel) + { + if (Object.ReferenceEquals(null, secondLogModel)) return false; + if (Object.ReferenceEquals(this, secondLogModel)) return true; + + return String.Equals(Severity, secondLogModel.Severity) && String.Equals(Message, secondLogModel.Message); + } + public override bool Equals(object value) + { + return Equals(value as LogModel); + } + public override int GetHashCode() + { + unchecked + { + // Choose large primes to avoid hashing collisions + const int HashingBase = (int)2166136261; + const int HashingMultiplier = 16777619; + + int hash = HashingBase; + hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, Message) ? Message.GetHashCode() : 0); + hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, Severity) ? Severity.GetHashCode() : 0); + return hash; + } } } } diff --git a/LoggingClient/LoggingClient/ViewModel/LogViewModel.cs b/LoggingClient/LoggingClient/ViewModel/LogViewModel.cs old mode 100644 new mode 100755 index 67dac29..f84825a --- a/LoggingClient/LoggingClient/ViewModel/LogViewModel.cs +++ b/LoggingClient/LoggingClient/ViewModel/LogViewModel.cs @@ -7,7 +7,9 @@ using System.Windows.Input; using MySql.Data.MySqlClient; using LoggingClient.Model; using LoggingClient.ViewModel.Commands; - +using DuplicateCheckerLib; +using System.Linq; + namespace LoggingClient.ViewModel { public class LogViewModel : INotifyPropertyChanged @@ -17,17 +19,28 @@ namespace LoggingClient.ViewModel private string _enterHostname; private int _enterSeverity; private string _enterMessage; + private readonly DuplicateChecker _duplicateChecker; private ICommand _btnLoadDataClick; private ICommand _btnConfirmdataClick; private ICommand _btnAdddataClick; + private ICommand _btnFindDuplicateClick; - public ObservableCollection Logs { get; set; } + public ObservableCollection Logs + { + get => _logs; + set + { + _logs = value; + OnPropertyChanged("Logs"); + } + } + private ObservableCollection _logs; public ObservableCollection SeverityComboBox { get; set; } public LogViewModel() { - TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;"; + TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=foekicoe9i4kpos;"; _enterSeverity = 1; Logs = new ObservableCollection(); @@ -36,6 +49,7 @@ namespace LoggingClient.ViewModel new SeverityComboBoxItem(){Id=2, Severity= 2}, new SeverityComboBoxItem(){Id=3, Severity= 3} }; + _duplicateChecker = new DuplicateChecker(); } public LogModel MySelectedItem { get; set; } public event PropertyChangedEventHandler PropertyChanged; @@ -110,6 +124,18 @@ namespace LoggingClient.ViewModel })); } } + + public ICommand BtnFindDuplicateClick + { + get + { + return _btnFindDuplicateClick ?? (_btnFindDuplicateClick = new RelayCommand( + x => + { + BtnFindDuplicate_Click(); + })); + } + } public ICommand BtnConfirmDataClick { get @@ -184,7 +210,7 @@ namespace LoggingClient.ViewModel { cmd.CommandText = "LogClear"; cmd.CommandType = CommandType.StoredProcedure; - cmd.Parameters.AddWithValue("_logentries_id", MySelectedItem.id); + cmd.Parameters.AddWithValue("_logentries_id", MySelectedItem.Id); cmd.ExecuteNonQuery(); } } @@ -220,6 +246,15 @@ namespace LoggingClient.ViewModel { MessageBox.Show("Error occurred: " + ex.Message); } + } + public ObservableCollection BtnFindDuplicate_Click() + { + LoadData(); + + var duplicateList = _duplicateChecker.FindDuplicates(Logs); + Logs = new ObservableCollection(duplicateList.Cast()); + + return Logs; } private void OnPropertyChanged(string propertyName) { diff --git a/LoggingClient/LoggingClient/Views/LogView.xaml b/LoggingClient/LoggingClient/Views/LogView.xaml old mode 100644 new mode 100755 index 9c65790..ed4f076 --- a/LoggingClient/LoggingClient/Views/LogView.xaml +++ b/LoggingClient/LoggingClient/Views/LogView.xaml @@ -17,21 +17,22 @@ Text="LogReader" VerticalAlignment="Top" Width="310" FontSize="20" FontStretch= - - - - - - - + + + + + + +