示例#1
0
 public void Setup()
 {
     SelectPdfCmd = new RelayCommand(x => SelectPdfCmdExecute());
     ClosingCmd = new ActionCommand<System.ComponentModel.CancelEventArgs>(ClosingExecute);
     MySqlHelper.RefreshAll += Refresh;
     Refresh();
 }
示例#2
0
        public void ActionCommands_InvalidInput_RespondsAsExpected()
        {
            // arrange
            var fireBasic = new MockActionCommand();
            var fireParameter = new MockActionCommand();

            ICommand parameterCommandInt32 = new ActionCommand<int>(fireParameter.ExecuteParam, fireParameter.CanExecuteParam);
            ICommand parameterCommandObject = new ActionCommand<object>((o) => { });
            ICommand parameterCommandObjectFunc = new ActionCommand<object>((o) => { }, (o) => { return true; });

            // assert
            try
            {
                parameterCommandInt32.CanExecute(null);
                Assert.Fail("Expected error");
            }
            catch (NullReferenceException) { }
            try
            {
                parameterCommandInt32.Execute(null);
                Assert.Fail("Expected error");
            }
            catch (NullReferenceException) { }

            parameterCommandObject.Execute(null);
            parameterCommandObjectFunc.Execute(null);

            Assert.IsTrue(parameterCommandObject.CanExecute(null));
            Assert.IsTrue(parameterCommandObjectFunc.CanExecute(null));
        }
示例#3
0
        public MainWindowViewModel(IMainWindow mainWindow, IEnumerable<IBuildServer> buildServers)
        {
            BuildServers = buildServers.Select(b => new BuildServerViewModel(b));

            CloseApplicationCommand = new ActionCommand(() => Application.Current.Shutdown());
            MinimizeToTrayCommand = new ActionCommand(mainWindow.MinimizeToTray);
        }
示例#4
0
 public OrderListVm()
 {
     Loading = false;
     DicCache.Instance.GetDic(null, "BULIDING_LEVEL");
     Search();
     PageChangeCommand = new ActionCommand(PageChange);
 }
示例#5
0
        public FeedsViewModel()
        {
            Model = ReaderModel.Instance;
            AddFeedFormVisibility = Visibility.Collapsed;
            AddFeedCommand = new ActionCommand(delegate(object o)
                                                   {
                                                       var url = (string) o;
                                                       Uri feedUri;
                                                       Uri.TryCreate(url, UriKind.Absolute, out feedUri);
                                                       if (feedUri == null)
                                                           return;
                                                       var request = new WebClient();
                                                       request.DownloadStringCompleted +=
                                                           delegate(object sender, DownloadStringCompletedEventArgs e)
                                                               {
                                                                   if (e.Error != null)
                                                                       return;
                                                                   AddFeedFormVisibility = Visibility.Collapsed;
                                                                   string xml = e.Result;
                                                                   if (xml.Length == 0)
                                                                       return;

                                                                   var stringReader = new StringReader(xml);
                                                                   XmlReader reader = XmlReader.Create(stringReader);
                                                                   SyndicationFeed feed = SyndicationFeed.Load(reader);

                                                                   if (Feeds.Where(f => f.Title.Text == feed.Title.Text).ToList().Count > 0)
                                                                       return;

                                                                   Feeds.Add(feed);
                                                               };
                                                       request.DownloadStringAsync(feedUri);
                                                   });
        }
        public PdfViewModel()
        {
            if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                return;
            }

            string currentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);

            string path1 = Path.Combine(currentFolder, @"SamplePDF1.pdf");

            string path2 = Path.Combine(currentFolder, @"SamplePDF2.pdf");

            pdfChoices = new string[]
                              {
                                  path1,
                                  path2,
                              };
            CurrentPdf = pdfChoices[currentPdfChoiceIndex];
            Console.WriteLine("currentpdf:" + CurrentPdf);

            SwapPdfsCommand = new ActionCommand(() =>
            {
                currentPdfChoiceIndex ^= 1;
                CurrentPdf = pdfChoices[currentPdfChoiceIndex];
            });
        }
		public ServerListViewModel(IoCContainer iocc)
		{
			this.iocc   = iocc;
			config      = iocc.RetrieveContract<Configuration>();

			tokenSource = new CancellationTokenSource();
			token       = tokenSource.Token;

			RefreshCommand    = new ActionCommand(x => Application.Current.Dispatcher.InvokeAsync(UpdateServerList), x => true);
			JoinServerCommand = new ActionCommand(ConnectTo, x => Servers.CurrentItem != null);

			servers    = new ObservableCollection<ServerViewModel>();
			viewSource = new CollectionViewSource {Source = servers};

			viewSource.SortDescriptions.Add(new SortDescription("Players", ListSortDirection.Descending));

			viewSource.Filter += (s, e) =>
			                     {
				                     ServerViewModel model = e.Item as ServerViewModel;

				                     e.Accepted = model != null && model.Version.Equals(RxVersion, StringComparison.OrdinalIgnoreCase);
			                     };

			Servers    = viewSource.View;
			pingTask   = Task.Factory.StartNew(PingServers, token);
		}
