add resharper and hover effect for modules; change navigation bar

This commit is contained in:
Rene Schwarz
2021-08-10 02:03:11 +02:00
parent cdb86331e5
commit 910383775b
64 changed files with 792 additions and 832 deletions

View File

@@ -16,37 +16,49 @@ namespace Server_Dashboard {
//List with all Modules inside
public ObservableCollection<ModuleData> Modules { get; set; }
//Creates Default Modules, remove before release and when implementing the actual data comming from the socket
//Creates Default Modules, remove before release and when implementing the actual data coming from the socket
public DashboardModuleViewModel(DataTable moduleData) {
Modules = new ObservableCollection<ModuleData>();
foreach (DataRow row in moduleData.Rows) {
if (row[0] != null) {
byte[] iconBytes = row[3] == DBNull.Value ? null : (byte[])row[3];
Modules.Add(new ModuleData(true) {
ModuleName = (string)row?[2],
Creator = (string)row?[0],
ModuleIcon = ConvertByteToBitmapImage(iconBytes),
CreationDate = (DateTime)row?[1],
ServerInformation = null
});
if (row[0] == null)
return;
byte[] iconBytes = row[3] == DBNull.Value ? null : (byte[])row[3];
DataTable serverData = DatabaseHandler.GetServerData((int)row[4]);
ServerInformation serverInformation = null;
if (serverData.Rows.Count != 0) {
DataRow serverRow = serverData.Rows[0];
serverInformation = new ServerInformation {
ServerName = (string)serverRow[4] ?? "",
PublicIpAddress = (string)serverRow[6] ?? "",
PrivateIpAddress = (string)serverRow[5] ?? "",
Uptime = (TimeSpan)serverRow[7],
OsUserName = (string)serverRow[3] ?? ""
};
}
Modules.Add(new ModuleData(false) {
ModuleName = (string)row[2] ?? "",
Creator = (string)row[0] ?? "",
ModuleIcon = ConvertByteToBitmapImage(iconBytes),
CreationDate = (DateTime)row[1],
ServerInformation = serverInformation
});
}
}
private BitmapImage ConvertByteToBitmapImage(byte[] icon) {
if (icon != null) {
try {
using MemoryStream ms = new MemoryStream(icon);
BitmapImage moduleIcon = new BitmapImage();
moduleIcon.BeginInit();
moduleIcon.StreamSource = ms;
moduleIcon.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
moduleIcon.CacheOption = BitmapCacheOption.OnLoad;
moduleIcon.EndInit();
moduleIcon.Freeze();
return moduleIcon;
} catch { }
}
private static BitmapImage ConvertByteToBitmapImage(byte[] icon) {
if (icon == null)
return null;
try {
using MemoryStream ms = new MemoryStream(icon);
BitmapImage moduleIcon = new BitmapImage();
moduleIcon.BeginInit();
moduleIcon.StreamSource = ms;
moduleIcon.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
moduleIcon.CacheOption = BitmapCacheOption.OnLoad;
moduleIcon.EndInit();
moduleIcon.Freeze();
return moduleIcon;
} catch { }
return null;
}
}

View File

@@ -1,13 +1,9 @@
using Server_Dashboard.Views.DashboardPages.ModuleCRUD;
using System.Collections.ObjectModel;
using System.Data;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
using Server_Dashboard_Socket;
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
namespace Server_Dashboard {
@@ -53,7 +49,7 @@ namespace Server_Dashboard {
#region Constructor
public DashboardViewModel(string username) {
//Command inits
//Command init
OpenLinkCommand = new RelayCommand(OpenLink);
OpenNewModuleWindowCommand = new RelayCommand(OpenNewModuleWindow);
@@ -77,16 +73,14 @@ namespace Server_Dashboard {
/// Opens a given link in the default browser
/// </summary>
/// <param name="param">The Link to be opened e.g. https://github.com/Crylia/Server-Dashboard </param>
private void OpenLink(object param) {
Process.Start(new ProcessStartInfo((string)param) { UseShellExecute = true });
}
private static void OpenLink(object param) => Process.Start(new ProcessStartInfo((string)param) { UseShellExecute = true });
/// <summary>
/// Creates a new window to create a new Module
/// </summary>
/// <param name="param">Nothing</param>
private void OpenNewModuleWindow(object param) {
//Creates a new CreateModulePopup and sets this view model as datacontext
//Creates a new CreateModulePopup and sets this view model as data context
CreateModulePopup cmp = new CreateModulePopup {
DataContext = new CreateModuleViewModel(User.UserName)
};
@@ -98,9 +92,8 @@ namespace Server_Dashboard {
}
private void GetModules() {
DataTable moduleData = DatabaseHandler.GetUserModuleData(User.UID);
dmvm = new DashboardModuleViewModel(moduleData);
//Sets the local module to the dashboardviewmodule modules
dmvm = new DashboardModuleViewModel(DatabaseHandler.GetUserModuleData(User.UID));
//Sets the local module to the dashboard view module modules
Modules = dmvm.Modules;
}

View File

@@ -17,7 +17,7 @@ namespace Server_Dashboard {
private string serverName;
public string ServerName {
get { return serverName; }
get => serverName;
set {
if (serverName != value)
serverName = value;
@@ -28,7 +28,7 @@ namespace Server_Dashboard {
private string moduleName;
public string ModuleName {
get { return moduleName; }
get => moduleName;
set {
if (moduleName != value)
moduleName = value;
@@ -36,21 +36,21 @@ namespace Server_Dashboard {
}
}
private string ipAdress;
private string ipAddress;
public string IPAdress {
get { return ipAdress; }
public string IpAddress {
get => ipAddress;
set {
if (ipAdress != value)
ipAdress = value;
OnPropertyChanged(nameof(ipAdress));
if (ipAddress != value)
ipAddress = value;
OnPropertyChanged(nameof(ipAddress));
}
}
private string port;
public string Port {
get { return port; }
get => port;
set {
if (port != value)
port = value;
@@ -61,7 +61,7 @@ namespace Server_Dashboard {
private BitmapImage moduleIcon;
public BitmapImage ModuleIcon {
get { return moduleIcon; }
get => moduleIcon;
set {
if (moduleIcon != value)
moduleIcon = value;
@@ -72,7 +72,7 @@ namespace Server_Dashboard {
private string userInformationMessage;
public string UserInformationMessage {
get { return userInformationMessage; }
get => userInformationMessage;
set {
if (userInformationMessage != value)
userInformationMessage = value;
@@ -108,39 +108,39 @@ namespace Server_Dashboard {
/// <param name="param">Nothing</param>
private async void CreateModuleAsync(object param) {
//Checks if the IP field is not empty and valid
if (!String.IsNullOrWhiteSpace(ipAdress) && ipFilter.IsMatch(ipAdress)) {
//Gives the Module a default name if the user doesnt name it
if (String.IsNullOrWhiteSpace(moduleName))
if (!string.IsNullOrWhiteSpace(ipAddress) && ipFilter.IsMatch(ipAddress)) {
//Gives the Module a default name if the user doesn't name it
if (string.IsNullOrWhiteSpace(moduleName))
moduleName = "Module";
//Gives the Server a default name is the user doesnt name it
if (String.IsNullOrWhiteSpace(serverName))
//Gives the Server a default name is the user doesn't name it
if (string.IsNullOrWhiteSpace(serverName))
serverName = "Server";
//Makes sure the name isnt any longer than characters
//Makes sure the name isn't any longer than characters
if (moduleName.Length >= 20) {
UserInformationMessage = "The Module Name is too long";
return;
}
//Makes sure the name isnt any longer than characters
//Makes sure the name isn't any longer than characters
if (serverName.Length >= 20) {
UserInformationMessage = "The Server Name is too long";
return;
}
//Clears the error message if there isnt any error
//Clears the error message if there isn't any error
UserInformationMessage = "";
byte[] moduleIconStream = null;
if (moduleIcon != null) {
try {
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(moduleIcon));
using MemoryStream ms = new MemoryStream();
await using MemoryStream ms = new MemoryStream();
encoder.Save(ms);
moduleIconStream = ms.ToArray();
} catch { }
} catch (Exception) { }
}
if (await Task.Run(() => DatabaseHandler.CreateNewModule(ipAdress, moduleName, serverName, username, moduleIconStream, port)) == 0) {
if (await Task.Run(() => DatabaseHandler.CreateNewModule(ipAddress, moduleName, serverName, username, moduleIconStream, port)) == 0) {
Close?.Invoke();
} else {
UserInformationMessage = "Unknown error occured, please try again later";
UserInformationMessage = "Unknown error occurred, please try again later";
}
} else {
UserInformationMessage = "The IP Address is invalid";
@@ -156,7 +156,7 @@ namespace Server_Dashboard {
Title = "Choose an Image",
Filter = "Supported format|*.jpg;*.jpeg;*.png"
};
if ((bool)ofd.ShowDialog()) {
if (Convert.ToBoolean(ofd.ShowDialog())) {
ModuleIcon = new BitmapImage(new Uri(ofd.FileName));
}
}