Example #1
0
 private Updater()
 {
     CheckCommand = new DelegateCommand(async () =>
     {
         CheckCommand.CanExecute = false;
         bool result = await TryFindUpdateAsync();
         Status = result ? UpdaterStatus.Download : UpdaterStatus.Check;
         if (result && isautoupdate)
         {
             DispatcherHelper.UIDispatcher.Invoke(() =>
             {
                 if (MessageBox.Show($"{StringTable.Update_Text_Download}{NewVersion}",
                     StringTable.Update, MessageBoxButton.OKCancel, MessageBoxImage.Information)
                     == MessageBoxResult.OK)
                     new AboutWindow { Owner = Application.Current.MainWindow }.ShowDialog();
             });
             if (Config.Current.AutoDownloadUpdate) DownloadCommand.Execute(null);
             else isautoupdate = false;
         }
         else isautoupdate = false;
         CheckCommand.CanExecute = true;
     });
     DownloadCommand = new DelegateCommand(async () =>
     {
         Status = UpdaterStatus.CancelDownload;
         bool result = await DownloadUpdateAsync();
         Status = result ? UpdaterStatus.UpdateFile : UpdaterStatus.Download;
         if (result && isautoupdate) UpdateFileCommand.Execute(null);
         else isautoupdate = false;
     });
     CancelDownloadCommand = new DelegateCommand(() =>
     {
         downloadwebclient?.CancelAsync();
         Status = UpdaterStatus.Download;
     });
     UpdateFileCommand = new DelegateCommand(async () =>
     {
         UpdateFileCommand.CanExecute = false;
         await UpdateFileAsync();
         UpdateFileCommand.CanExecute = true;
         Status = UpdaterStatus.Restart;
         isautoupdate = false;
     });
     RestartCommand = new DelegateCommand(Restart);
     Timer.Elapsed += (_, __) =>
     {
         if (Status == UpdaterStatus.Check && Config.Current.AutoCheckUpdate)
         {
             isautoupdate = true;
             DispatcherHelper.UIDispatcher.Invoke(() => CheckCommand.Execute(null));
         }
     };
     isautoupdate = true;
     CheckCommand.Execute(null);
 }
        public async Task TestConstructionAndExecute()
        {
            bool actioned1 = false;
            var command1 = new DelegateCommand<string>((s) => actioned1 = true);
            await command1.Execute(null);
            Assert.True(actioned1);
            Assert.Throws<ArgumentNullException>(() => new DelegateCommand<string>((s) => { }, null));
            Assert.Throws<ArgumentNullException>(() => new DelegateCommand<string>(null, null));
            Assert.Throws<ArgumentNullException>(() => new DelegateCommand<string>(null));
            bool actioned2 = false;
            var command2 = new DelegateCommand<string>((s) =>
                {
                    if (s == "Test")
                    {
                        actioned2 = true;
                    }
                });
            await command2.Execute("Test");
            Assert.True(actioned2);

            bool actioned3 = false;
            var command3 = new DelegateCommand<string>((s) => actioned3 = true);
            await command3.Execute(null);
            Assert.True(actioned3);
            Assert.Throws<ArgumentNullException>(() => new DelegateCommand(() => { }, null));
            Assert.Throws<ArgumentNullException>(() => new DelegateCommand(null, null));
            Assert.Throws<ArgumentNullException>(() => new DelegateCommand(null));
        }
        public ItemListFilterViewModel(IEventAggregator iEventAggregator, int _numControls)
        {
            this.iEventAggregator = iEventAggregator;
            buttonActions = new string[] { "FILTER_RESET", "FILTER_TYPE", "FILTER_FILES" };
            Filter = "";
            FilterType = "Contains";
            numControls = _numControls;

            MoveRightCommand = new DelegateCommand(MoveRight, CanMoveRight);
            MoveLeftCommand = new DelegateCommand(MoveLeft, CanMoveLeft);
            RemoveLastCharFromFilterCommand = new DelegateCommand(RemoveLastCharFromFilter, CanRemoveLastCharFromFilter);
            ResetFiltersCommand = new DelegateCommand(ResetFilters, CanResetFilters);

            EventMap = new Dictionary<string, Action>()
            {
                {"FILTER_MOVE_LEFT", () =>
                    {
                        if (MoveLeftCommand.CanExecute())
                        {
                            MoveLeftCommand.Execute();
                        }
                    }
                },
                {"FILTER_MOVE_RIGHT", () =>
                    {
                        if (MoveRightCommand.CanExecute())
                        {
                            MoveRightCommand.Execute();
                        }
                    }
                },
                {"CHAR_BACK", () =>
                    {
                        if (RemoveLastCharFromFilterCommand.CanExecute())
                        {
                            RemoveLastCharFromFilterCommand.Execute();
                        }
                    }
                }

            };

            EventMapParam = new Dictionary<string, Action<string>>()
            {
                {"CHAR_SELECT", AppendToFilter},
                {"VOS_OPTION",  (_filterType) =>
                    {
                        FilterType = _filterType;
                    }
                }
            };

            filterViewToken = this.iEventAggregator.GetEvent<PubSubEvent<ViewEventArgs>>().Subscribe(
                (viewEventArgs) =>
                {
                    EventHandler(viewEventArgs);
                }
            );
        }
        public void Generic_DelegateCommand_Receives_Execute_Parameter()
        {
            int executeParameter = 0;
            var command = new DelegateCommand<int>(x => executeParameter = x);

            command.Execute(55);

            Assert.That(executeParameter, Is.EqualTo(55));
        }
        public void Calling_Execute_Runs_Delegate()
        {
            bool commandWasRun = false;
            var command = new DelegateCommand(() => commandWasRun = true);

            command.Execute(null);

            Assert.That(commandWasRun);
        }
        public void ConstructorWithOnlyExecuteMethodForExecuteTest()
        {
            var command = new DelegateCommand(m_CommandManager,
                                              ExecuteMethod);

            command.Execute();

            Assert.True(m_IsExecuted,
                        "IsExecuted");
        }
        public void TestNullObjectParameterCommand()
        {
            DelegateCommand<object, object> testMessageOutputCommand = new
                DelegateCommand<object, object>(WriteTestMessage, null, null);

            using (var writer = new StringWriter())
            {
                Console.SetOut(writer);
                testMessageOutputCommand.Execute();
                Assert.AreEqual("is that working??!!"+ Environment.NewLine, writer.ToString());
            }
        }
        public void TestTwoParameterCommand()
        {
            TestReceiver receiver1 = new TestReceiver();
            ICommand testMessageOutputCommand = new
                DelegateCommand<string, string>(receiver1.ReceiverAction, "hello", "yunyun");

            using (var writer = new StringWriter())
            {
                Console.SetOut(writer);
                testMessageOutputCommand.Execute();
                Assert.AreEqual("hellois that working yunyun" + Environment.NewLine, writer.ToString());
            }
        }
