add resharper and hover effect for modules; change navigation bar
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Server_Dashboard {
|
||||
|
||||
/// <summary>
|
||||
/// Base View Model all the other view models inherit from
|
||||
/// Makes me write the INotifyPropertyChanged only once
|
||||
/// </summary>
|
||||
public class BaseViewModel : INotifyPropertyChanged {
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
|
||||
|
||||
protected void OnPropertyChanged(string prop) {
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,11 +81,11 @@ namespace Server_Dashboard {
|
||||
LoginCommand = new RelayCommand(LoginAsync);
|
||||
//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
|
||||
//Takes the saved Username and Remember me button status and pre fills the username and checks the Remember me button
|
||||
Username = Settings.Default.Username;
|
||||
RememberUser = Settings.Default.RememberMe;
|
||||
}
|
||||
//TODO: Autologin
|
||||
//TODO: Auto login
|
||||
//AutoLoginAsync();
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Server_Dashboard {
|
||||
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
|
||||
//Sends the Username and Password to the database and saved the result, 1 successful, 0 wrong username or password
|
||||
int result = await Task.Run(() => DatabaseHandler.CheckLogin(Username, (parameter as IHavePassword).SecurePassword.Unsecure()));
|
||||
//hides the loading again
|
||||
Loading = "Hidden";
|
||||
@@ -142,7 +142,7 @@ namespace Server_Dashboard {
|
||||
//If the remember user option is checked and the cookie is not set save everything locally
|
||||
if (RememberUser && Settings.Default.Username != Username) {
|
||||
//Creates a new GUID with the username at the end, this is the cookie
|
||||
var cookie = $"{Guid.NewGuid().ToString()}+user:{Username}";
|
||||
var cookie = $"{Guid.NewGuid()}+user:{Username}";
|
||||
//Saves cookie, Username Remember me option to the local storage (Settings.settings)
|
||||
Settings.Default.Cookies = cookie;
|
||||
Settings.Default.Username = Username;
|
||||
@@ -197,7 +197,7 @@ namespace Server_Dashboard {
|
||||
|
||||
#region private functions
|
||||
|
||||
//TODO: Add autologin function that locks the UI untill the user hits the abort button or the login completes
|
||||
//TODO: Add auto login function that locks the UI until 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)) {
|
||||
Loading = "Visible";
|
||||
|
||||
Reference in New Issue
Block a user