private async void CopyAsProfileAction()
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = LocalizationManager.GetStringByKey("String_Header_CopyClient")
            };

            WakeOnLANClientViewModel wakeOnLANClientViewModel = new WakeOnLANClientViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);

                WakeOnLANClientInfo wakeOnLANClientInfo = new WakeOnLANClientInfo
                {
                    Name       = instance.Name,
                    MACAddress = instance.MACAddress,
                    Broadcast  = instance.Broadcast,
                    Port       = instance.Port,
                    Group      = instance.Group
                };

                WakeOnLANClientManager.AddClient(wakeOnLANClientInfo);
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
            }, WakeOnLANClientManager.GetClientGroups(), SelectedClient);

            customDialog.Content = new WakeOnLANClientDialog
            {
                DataContext = wakeOnLANClientViewModel
            };

            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
        public WakeOnLANViewModel(IDialogCoordinator instance)
        {
            dialogCoordinator = instance;

            if (WakeOnLANClientManager.Clients == null)
            {
                WakeOnLANClientManager.Load();
            }

            _wakeOnLANClients = CollectionViewSource.GetDefaultView(WakeOnLANClientManager.Clients);
            _wakeOnLANClients.GroupDescriptions.Add(new PropertyGroupDescription(nameof(WakeOnLANClientInfo.Group)));
            _wakeOnLANClients.SortDescriptions.Add(new SortDescription(nameof(WakeOnLANClientInfo.Group), ListSortDirection.Ascending));
            _wakeOnLANClients.SortDescriptions.Add(new SortDescription(nameof(WakeOnLANClientInfo.Name), ListSortDirection.Ascending));
            _wakeOnLANClients.Filter = o =>
            {
                if (string.IsNullOrEmpty(Search))
                {
                    return(true);
                }

                WakeOnLANClientInfo info = o as WakeOnLANClientInfo;

                string search = Search.Trim();

                // Search by: Name
                return(info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1);
            };

            LoadSettings();

            _isLoading = true;
        }
示例#3
0
        private async void EditClientAction()
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = Application.Current.Resources["String_Header_EditClient"] as string
            };

            WakeOnLANClientViewModel wakeOnLANClientViewModel = new WakeOnLANClientViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);

                WakeOnLANClientManager.RemoveClient(SelectedClient);

                WakeOnLANClientInfo wakeOnLANClientInfo = new WakeOnLANClientInfo
                {
                    Name       = instance.Name,
                    MACAddress = instance.MACAddress,
                    Broadcast  = instance.Broadcast,
                    Port       = instance.Port,
                    Group      = instance.Group
                };

                WakeOnLANClientManager.AddClient(wakeOnLANClientInfo);
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
            }, WakeOnLANClientManager.GetClientGroups(), SelectedClient);

            customDialog.Content = new WakeOnLANClientDialog
            {
                DataContext = wakeOnLANClientViewModel
            };

            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
        private async void AddClientAction()
        {
            MetroDialogSettings settings = AppearanceManager.MetroDialog;

            settings.AffirmativeButtonText = Application.Current.Resources["String_Button_Add"] as string;
            settings.NegativeButtonText    = Application.Current.Resources["String_Button_Cancel"] as string;
            settings.DefaultButtonFocus    = MessageDialogResult.Affirmative;

            string hostname = await dialogCoordinator.ShowInputAsync(this, Application.Current.Resources["String_Header_AddClient"] as string, Application.Current.Resources["String_EnterHostnameForClient"] as string, settings);

            if (string.IsNullOrEmpty(hostname))
            {
                return;
            }

            WakeOnLANClientInfo client = new WakeOnLANClientInfo
            {
                Hostname   = hostname.ToUpper(),
                MACAddress = MACAddressHelper.GetDefaultFormat(MACAddress),
                Broadcast  = Broadcast,
                Port       = Port
            };

            WakeOnLANClientManager.AddClient(client);
        }
        public WakeOnLANClientViewModel(Action <WakeOnLANClientViewModel> saveCommand, Action <WakeOnLANClientViewModel> cancelHandler, List <string> groups, WakeOnLANClientInfo clientInfo = null)
        {
            _saveCommand   = new RelayCommand(p => saveCommand(this));
            _cancelCommand = new RelayCommand(p => cancelHandler(this));

            _clientInfo = clientInfo ?? new WakeOnLANClientInfo();

            Name       = _clientInfo.Name;
            MACAddress = _clientInfo.MACAddress;
            Broadcast  = _clientInfo.Broadcast;
            Port       = _clientInfo.Port;
            Group      = string.IsNullOrEmpty(_clientInfo.Group) ? Application.Current.Resources["String_Default"] as string : _clientInfo.Group;

            _groups = CollectionViewSource.GetDefaultView(groups);
            _groups.SortDescriptions.Add(new SortDescription());

            _isLoading = false;
        }
示例#6
0
        public WakeOnLANClientViewModel(Action <WakeOnLANClientViewModel> saveCommand, Action <WakeOnLANClientViewModel> cancelHandler, List <string> groups, WakeOnLANClientInfo clientInfo = null)
        {
            _saveCommand   = new RelayCommand(p => saveCommand(this));
            _cancelCommand = new RelayCommand(p => cancelHandler(this));

            _clientInfo = clientInfo ?? new WakeOnLANClientInfo();

            Name       = _clientInfo.Name;
            MACAddress = _clientInfo.MACAddress;
            Broadcast  = _clientInfo.Broadcast;
            Port       = _clientInfo.Port;

            // Get the group, if not --> get the first group (ascending), fallback --> default group
            Group = string.IsNullOrEmpty(_clientInfo.Group) ? (groups.Count > 0 ? groups.OrderBy(x => x).First() : Application.Current.Resources["String_Default"] as string) : _clientInfo.Group;

            _groups = CollectionViewSource.GetDefaultView(groups);
            _groups.SortDescriptions.Add(new SortDescription());

            _isLoading = false;
        }