示例#8
0
        public void ActionCommands_FireAsExpected()
        {
            // arrange
            var fireBasic = new MockActionCommand();
            var fireParameter = new MockActionCommand();

            ICommand basicCommand = new ActionCommand(fireBasic.ExecuteNone, fireBasic.CanExecute);
            ICommand valueTypeCommand = new ActionCommand<int>(fireParameter.ExecuteParam, fireParameter.CanExecuteParam);

            // act
            basicCommand.Execute(null);
            basicCommand.Execute("n/a input");
            valueTypeCommand.Execute(2);

            Assert.IsTrue(basicCommand.CanExecute(null));
            Assert.IsTrue(basicCommand.CanExecute("any input ignored"));
            Assert.IsTrue(valueTypeCommand.CanExecute(1));

            // assert
            Assert.IsTrue(fireBasic.ExecuteFired);
            Assert.IsTrue(fireBasic.TestFired);

            Assert.IsTrue(fireParameter.ExecuteFired);
            Assert.IsTrue(fireParameter.TestFired);
            Assert.AreEqual(2, fireParameter.ObjectsPassedIn.Count);
            Assert.AreEqual(3, fireParameter.ObjectsPassedIn.Sum());
        }
示例#9
0
        public OverviewViewModel()
        {
            today = DateTime.Today;

            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMinutes(1);
            timer.Tick += (sender, args) =>
                {
                    if (DateTime.Today <= today) return;

                    today = DateTime.Today;
                    UpdateHeaders();
                };
            timer.Start();

            ItemSelectionChangedCommand = new ActionCommand(ItemSelectionChanged);
            LinkCommand = new ActionCommand(ShowLink);
            LoadedCommand = new ActionCommand(Loaded);
            TodayCommand = new ActionCommand(_ => Show(MenuRepository.GetTodaysMenu()));
            ExpandAllCommand = new ActionCommand(_ => SetAllExpansion(true));
            CollapseAllCommand = new ActionCommand(_ =>
                {
                    SetAllSelection(false);
                    SetAllExpansion(false);
                });
        }
示例#10
0
 public MainWindowViewModel(IGameEngine gameEngine, IObservable<IGameEvent> events,
                            IViewController viewController)
 {
     _events = events;
     _viewController = viewController;
     GameEngine = gameEngine;
     Hit = new ActionCommand(OnPlayerHit2);
 }
示例#11
0
 public SelectGameViewModel(Action<SelectGameViewModel> successAction, Action<SelectGameViewModel> cancelAction)
 {
     this.successCommand = new ActionCommand<SelectGameViewModel>(successAction);
     this.cancelCommand = new ActionCommand<SelectGameViewModel>(cancelAction);
     this.SelectedBoardSize = 7;
     this.HumanVersusComputer = true;
     this.SkillLevel = ComputerSkillLevel.Medium;
 }
