public ListViewModel(KeyEntry key, TimeSpan?ttl) : base(key, ttl) { SetupAsync(); AddCommand = new ParameterCommand(Add); DeleteCommand = new ParameterCommand(Delete); SaveCommand = new Command(async() => await Save()); }
public AboutViewModel() { CloseCommand = new ParameterCommand <ICloseable>(OnClick); NavigateToWebsiteCommand = new ParameterCommand <RequestNavigateEventArgs>(NavigateToWebsite); WindowHeight = SystemParameters.PrimaryScreenHeight * 0.5; WindowWidth = SystemParameters.PrimaryScreenWidth * 0.5; }
public void ExecuteShouldExecuteAction() { this.command = new ParameterCommand(this.TestAction); this.command.Execute(new object()); Assert.IsTrue(this.actionHasBeenExecuted); }
public void CanExecuteShouldReturnTrueWhenInjectedPredicateIsNull() { this.command = new ParameterCommand(this.TestAction); bool result = this.command.CanExecute(new object()); Assert.IsTrue(result); }
public SiteViewModel() { var siteFactory = new SiteFactory(); sites = siteFactory.GetSites().ToList(); ParameterCommand = new ParameterCommand(this); MenuVisability = true; BrowserVisability = false; }
public CalculatorViewModel() { _enterDigit = new ParameterCommand <char>(Convert.ToChar, EnterDigit, _ => true); _enterOperator = new ParameterCommand <Operator>(_ => (Operator)Enum.Parse(typeof(Operator), _.ToString()), EnterOperator, IsOperatorAvailable); _enterControl = new ParameterCommand <Control>(_ => (Control)Enum.Parse(typeof(Control), _.ToString()), EnterControl, IsControlAvailable); _displayValue = "0"; }
public void CanExecuteShouldEvaluatePredicate(bool parameter) { bool Predicate(object b) => (bool)b; this.command = new ParameterCommand(this.TestAction, Predicate); bool result = this.command.CanExecute(parameter); Assert.AreEqual(parameter, result); }
public ScreenViewModel(int left, int top, int width, int height) { _windowLeft = left; _windowTop = top; _windowWidth = width; _windowHeight = height; MouseMoveCommand = new ParameterCommand <MouseEventArgs>(OnMouseMove); MouseDownCommand = new ParameterCommand <MouseEventArgs>(OnMouseDown); MouseUpCommand = new ParameterCommand <MouseEventArgs>(OnMouseUp); _isCapturing = false; _clipArea = new Rect(); WindowArea = new Rect(_windowLeft, _windowTop, _windowWidth, _windowHeight); }
public MainViewModel() { _machineContext = new MachineContext(); ClickCommand = new ParameterCommand <string>(OnClick); SelectItemCommand = new ParameterCommand <string>(OnItemSelected); MenuCommand = new ParameterCommand <string>(OnMenuItemSelected); OnDropCommand = new ParameterCommand <DragEventArgs>(OnDrop); _imageService = new ImageService(); _OCRService = new OCRService(); _windowsManager = new WindowsManager(); WindowHeight = SystemParameters.PrimaryScreenHeight * 0.6; WindowWidth = SystemParameters.PrimaryScreenWidth * 0.6; SelectedOCRLanguage = "eng"; WindowVisibility = Visibility.Visible; OCRResult = new List <string>(); }
/// <summary> /// MenuViewModel constructor /// </summary> /// <param name="onlineViewModel">Parent viewmodel</param> /// <param name="user">User information</param> public MenuViewModel(OnlineViewModel onlineViewModel, User user, Connection connection) { User = user; Connection = connection; Connection.UpdateMenuButtons = UpdateButtons; OnlineViewModel = onlineViewModel; ChatHistoryList = new ObservableCollection <ChatData>(); FilteredHistoryList = new ObservableCollection <ChatData>(); Task.Run(() => LoadHistory()); // Create new command objects SendRequestCommand = new DelegateCommand(SendRequest, IsDisconnected); ExitButtonCommand = new DelegateCommand(HandleExit); AcceptButtonCommand = new DelegateCommand(AcceptRequest); DeclineButtonCommand = new DelegateCommand(DeclineRequest); ViewChatCommand = new ParameterCommand(ViewChatFromHistory, IsDisconnected); }
public MainWindowViewModel() { NavCommand = new ParameterCommand <string>(SwitchView); CurrentViewModel = _tourListViewModel; // Fix error if login disabled int user_id = (int)Application.Current.Resources["user_id"]; // int user_id = 3; var visitor = LoginService.GetUserByID(user_id); CurrentVisitor = new Visitor { VisitorID = visitor.VisitorModelID, Name = visitor.Name, Age = visitor.Age, Gender = visitor.Gender, Email = visitor.Email, }; }
public CardGameViewModel() { NextCards = new DefaultCommand(OnNextCards); New = new DefaultCommand(OnNew); Close = new DefaultCommand(OnClose); MarkAsOk = new DefaultCommand(() => OnMarkAs(true), IsRecallMode); MarkAsFailed = new DefaultCommand(() => OnMarkAs(false), IsRecallMode); MarkFlip = new DefaultCommand(OnMarkFlip); SelectDeck = new ParameterCommand(OnSelectDeck); Restart = new DefaultCommand(OnRestart); StoreResult = new DefaultCommand(OnStoreResult, IsRecallMode); // Init the decks var facade = FacadeFactory.Create(); var settings = facade.Get <GameSetting>(Bootstrap.Settings) as GameSetting; AvailableDecks = new ObservableCollection <DeckConfiguration>(settings.AvailableDecks); CurrentDeck = AvailableDecks.First(); // Start the game OnNew(); }
public virtual async Task <ActuatorCommandProcessResult> Act(ParameterCommand command) { var commandImpacts = ActuatorDeviceInfo .Impacts .Where(x => x.IsLessOrSameFromSameDirection(command.CommandImpact)) .ToArray(); if (!commandImpacts.Any()) { throw new InvalidOperationException($"Can't process command with impact {command.CommandImpact}"); } var selectedImpact = commandImpacts.MinBy(x => Math.Abs(Math.Abs((int)x) - Math.Abs((int)command.CommandImpact))); var commandToExecute = new RpcCommandRequest() { CommandId = Guid.NewGuid(), Impact = selectedImpact, Parameter = command.Parameter, DeviceId = ActuatorDeviceInfo.Id }; var requestResult = await _rpcMqttClient.ProcessRpcRequest <RpcCommandResponse, RpcCommandRequest>( "command/response", "command/request", commandToExecute).ConfigureAwait(false); return(new ActuatorCommandProcessResult() { Error = requestResult.FailedMessage, Failed = requestResult.IsFailed, ExecutedCommand = new ParameterCommand() { CommandImpact = commandToExecute.Impact, Parameter = command.Parameter } }); }
public AppController(MainWindow MainAppWindow) { _instance = this; Log.AllCallback = AddLogMessage; Data = new MainAppData(); Data.SaveKeywordsCommand = new ActionCommand(SaveKeywords); Data.SaveKeywordsAsCommand = new ActionCommand(SaveKeywordsAs); ProjectControllers = new Dictionary <string, IProjectController>(); OpenGitWebsiteCommand = new ActionCommand(() => { Helpers.Web.OpenUri("https://git-scm.com/downloads"); }); SetSetupFoldersToMyDocumentsCommand = new ActionCommand(SwitchSettingsFoldersToMyDocuments); SetSetupFoldersToRelativeCommand = new ActionCommand(MakeSettingsFolderPortable); OpenProjectReadmeInMarkdownConverterCommand = new ParameterCommand(OpenProjectReadmeInMarkdownConverter); mainWindow = MainAppWindow; Data.Portable = File.Exists(DefaultPaths.PortableSettingsFile); if (Data.Portable) { DefaultPaths.RootFolder = DefaultPaths.DefaultPortableRootFolder; } else { var myDocumentsRoot = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (Directory.Exists(myDocumentsRoot)) { DefaultPaths.RootFolder = Path.Combine(myDocumentsRoot, DefaultPaths.DefaultMyDocumentsRootFolder); } } InitDefaultMenus(); }
private async Task <ParameterCommandProcessResult> ProcessParameterCommand(ParameterCommand parameterCommand) { var actuators = _deviceRepository.GetActuatorsByParameter(parameterCommand.Parameter); var constantImpactActuators = actuators.Where(x => x.ActuatorDeviceInfo.IsConstantImpact).ToArray(); var constantCommandResults = constantImpactActuators.Select(ActuatorCommandProcessResult.CreateForConstantActuator); if (parameterCommand.CommandImpact == CommandImpact.NoChange) { if (constantImpactActuators.Length > 0) { return(CombineProcessingResult(constantCommandResults.ToArray())); } return(new ParameterCommandProcessResult { Impacts = new [] { CommandImpact.NoChange } }); } var selectedActuators = actuators.Where(x => IsActuatorApplicable(x, parameterCommand.CommandImpact)); var actuatorsTasks = selectedActuators.Select(x => x.Act(parameterCommand)); var results = await Task.WhenAll(actuatorsTasks.ToArray()).ConfigureAwait(false); return(CombineProcessingResult(results.Concat(constantCommandResults).ToArray())); }
public LoginViewModel(IQueryService service) { _service = service; Login = new ParameterCommand<PasswordBox>(execute: ExecuteLogin, canExecute: IsLoginInformationComplete); }
public SettingsEntryData() { OnOpened = new ParameterCommand(OnFileOpened); }
internal override void BuildAction(string action) { base.BuildAction(action); this.parameterCommand = new ParameterCommand(this.CommandArguments, this.SessionService.Object, this.FilterService.Object); }
public void Throws_InvalidOperationException_On_Wrong_ArgumentType() { var command = new ParameterCommand<int>((i) => { }); ExtendedAssert.Throws<InvalidOperationException>(() => command.Execute("fdsa")); }
public void Returns_False_When_Func_Returns_False() { var command = new ParameterCommand<string>((string s) => { }, (string s) => { return false; }); Assert.IsFalse(command.CanExecute(null)); }
public ViewModelBase() { this.ParameterCommand = new ParameterCommand(this); }
public LoginWindowViewModel() { LoginCommand = new ParameterCommand <object>(Login, canLogin); }
public void Returns_True_When_No_Func_Is_Specified() { var command = new ParameterCommand<string>((string s) => { }); Assert.IsTrue(command.CanExecute(null)); }
public MainWindowViewModel() { SetModeCommand = new ParameterCommand(SetMode); }
public ViewModelBase() { SimpleCommand = new SimpleCommand(this); ParameterCommand = new ParameterCommand(this); }
public void Throws_InvalidOperationException_When_Wrong_Type_Is_Passed_In() { var command = new ParameterCommand<string>((string s) => { }, (string s) => { return false; }); ExtendedAssert.Throws<InvalidOperationException>(() => command.CanExecute(12)); }
public void Executes_Passed_In_Action() { bool wasCalled = false; var command = new ParameterCommand<int>((i) => { wasCalled = true; }); command.Execute(12); Assert.IsTrue(wasCalled); }