add auto module fetch on startup and finished module creation form for real now
This commit is contained in:
@@ -14,46 +14,40 @@ namespace Server_Dashboard {
|
||||
internal class DashboardModuleViewModel : BaseViewModel {
|
||||
|
||||
//List with all Modules inside
|
||||
public ObservableCollection<DashboardModule> Modules { get; set; }
|
||||
public ObservableCollection<ModuleData> Modules { get; set; }
|
||||
|
||||
//Creates Default Modules, remove before release and when implementing the actual data comming from the socket
|
||||
public DashboardModuleViewModel(DataTable userdata) {
|
||||
GetModules(userdata);
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GetModules(DataTable userdata) {
|
||||
Modules = new ObservableCollection<DashboardModule>();
|
||||
foreach (DataRow row in userdata.Rows) {
|
||||
BitmapImage moduleIcon = null;
|
||||
if (row[5] != DBNull.Value) {
|
||||
using MemoryStream ms = new MemoryStream((byte[])row[5]);
|
||||
moduleIcon = new BitmapImage();
|
||||
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();
|
||||
}
|
||||
Modules.Add(new DashboardModule(true) {
|
||||
ModuleName = (string)row[4],
|
||||
Creator = (string)row[1],
|
||||
ModuleIcon = moduleIcon,
|
||||
CreationDate = DateTime.Now.ToString(),
|
||||
ServerInfo = new ServerInformation() {
|
||||
GpuUsage = "20",
|
||||
CpuUsage = "20",
|
||||
CpuTemp = "88.88",
|
||||
DeployDate = DateTime.Now.ToString(),
|
||||
GpuTemp = "69.69",
|
||||
ServerName = "Ubuntu",
|
||||
OSUserName = "crylia ",
|
||||
PrivateIpAdress = "192.168.1.1",
|
||||
PublicIpAdress = "85.69.102.58",
|
||||
Uptime = DateTime.Now.ToString()
|
||||
}
|
||||
});
|
||||
return moduleIcon;
|
||||
} catch { }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ using System.Windows.Input;
|
||||
using Server_Dashboard_Socket;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Server_Dashboard {
|
||||
|
||||
@@ -16,28 +18,28 @@ namespace Server_Dashboard {
|
||||
|
||||
#region Private Values
|
||||
|
||||
private readonly DashboardModuleViewModel dmvm;
|
||||
private DashboardModuleViewModel dmvm;
|
||||
|
||||
#endregion Private Values
|
||||
|
||||
#region Properties
|
||||
|
||||
//The Username displayed defaults to Username
|
||||
private string userName;
|
||||
private User user;
|
||||
|
||||
public string UserName {
|
||||
get { return userName; }
|
||||
public User User {
|
||||
get { return user; }
|
||||
set {
|
||||
if (userName != value)
|
||||
userName = value;
|
||||
OnPropertyChanged(nameof(userName));
|
||||
if (user != value)
|
||||
user = value;
|
||||
OnPropertyChanged(nameof(user));
|
||||
}
|
||||
}
|
||||
|
||||
//List that contains every Module
|
||||
private ObservableCollection<DashboardModule> modules;
|
||||
private ObservableCollection<ModuleData> modules;
|
||||
|
||||
public ObservableCollection<DashboardModule> Modules {
|
||||
public ObservableCollection<ModuleData> Modules {
|
||||
get { return modules; }
|
||||
set {
|
||||
if (value != modules)
|
||||
@@ -51,15 +53,13 @@ namespace Server_Dashboard {
|
||||
#region Constructor
|
||||
|
||||
public DashboardViewModel(string username) {
|
||||
UserName = username;
|
||||
//Command inits
|
||||
OpenLinkCommand = new RelayCommand(OpenLink);
|
||||
OpenNewModuleWindowCommand = new RelayCommand(OpenNewModuleWindow);
|
||||
|
||||
DataTable Userdata = DatabaseHandler.GetUserData(username);
|
||||
dmvm = new DashboardModuleViewModel(Userdata);
|
||||
//Sets the local module to the dashboardviewmodule modules
|
||||
Modules = dmvm.Modules;
|
||||
DataTable userData = DatabaseHandler.GetUserData(username);
|
||||
User = new User(userData);
|
||||
GetModules();
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
@@ -88,12 +88,20 @@ namespace Server_Dashboard {
|
||||
private void OpenNewModuleWindow(object param) {
|
||||
//Creates a new CreateModulePopup and sets this view model as datacontext
|
||||
CreateModulePopup cmp = new CreateModulePopup {
|
||||
DataContext = new CreateModuleViewModel(UserName)
|
||||
DataContext = new CreateModuleViewModel(User.UserName)
|
||||
};
|
||||
//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();
|
||||
GetModules();
|
||||
}
|
||||
|
||||
private void GetModules() {
|
||||
DataTable moduleData = DatabaseHandler.GetUserModuleData(User.UID);
|
||||
dmvm = new DashboardModuleViewModel(moduleData);
|
||||
//Sets the local module to the dashboardviewmodule modules
|
||||
Modules = dmvm.Modules;
|
||||
}
|
||||
|
||||
#endregion Commands
|
||||
|
||||
@@ -140,9 +140,9 @@ namespace Server_Dashboard {
|
||||
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)) {
|
||||
if (RememberUser && Settings.Default.Username != Username) {
|
||||
//Creates a new GUID with the username at the end, this is the cookie
|
||||
var cookie = new Guid().ToString() + Username;
|
||||
var cookie = $"{Guid.NewGuid().ToString()}+user:{Username}";
|
||||
//Saves cookie, Username Remember me option to the local storage (Settings.settings)
|
||||
Settings.Default.Cookies = cookie;
|
||||
Settings.Default.Username = Username;
|
||||
|
||||
Reference in New Issue
Block a user