Created GUI; functionality of Load Data and Confirm

This commit is contained in:
frauseo 2020-05-23 18:54:14 +02:00
parent e1ce5a851b
commit f6be9f23f8
21 changed files with 1060 additions and 339 deletions

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MonitoringClient.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<MonitoringClient.Properties.Settings>
<setting name="ConnectionString" serializeAs="String">
<value />
</setting>
</MonitoringClient.Properties.Settings>
</userSettings>
</configuration>

View File

@ -0,0 +1,36 @@
<Application x:Class="LoggingClient.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LoggingClient"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Right"
Foreground="Orange"
FontSize="12pt">
</TextBlock>
<Border BorderBrush="Red" BorderThickness="1">
<AdornedElementPlaceholder />
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
</Application.Resources>
</Application>

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace WpfControlNugget
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View File

@ -1,21 +1,22 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <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')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2622c2fc-3522-4d6f-b021-f63a243e77f1}</ProjectGuid> <ProjectGuid>{2622C2FC-3522-4D6F-B021-F63A243E77F1}</ProjectGuid>
<OutputType>library</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>LoggingClient</RootNamespace> <RootNamespace>LoggingClient</RootNamespace>
<AssemblyName>LoggingClient</AssemblyName> <AssemblyName>LoggingClient</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
@ -25,6 +26,7 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
@ -32,72 +34,102 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup> <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="MySql.Data, Version=8.0.16.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.8.0.16\lib\net452\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Design" />
<Reference Include="System.Management" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Xaml"> <Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework> <RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Include="UserControl1.xaml"> <ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Model\SeverityComboBoxItem.cs" />
<Compile Include="Validators\IntRangeValidationRule.cs" />
<Compile Include="ViewModel\Commands\RelayCommand.cs" />
<Compile Include="Validators\StringRangeValidationRule.cs" />
<Compile Include="Views\LogView.xaml.cs">
<DependentUpon>LogView.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Compile Include="UserControl1.xaml.cs"> <Compile Include="App.xaml.cs">
<DependentUpon>UserControl1.xaml</DependentUpon> <DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Model\LogModel.cs" />
<Compile Include="ViewModel\LogViewModel.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Views\LogView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Properties\Resources.Designer.cs"> <Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="Properties\Settings.Designer.cs"> <Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon> <DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput> <DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile> </Compile>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -0,0 +1,9 @@
<Window x:Class="LoggingClient.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:views="clr-namespace:LoggingClient.Views"
Title="MainWindow" Height="450" Width="800" ResizeMode="NoResize">
<Grid>
<views:LogView x:Name = "LogView"/>
</Grid>
</Window>

View File

@ -12,15 +12,18 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;
namespace LoggingClient namespace LoggingClient
{ {
/// <summary> /// <summary>
/// Interaction logic for UserControl1.xaml /// Interaction logic for MainWindow.xaml
/// </summary> /// </summary>
public partial class UserControl1 : UserControl public partial class MainWindow : Window
{ {
public UserControl1() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
} }

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 string severity { get; set; }
public DateTime timestamp { get; set; }
public string message { get; set; }
public LogModel(int id, string pod, string location, string hostname, string 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

@ -7,12 +7,12 @@ using System.Windows;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("LoggingClient")] [assembly: AssemblyTitle("WpfControlNugget")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoggingClient")] [assembly: AssemblyProduct("WpfControlNugget")]
[assembly: AssemblyCopyright("Copyright © 2020")] [assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]

View File

@ -8,7 +8,8 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace LoggingClient.Properties { namespace WpfControlNugget.Properties
{
/// <summary> /// <summary>
@ -21,24 +22,29 @@ namespace LoggingClient.Properties {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources { internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan; private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture; private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() { internal Resources()
{
} }
/// <summary> /// <summary>
/// Returns the cached ResourceManager instance used by this class. /// Returns the cached ResourceManager instance used by this class.
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager { internal static global::System.Resources.ResourceManager ResourceManager
get { {
if ((resourceMan == null)) { get
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("LoggingClient.Properties.Resources", typeof(Resources).Assembly); {
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfControlNugget.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp; resourceMan = temp;
} }
return resourceMan; return resourceMan;
@ -50,11 +56,14 @@ namespace LoggingClient.Properties {
/// resource lookups using this strongly typed resource class. /// resource lookups using this strongly typed resource class.
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture { internal static global::System.Globalization.CultureInfo Culture
get { {
get
{
return resourceCulture; return resourceCulture;
} }
set { set
{
resourceCulture = value; resourceCulture = value;
} }
} }

View File

@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace LoggingClient.Properties namespace WpfControlNugget.Properties
{ {

View File

@ -1,12 +0,0 @@
<UserControl x:Class="LoggingClient.UserControl1"
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"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

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,221 @@
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=;Uid=root;Pwd=;";
_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())
{
Logs.Add(new LogModel(
reader.GetInt32("id"),
reader.GetString("pod"),
reader.GetString("location"),
reader.GetString("hostname"),
reader.GetString("severity"),
reader.GetDateTime("timestamp"),
reader.GetString("message")
));
}
}
}
}
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,100 @@
<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 Height="450" Width="800" 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,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Security.Cryptography.X509Certificates;
using LoggingClient.ViewModel;
namespace LoggingClient.Views
{
public partial class LogView : UserControl
{
public LogView()
{
InitializeComponent();
DataContext = new LogViewModel();
}
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle" version="1.8.3.1" targetFramework="net461" />
<package id="Google.Protobuf" version="3.6.1" targetFramework="net461" />
<package id="MySql.Data" version="8.0.16" targetFramework="net461" />
</packages>