add Find Duplicate Functionality
This commit is contained in:
parent
9d7c8e4632
commit
222ec50064
@ -41,6 +41,9 @@
|
|||||||
<Reference Include="BouncyCastle.Crypto, Version=1.8.3.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
|
<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>
|
<HintPath>..\packages\BouncyCastle.1.8.3.1\lib\BouncyCastle.Crypto.dll</HintPath>
|
||||||
</Reference>
|
</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">
|
<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>
|
<HintPath>..\packages\Google.Protobuf.3.6.1\lib\net45\Google.Protobuf.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
64
LoggingClient/LoggingClient/Model/LogModel.cs
Normal file → Executable file
64
LoggingClient/LoggingClient/Model/LogModel.cs
Normal file → Executable file
@ -1,32 +1,52 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using DuplicateCheckerLib;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace LoggingClient.Model
|
namespace LoggingClient.Model
|
||||||
{
|
{
|
||||||
public class LogModel
|
public class LogModel : IEntity
|
||||||
{
|
{
|
||||||
public int id { get; set; }
|
public int Id { get; set; }
|
||||||
public string pod { get; set; }
|
public string Pod { get; set; }
|
||||||
public string location { get; set; }
|
public string Location { get; set; }
|
||||||
public string hostname { get; set; }
|
public string Hostname { get; set; }
|
||||||
public int severity { get; set; }
|
public int Severity { get; set; }
|
||||||
public DateTime timestamp { get; set; }
|
public DateTime Timestamp { get; set; }
|
||||||
public string message { get; set; }
|
public string Message { get; set; }
|
||||||
|
|
||||||
public LogModel(int id, string pod, string location, string hostname, int severity, DateTime timestamp, string message)
|
public LogModel(int id, string pod, string location, string hostname, int severity, DateTime timestamp, string message)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.Id = id;
|
||||||
this.pod = pod;
|
this.Pod = pod;
|
||||||
this.location = location;
|
this.Location = location;
|
||||||
this.hostname = hostname;
|
this.Hostname = hostname;
|
||||||
this.severity = severity;
|
this.Severity = severity;
|
||||||
this.timestamp = timestamp;
|
this.Timestamp = timestamp;
|
||||||
this.message = message;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
LoggingClient/LoggingClient/ViewModel/LogViewModel.cs
Normal file → Executable file
43
LoggingClient/LoggingClient/ViewModel/LogViewModel.cs
Normal file → Executable file
@ -7,7 +7,9 @@ using System.Windows.Input;
|
|||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
using LoggingClient.Model;
|
using LoggingClient.Model;
|
||||||
using LoggingClient.ViewModel.Commands;
|
using LoggingClient.ViewModel.Commands;
|
||||||
|
using DuplicateCheckerLib;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace LoggingClient.ViewModel
|
namespace LoggingClient.ViewModel
|
||||||
{
|
{
|
||||||
public class LogViewModel : INotifyPropertyChanged
|
public class LogViewModel : INotifyPropertyChanged
|
||||||
@ -17,17 +19,28 @@ namespace LoggingClient.ViewModel
|
|||||||
private string _enterHostname;
|
private string _enterHostname;
|
||||||
private int _enterSeverity;
|
private int _enterSeverity;
|
||||||
private string _enterMessage;
|
private string _enterMessage;
|
||||||
|
private readonly DuplicateChecker _duplicateChecker;
|
||||||
|
|
||||||
private ICommand _btnLoadDataClick;
|
private ICommand _btnLoadDataClick;
|
||||||
private ICommand _btnConfirmdataClick;
|
private ICommand _btnConfirmdataClick;
|
||||||
private ICommand _btnAdddataClick;
|
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 ObservableCollection<SeverityComboBoxItem> SeverityComboBox { get; set; }
|
||||||
|
|
||||||
public LogViewModel()
|
public LogViewModel()
|
||||||
{
|
{
|
||||||
TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;";
|
TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=foekicoe9i4kpos;";
|
||||||
_enterSeverity = 1;
|
_enterSeverity = 1;
|
||||||
|
|
||||||
Logs = new ObservableCollection<LogModel>();
|
Logs = new ObservableCollection<LogModel>();
|
||||||
@ -36,6 +49,7 @@ namespace LoggingClient.ViewModel
|
|||||||
new SeverityComboBoxItem(){Id=2, Severity= 2},
|
new SeverityComboBoxItem(){Id=2, Severity= 2},
|
||||||
new SeverityComboBoxItem(){Id=3, Severity= 3}
|
new SeverityComboBoxItem(){Id=3, Severity= 3}
|
||||||
};
|
};
|
||||||
|
_duplicateChecker = new DuplicateChecker();
|
||||||
}
|
}
|
||||||
public LogModel MySelectedItem { get; set; }
|
public LogModel MySelectedItem { get; set; }
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
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
|
public ICommand BtnConfirmDataClick
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -184,7 +210,7 @@ namespace LoggingClient.ViewModel
|
|||||||
{
|
{
|
||||||
cmd.CommandText = "LogClear";
|
cmd.CommandText = "LogClear";
|
||||||
cmd.CommandType = CommandType.StoredProcedure;
|
cmd.CommandType = CommandType.StoredProcedure;
|
||||||
cmd.Parameters.AddWithValue("_logentries_id", MySelectedItem.id);
|
cmd.Parameters.AddWithValue("_logentries_id", MySelectedItem.Id);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,6 +246,15 @@ namespace LoggingClient.ViewModel
|
|||||||
{
|
{
|
||||||
MessageBox.Show("Error occurred: " + ex.Message);
|
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)
|
private void OnPropertyChanged(string propertyName)
|
||||||
{
|
{
|
||||||
|
17
LoggingClient/LoggingClient/Views/LogView.xaml
Normal file → Executable file
17
LoggingClient/LoggingClient/Views/LogView.xaml
Normal file → Executable 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}"
|
<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">
|
CanUserResizeRows="False">
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn Binding="{Binding Path=id}" Header="id" Width="70" 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=Pod}" Header="POD" Width="70" IsReadOnly="True" />
|
||||||
<DataGridTextColumn Binding="{Binding Path=location}" Header="location" Width="111" 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=Hostname}" Header="Hostname" Width="111" IsReadOnly="True" />
|
||||||
<DataGridTextColumn Binding="{Binding Path=severity}" Header="severity" Width="70" 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=Timestamp}" Header="Timestamp" Width="130" IsReadOnly="True" />
|
||||||
<DataGridTextColumn Binding="{Binding Path=message}" Header="message" Width="215" IsReadOnly="True" />
|
<DataGridTextColumn Binding="{Binding Path=Message}" Header="Message" Width="215" IsReadOnly="True" />
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</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"/>
|
<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" />
|
<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="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="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>
|
<Button.Style>
|
||||||
<Style TargetType="{x:Type Button}">
|
<Style TargetType="{x:Type Button}">
|
||||||
<Style.Triggers>
|
<Style.Triggers>
|
||||||
|
0
LoggingClient/LoggingClient/Views/LogView.xaml.cs
Normal file → Executable file
0
LoggingClient/LoggingClient/Views/LogView.xaml.cs
Normal file → Executable file
Loading…
Reference in New Issue
Block a user