示例#12
0
 private void WireUpCommands()
 {
     AddMessageCommand = new ActionCommand(() =>
     {
         var vm = Create();
         this.Messages.AddItem(vm);
     });
 }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FilterSelector"/> class.
 /// </summary>
 public FilterSelector()
 {
     DefaultStyleKey = typeof(FilterSelector);
     UpdateSelectedFilterCommand = new ActionCommand<IFilter>(ExecuteUpdateSelectedFilter, CanUpdateSelectedFilter);
     FilterOptionsCommand = new ActionCommand<IFilterDescriptor>(ExecuteFilterOptions);
     var isEnabledListener = DependencyPropertyChangedListener.Create(this, "IsEnabled");
     isEnabledListener.ValueChanged += (sender, args) => UpdateIsBusy();
 }
        public void CanExecute_Object_Generic_Default()
        {
            var random = new Random();
            Object parameter = random.Next();

            var command = new ActionCommand<int>(null, null);

            Assert.IsTrue(((ICommand)command).CanExecute(parameter));
        }
        public void CanExecute_Generic()
        {
            var random = new Random();
            var parameter = random.Next();

            var command = new ActionCommand<int>(null, i => { return true; });

            Assert.IsTrue(command.CanExecute(parameter));
        }
        public void CanExecute_Default()
        {
            var random = new Random();
            var parameter = random.Next();

            var command = new ActionCommand(null, null);

            Assert.IsTrue(command.CanExecute(parameter));
        }
示例#17
0
 public MainWindowVM()
 {
     pieceListVM = new PieceListVM();
     interpretListVM = new InterpretListVM();
     GenreListVM = new GenreListVM();
     KeyDownCmd = new ActionCommand<KeyEventArgs>(this.KeyDownCmdExecute);
     NewInterpretCmd = new RelayCommand(x => NewInterpretCmdExecute());
     instance = this;
 }
示例#18
0
 public InterpretListVM()
 {
     MySqlHelper.RefreshAll += Refresh;
     MouseDoubleClickCmd = new ActionCommand<MouseButtonEventArgs>(MouseDoubleClickCmdExecute);
     ShowPiecesCmd = new RelayCommand( x => ShowPiecesCmdExecute(x));
     NewInterpretCmd = new RelayCommand(x => NewInterpretCmdExecute());
     KeyUpCmd = new ActionCommand<KeyEventArgs>(KeyUpCmdExecute);
     DeleteInterpretCmd = new RelayCommand(x => DeleteInterpretCmdExecute());
 }
