first commit

This commit is contained in:
frauseo 2020-05-30 19:58:21 +02:00
commit 9257927aa7
14 changed files with 1158 additions and 0 deletions

355
.gitignore vendored Normal file
View File

@ -0,0 +1,355 @@
# Created by https://www.gitignore.io/api/csharp
# Edit at https://www.gitignore.io/?templates=csharp
### Csharp ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# End of https://www.gitignore.io/api/csharp

25
LoggingClient.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoggingClient", "LoggingClient\LoggingClient.csproj", "{F29F34C6-BCAE-48BE-A698-845B1E45DE96}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F29F34C6-BCAE-48BE-A698-845B1E45DE96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F29F34C6-BCAE-48BE-A698-845B1E45DE96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F29F34C6-BCAE-48BE-A698-845B1E45DE96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F29F34C6-BCAE-48BE-A698-845B1E45DE96}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0BD9A3EC-EBC8-48BB-BA13-E0A6DCC7533F}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F29F34C6-BCAE-48BE-A698-845B1E45DE96}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LoggingClient</RootNamespace>
<AssemblyName>LoggingClient</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<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="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>
<Reference Include="K4os.Compression.LZ4, Version=1.1.11.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d, processorArchitecture=MSIL">
<HintPath>..\packages\K4os.Compression.LZ4.1.1.11\lib\net46\K4os.Compression.LZ4.dll</HintPath>
</Reference>
<Reference Include="K4os.Compression.LZ4.Streams, Version=1.1.11.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d, processorArchitecture=MSIL">
<HintPath>..\packages\K4os.Compression.LZ4.Streams.1.1.11\lib\net46\K4os.Compression.LZ4.Streams.dll</HintPath>
</Reference>
<Reference Include="K4os.Hash.xxHash, Version=1.0.6.0, Culture=neutral, PublicKeyToken=32cd54395057cec3, processorArchitecture=MSIL">
<HintPath>..\packages\K4os.Hash.xxHash.1.0.6\lib\net46\K4os.Hash.xxHash.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=8.0.20.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.8.0.20\lib\net452\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Renci.SshNet, Version=2016.1.0.0, Culture=neutral, PublicKeyToken=1cee9f8bde3db106, processorArchitecture=MSIL">
<HintPath>..\packages\SSH.NET.2016.1.0\lib\net40\Renci.SshNet.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Design" />
<Reference Include="System.Management" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Transactions" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Ubiety.Dns.Core, Version=2.2.1.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.8.0.20\lib\net452\Ubiety.Dns.Core.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="Zstandard.Net, Version=1.1.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.8.0.20\lib\net452\Zstandard.Net.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Model\LogModel.cs" />
<Compile Include="Model\SeverityComboBoxItem.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Validators\IntRangeValidationRule.cs" />
<Compile Include="Validators\StringRangeValidationRule.cs" />
<Compile Include="ViewModel\Commands\RelayCommand.cs" />
<Compile Include="ViewModel\LogViewModel.cs" />
<Compile Include="Views\LogView.xaml.cs">
<DependentUpon>LogView.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Page Include="Views\LogView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,32 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LoggingClient.Model
{
public class LogModel
{
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;
}
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace LoggingClient.Model
{
public class SeverityComboBoxItem
{
public int Id { get; set; }
public int Severity { get; set; }
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LoggingClient")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoggingClient")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f29f34c6-bcae-48be-a698-845b1e45de96")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace LoggingClient.Validators
{
public class IntRangeValidationRule : ValidationRule
{
private int Min = 1;
private int Max = 3;
public int MinimumLength
{
get { return Min; }
set { Min = value; }
}
public int MaximumLength
{
get { return Max; }
set { Max = value; }
}
public override ValidationResult Validate(object value,
CultureInfo cultureInfo)
{
int parameter = 0;
try
{
if (((string)value).Length > 0)
{
parameter = Int32.Parse((String)value);
}
}
catch (Exception e)
{
return new ValidationResult(false, "Illegal characters or "
+ e.Message);
}
if ((parameter < this.Min) || (parameter > this.Max))
{
return new ValidationResult(false,
"Severity must be a number between "
+ this.Min + " - " + this.Max + ".");
}
return new ValidationResult(true, null);
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace LoggingClient.Validators
{
public class StringRangeValidationRule : ValidationRule
{
private int _minimumLength = 3;
private int _maximumLength = 255;
public int MinimumLength
{
get { return _minimumLength; }
set { _minimumLength = value; }
}
public int MaximumLength
{
get { return _maximumLength; }
set { _maximumLength = value; }
}
public string ErrorMessage { get; set; }
public override ValidationResult Validate(object value,
CultureInfo cultureInfo)
{
ValidationResult result = new ValidationResult(true, null);
string inputString = (value ?? string.Empty).ToString();
if (inputString.Length < this.MinimumLength ||
(this.MaximumLength > 0 &&
inputString.Length > this.MaximumLength))
{
result = new ValidationResult(false, this.ErrorMessage);
}
return result;
}
}
}

View File

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace LoggingClient.ViewModel.Commands
{
public class RelayCommand<T> : ICommand
{
private readonly Predicate<T> _canExecute;
private readonly Action<T> _execute;
public RelayCommand(Action<T> execute)
: this(execute, null)
{
_execute = execute;
}
public RelayCommand(Action<T> execute, Predicate<T> canExecute)
{
if (execute == null)
{
throw new ArgumentNullException("execute");
}
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute == null || _canExecute((T)parameter);
}
public void Execute(object parameter)
{
_execute((T)parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
}
public class RelayCommand : ICommand
{
private readonly Predicate<object> _canExecute;
private readonly Action<object> _execute;
public RelayCommand(Action<object> execute)
: this(execute, null)
{
_execute = execute;
}
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
if (execute == null)
{
throw new ArgumentNullException("execute");
}
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute == null || _canExecute(parameter);
}
public void Execute(object parameter)
{
_execute(parameter);
}
// Ensures WPF commanding infrastructure asks all RelayCommand objects whether their
// associated views should be enabled whenever a command is invoked
public event EventHandler CanExecuteChanged
{
add
{
CommandManager.RequerySuggested += value;
CanExecuteChangedInternal += value;
}
remove
{
CommandManager.RequerySuggested -= value;
CanExecuteChangedInternal -= value;
}
}
private event EventHandler CanExecuteChangedInternal;
public void RaiseCanExecuteChanged()
{
//CanExecuteChangedInternal.Raise(this);
}
}
}

View File

@ -0,0 +1,229 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Input;
using MySql.Data.MySqlClient;
using LoggingClient.Model;
using LoggingClient.ViewModel.Commands;
namespace LoggingClient.ViewModel
{
public class LogViewModel : INotifyPropertyChanged
{
private string _txtConnectionString;
private string _enterPod;
private string _enterHostname;
private int _enterSeverity;
private string _enterMessage;
private ICommand _btnLoadDataClick;
private ICommand _btnConfirmdataClick;
private ICommand _btnAdddataClick;
public ObservableCollection<LogModel> Logs { get; set; }
public ObservableCollection<SeverityComboBoxItem> SeverityComboBox { get; set; }
public LogViewModel()
{
TxtConnectionString = "Server=localhost;Database=DATABASENAME;Uid=root;Pwd=MySQLPASSWORD;";
_enterSeverity = 1;
Logs = new ObservableCollection<LogModel>();
SeverityComboBox = new ObservableCollection<SeverityComboBoxItem>(){
new SeverityComboBoxItem(){Id=1, Severity= 1},
new SeverityComboBoxItem(){Id=2, Severity= 2},
new SeverityComboBoxItem(){Id=3, Severity= 3}
};
}
public LogModel MySelectedItem { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public SeverityComboBoxItem SetSeverity { get; set; }
public string TxtConnectionString
{
get => _txtConnectionString;
set
{
_txtConnectionString = value;
OnPropertyChanged(nameof(TxtConnectionString));
}
}
public string EnterPod
{
get => _enterPod;
set
{
_enterPod = value;
OnPropertyChanged(nameof(EnterPod));
}
}
public string EnterHostname
{
get => _enterHostname;
set
{
_enterHostname = value;
OnPropertyChanged(nameof(EnterHostname));
}
}
public int EnterSeverity
{
get => _enterSeverity;
set
{
_enterSeverity = value;
OnPropertyChanged(nameof(EnterSeverity));
}
}
public string EnterMessage
{
get => _enterMessage;
set
{
_enterMessage = value;
OnPropertyChanged(nameof(EnterMessage));
}
}
public ICommand BtnLoadDataClick
{
get
{
return _btnLoadDataClick ?? (_btnLoadDataClick = new RelayCommand(
x =>
{
BtnLoadData_Click();
}));
}
}
public ICommand BtnAddDataClick
{
get
{
return _btnAdddataClick ?? (_btnAdddataClick = new RelayCommand(
x =>
{
BtnAdd_Click();
}));
}
}
public ICommand BtnConfirmDataClick
{
get
{
return _btnConfirmdataClick ?? (_btnConfirmdataClick = new RelayCommand(
x =>
{
BtnLogClear_Click();
}));
}
}
public void BtnLoadData_Click()
{
try
{
LoadData();
}
catch (Exception ex)
{
MessageBox.Show("Error occurred: " + ex.Message);
}
}
private void LoadData()
{
try
{
Logs.Clear();
using (var conn = new MySqlConnection(TxtConnectionString))
{
conn.Open();
using (var cmd = new MySqlCommand("SELECT id, pod, location, hostname, severity, timestamp, message FROM v_logentries ORDER BY timestamp", conn))
{
var reader = cmd.ExecuteReader();
while (reader.Read())
{
// ISDBNull Check because location can be NULL in Database
var location = "";
if (!reader.IsDBNull(reader.GetOrdinal("location")))
{
location = reader.GetString("location");
}
Logs.Add(new LogModel(
reader.GetInt32("id"),
reader.GetString("pod"),
location,
reader.GetString("hostname"),
reader.GetInt32("severity"),
reader.GetDateTime("timestamp"),
reader.GetString("message")
));
}
}
conn.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("Error occurred: " + ex.Message);
}
}
private void BtnLogClear_Click()
{
if (MySelectedItem == null) return;
try
{
using (var conn = new MySqlConnection(TxtConnectionString))
{
conn.Open();
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "LogClear";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("_logentries_id", MySelectedItem.id);
cmd.ExecuteNonQuery();
}
}
LoadData();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.ToString());
}
}
private void BtnAdd_Click()
{
try
{
using (var conn = new MySqlConnection(TxtConnectionString))
{
using (MySqlCommand cmd = new MySqlCommand("LogMessageAdd", conn))
{
conn.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@i_pod", MySqlDbType.String).Value = EnterPod;
cmd.Parameters.Add("@i_hostname", MySqlDbType.String).Value = EnterHostname;
cmd.Parameters.Add("@i_severity", MySqlDbType.Int32).Value = EnterSeverity;
cmd.Parameters.Add("@i_message", MySqlDbType.String).Value = EnterMessage;
cmd.ExecuteNonQuery();
}
LoadData();
}
}
catch (Exception ex)
{
MessageBox.Show("Error occurred: " + ex.Message);
}
}
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@ -0,0 +1,96 @@
<UserControl x:Class="LoggingClient.Views.LogView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LoggingClient.Views"
xmlns:validators="clr-namespace:LoggingClient.Validators"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="#FF89A9B2">
<TextBlock Height="32" HorizontalAlignment="Left" Margin="10,18,0,0" Name="TextBlockHeading"
Text="LogReader" VerticalAlignment="Top" Width="310" FontSize="20" FontStretch="Normal"/>
<Grid HorizontalAlignment="Left" Height="416" VerticalAlignment="Top" Width="773">
<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" />
</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="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.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding Text.Length, ElementName=EnterPod, UpdateSourceTrigger=PropertyChanged}" Value="0">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
<DataTrigger Binding="{Binding Text.Length, ElementName=EnterHostname, UpdateSourceTrigger=PropertyChanged}" Value="0">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
<DataTrigger Binding="{Binding Text.Length, ElementName=EnterSeverity, UpdateSourceTrigger=PropertyChanged}" Value="0">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
<DataTrigger Binding="{Binding Text.Length, ElementName=EnterMessage, UpdateSourceTrigger=PropertyChanged}" Value="0">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<TextBox HorizontalAlignment="Left" Height="25" Margin="10,355,0,0" TextWrapping="Wrap" Name="EnterPod" VerticalAlignment="Top" Width="110">
<TextBox.Text>
<Binding Path="EnterPod" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<validators:StringRangeValidationRule
ErrorMessage="Pod must contain atleast 3 characters up to 255" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<TextBox HorizontalAlignment="Left" Height="25" Margin="125,355,0,0" TextWrapping="Wrap" Name="EnterHostname" VerticalAlignment="Top" Width="110">
<TextBox.Text>
<Binding Path="EnterHostname" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<validators:StringRangeValidationRule
ErrorMessage="Hostname must contain atleast 3 characters up to 255" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<TextBox HorizontalAlignment="Left" Height="25" Margin="240,355,0,0" TextWrapping="Wrap" Name="EnterSeverity" VerticalAlignment="Top" Width="110" >
<TextBox.Text>
<Binding Path="EnterSeverity" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<validators:IntRangeValidationRule/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<TextBox HorizontalAlignment="Left" Height="50" Margin="355,355,0,0" TextWrapping="Wrap" Name="EnterMessage" VerticalAlignment="Top" Width="110">
<TextBox.Text>
<Binding Path="EnterMessage" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<validators:StringRangeValidationRule
ErrorMessage="Message must contain atleast 3 characters up to 255" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<Label Content="Enter Pod" HorizontalAlignment="Left" Margin="10,324,0,0" VerticalAlignment="Top" Width="110"/>
<Label Content="Enter Hostname" HorizontalAlignment="Left" Margin="125,324,0,0" VerticalAlignment="Top" Width="110"/>
<Label Content="Enter Severity" HorizontalAlignment="Left" Margin="240,324,0,0" VerticalAlignment="Top" Width="110"/>
<Label Content="Enter Message" HorizontalAlignment="Left" Margin="355,324,0,0" VerticalAlignment="Top" Width="110"/>
</Grid>
</Grid>
</UserControl>

View File

@ -0,0 +1,17 @@
using LoggingClient.ViewModel;
using System.Windows.Controls;
namespace LoggingClient.Views
{
/// <summary>
/// Interaction logic for LogView.xaml
/// </summary>
public partial class LogView : UserControl
{
public LogView()
{
InitializeComponent();
DataContext = new LogViewModel();
}
}
}

15
LoggingClient/app.config Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle" version="1.8.3.1" targetFramework="net472" />
<package id="Google.Protobuf" version="3.6.1" targetFramework="net472" />
<package id="K4os.Compression.LZ4" version="1.1.11" targetFramework="net472" />
<package id="K4os.Compression.LZ4.Streams" version="1.1.11" targetFramework="net472" />
<package id="K4os.Hash.xxHash" version="1.0.6" targetFramework="net472" />
<package id="MySql.Data" version="8.0.20" targetFramework="net472" />
<package id="SSH.NET" version="2016.1.0" targetFramework="net472" />
<package id="System.Buffers" version="4.5.0" targetFramework="net472" />
<package id="System.Memory" version="4.5.3" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net472" />
</packages>