add Find Duplicate Functionality

This commit is contained in:
Francesco 2020-07-21 19:19:57 +02:00
parent 9d7c8e4632
commit 222ec50064
5 changed files with 93 additions and 34 deletions

View File

@ -41,6 +41,9 @@
<Reference Include="BouncyCastle.Crypto, Version=1.8.3.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\packages\BouncyCastle.1.8.3.1\lib\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="DuplicateCheckerLib">
<HintPath>..\..\Aufgaben\DuplicateCheckerLib\DuplicateCheckerLib.dll</HintPath>
</Reference>
<Reference Include="Google.Protobuf, Version=3.6.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
<HintPath>..\packages\Google.Protobuf.3.6.1\lib\net45\Google.Protobuf.dll</HintPath>
</Reference>

62
LoggingClient/LoggingClient/Model/LogModel.cs Normal file → Executable file
View File

@ -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;
}
}
}
}

41
LoggingClient/LoggingClient/ViewModel/LogViewModel.cs Normal file → Executable file
View File

@ -7,6 +7,8 @@ using System.Windows.Input;
using MySql.Data.MySqlClient;
using LoggingClient.Model;
using LoggingClient.ViewModel.Commands;
using DuplicateCheckerLib;
using System.Linq;
namespace LoggingClient.ViewModel
{
@ -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<LogModel> Logs { get; set; }
public ObservableCollection<LogModel> Logs
{
get => _logs;
set
{
_logs = value;
OnPropertyChanged("Logs");
}
}
private ObservableCollection<LogModel> _logs;
public ObservableCollection<SeverityComboBoxItem> 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<LogModel>();
@ -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();
}
}
@ -221,6 +247,15 @@ namespace LoggingClient.ViewModel
MessageBox.Show("Error occurred: " + ex.Message);
}
}
public ObservableCollection<LogModel> BtnFindDuplicate_Click()
{
LoadData();
var duplicateList = _duplicateChecker.FindDuplicates(Logs);
Logs = new ObservableCollection<LogModel>(duplicateList.Cast<LogModel>());
return Logs;
}
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

17
LoggingClient/LoggingClient/Views/LogView.xaml Normal file → Executable file
View File

@ -17,21 +17,22 @@ Text="LogReader" VerticalAlignment="Top" Width="310" FontSize="20" FontStretch=
<DataGrid AutoGenerateColumns="False" HorizontalAlignment="Left" SelectedItem="{Binding MySelectedItem, Mode=TwoWay}" Margin="10,55,0,97" Name="DataGridCustomers" Width="780" ItemsSource="{Binding Path=Logs}"
CanUserResizeRows="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=id}" Header="id" Width="70" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=pod}" Header="pod" Width="70" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=location}" Header="location" Width="111" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=hostname}" Header="hostname" Width="111" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=severity}" Header="severity" Width="70" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=timestamp}" Header="timestamp" Width="130" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=message}" Header="message" Width="215" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=Id}" Header="ID" Width="70" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=Pod}" Header="POD" Width="70" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=Location}" Header="Location" Width="111" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=Hostname}" Header="Hostname" Width="111" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=Severity}" Header="Severity" Width="70" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=Timestamp}" Header="Timestamp" Width="130" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Path=Message}" Header="Message" Width="215" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
<Label Content="Database Connection" HorizontalAlignment="Left" Margin="118,22,0,0" VerticalAlignment="Top" Height="23" Width="125" Background="{x:Null}" RenderTransformOrigin="0.366,0.725"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="248,22,0,0" TextWrapping="Wrap" Text="{Binding TxtConnectionString}" Name="TxtConnectionString" VerticalAlignment="Top" Width="525" />
<Button Content="Find duplicate" Height="25" HorizontalAlignment="Left" Margin="545,355,0,0" x:Name="BtnFindDuplicate" VerticalAlignment="Top" Width="78" Command="{Binding BtnFindDuplicateClick}" />
<Button Content="Load Data" Height="25" HorizontalAlignment="Left" Margin="628,355,0,0" Name="Btnloaddata" VerticalAlignment="Top" Width="70" Command="{Binding BtnLoadDataClick}" />
<Button Content="Confirm" Height="25" HorizontalAlignment="Left" Margin="703,355,0,0" Name="BtnConfirm" VerticalAlignment="Top" Width="70" Command="{Binding BtnConfirmDataClick}"/>
<Button Content="Add" Height="25" HorizontalAlignment="Left" Margin="553,355,0,0" Name="BtnAdd" VerticalAlignment="Top" Width="70" Command="{Binding BtnAddDataClick}">
<Button Content="Add" Height="25" HorizontalAlignment="Left" Margin="470,355,0,0" Name="BtnAdd" VerticalAlignment="Top" Width="70" Command="{Binding BtnAddDataClick}">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>

0
LoggingClient/LoggingClient/Views/LogView.xaml.cs Normal file → Executable file
View File