diff --git a/src/Pace.Server/App.axaml b/src/Pace.Server/App.axaml new file mode 100644 index 0000000..5645ee5 --- /dev/null +++ b/src/Pace.Server/App.axaml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/src/Pace.Server/App.axaml.cs b/src/Pace.Server/App.axaml.cs new file mode 100644 index 0000000..23234b6 --- /dev/null +++ b/src/Pace.Server/App.axaml.cs @@ -0,0 +1,31 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using Pace.Server.View; +using Pace.Server.ViewModel; + +namespace Pace.Server; + +/// +/// Interaction logic for App.xaml +/// +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow + { + DataContext = new MainViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } +} \ No newline at end of file diff --git a/src/Pace.Server/App.config b/src/Pace.Server/App.config deleted file mode 100644 index 731f6de..0000000 --- a/src/Pace.Server/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/Pace.Server/App.xaml b/src/Pace.Server/App.xaml deleted file mode 100644 index 9cc6f15..0000000 --- a/src/Pace.Server/App.xaml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Pace.Server/App.xaml.cs b/src/Pace.Server/App.xaml.cs deleted file mode 100644 index 36392f9..0000000 --- a/src/Pace.Server/App.xaml.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Windows; - -namespace Pace.Server; - -/// -/// Interaction logic for App.xaml -/// -public partial class App : Application -{ -} \ No newline at end of file diff --git a/src/Pace.Server/Converters/FileSizeConverter.cs b/src/Pace.Server/Converters/FileSizeConverter.cs index c2e11a7..8e0ca2d 100644 --- a/src/Pace.Server/Converters/FileSizeConverter.cs +++ b/src/Pace.Server/Converters/FileSizeConverter.cs @@ -1,13 +1,14 @@ -using Pace.Common.Model; +using Avalonia.Data.Converters; +using Pace.Common.Model; using System; +using System.Collections.Generic; using System.Globalization; -using System.Windows.Data; namespace Pace.Server.Converters; public class FileSizeConverter : IMultiValueConverter { - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + public object Convert(IList values, Type targetType, object parameter, CultureInfo culture) { long size = (long)values[0]; var fileType = (FileType)values[1]; @@ -34,11 +35,6 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur minifiedSize = size / 1073741824; } - return $"{minifiedSize.ToString()} {unit}"; - } - - public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); + return $"{minifiedSize} {unit}"; } } \ No newline at end of file diff --git a/src/Pace.Server/Converters/FileTypeConverter.cs b/src/Pace.Server/Converters/FileTypeConverter.cs index baaf5d8..5d4884b 100644 --- a/src/Pace.Server/Converters/FileTypeConverter.cs +++ b/src/Pace.Server/Converters/FileTypeConverter.cs @@ -1,11 +1,10 @@ -using Pace.Common.Model; +using Avalonia.Data.Converters; +using Pace.Common.Model; using System; using System.Globalization; -using System.Windows.Data; namespace Pace.Server.Converters; -[ValueConversion(typeof(FileType), typeof(string))] public class FileTypeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) @@ -13,7 +12,6 @@ public object Convert(object value, Type targetType, object parameter, CultureIn var type = (FileType)value; return type == FileType.File ? Resources.Strings.FileType_File : Resources.Strings.FileType_Folder; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var type = (string)value; diff --git a/src/Pace.Server/Pace.Server.csproj b/src/Pace.Server/Pace.Server.csproj index 0becc1f..5fd0b56 100644 --- a/src/Pace.Server/Pace.Server.csproj +++ b/src/Pace.Server/Pace.Server.csproj @@ -1,10 +1,8 @@  - net6.0-windows - WinExe + net6.0 + WinExe false - true - true Resources\icon.ico @@ -13,8 +11,14 @@ + + + + + + - + diff --git a/src/Pace.Server/Program.cs b/src/Pace.Server/Program.cs new file mode 100644 index 0000000..0684d03 --- /dev/null +++ b/src/Pace.Server/Program.cs @@ -0,0 +1,16 @@ +using Avalonia; +using System; + +namespace Pace.Server; + +public class Program +{ + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() + .UsePlatformDetect() + .LogToTrace(); +} diff --git a/src/Pace.Server/Properties/AssemblyInfo.cs b/src/Pace.Server/Properties/AssemblyInfo.cs deleted file mode 100644 index 5c048de..0000000 --- a/src/Pace.Server/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; -using System.Windows; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Pace.Server")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Pace.Server")] -[assembly: AssemblyCopyright("Copyright © 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -//In order to begin building localizable applications, set -//CultureYouAreCodingWith in your .csproj file -//inside a . For example, if you are using US english -//in your source files, set the to en-US. Then uncomment -//the NeutralResourceLanguage attribute below. Update the "en-US" in -//the line below to match the UICulture setting in the project file. - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] - - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Pace.Server/Properties/Resources.Designer.cs b/src/Pace.Server/Properties/Resources.Designer.cs deleted file mode 100644 index ea447e7..0000000 --- a/src/Pace.Server/Properties/Resources.Designer.cs +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Pace.Server.Properties; - - -/// -/// A strongly-typed resource class, for looking up localized strings, etc. -/// -// This class was auto-generated by the StronglyTypedResourceBuilder -// class via a tool like ResGen or Visual Studio. -// To add or remove a member, edit your .ResX file then rerun ResGen -// with the /str option, or rebuild your VS project. -[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] -[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] -[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] -internal class Resources -{ - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Pace.Server.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } -} diff --git a/src/Pace.Server/Properties/Resources.resx b/src/Pace.Server/Properties/Resources.resx deleted file mode 100644 index af7dbeb..0000000 --- a/src/Pace.Server/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/src/Pace.Server/Properties/Settings.Designer.cs b/src/Pace.Server/Properties/Settings.Designer.cs deleted file mode 100644 index 3eabe6a..0000000 --- a/src/Pace.Server/Properties/Settings.Designer.cs +++ /dev/null @@ -1,28 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Pace.Server.Properties; - - -[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] -[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] -internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase -{ - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } -} diff --git a/src/Pace.Server/Properties/Settings.settings b/src/Pace.Server/Properties/Settings.settings deleted file mode 100644 index 033d7a5..0000000 --- a/src/Pace.Server/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/Pace.Server/Resources/sss.ico b/src/Pace.Server/Resources/sss.ico deleted file mode 100644 index 8ca8fa6..0000000 Binary files a/src/Pace.Server/Resources/sss.ico and /dev/null differ diff --git a/src/Pace.Server/View/FileExplorerWindow.xaml b/src/Pace.Server/View/FileExplorerWindow.xaml deleted file mode 100644 index 6fc037d..0000000 --- a/src/Pace.Server/View/FileExplorerWindow.xaml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Pace.Server/View/FileExplorerWindow.xaml.cs b/src/Pace.Server/View/FileExplorerWindow.xaml.cs deleted file mode 100644 index 458702f..0000000 --- a/src/Pace.Server/View/FileExplorerWindow.xaml.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Pace.Server.Model; -using Pace.Server.Network; -using Pace.Server.ViewModel; -using System.Windows; - -namespace Pace.Server.View; - -/// -/// Interaction logic for FileExplorerWindow.xaml -/// -public partial class FileExplorerWindow : Window -{ - public FileExplorerWindow(PaceServer server, ClientInfo client) - { - InitializeComponent(); - DataContext = new FileExplorerViewModel(server, client); - } -} \ No newline at end of file diff --git a/src/Pace.Server/View/MainWindow.axaml b/src/Pace.Server/View/MainWindow.axaml new file mode 100644 index 0000000..a2ad8e6 --- /dev/null +++ b/src/Pace.Server/View/MainWindow.axaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Pace.Server/View/MainWindow.xaml.cs b/src/Pace.Server/View/MainWindow.axaml.cs similarity index 76% rename from src/Pace.Server/View/MainWindow.xaml.cs rename to src/Pace.Server/View/MainWindow.axaml.cs index 04b512a..b6034bc 100644 --- a/src/Pace.Server/View/MainWindow.xaml.cs +++ b/src/Pace.Server/View/MainWindow.axaml.cs @@ -1,6 +1,6 @@ -using System.Windows; +using Avalonia.Controls; -namespace Pace.Server; +namespace Pace.Server.View; /// /// Interaction logic for MainWindow.xaml diff --git a/src/Pace.Server/View/MainWindow.xaml b/src/Pace.Server/View/MainWindow.xaml deleted file mode 100644 index 16b3b3d..0000000 --- a/src/Pace.Server/View/MainWindow.xaml +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - PACE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Pace.Server/ViewModel/FileExplorerViewModel.cs b/src/Pace.Server/ViewModel/FileExplorerViewModel.cs index f46a443..3476b46 100644 --- a/src/Pace.Server/ViewModel/FileExplorerViewModel.cs +++ b/src/Pace.Server/ViewModel/FileExplorerViewModel.cs @@ -1,4 +1,6 @@ -using Pace.Common.Model; +using Avalonia.Threading; +using CommunityToolkit.Mvvm.Input; +using Pace.Common.Model; using Pace.Common.Network.Packets; using Pace.Common.Network.Packets.Client; using Pace.Common.Network.Packets.Server; @@ -6,7 +8,6 @@ using Pace.Server.Network; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Windows; using System.Windows.Input; namespace Pace.Server.ViewModel; @@ -18,8 +19,8 @@ public class FileExplorerViewModel : ViewModelBase public Stack ForwardHistory { get; set; } public Stack BackHistory { get; set; } - public bool CanGoForward { get { return ForwardHistory.Count > 0; } } - public bool CanGoBackward { get { return BackHistory.Count > 0; } } + public bool CanGoForward => ForwardHistory.Count > 0; + public bool CanGoBackward => BackHistory.Count > 0; private string[] drives; public string[] Drives @@ -28,7 +29,7 @@ public string[] Drives set { drives = value; - OnPropertyChanged(() => Drives); + OnPropertyChanged(nameof(Drives)); } } @@ -39,7 +40,7 @@ public FileSystemEntry CurrentDirectory set { currentDirectory = value; - OnPropertyChanged(() => CurrentDirectory); + OnPropertyChanged(nameof(CurrentDirectory)); } } @@ -50,7 +51,7 @@ public FileSystemEntry SelectedFile set { selectedFile = value; - OnPropertyChanged(() => selectedFile); + OnPropertyChanged(nameof(SelectedFile)); } } @@ -92,7 +93,7 @@ public FileExplorerViewModel(PaceServer server, ClientInfo client) private void HandleGetDirectory(IPacket packet) { - Application.Current.Dispatcher.Invoke(() => + Dispatcher.UIThread.InvokeAsync(() => { Files.Clear(); }); @@ -108,12 +109,12 @@ private void HandleGetDirectory(IPacket packet) BackHistory.Push(previousDirectory); } - OnPropertyChanged(() => CanGoForward); - OnPropertyChanged(() => CanGoBackward); + OnPropertyChanged(nameof(CanGoForward)); + OnPropertyChanged(nameof(CanGoBackward)); for (int i = 0; i < directoryResponse.Folders.Length; i++) { - Application.Current.Dispatcher.Invoke(() => + Dispatcher.UIThread.InvokeAsync(() => { Files.Add(new FileSystemEntry ( @@ -127,7 +128,7 @@ private void HandleGetDirectory(IPacket packet) for (int i = 0; i < directoryResponse.Files.Length; i++) { - Application.Current.Dispatcher.Invoke(() => + Dispatcher.UIThread.InvokeAsync(() => { Files.Add(new FileSystemEntry ( @@ -149,7 +150,6 @@ private void HandleGetDrives(IPacket packet) private void HandleNotifyStatus(IPacket packet) { var statusPacket = (NotifyStatusResponsePacket)packet; - MessageBox.Show(statusPacket.StatusMessage, "Notification", MessageBoxButton.OK, MessageBoxImage.Information); } private void Navigate(string path) @@ -160,7 +160,9 @@ private void Navigate(string path) private void NavigateSelected(string s) { if (SelectedFile.Type != FileType.Directory) + { return; + } Navigate(SelectedFile.Path); } @@ -188,9 +190,9 @@ private void NavigateBack(string s) private void DeleteFile(string s) { - var result = MessageBox.Show($"Delete {SelectedFile.Name}?", "File deletion", MessageBoxButton.YesNo, MessageBoxImage.Warning); - - if (result == MessageBoxResult.Yes) + if (false) + { Client.Owner.SendPacket(new DeleteFileRequestPacket(SelectedFile.Path)); + } } } \ No newline at end of file diff --git a/src/Pace.Server/ViewModel/FileWindowService.cs b/src/Pace.Server/ViewModel/FileWindowService.cs index 5f747c1..79aa775 100644 --- a/src/Pace.Server/ViewModel/FileWindowService.cs +++ b/src/Pace.Server/ViewModel/FileWindowService.cs @@ -1,7 +1,5 @@ using Pace.Server.Model; using Pace.Server.Network; -using Pace.Server.View; -using System.Windows; namespace Pace.Server.ViewModel; @@ -9,20 +7,20 @@ public class FileWindowService { public void ShowWindow(PaceServer server, ClientInfo client) { - var window = new FileExplorerWindow(server, client); + //var window = new FileExplorerWindow(server, client); - // TODO: Probably not an optimal place to put this in, remember to handle this somewhere else - server.ClientDisconnected += (sender, args) => - { - if (args.Client == client.Owner) - { - Application.Current.Dispatcher.Invoke(() => - { - window.Close(); - }); - } - }; + //// TODO: Probably not an optimal place to put this in, remember to handle this somewhere else + //server.ClientDisconnected += (sender, args) => + //{ + // if (args.Client == client.Owner) + // { + // Dispatcher.UIThread.InvokeAsync(() => + // { + // window.Close(); + // }); + // } + //}; - window.Show(); + //window.Show(); } } \ No newline at end of file diff --git a/src/Pace.Server/ViewModel/ClientViewModel.cs b/src/Pace.Server/ViewModel/MainViewModel.cs similarity index 77% rename from src/Pace.Server/ViewModel/ClientViewModel.cs rename to src/Pace.Server/ViewModel/MainViewModel.cs index 19fb2e0..3e9e13a 100644 --- a/src/Pace.Server/ViewModel/ClientViewModel.cs +++ b/src/Pace.Server/ViewModel/MainViewModel.cs @@ -1,19 +1,17 @@ -using MaterialDesignThemes.Wpf; +using Avalonia.Threading; +using CommunityToolkit.Mvvm.Input; using Pace.Common.Network.Packets; using Pace.Common.Network.Packets.Client; using Pace.Common.Network.Packets.Server; using Pace.Server.Model; using Pace.Server.Network; -using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.ComponentModel; using System.Linq; -using System.Windows; namespace Pace.Server.ViewModel; -public class ClientViewModel : ViewModelBase +public class MainViewModel : ViewModelBase { private readonly PaceServer server; private readonly FileWindowService fileManagerService; @@ -25,8 +23,8 @@ public ClientInfo SelectedClient set { selectedClient = value; - OnPropertyChanged(() => selectedClient); - OnPropertyChanged(() => IsItemSelected); + OnPropertyChanged(nameof(SelectedClient)); + OnPropertyChanged(nameof(IsItemSelected)); } } @@ -34,29 +32,18 @@ public ClientInfo SelectedClient public ObservableCollection Clients { get; set; } - public SnackbarMessageQueue ConnectedMessageQueue { get; set; } - public RelayCommand OpenFileManagerCommand { get; set; } public RelayCommand RestartCommand { get; set; } - public ClientViewModel() + public MainViewModel() { fileManagerService = new FileWindowService(); Clients = new ObservableCollection(); - ConnectedMessageQueue = new SnackbarMessageQueue(TimeSpan.FromMilliseconds(5000)); - OpenFileManagerCommand = new RelayCommand(OpenFileManager); RestartCommand = new RelayCommand(RestartClient); - #if DEBUG - if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) - { - return; - } - #endif - server = new PaceServer(); server.ClientConnected += Server_ClientConnected; server.ClientDisconnected += Server_ClientDisconnected; @@ -68,8 +55,6 @@ public ClientViewModel() private void Server_ClientConnected(object sender, ClientEventArgs e) { - ConnectedMessageQueue.Enqueue(string.Format(Resources.Strings.Main_ClientConnected, e.Client.RemoteAddress)); - e.Client.SendPacket(new GetSystemInfoRequestPacket()); } @@ -83,7 +68,7 @@ private void Server_ClientDisconnected(object sender, ClientEventArgs e) SelectedClient = null; } - Application.Current.Dispatcher.Invoke(() => + Dispatcher.UIThread.InvokeAsync(() => { Clients.Remove(client); }); @@ -114,7 +99,7 @@ private void HandleSystemInfo(IPacket packet) OS = systemInfoResponse.OS }; - Application.Current.Dispatcher.Invoke(() => + Dispatcher.UIThread.InvokeAsync(() => { Clients.Add(clientInfo); }); diff --git a/src/Pace.Server/ViewModel/RelayCommand.cs b/src/Pace.Server/ViewModel/RelayCommand.cs deleted file mode 100644 index a8767af..0000000 --- a/src/Pace.Server/ViewModel/RelayCommand.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Windows.Input; - -namespace Pace.Server.ViewModel; - -public class RelayCommand : ICommand -{ - #region Fields - - private readonly Action _execute = null; - private readonly Predicate _canExecute = null; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of . - /// - /// Delegate to execute when Execute is called on the command. This can be null to just hook up a CanExecute delegate. - /// will always return true. - public RelayCommand(Action execute) - : this(execute, null) - { - } - - /// - /// Creates a new command. - /// - /// The execution logic. - /// The execution status logic. - public RelayCommand(Action execute, Predicate canExecute) - { - _execute = execute ?? throw new ArgumentNullException("execute"); - _canExecute = canExecute; - } - - #endregion - - #region ICommand Members - - /// - ///Defines the method that determines whether the command can execute in its current state. - /// - ///Data used by the command. If the command does not require data to be passed, this object can be set to null. - /// - ///true if this command can be executed; otherwise, false. - /// - public bool CanExecute(object parameter) - { - return _canExecute == null ? true : _canExecute((T)parameter); - } - - /// - ///Occurs when changes occur that affect whether or not the command should execute. - /// - public event EventHandler CanExecuteChanged - { - add { CommandManager.RequerySuggested += value; } - remove { CommandManager.RequerySuggested -= value; } - } - - /// - ///Defines the method to be called when the command is invoked. - /// - ///Data used by the command. If the command does not require data to be passed, this object can be set to . - public void Execute(object parameter) - { - _execute((T)parameter); - } - - #endregion -} \ No newline at end of file diff --git a/src/Pace.Server/ViewModel/ViewModelBase.cs b/src/Pace.Server/ViewModel/ViewModelBase.cs index 479ecdf..10c30cf 100644 --- a/src/Pace.Server/ViewModel/ViewModelBase.cs +++ b/src/Pace.Server/ViewModel/ViewModelBase.cs @@ -1,25 +1,7 @@ -using System; -using System.ComponentModel; -using System.Linq.Expressions; +using CommunityToolkit.Mvvm.ComponentModel; namespace Pace.Server.ViewModel; -public abstract class ViewModelBase : INotifyPropertyChanged +public abstract class ViewModelBase : ObservableObject { - public event PropertyChangedEventHandler PropertyChanged; - - public virtual void OnPropertyChanged(string propertyName) - { - PropertyChangedEventHandler handler = PropertyChanged; - if (handler != null) - { - var e = new PropertyChangedEventArgs(propertyName); - handler(this, e); - } - } - - public virtual void OnPropertyChanged(Expression> propertyNameExpression) - { - OnPropertyChanged(((MemberExpression)propertyNameExpression.Body).Member.Name); - } } \ No newline at end of file