diff --git a/LoggingClient/LoggingClient/LoggingClient.csproj b/LoggingClient/LoggingClient/LoggingClient.csproj
index aad4d26..78148cf 100644
--- a/LoggingClient/LoggingClient/LoggingClient.csproj
+++ b/LoggingClient/LoggingClient/LoggingClient.csproj
@@ -80,14 +80,22 @@
+
+
+
+
+
+
+ LocationView.xaml
+ LogView.xaml
@@ -105,6 +113,10 @@
MainWindow.xamlCode
+
+ Designer
+ MSBuild:Compile
+ DesignerMSBuild:Compile
diff --git a/LoggingClient/LoggingClient/MainWindow.xaml b/LoggingClient/LoggingClient/MainWindow.xaml
old mode 100644
new mode 100755
index 56acf2f..8a9132f
--- a/LoggingClient/LoggingClient/MainWindow.xaml
+++ b/LoggingClient/LoggingClient/MainWindow.xaml
@@ -2,8 +2,40 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:views="clr-namespace:LoggingClient.Views"
+ xmlns:local="clr-namespace:LoggingClient.ViewModel"
Title="MainWindow" Height="450" Width="800" ResizeMode="NoResize">
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LoggingClient/LoggingClient/Model/Location.cs b/LoggingClient/LoggingClient/Model/Location.cs
index 5012d62..fdb4dec 100755
--- a/LoggingClient/LoggingClient/Model/Location.cs
+++ b/LoggingClient/LoggingClient/Model/Location.cs
@@ -1,12 +1,26 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace LoggingClient.Model
+namespace LoggingClient.Model
{
- class Location : Model
+ public class Location : Model
{
+ public int ParentId { get; set; }
+ public int AddressId { get; set; }
+ public string Designation { get; set; }
+ public int BuildingNr { get; set; }
+ public int RoomNr { get; set; }
+
+ public Location()
+ {
+ // Emty Constructor
+ }
+
+ public Location(int id, int parentId, int addressId, string designation, int buildingNr, int roomNr)
+ {
+ this.Id = id;
+ this.ParentId = parentId;
+ this.AddressId = addressId;
+ this.Designation = designation;
+ this.BuildingNr = buildingNr;
+ this.RoomNr = roomNr;
+ }
}
}
diff --git a/LoggingClient/LoggingClient/Model/Logging.cs b/LoggingClient/LoggingClient/Model/Logging.cs
index 170146d..3653203 100755
--- a/LoggingClient/LoggingClient/Model/Logging.cs
+++ b/LoggingClient/LoggingClient/Model/Logging.cs
@@ -2,9 +2,8 @@
namespace LoggingClient.Model
{
- public class Logging : Model
+ public class Logging : Model
{
- public int Id { get; set; }
public string Pod { get; set; }
public string Location { get; set; }
public string Hostname { get; set; }
diff --git a/LoggingClient/LoggingClient/Model/Model.cs b/LoggingClient/LoggingClient/Model/Model.cs
index 46e3758..77f1460 100755
--- a/LoggingClient/LoggingClient/Model/Model.cs
+++ b/LoggingClient/LoggingClient/Model/Model.cs
@@ -1,13 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using DuplicateCheckerLib;
+using DuplicateCheckerLib;
namespace LoggingClient.Model
{
- public class Model : IEntity
+ public abstract class Model : IEntity
{
+ public int Id { get; set; }
}
}
diff --git a/LoggingClient/LoggingClient/Model/Node.cs b/LoggingClient/LoggingClient/Model/Node.cs
new file mode 100755
index 0000000..15bc92f
--- /dev/null
+++ b/LoggingClient/LoggingClient/Model/Node.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LoggingClient.Model
+{
+ public class Node
+ {
+ public M ValueObject { get; set; }
+ public Node ParentNode { get; set; }
+ public List> ChildNodesList { get; set; }
+
+ public Node()
+ {
+ this.ChildNodesList = new List>();
+ }
+ public Node(M valueObject)
+ {
+ this.ValueObject = valueObject;
+ this.ParentNode = default;
+ this.ChildNodesList = new List>();
+ }
+
+ public Node(Node parentNode, M valueObject)
+ {
+ this.ValueObject = valueObject;
+ this.ParentNode = parentNode;
+ this.ChildNodesList = new List>();
+ }
+
+ public void AddChildNode(Node childNode)
+ {
+ this.ChildNodesList.Add(childNode);
+ }
+
+ public override string ToString()
+ {
+ if (ValueObject != null)
+ {
+ return ValueObject.ToString();
+ }
+ return "-1";
+ }
+ }
+}
diff --git a/LoggingClient/LoggingClient/Model/SeverityComboBoxItem.cs b/LoggingClient/LoggingClient/Model/SeverityComboBoxItem.cs
old mode 100644
new mode 100755
index 9867ef7..9524610
--- a/LoggingClient/LoggingClient/Model/SeverityComboBoxItem.cs
+++ b/LoggingClient/LoggingClient/Model/SeverityComboBoxItem.cs
@@ -13,5 +13,4 @@ namespace LoggingClient.Model
public int Id { get; set; }
public int Severity { get; set; }
}
-
}
diff --git a/LoggingClient/LoggingClient/Repository/LocationRepository.cs b/LoggingClient/LoggingClient/Repository/LocationRepository.cs
index f13ec8e..56f2b08 100755
--- a/LoggingClient/LoggingClient/Repository/LocationRepository.cs
+++ b/LoggingClient/LoggingClient/Repository/LocationRepository.cs
@@ -1,50 +1,198 @@
using LoggingClient.Model;
+using MySql.Data.MySqlClient;
+using System;
using System.Collections.Generic;
+using System.Windows;
namespace LoggingClient.Repository
{
class LocationRepository : RepositoryBase
{
- public override string TableName => throw new System.NotImplementedException();
+ public override string TableName => "Location";
+ public override string ColumnsForSelect => "location_id, parent_location, address_fk, designation, building, room";
+ public override string ColumnsForAdd => "parent_location, address_fk, designation, building, room";
+ public override string PrimaryKeyFromTable => "location_id";
- public override void Add(Location entity)
+ public List Locations { get; set; }
+ public Location _Locations { get; set; }
+ public LocationRepository(string connectionString) : base(connectionString)
{
- throw new System.NotImplementedException();
+ Locations = new List();
+ }
+ public override void Add(Location location)
+ {
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = conn.CreateCommand())
+ {
+ cmd.CommandText =
+ $"INSERT INTO {TableName} ({ColumnsForAdd}) " +
+ $"VALUES " +
+ $"(parentId = {location.ParentId}, address_fk = {location.AddressId} , designation = '{location.Designation}', building = {location.BuildingNr} , room = {location.RoomNr} )";
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ }
}
- public override long Count(string whereCondition, Dictionary parameterValues)
+ public override void Delete(Location location)
{
- throw new System.NotImplementedException();
- }
-
- public override long Count()
- {
- throw new System.NotImplementedException();
- }
-
- public override void Delete(Location entity)
- {
- throw new System.NotImplementedException();
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = conn.CreateCommand())
+ {
+ cmd.CommandText = $"DELETE FROM {TableName} WHERE location_id = {location.Id}";
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ }
}
public override List GetAll(string whereCondition, Dictionary parameterValues)
{
- throw new System.NotImplementedException();
+ var whereCon = whereCondition;
+ if (parameterValues.Count > 0 && whereCondition != null)
+ {
+ foreach (KeyValuePair p in parameterValues)
+ {
+ whereCon = whereCon.Replace($"@{p.Key}", p.Value.ToString());
+ }
+ }
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = conn.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName} WHERE {whereCon}";
+ var reader = cmd.ExecuteReader();
+ while (reader.Read())
+ {
+ Locations.Add(new Location(
+
+ reader.GetInt32("location_id"),
+ reader.GetInt32("parent_location"),
+ reader.GetInt32("address_fk"),
+ reader.GetValue(reader.GetOrdinal("designation")) as string,
+ reader.GetInt32("building"),
+ reader.GetInt32("room")
+ ));
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ }
+ return Locations;
}
public override List GetAll()
{
- throw new System.NotImplementedException();
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = conn.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName}";
+ var reader = cmd.ExecuteReader();
+ while (reader.Read())
+ {
+ Locations.Add(new Location(
+
+ reader.GetInt32("location_id"),
+ reader.GetInt32("parent_location"),
+ reader.GetInt32("address_fk"),
+ reader.GetValue(reader.GetOrdinal("designation")) as string,
+ reader.GetInt32("building"),
+ reader.GetInt32("room")
+ ));
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ }
+ return Locations;
+ }
+
+ public override void CallStoredProcedure(Location entity)
+ {
+ throw new System.NotSupportedException();
}
public override Location GetSingle
(P pkValue)
{
- throw new System.NotImplementedException();
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = conn.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName} WHERE {PrimaryKeyFromTable} = {pkValue}";
+ var reader = cmd.ExecuteReader();
+ while (reader.Read())
+ {
+ _Locations = (new Location(
+
+ reader.GetInt32("location_id"),
+ reader.GetInt32("parent_location"),
+ reader.GetInt32("address_fk"),
+ reader.GetValue(reader.GetOrdinal("designation")) as string,
+ reader.GetInt32("building"),
+ reader.GetInt32("room")
+ ));
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ }
+ return _Locations;
}
- public override void Update(Location entity)
+ public override void Update(Location location)
{
- throw new System.NotImplementedException();
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = conn.CreateCommand())
+ {
+ cmd.CommandText =
+ $"UPDATE {TableName} SET address_fk = {location.Id} , designation = '{location.Designation}', building = {location.BuildingNr} , room = {location.RoomNr} WHERE location_id = {location.Id}";
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ }
}
}
}
diff --git a/LoggingClient/LoggingClient/Repository/LoggingRepository.cs b/LoggingClient/LoggingClient/Repository/LoggingRepository.cs
index 36bf3d4..f1a2a31 100755
--- a/LoggingClient/LoggingClient/Repository/LoggingRepository.cs
+++ b/LoggingClient/LoggingClient/Repository/LoggingRepository.cs
@@ -1,54 +1,192 @@
-using LoggingClient.Model;
-using System;
+using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows;
+using MySql.Data.MySqlClient;
+using LoggingClient.Model;
namespace LoggingClient.Repository
{
class LoggingRepository : RepositoryBase
{
- public override string TableName => throw new NotImplementedException();
+ public override string TableName => "v_logentries";
+ public override string ColumnsForSelect => "id, pod, location, hostname, severity, timestamp, message";
+ public override string ColumnsForAdd { get; }
+ public override string PrimaryKeyFromTable => "id";
- public override void Add(Logging entity)
- {
- throw new NotImplementedException();
- }
+ public List Logs { get; set; }
+ public Logging _Logs { get; set; }
- public override long Count(string whereCondition, Dictionary parameterValues)
+ public LoggingRepository(string connectionString) : base(connectionString)
{
- throw new NotImplementedException();
- }
-
- public override long Count()
- {
- throw new NotImplementedException();
- }
-
- public override void Delete(Logging entity)
- {
- throw new NotImplementedException();
- }
-
- public override List GetAll(string whereCondition, Dictionary parameterValues)
- {
- throw new NotImplementedException();
- }
-
- public override List GetAll()
- {
- throw new NotImplementedException();
+ Logs = new List();
}
public override Logging GetSingle
(P pkValue)
{
- throw new NotImplementedException();
- }
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = conn.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName} WHERE {PrimaryKeyFromTable} = {pkValue}";
+ var reader = cmd.ExecuteReader();
+ while (reader.Read())
+ {
+ _Logs = (new Logging(
+ reader.GetInt32("id"),
+ reader.GetValue(reader.GetOrdinal("pod")) as string,
+ reader.GetValue(reader.GetOrdinal("location")) as string,
+ reader.GetValue(reader.GetOrdinal("hostname")) as string,
+ reader.GetInt32("severity"),
+ reader.GetDateTime("timestamp"),
+ reader.GetValue(reader.GetOrdinal("message")) as string
+ ));
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ }
+ return _Logs;
+ }
+ public override void Add(Logging newLogging)
+ {
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = conn.CreateCommand())
+ {
+ cmd.CommandText = "LogMessageAdd";
+ cmd.CommandType = CommandType.StoredProcedure;
+
+ cmd.Parameters.Add("@i_pod", MySqlDbType.String).Value = newLogging.Pod;
+ cmd.Parameters.Add("@i_hostname", MySqlDbType.String).Value = newLogging.Hostname;
+ cmd.Parameters.Add("@i_severity", MySqlDbType.Int32).Value = newLogging.Severity;
+ cmd.Parameters.Add("@i_message", MySqlDbType.String).Value = newLogging.Message;
+
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ }
+ }
+ public override void Delete(Logging entity)
+ {
+ throw new System.NotSupportedException();
+ }
public override void Update(Logging entity)
{
- throw new NotImplementedException();
+ throw new System.NotSupportedException();
+ }
+ public override List GetAll(string whereCondition, Dictionary parameterValues)
+ {
+ var whereCon = whereCondition;
+ if (parameterValues.Count > 0 && whereCondition != null)
+ {
+ foreach (KeyValuePair p in parameterValues)
+ {
+ whereCon = whereCon.Replace($"@{p.Key}", p.Value.ToString());
+ }
+ }
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = conn.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName} WHERE {whereCon}";
+ var reader = cmd.ExecuteReader();
+ while (reader.Read())
+ {
+ Logs.Add(new Logging(
+
+ reader.GetInt32("id"),
+ reader.GetValue(reader.GetOrdinal("pod")) as string,
+ reader.GetValue(reader.GetOrdinal("location")) as string,
+ reader.GetValue(reader.GetOrdinal("hostname")) as string,
+ reader.GetInt32("severity"),
+ reader.GetDateTime("timestamp"),
+ reader.GetValue(reader.GetOrdinal("message")) as string
+ ));
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ }
+ return Logs;
+ }
+ public override List GetAll()
+ {
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = conn.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName}";
+ var reader = cmd.ExecuteReader();
+ while (reader.Read())
+ {
+ Logs.Add(new Logging(
+
+ reader.GetInt32("id"),
+ reader.GetValue(reader.GetOrdinal("pod")) as string,
+ reader.GetValue(reader.GetOrdinal("location")) as string,
+ reader.GetValue(reader.GetOrdinal("hostname")) as string,
+ reader.GetInt32("severity"),
+ reader.GetDateTime("timestamp"),
+ reader.GetValue(reader.GetOrdinal("message")) as string
+ ));
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ }
+ return Logs;
+ }
+ public override void CallStoredProcedure(Logging logModelEntry)
+ {
+ try
+ {
+ using (var conn = new MySqlConnection(ConnectionString))
+ {
+ conn.Open();
+ using (var cmd = conn.CreateCommand())
+ {
+ cmd.CommandText = "LogClear";
+ cmd.CommandType = CommandType.StoredProcedure;
+ cmd.Parameters.AddWithValue("_logentries_id", logModelEntry.Id);
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ catch (MySqlException ex)
+ {
+ MessageBox.Show(ex.ToString());
+ }
}
}
-}
+}
\ No newline at end of file
diff --git a/LoggingClient/LoggingClient/Repository/RepositoryBase.cs b/LoggingClient/LoggingClient/Repository/RepositoryBase.cs
index b2000f2..f2289f9 100755
--- a/LoggingClient/LoggingClient/Repository/RepositoryBase.cs
+++ b/LoggingClient/LoggingClient/Repository/RepositoryBase.cs
@@ -1,22 +1,86 @@
-using System;
+using MySql.Data.MySqlClient;
+using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Windows;
namespace LoggingClient.Repository
{
public abstract class RepositoryBase : IRepositoryBase
{
- public abstract string TableName { get; }
+ protected RepositoryBase(string connectionString)
+ {
+ this.ConnectionString = connectionString;
+ }
+ protected string ConnectionString { get; }
+ public abstract M GetSingle
(P pkValue);
public abstract void Add(M entity);
- public abstract long Count(string whereCondition, Dictionary parameterValues);
- public abstract long Count();
+
public abstract void Delete(M entity);
- public abstract List GetAll(string whereCondition, Dictionary parameterValues);
- public abstract List GetAll();
- public abstract M GetSingle
(P pkValue);
+
public abstract void Update(M entity);
+ public abstract List GetAll(string whereCondition, Dictionary parameterValues);
+
+ public abstract List GetAll();
+
+ public abstract void CallStoredProcedure(M entity);
+
+ public IQueryable Query(string whereCondition, Dictionary parameterValues)
+ {
+ throw new System.NotSupportedException();
+ }
+ public long Count(string whereCondition, Dictionary parameterValues)
+ {
+ var whereCon = whereCondition;
+ if (parameterValues.Count > 0 && whereCondition != null)
+ {
+ foreach (KeyValuePair p in parameterValues)
+ {
+ whereCon = whereCon.Replace($"@{p.Key}", p.Value.ToString());
+ }
+ }
+ try
+ {
+ using (var conn = new MySqlConnection(this.ConnectionString))
+ {
+ using (var cmd = conn.CreateCommand())
+ {
+ conn.Open();
+ cmd.CommandText = $"select count(*) from {this.TableName} where {whereCon}";
+ return (long)cmd.ExecuteScalar();
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ return -1;
+ }
+ }
+ public long Count()
+ {
+ try
+ {
+ using (var conn = new MySqlConnection(this.ConnectionString))
+ {
+ using (var cmd = conn.CreateCommand())
+ {
+ conn.Open();
+ cmd.CommandText = $"select count(*) from {this.TableName}";
+ return (long)cmd.ExecuteScalar();
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Error occurred: " + ex.Message);
+ return -1;
+ }
+ }
+ public abstract string TableName { get; }
+ public abstract string ColumnsForSelect { get; }
+ public abstract string ColumnsForAdd { get; }
+ public abstract string PrimaryKeyFromTable { get; }
}
}
\ No newline at end of file
diff --git a/LoggingClient/LoggingClient/ViewModel/Commands/BaseCommand.cs b/LoggingClient/LoggingClient/ViewModel/Commands/BaseCommand.cs
new file mode 100755
index 0000000..dc5c328
--- /dev/null
+++ b/LoggingClient/LoggingClient/ViewModel/Commands/BaseCommand.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+
+namespace WpfControlNugget.ViewModel.Commands
+{
+ public class BaseCommand : ICommand
+ {
+ private Action