示例#19
0
 public MenuItem(String name, String url)
 {
     Name = name;
     URL = "/" + url;
     _originalUrl = "/" + url;
     Items = new MenuItemsCollection(this);
     MenuCommand = new ActionCommand<object>(
     obj => Navigate(), obj => true);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="FeatureDataForm"/> class.
        /// </summary>
        public FeatureDataForm()
        {
#if NETFX_CORE
            DefaultStyleKey = typeof(FeatureDataForm);
#endif
            Fields = new ObservableCollection<string>();
            ApplyCommand = new ActionCommand(ApplyChanges,CanApplyChanges);
            ResetCommand = new ActionCommand(Reset,CanReset);
        }
        public MainViewModel()
        {
            _addPacketCommand = new ActionCommand(AddEmptyPacket);
            _loadCommand = new ActionCommand(LoadState);
            _saveCommand = new ActionCommand(SaveState);
            _exportCommand = new ActionCommand(ExportState);

            LinkProperties("SelectedPacket", "IsPacketSelected");
        }
示例#22
0
        public void RaiseCanExecuteChangedTest()
        {
            var canExecuteHandled = false;

            ICommand cmd = new ActionCommand<object>();
            cmd.CanExecuteChanged += (sender, args) => canExecuteHandled = true;
            cmd.RaiseCanExecuteChanged();

            Assert.IsTrue(canExecuteHandled);
        }
示例#23
0
 private void SetDefaults()
 {
     LoginCommand = new ActionCommand { Command = () => Login() };
     PurchaseCommand = new ActionCommand { Command = () => Purchase() };
     LogoutCommand = new ActionCommand { Command = () => Logout() };
     CurrentUser = "******";
     LoginWindowVisible = Visibility.Visible;
     LogoutButtonVisible = Visibility.Collapsed;
     PurchaseVisible = Visibility.Collapsed;
 } 
示例#24
0
 public IconViewModel()
 {
     WindowManager.Manager.ActiveWindowChanged += Manager_ActiveWindowChanged;
     Windows = new ObservableCollection<Win32Window>();
     Windows.CollectionChanged += Windows_CollectionChanged;
     MinimizeCommand = new ActionCommand(MinimizeAction);
     RestoreCommand = new ActionCommand(RestoreAction);
     CloseCommand = new ActionCommand(CloseAction);
     ExitCommand = new ActionCommand(ExitAction);
 }
示例#25
0
 private void Setup()
 {
     AddGenreCmd = new RelayCommand(x => AddGenreCmdExecute());
     AddInterpretCmd = new RelayCommand(x => AddInterpretCmdExecute());
     DeleteGenreCmd = new RelayCommand(x => DeleteGenreCmdExecute());
     DeleteInterpretCmd = new RelayCommand(x => DeleteInterpretCmdExecute());
     ClosingCmd = new ActionCommand<System.ComponentModel.CancelEventArgs>(ClosingExecute);
     EditPartCmd = new RelayCommand(x => EditPartCmdExecute());
     MySqlHelper.RefreshAll += Refresh;
     Refresh();
 }
 public DetailsViewModel(IScreen screen)
 {
     HostScreen = screen;
     shortcuts = new ReactiveList<ShortcutViewModel>();
     ShortcutsView = CreateCollectionView(shortcuts);
     OpenShortcutLocationCommand = new ActionCommand<IList>(OpenShortcutLocation, l => true);
     AddToIgnoreCommand = new ActionCommand<IList>(AddToIgnoreList, l => true);
     ShowFlyoutCommand = new ActionCommand<IList>(ShowFlyout, l => true);
     LoadShortcuts();
     MessageBus.Current.Listen<UpdateShortcutsWithSameTargetCommand>()
         .Subscribe(UpdateShortcutsWithSameTarget);
 }
 public VirtualKeyboardControl()
 {
     if (VKeys == null)
     {
         VKeys = new ObservableCollection<VKey>();
     }
     Languages = new List<Language>();
     LanguageSelectedCommand = new ActionCommand(OnLanguageChanged);
     KeyDoubleClickCommand = new ActionCommand(OnKeyDoubleClickCommand);
     KeyPressCommand = new ActionCommand(OnKeyPress);
     Load();
 }
示例#28
0
        public MainWindowViewModel(HexBoardViewModel hexBoard)
        {
            this.hexBoard = hexBoard;
            this.hexBoard.OnCellPlayed += this.HexBoardCellPlayed;

            this.clearCommand = new ActionCommand<MainWindowViewModel>(vm => vm.ClearBoard());
            this.clearCommand.Enabled = false;

            this.showDebugBoardCommand = new ShowDebugBoardCommand();

            this.computerMoveCommand = new ActionCommand<MainWindowViewModel>(vm => vm.DoComputerMove());
        }
示例#29
0
 public void Setup()
 {
     SelectedFiles = new ObservableCollection<File>();
     ImportCmd = new RelayCommand(x => ImportCmdExecute());
     OKCmd = new RelayCommand(x => OKCmdExecute());
     SelectedSelectedFileDownCmd = new RelayCommand(x => SelectedSelectedFileDownCmdExecute());
     SelectedSelectedFileUpCmd = new RelayCommand(x => SelectedSelectedFileUpCmdExecute());
     ImportFileMouseClickCmd = new ActionCommand<MouseButtonEventArgs>(ImportFileMouseClickCmdExecute);
     ClosingCmd = new ActionCommand<System.ComponentModel.CancelEventArgs>(ClosingExecute);
     MySqlHelper.RefreshAll += Refresh;
     Refresh();
 }
        public ProgressDialogViewModel(Action cancelAction,
                                       Action showDialog,
                                       Action closeDialog)
        {
            VerifyArgument.IsNotNull("cancelAction", cancelAction);
            VerifyArgument.IsNotNull("showDialog", showDialog);
            VerifyArgument.IsNotNull("closeDialog", closeDialog);

            _showDialog = showDialog;
            _closeDialog = closeDialog;
            CancelCommand = new ActionCommand(cancelAction);
        }