diff --git a/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 b/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2
index 5836e70..0982798 100644
Binary files a/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 and b/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 differ
diff --git a/.vs/Server Dashboard/v16/.suo b/.vs/Server Dashboard/v16/.suo
index 7707516..3d88c30 100644
Binary files a/.vs/Server Dashboard/v16/.suo and b/.vs/Server Dashboard/v16/.suo differ
diff --git a/Server Dashboard Socket/EchoServer.cs b/Server Dashboard Socket/EchoServer.cs
index 906621a..0d5fade 100644
--- a/Server Dashboard Socket/EchoServer.cs
+++ b/Server Dashboard Socket/EchoServer.cs
@@ -4,6 +4,9 @@ using System.Net.Sockets;
using System.Threading.Tasks;
namespace Server_Dashboard_Socket {
+ ///
+ /// Basic echo server to test the socket connection
+ ///
public class EchoServer {
public void Start(int port = 9565) {
IPEndPoint endPoint = new IPEndPoint(IPAddress.Loopback, port);
diff --git a/Server Dashboard/App.xaml b/Server Dashboard/App.xaml
index 689ca61..cf4f5d7 100644
--- a/Server Dashboard/App.xaml
+++ b/Server Dashboard/App.xaml
@@ -356,6 +356,5 @@
-
diff --git a/Server Dashboard/AttachedProperty/BaseAttachedProperty.cs b/Server Dashboard/AttachedProperty/BaseAttachedProperty.cs
index 55ae5e3..1046070 100644
--- a/Server Dashboard/AttachedProperty/BaseAttachedProperty.cs
+++ b/Server Dashboard/AttachedProperty/BaseAttachedProperty.cs
@@ -4,6 +4,11 @@ using System.Text;
using System.Windows;
namespace Server_Dashboard {
+ ///
+ /// Attached property base class
+ ///
+ ///
+ ///
public abstract class BaseAttachedProperty
where Parent : BaseAttachedProperty, new() {
public event Action ValueChanged = (sender, e) => { };
diff --git a/Server Dashboard/AttachedProperty/HyperlinkProperties.cs b/Server Dashboard/AttachedProperty/HyperlinkProperties.cs
index 3e442c2..47d27c6 100644
--- a/Server Dashboard/AttachedProperty/HyperlinkProperties.cs
+++ b/Server Dashboard/AttachedProperty/HyperlinkProperties.cs
@@ -5,8 +5,7 @@ using System.Text;
using System.Windows;
using System.Windows.Documents;
-namespace Server_Dashboard
- {
+namespace Server_Dashboard {
public static class HyperlinkExtensions {
public static bool GetIsExternal(DependencyObject obj) {
return (bool)obj.GetValue(IsExternalProperty);
diff --git a/Server Dashboard/Controls/Dashboard/CRUD Popup/CreateModulePopup.xaml b/Server Dashboard/Controls/Dashboard/CRUD Popup/CreateModulePopup.xaml
index cfb80fe..2cadfe9 100644
--- a/Server Dashboard/Controls/Dashboard/CRUD Popup/CreateModulePopup.xaml
+++ b/Server Dashboard/Controls/Dashboard/CRUD Popup/CreateModulePopup.xaml
@@ -6,19 +6,12 @@
xmlns:local="clr-namespace:Server_Dashboard.Views.DashboardPages.ModuleCRUD"
xmlns:root="clr-namespace:Server_Dashboard" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
d:DataContext="{d:DesignInstance Type=root:DashboardModuleViewModel}"
- mc:Ignorable="d"
- ResizeMode="NoResize"
- Height="700"
- Width="500"
- d:WindowStyle="None"
- >
+ mc:Ignorable="d" ResizeMode="NoResize" Height="700" Width="500" d:WindowStyle="None">
-
+
+
@@ -27,10 +20,8 @@
-
+
+
@@ -40,19 +31,8 @@
-
-
-
+
@@ -76,192 +52,98 @@
+
-
+
-
+
-
-
+
+
+
-
+
-
+
-
+
-
+
+
-
+
-
+
-
-
+
+
+
-
+
-
+
-
-
+
+
+
-
+
@@ -270,38 +152,16 @@
-
-
+
+
-
+
+
diff --git a/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml b/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml
index b7837ae..1995673 100644
--- a/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml
+++ b/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml
@@ -12,83 +12,13 @@
+
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml.cs b/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml.cs
index ba7514e..b23d1b9 100644
--- a/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml.cs
+++ b/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml.cs
@@ -13,37 +13,47 @@ using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Server_Dashboard.Controls.DoubleRoundProgressBar {
+ ///
+ /// DependencyProperties
+ ///
public partial class DoubleRoundProgressBar : UserControl {
+ //Property for the ReadIndicatorBrush
public static DependencyProperty ReadIndicatorBrushProperty = DependencyProperty.Register("ReadIndicatorBrush", typeof(Brush), typeof(DoubleRoundProgressBar));
public Brush ReadIndicatorBrush {
get { return (Brush)GetValue(ReadIndicatorBrushProperty); }
set { SetValue(ReadIndicatorBrushProperty, value); }
}
+ //Property for the WriteIndicatorBrush
public static DependencyProperty WriteIndicatorBrushProperty = DependencyProperty.Register("WriteIndicatorBrush", typeof(Brush), typeof(DoubleRoundProgressBar));
public Brush WriteIndicatorBrush {
get { return (Brush)GetValue(WriteIndicatorBrushProperty); }
set { SetValue(WriteIndicatorBrushProperty, value); }
}
+ //Property for the BackgroundBrush
public static DependencyProperty BackgroundBrushProperty = DependencyProperty.Register("BackgroundBrush", typeof(Brush), typeof(DoubleRoundProgressBar));
public Brush BackgroundBrush {
get { return (Brush)GetValue(BackgroundBrushProperty); }
set { SetValue(BackgroundBrushProperty, value); }
}
+ //Property for the ProgressBorderBrush
public static DependencyProperty ProgressBorderBrushProperty = DependencyProperty.Register("ProgressBorderBrush", typeof(Brush), typeof(DoubleRoundProgressBar));
public Brush ProgressBorderBrush {
get { return (Brush)GetValue(ProgressBorderBrushProperty); }
set { SetValue(ProgressBorderBrushProperty, value); }
}
+ //Property for the Value Write
public static DependencyProperty ValueWriteProperty = DependencyProperty.Register("ValueWrite", typeof(int), typeof(DoubleRoundProgressBar));
public int ValueWrite {
get { return (int)GetValue(ValueWriteProperty); }
set { SetValue(ValueWriteProperty, value); }
}
+
+ //Property for the Value Read
public static DependencyProperty ValueReadProperty = DependencyProperty.Register("ValueRead", typeof(int), typeof(DoubleRoundProgressBar));
public int ValueRead {
get { return (int)GetValue(ValueReadProperty); }
diff --git a/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml b/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml
index 485916e..4ef2d9c 100644
--- a/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml
+++ b/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml
@@ -6,52 +6,14 @@
xmlns:local="clr-namespace:Server_Dashboard.Controls.HalfRoundProgressBar"
xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
xmlns:root="clr-namespace:Server_Dashboard"
- mc:Ignorable="d"
- x:Name="_this"
- d:DesignHeight="50" d:DesignWidth="50">
+ mc:Ignorable="d" x:Name="_this" d:DesignHeight="50" d:DesignWidth="50">
+
-
-
-
+
+
+
diff --git a/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml.cs b/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml.cs
index 79fe1cb..7d8bff0 100644
--- a/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml.cs
+++ b/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml.cs
@@ -13,26 +13,33 @@ using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Server_Dashboard.Controls.HalfRoundProgressBar {
+ ///
+ /// Dependency Properties
+ ///
public partial class HalfRoundProgressBar : UserControl {
-
+
+ //Indicator Brush Property
public static DependencyProperty IndicatorBrushProperty = DependencyProperty.Register("IndicatorBrush", typeof(Brush), typeof(HalfRoundProgressBar));
public Brush IndicatorBrush {
get { return (Brush)GetValue(IndicatorBrushProperty); }
set { SetValue(IndicatorBrushProperty, value); }
}
+ //Background Brush Property
public static DependencyProperty BackgroundBrushProperty = DependencyProperty.Register("BackgroundBrush", typeof(Brush), typeof(HalfRoundProgressBar));
public Brush BackgroundBrush {
get { return (Brush)GetValue(BackgroundBrushProperty); }
set { SetValue(BackgroundBrushProperty, value); }
}
+ //ProgressBorder Property
public static DependencyProperty ProgressBorderBrushProperty = DependencyProperty.Register("ProgressBorderBrush", typeof(Brush), typeof(HalfRoundProgressBar));
public Brush ProgressBorderBrush {
get { return (Brush)GetValue(ProgressBorderBrushProperty); }
set { SetValue(ProgressBorderBrushProperty, value); }
}
+ //Value
public static DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(int), typeof(HalfRoundProgressBar));
public int Value {
get { return (int)GetValue(ValueProperty); }
diff --git a/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml b/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml
index 0c7cfea..9b08883 100644
--- a/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml
+++ b/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml
@@ -5,50 +5,27 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Server_Dashboard.Controls"
- mc:Ignorable="d"
- >
+ mc:Ignorable="d">
+
-
+
-
+
-
+
-
+
-
-
-
+
+
+
@@ -56,17 +33,10 @@
-
+
-
+
diff --git a/Server Dashboard/Controls/ServerModules/ServerModule.xaml b/Server Dashboard/Controls/ServerModules/ServerModule.xaml
index 10191f7..aa34d7e 100644
--- a/Server Dashboard/Controls/ServerModules/ServerModule.xaml
+++ b/Server Dashboard/Controls/ServerModules/ServerModule.xaml
@@ -5,8 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Server_Dashboard.Controls.ServerModules"
xmlns:halfroundprogressbar="clr-namespace:Server_Dashboard.Controls.HalfRoundProgressBar"
- xmlns:doubleroundprogressbar="clr-namespace:Server_Dashboard.Controls.DoubleRoundProgressBar"
- mc:Ignorable="d">
+ xmlns:doubleroundprogressbar="clr-namespace:Server_Dashboard.Controls.DoubleRoundProgressBar" mc:Ignorable="d">
+
@@ -16,11 +16,8 @@
-
+
+
@@ -48,11 +45,13 @@
+
+
@@ -133,6 +132,7 @@
+
@@ -143,117 +143,25 @@
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
diff --git a/Server Dashboard/DashboardModules/DashboardModule.cs b/Server Dashboard/DashboardModules/DashboardModule.cs
index 57a876b..16d3259 100644
--- a/Server Dashboard/DashboardModules/DashboardModule.cs
+++ b/Server Dashboard/DashboardModules/DashboardModule.cs
@@ -3,16 +3,31 @@ using System.Collections.Generic;
using System.Text;
namespace Server_Dashboard {
+ ///
+ /// Dashboard Module class that holds all the information that gets displayed
+ ///
class DashboardModule {
+ //The name the user gives the module
public string ModuleName { get; set; }
+ //The user who created it
public string Creator { get; set; }
+ //All the information that the server had
public ServerInformation ServerInfo { get; set; }
+ //The status indicator
public string StatusIndicator { get; set; }
+ //The background color of the status indicator
public string StatusIndicatorBG { get; set; }
+ //If the server is avaibale or not
public bool ServerAvailable { get; set; }
+ //The Module icon the user give the server, defaults to a generic server symbol
public string ModuleIcon { get; set; }
+ //Creation date with System.DateTime.Now
public string CreationDate { get; set; }
+ ///
+ /// This will set the Module status indicator red or green if the server is available or not
+ ///
+ ///
public DashboardModule(bool serverAvailable) {
ServerAvailable = serverAvailable;
StatusIndicator = ServerAvailable ? "#20c657" : "#e53935";
diff --git a/Server Dashboard/DashboardModules/NewModuleInformation.cs b/Server Dashboard/DashboardModules/NewModuleInformation.cs
index ecf0308..e820a56 100644
--- a/Server Dashboard/DashboardModules/NewModuleInformation.cs
+++ b/Server Dashboard/DashboardModules/NewModuleInformation.cs
@@ -3,10 +3,19 @@ using System.Collections.Generic;
using System.Text;
namespace Server_Dashboard.DashboardModules {
+ ///
+ /// The Information the user puts into the CreateNewModule form
+ ///
class NewModuleInformation {
+ //The Name of the Module
+ public string ModuleName { get; set; }
+ //The Name of the Server
public string ServerName { get; set; }
+ //The Username
public string Username { get; set; }
+ //IPv4 Adress
public string IPAdress { get; set; }
+ //Port, defaults to 22
public int Port { get; set; }
}
}
diff --git a/Server Dashboard/DashboardModules/ServerInformation.cs b/Server Dashboard/DashboardModules/ServerInformation.cs
index 0bbc625..74cebbf 100644
--- a/Server Dashboard/DashboardModules/ServerInformation.cs
+++ b/Server Dashboard/DashboardModules/ServerInformation.cs
@@ -4,16 +4,30 @@ using System.Collections.ObjectModel;
using System.Text;
namespace Server_Dashboard {
+ ///
+ /// Server information class, this will probably scale pretty big later on
+ /// This will hold all the information the socket will gather
+ ///
class ServerInformation {
+ //The ServerName
public string ServerName { get; set; }
+ //The unix or windows username
public string OSUserName { get; set; }
+ //Cpu Temp in C
public string CpuTemp { get; set; }
+ //Gpu Temp in C
public string GpuTemp { get; set; }
+ //Server uptime
public string Uptime { get; set; }
+ //When the server was first deployed
public string DeployDate { get; set; }
+ //Public IPv4 Adress
public string PublicIpAdress { get; set; }
+ //Private IP adress from the servers network
public string PrivateIpAdress { get; set; }
+ //GPU usage in %
public string GpuUsage { get; set; }
+ //CPU usage in %
public string CpuUsage { get; set; }
}
}
diff --git a/Server Dashboard/Database/DatabaseHandler.cs b/Server Dashboard/Database/DatabaseHandler.cs
index 5fce34a..a0b2e19 100644
--- a/Server Dashboard/Database/DatabaseHandler.cs
+++ b/Server Dashboard/Database/DatabaseHandler.cs
@@ -7,92 +7,149 @@ using System.Data.SqlClient;
using System.Reflection;
namespace Server_Dashboard {
+ ///
+ /// Database class to access the database
+ ///
public static class DatabaseHandler {
-
- public static DataTable GetServerInformation() {
-
- return null;
- }
-
+ #region Public Methods
+ ///
+ /// Checks the user credentials
+ ///
+ /// The username
+ /// The plain text password
+ /// [0] is false, [1] is true, [2] connection error
public static int CheckLogin(string uname, string passwd) {
+ //Creates the database connection
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) {
try {
+ //Open the connection
con.Open();
+ //SQL Query
string query = "EXEC ValidateUserLogin @Username = @uname, @Password = @passwd, @Valid = @valid OUTPUT";
+ //Creates a new command
using (SqlCommand com = new SqlCommand(query, con)) {
+ //For security reasons the values are added with this function
+ //this will avoid SQL Injections
com.Parameters.AddWithValue("@uname", uname);
com.Parameters.AddWithValue("@passwd", passwd);
com.Parameters.Add("@valid", SqlDbType.NVarChar, 250);
com.Parameters["@valid"].Direction = ParameterDirection.Output;
+ //Execute without a return value
com.ExecuteNonQuery();
+ //The Return value from the SQL Stored Procedure will have the answer to life
return Convert.ToInt32(com.Parameters["@Valid"].Value);
}
+ //Catch any error
} catch (SqlException ex) {
return ex.Number;
} finally {
+ //Always close the connection
con.Close();
}
}
}
-
+ ///
+ /// Currently obscolete, would check the Username and Cookie
+ ///
+ /// Locally stored user cookie
+ /// Locally stored username
+ /// [0] is false, [1] is true, [2] connection error
public static int CheckCookie(string cookie, string username) {
+ //Creates the database connection
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) {
try {
+ //Open the connection
con.Open();
+ //SQL Query
string query = "EXEC CheckUserCookie @Cookie = @cookie, @UserName = @username, @Valid = @valid OUTPUT";
+ //Creates a new command
using (SqlCommand com = new SqlCommand(query, con)) {
+ //For security reasons the values are added with this function
+ //this will avoid SQL Injections
com.Parameters.AddWithValue("@cookie", cookie);
com.Parameters.AddWithValue("@username", username);
com.Parameters.Add("@valid", SqlDbType.Bit);
com.Parameters["@valid"].Direction = ParameterDirection.Output;
+ //Execute without a return value
com.ExecuteNonQuery();
+ //The Return value from the SQL Stored Procedure will have the answer to life
return Convert.ToInt32(com.Parameters["@Valid"].Value);
}
+ //Catch any error
} catch (SqlException ex) {
return ex.Number;
} finally {
+ //Always close the connection
con.Close();
}
}
}
-
+ ///
+ /// Deletes a the cookie from the given user
+ ///
+ /// User who doesnt deserve any delicious cookies :3
public static void DeleteCookie(string username) {
+ //Creates the database connection
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) {
try {
+ //Open the connection
con.Open();
+ //SQL Query
string query = "EXEC DeleteUserCookie @Username = @username, @ResponseMessage = @response OUTPUT";
+ //Creates a new command
using (SqlCommand com = new SqlCommand(query, con)) {
+ //For security reasons the values are added with this function
+ //this will avoid SQL Injections
com.Parameters.AddWithValue("@username", username);
com.Parameters.Add("@response", SqlDbType.NVarChar, 250);
com.Parameters["@response"].Direction = ParameterDirection.Output;
+ //Execute without a return value
com.ExecuteNonQuery();
}
- } catch (SqlException ex) {
+ //Catch any error, dont return them, why would you?
+ } catch {
} finally {
+ //Always close the connection
con.Close();
}
}
}
-
+ ///
+ /// Adds a new Cookie to a user
+ ///
+ /// The delicious locally stored cookie
+ /// The User who deserves a cookie :3
+ /// [0] is false, [1] is true, [2] connection error
public static int AddCookie(string cookie, string username) {
+ //Creates the database connection
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) {
try {
+ //Open the connection
con.Open();
+ //SQL Query
string query = "EXEC AddCookieToUser @Cookie = @cookie, @UserName = @username, @ResponseMessage = @response OUTPUT";
+ //Creates a new command
using (SqlCommand com = new SqlCommand(query, con)) {
+ //For security reasons the values are added with this function
+ //this will avoid SQL Injections
com.Parameters.AddWithValue("@cookie", cookie);
com.Parameters.AddWithValue("@username", username);
com.Parameters.Add("@response", SqlDbType.NVarChar, 250);
com.Parameters["@response"].Direction = ParameterDirection.Output;
+ //Execute without a return value
com.ExecuteNonQuery();
+ //The Return value from the SQL Stored Procedure will have the answer to life
return Convert.ToInt32(com.Parameters["@ResponseMessage"].Value);
}
+ //Catch any error
} catch (SqlException ex) {
return ex.Number;
} finally {
+ //Always close connection
con.Close();
}
}
}
+ #endregion
}
}
diff --git a/Server Dashboard/Interfaces/IHavePassword.cs b/Server Dashboard/Interfaces/IHavePassword.cs
index 9c82b1a..3ceecd7 100644
--- a/Server Dashboard/Interfaces/IHavePassword.cs
+++ b/Server Dashboard/Interfaces/IHavePassword.cs
@@ -4,6 +4,9 @@ using System.Security;
using System.Text;
namespace Server_Dashboard {
+ ///
+ /// Interface that makes a SecurePassword go one way
+ ///
public interface IHavePassword {
SecureString SecurePassword { get; }
}
diff --git a/Server Dashboard/Interfaces/IWindowHelper.cs b/Server Dashboard/Interfaces/IWindowHelper.cs
index 15cf65a..defc651 100644
--- a/Server Dashboard/Interfaces/IWindowHelper.cs
+++ b/Server Dashboard/Interfaces/IWindowHelper.cs
@@ -3,6 +3,9 @@ using System.Collections.Generic;
using System.Text;
namespace Server_Dashboard {
+ ///
+ /// Interface to help close a window with a button
+ ///
interface IWindowHelper {
Action Close { get; set; }
}
diff --git a/Server Dashboard/LoginWindow.xaml b/Server Dashboard/LoginWindow.xaml
index 9c41ac0..6c6aeb0 100644
--- a/Server Dashboard/LoginWindow.xaml
+++ b/Server Dashboard/LoginWindow.xaml
@@ -8,14 +8,14 @@
xmlns:loading="clr-namespace:Server_Dashboard.Controls"
x:Name="Login"
mc:Ignorable="d"
- Title="Server Dashboard" Height="700" Width="500" WindowStyle="None" Background="Transparent" ResizeMode="CanResize" local:CloseProperty.Value="True">
+ Title="Server Dashboard"
+ Height="700" Width="500" WindowStyle="None" Background="Transparent" ResizeMode="CanResize" local:CloseProperty.Value="True">
-
@@ -36,7 +36,6 @@
-
@@ -56,37 +55,15 @@
-
-
-
-
+
+
+
-
+
@@ -97,48 +74,19 @@
-
-
+
-
+
-
-
-
+
+
+
@@ -146,17 +94,8 @@
-
-
+
@@ -166,35 +105,14 @@
-
+
-
+
-
+
-
+
@@ -203,29 +121,11 @@
-
-
+
-
-
+
@@ -236,37 +136,15 @@
-
-
+
+
-
+
-
+
Forgot password
@@ -275,39 +153,19 @@
-
-
-
+
+
-
+
-
-
\ No newline at end of file
diff --git a/Server Dashboard/Security/SecureStringHelpers.cs b/Server Dashboard/Security/SecureStringHelpers.cs
index 800056b..a5f1bc2 100644
--- a/Server Dashboard/Security/SecureStringHelpers.cs
+++ b/Server Dashboard/Security/SecureStringHelpers.cs
@@ -5,12 +5,19 @@ using System.Security;
using System.Text;
namespace Server_Dashboard {
+ ///
+ /// Secure string helper class to unsecure the Password b4 it goes to the database
+ ///
public static class SecureStringHelpers {
+ //Unsecures a given password
public static string Unsecure(this SecureString secureString) {
+ //If empty return nothing
if (secureString == null)
return string.Empty;
+ //New zero pointer
var unmanagedString = IntPtr.Zero;
+ //Try to unsecure the string
try {
unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(secureString);
return Marshal.PtrToStringUni(unmanagedString);
diff --git a/Server Dashboard/ValueConverter/ValueToAngleConverter.cs b/Server Dashboard/ValueConverter/ValueToAngleConverter.cs
index c738576..13c39ef 100644
--- a/Server Dashboard/ValueConverter/ValueToAngleConverter.cs
+++ b/Server Dashboard/ValueConverter/ValueToAngleConverter.cs
@@ -5,6 +5,9 @@ using System.Text;
using System.Windows.Data;
namespace Server_Dashboard {
+ ///
+ /// Value to angle converter
+ ///
[ValueConversion(typeof(int), typeof(double))]
public class ValueToAngleConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => (int)value * 0.01 * 360;
diff --git a/Server Dashboard/ViewModels/BaseViewModel/BaseViewModel.cs b/Server Dashboard/ViewModels/BaseViewModel/BaseViewModel.cs
index 0360c5b..083972f 100644
--- a/Server Dashboard/ViewModels/BaseViewModel/BaseViewModel.cs
+++ b/Server Dashboard/ViewModels/BaseViewModel/BaseViewModel.cs
@@ -4,6 +4,10 @@ using System.ComponentModel;
using System.Text;
namespace Server_Dashboard {
+ ///
+ /// Base View Model all the other view models inherit from
+ /// Makes me write the INotifyPropertyChanged only once
+ ///
class BaseViewModel : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
diff --git a/Server Dashboard/ViewModels/Dashboard/DashboardModuleViewModel.cs b/Server Dashboard/ViewModels/Dashboard/DashboardModuleViewModel.cs
index 9493e9d..52d7403 100644
--- a/Server Dashboard/ViewModels/Dashboard/DashboardModuleViewModel.cs
+++ b/Server Dashboard/ViewModels/Dashboard/DashboardModuleViewModel.cs
@@ -4,19 +4,14 @@ using System.Collections.ObjectModel;
using System.Text;
namespace Server_Dashboard {
+ ///
+ /// View Model for the modules
+ ///
class DashboardModuleViewModel : BaseViewModel {
+ //List with all Modules inside
public ObservableCollection Modules { get; set; }
- private int gpuUsage;
-
- public int GPUUsage {
- get { return gpuUsage; }
- set {
- if(value != gpuUsage)
- gpuUsage = value;
- OnPropertyChanged(nameof(gpuUsage));
- }
- }
+ //Creates Default Modules, remove before release and when implementing the actual data comming from the socket
public DashboardModuleViewModel() {
Modules = new ObservableCollection();
for (int i = 0; i < 10; i++) {
diff --git a/Server Dashboard/ViewModels/Dashboard/DashboardViewModel.cs b/Server Dashboard/ViewModels/Dashboard/DashboardViewModel.cs
index e48a3ed..fbaa59f 100644
--- a/Server Dashboard/ViewModels/Dashboard/DashboardViewModel.cs
+++ b/Server Dashboard/ViewModels/Dashboard/DashboardViewModel.cs
@@ -6,10 +6,17 @@ using System.Windows.Input;
using Server_Dashboard_Socket;
namespace Server_Dashboard {
+ ///
+ /// View Model for the Dashboard
+ ///
class DashboardViewModel : BaseViewModel {
- private string userName = "Username";
- private DashboardModuleViewModel dmvm = new DashboardModuleViewModel();
+ #region Private Values
+ private readonly DashboardModuleViewModel dmvm = new DashboardModuleViewModel();
+ #endregion
+ #region Properties
+ //The Username displayed defaults to Username
+ private string userName = "Username";
public string UserName {
get { return userName; }
set {
@@ -19,8 +26,8 @@ namespace Server_Dashboard {
}
}
+ //List that contains every Module
private ObservableCollection modules;
-
public ObservableCollection Modules {
get { return modules; }
set {
@@ -29,32 +36,59 @@ namespace Server_Dashboard {
OnPropertyChanged(nameof(modules));
}
}
+ #endregion
+ #region Constructor
public DashboardViewModel() {
+ //Creates a new echo server, remove b4 release
EchoServer echoServer = new EchoServer();
echoServer.Start();
+ //Command inits
OpenLinkCommand = new RelayCommand(OpenLink);
OpenNewModuleWindowCommand = new RelayCommand(OpenNewModuleWindow);
CreateModuleCommand = new RelayCommand(CreateModule);
+ //Sets the local module to the dashboardviewmodule modules
Modules = dmvm.Modules;
}
+ #endregion
+ #region ICommands
public ICommand OpenLinkCommand { get; set; }
public ICommand OpenNewModuleWindowCommand { get; set; }
public ICommand CreateModuleCommand { get; set; }
+ #endregion
+
+ #region Commands
+ ///
+ /// Opens a given link in the default browser
+ ///
+ /// The Link to be opened e.g. https://github.com/Crylia/Server-Dashboard
private void OpenLink(object param) {
Process.Start(new ProcessStartInfo((string)param) { UseShellExecute = true });
}
-
+
+ ///
+ /// Creates a new window to create a new Module
+ ///
+ /// Nothing
private void OpenNewModuleWindow(object param) {
+ //Creates a new CreateModulePopup and sets this view model as datacontext
CreateModulePopup cmp = new CreateModulePopup {
DataContext = this
};
+ //Opens it in the middle of the screen, setting the parent window as owner causes the
+ //application to crash when NOT in debug mode(???)
cmp.WindowStartupLocation = WindowStartupLocation.CenterScreen;
cmp.ShowDialog();
}
+
+ ///
+ /// No function yes
+ ///
+ /// Nothing
private void CreateModule(object param) {
}
+ #endregion
}
}
diff --git a/Server Dashboard/ViewModels/Login/LoginViewModel.cs b/Server Dashboard/ViewModels/Login/LoginViewModel.cs
index 1999147..9df326f 100644
--- a/Server Dashboard/ViewModels/Login/LoginViewModel.cs
+++ b/Server Dashboard/ViewModels/Login/LoginViewModel.cs
@@ -5,10 +5,13 @@ using System.Windows.Input;
using System.Threading.Tasks;
namespace Server_Dashboard {
+ ///
+ /// View Model for the Login Window
+ ///
class LoginViewModel : BaseViewModel, IWindowHelper {
-
+ #region Properties
+ //Username Property
private string username;
-
public string Username {
get { return username; }
set {
@@ -17,9 +20,8 @@ namespace Server_Dashboard {
OnPropertyChanged(nameof(username));
}
}
-
+ //Error Text displays an error to help the user to fill the form
private string errorText;
-
public string ErrorText {
get { return errorText; }
set {
@@ -28,9 +30,8 @@ namespace Server_Dashboard {
OnPropertyChanged(nameof(errorText));
}
}
-
+ //Remember me button
private bool rememberUser;
-
public bool RememberUser {
get { return rememberUser; }
set {
@@ -39,9 +40,8 @@ namespace Server_Dashboard {
OnPropertyChanged(nameof(rememberUser));
}
}
-
+ //Loading circle, gets hidden and shown when logging in
private string loading;
-
public string Loading {
get { return loading; }
set {
@@ -50,76 +50,126 @@ namespace Server_Dashboard {
OnPropertyChanged(nameof(loading));
}
}
+ #endregion
+ #region Public Values
+ //Close action for the Window to close properly
public Action Close { get ; set; }
+ #endregion
+ #region Constructor
public LoginViewModel() {
+ //Loading circle is hidden on startup
Loading = "Hidden";
+ //Command inits
LoginCommand = new RelayCommand(LoginAsync);
- if (!String.IsNullOrEmpty(Settings.Default.Username)) {
+ //Checks if the Username and Cookie is saved in the Settings.settings
+ if (!String.IsNullOrEmpty(Settings.Default.Username) && !String.IsNullOrEmpty(Settings.Default.Cookies)) {
+ //Takes the saved Username and Remember me button status and prefills the username and checks the Remember me button
Username = Settings.Default.Username;
RememberUser = Settings.Default.RememberMe;
}
- AutoLoginAsync();
+ //TODO: Autologin
+ //AutoLoginAsync();
}
+ #endregion
+ #region ICommands
public ICommand LoginCommand { get; set; }
+ #endregion
+ #region Commands
+ ///
+ /// Async login
+ ///
+ /// Secure password string
private async void LoginAsync(object parameter) {
+ //Checks if the Username and Password field has content
if (!String.IsNullOrWhiteSpace(Username) && !String.IsNullOrWhiteSpace((parameter as IHavePassword).SecurePassword.Unsecure())) {
+ //Sets loading to true to show the loading icon
Loading = "Visible";
+ //Sends the Username and Password to the database and saved the result, 1 successfull, 0 wrong username or password
int result = await Task.Run(() => DatabaseHandler.CheckLogin(Username, (parameter as IHavePassword).SecurePassword.Unsecure()));
+ //hides the loading again
Loading = "Hidden";
+ /*result can be:
+ 0 for Wrong username or password
+ 1 for true username or password
+ 2 for network or database unreachable
+ default error for everything else
+ */
switch (result) {
case 0:
+ //Sets the error text and exits function
ErrorText = "Username or password is wrong.";
return;
case 1:
+ /*No idea why this is here, gonna let it be till the remember me and autologin is 100% done
if (RememberUser && !String.IsNullOrEmpty(Settings.Default.Cookies)) {
DatabaseHandler.CheckCookie(Settings.Default.Cookies, Username);
- }
+ }*/
+ //If the remember me is not checked and a cookie exists the local storage gets cleared
if (!RememberUser && !String.IsNullOrEmpty(Settings.Default.Cookies)) {
Settings.Default.Cookies = null;
Settings.Default.Username = "";
Settings.Default.RememberMe = false;
Settings.Default.Password = "";
Settings.Default.Save();
+ //Also deletes the cookie from the database
DatabaseHandler.DeleteCookie(Username);
}
+ //If the remember user option is checked and the cookie is not set save everything locally
if (RememberUser && String.IsNullOrEmpty(Settings.Default.Cookies)) {
- var guid = new Guid().ToString() + Username;
- Settings.Default.Cookies = guid;
+ //Creates a new GUID with the username at the end, this is the cookie
+ var cookie = new Guid().ToString() + Username;
+ //Saves cookie, Username Remember me option to the local storage (Settings.settings)
+ Settings.Default.Cookies = cookie;
Settings.Default.Username = Username;
Settings.Default.RememberMe = true;
- Settings.Default.Password = "*****";
Settings.Default.Save();
- DatabaseHandler.AddCookie(Username, guid);
+ //Saves the cookie in the database
+ DatabaseHandler.AddCookie(Username, cookie);
}
+ //Creates a new Dashboard window and shows it
DashboardWindow window = new DashboardWindow();
window.Show();
+ //When closed, close it correctly
Close?.Invoke();
return;
case 2:
+ //Sets the error text
ErrorText = "Server unreachable, connection timeout.";
return;
default:
+ //Sets the error text
ErrorText = "An unknown error has occured";
return;
}
+ //If the Username and password is blank
+ //All these IF's could be one but i made multiple for the different errors so the user knows whats wrong
} else if (String.IsNullOrWhiteSpace(Username) && String.IsNullOrWhiteSpace((parameter as IHavePassword).SecurePassword.Unsecure())) {
+ //Sets the error text
ErrorText = "Please provide a username and password";
return;
}
+ //Only if the Username is empty
if (String.IsNullOrWhiteSpace(Username)) {
+ //Sets the error text
ErrorText = "Username cannot be empty.";
return;
}
+ //Only if the password is empty
if (String.IsNullOrWhiteSpace((parameter as IHavePassword).SecurePassword.Unsecure())) {
+ //Sets the error text
ErrorText = "Password cannot be empty.";
return;
}
+ //If there is no error, clear the error text
ErrorText = "";
}
+ #endregion
+
+ #region private functions
//TODO: Add autologin function that locks the UI untill the user hits the abort button or the login completes
/*private async void AutoLoginAsync() {
if (Settings.Default.RememberMe && !String.IsNullOrEmpty(Settings.Default.Username) && !String.IsNullOrEmpty(Settings.Default.Cookies)) {
@@ -134,5 +184,6 @@ namespace Server_Dashboard {
}
}
}*/
+ #endregion
}
}
diff --git a/Server Dashboard/ViewModels/RelayCommand/RelayCommand.cs b/Server Dashboard/ViewModels/RelayCommand/RelayCommand.cs
index 07e6b46..361964b 100644
--- a/Server Dashboard/ViewModels/RelayCommand/RelayCommand.cs
+++ b/Server Dashboard/ViewModels/RelayCommand/RelayCommand.cs
@@ -7,7 +7,7 @@ namespace Server_Dashboard {
class RelayCommand : ICommand {
//New Action
- private Action