Example #9
0
        public VM主窗口()
        {
            AddProgress = new DelegateCommand((o) => _AddProgress());
            ScanFiles = new DelegateCommand((o) => _ScanFiles(o));
            WinClose = new DelegateCommand((o) => _WinClose());
            OpenFile = new DelegateCommand((o) => _OpenFile(o));
            LocateFile = new DelegateCommand((o) => _LocateFile());
            Edit = new DelegateCommand((o) => _Edit(o));
            CopyName = new DelegateCommand((o) => _CopyName());
            Search = new DelegateCommand((o) => _Search());
            ShowDetails = new DelegateCommand((o) => _ShowDetails());
            VisitBgm = new DelegateCommand((o) => _VisitBgm());
            VisitHP = new DelegateCommand((o) => _VisitHP());
            Manage = new DelegateCommand((o) => _Manage());
            Update = new DelegateCommand((o) => _Update());
            Finish = new DelegateCommand((o) => _Finish());
            UpdateInfo = new DelegateCommand((o) => _UpdateInfo());
            MusicInfo = new DelegateCommand((o) => _MusicInfo());

            ScanFiles.Execute(null);
        }
        public AddEditPasswordViewModel(INavigationService navigationService, IPasswordRepository passwordRepository)
        {
            _navigationService = navigationService;
            _passwordRepository = passwordRepository;

            SaveCommand = new DelegateCommand(() => Save(), () => CanSave);
            CopyToClipboardCommand = new DelegateCommand(() => CopyToClipboard());
            GoBackCommand = new DelegateCommand(() => navigationService.GoBack(), () => navigationService.CanGoBack());

            KeyPressAction = (eventArgs) =>
                {
                    switch (eventArgs.Key)
                    {
                        case VirtualKey.Enter:
                            {
                                if(CanSave)
                                    SaveCommand.Execute();
                            }
                            break;
                        default:
                            break;
                    }
                };
        }
Example #11
0
        public void Execute_PassesArgument_GenericStruct()
        {
            MockCommandHandler<int> handler = new MockCommandHandler<int>();
            DelegateCommand<int> command = new DelegateCommand<int>(handler.Execute);

            command.Execute(42);

            CollectionAssert.AreEqual(new[] { 42 }, (ICollection)handler.ArgumentList);
        }
Example #12
0
        public void Execute_PassesArgument_GenericClass()
        {
            MockCommandHandler<MockArgumentClass> handler = new MockCommandHandler<MockArgumentClass>();
            DelegateCommand<MockArgumentClass> command = new DelegateCommand<MockArgumentClass>(handler.Execute);
            MockArgumentClass argument = new MockArgumentClass();

            command.Execute(argument);

            CollectionAssert.AreEqual(new[] { argument }, (ICollection)handler.ArgumentList);
        }
Example #13
0
        public void Execute_CallsExecuteMethod_GenericStruct()
        {
            MockCommandHandler<int> handler = new MockCommandHandler<int>();
            DelegateCommand<int> command = new DelegateCommand<int>(handler.Execute);

            Assert.AreEqual(0, handler.ExecuteCallCount);

            command.Execute(42);

            Assert.AreEqual(1, handler.ExecuteCallCount);
        }
Example #14
0
        public void Execute_CallsExecuteMethod_GenericClass()
        {
            MockCommandHandler<MockArgumentClass> handler = new MockCommandHandler<MockArgumentClass>();
            DelegateCommand<MockArgumentClass> command = new DelegateCommand<MockArgumentClass>(handler.Execute);

            Assert.AreEqual(0, handler.ExecuteCallCount);

            command.Execute(new MockArgumentClass());

            Assert.AreEqual(1, handler.ExecuteCallCount);
        }
        public void Execute_CallsExecuteMethod_NonGeneric()
        {
            MockCommandHandler handler = new MockCommandHandler();
            DelegateCommand command = new DelegateCommand(handler.Execute);

            Assert.Equal(0, handler.ExecuteCallCount);

            command.Execute(new MockArgumentClass());

            Assert.Equal(1, handler.ExecuteCallCount);
        }