public void Execute(ICommand command, string user) { // check user permission to execute command ICommandContext context = new CommandContext(_repository, user); command.Execute(context); }
public static IApplicationBarMenuItem InsertMenuItem(this IApplicationBar bar, int index, string text, ICommand cmd) { var menu = new ApplicationBarMenuItem { Text = text }; menu.Click += (s, e) => cmd.Execute(null); bar.MenuItems.Insert(index, menu); return menu; }
public static void DoCommand(ICommand command) { if (command.Execute()) { undoStack.Push(command); redoStack.Clear(); } }
public void Execute(ICommand command) { command.Execute(); undoStack.Push(command); redoStack.Clear(); }
public static void TryExecute(ICommand command) { if (command != null) { command.Execute(null); } }
public void PushButton() { if (_reader.CommandData != null) { if (_commands.ContainsKey(_reader.CommandData)) { _command = _commands[_reader.CommandData]; try { _command.Execute(_reader); } catch (Exception exception) { _reader.Help(this, exception.Message); } } else { _reader.Help(this, "Неправильно введена команда!"); } } else { _reader.Help(this, null); } }
public TrayWindowViewModel(TaskbarIcon taskbarIcon) { _taskbarIcon = taskbarIcon; ExitCommand = new ExitCommand(); ShowCommand = new ShowAllCommand(); HideCommand = new HideAllCommand(); AddRepoCommand = new AddRepositoryCommand(); ShowAboutCommand = new ShowSingleViewCommand(typeof(AboutView)); LeftClickCommand = new ToggleShowHideCommand(); DoubleClickCommand = LeftClickCommand; ShowSettingsCommand = new ShowSingleViewCommand(typeof(SettingsView)); #if DEBUG ShowSettingsVisiblilty = "Visible"; #else ShowSettingsVisiblilty = "Collapsed"; #endif ShowUpdateCommand = new ShowSingleViewCommand(typeof(UpdateView)); CheckUpdateCommand = ShowUpdateCommand; HotkeyHelper.OnHotkeyChanged += (sender, args) => OnPropertyChanged("ShowHideHeader"); // todo: currently the only balloon is for update, so no distinction about what to do. _taskbarIcon.TrayBalloonTipClicked += (sender, args) => ShowUpdateCommand.Execute(null); UpdateManager.OnUpdateRequired += UpdateManager_OnUpdateRequired; UpdateManager.OnUpdateInfoChanged += delegate(object sender, EventArgs args) { OnPropertyChanged("CheckUpdateHeader"); OnPropertyChanged("ToolTipText"); }; }
public void Include (ICommand command) { command.CanExecuteChanged += (s, e) => { if (command.CanExecute (null)) command.Execute (null); }; }
public Notification Handle(ICommand command, ExecutionArguments executionArguments) { var prerequisiteResult = _prerequisiteChecker.Check(command, executionArguments); if (prerequisiteResult.HasErrors) { return prerequisiteResult; } var commandResult = command.Execute(executionArguments); if (commandResult.HasErrors) { return commandResult; } if (command.ChangesTheStatement()) { var commandHistory = new CommandHistory { Command = command.GetType().Name, Args = executionArguments.Args, Date = _systemService.CurrentDateTime }; Statement statement = executionArguments.Statement; statement.CommandHistory.Add(commandHistory); } return commandResult; }
public void InsertImage(BitmapImage image, Layer layer) { f_command = new InsertImageCommand(image, layer); f_undoCommands.Push(f_command); f_redoCommands.Clear(); f_command.Execute(); }
/// <summary> /// Creates a button and adds it to an application bar. /// </summary> /// <param name="appBar"></param> /// <param name="iconFilenameRelative"></param> /// <param name="command"></param> /// <param name="text"></param> /// <returns></returns> public static ApplicationBarIconButton CreateAndAddButton(this IApplicationBar appBar, string iconFilenameRelative, ICommand command, string text) { ApplicationBarIconButton btn = new ApplicationBarIconButton(new Uri("/icons/" + iconFilenameRelative, UriKind.Relative)); // First-time values. btn.IsEnabled = command.CanExecute(btn); btn.Text = text; // Adds click handler to execute the command upon click. btn.Click += (o, e) => { if (command.CanExecute(btn)) { command.Execute(btn); } }; // Adds CanExecute changed handler. command.CanExecuteChanged += (o, e) => { btn.IsEnabled = command.CanExecute(btn); }; // Adds the button. appBar.Buttons.Add(btn); return btn; }
public static IApplicationBarIconButton InsertButton(this IApplicationBar bar, int index, string imageUrl, string text, ICommand cmd) { var btn = new ApplicationBarIconButton { IconUri = new Uri(imageUrl, UriKind.Relative), Text = text }; btn.Click += (s, e) => cmd.Execute(null); bar.Buttons.Insert(index, btn); return btn; }
protected bool DoesNewPageCommandExecute(ICommand command, PageName expected) { var passedNewPage = PageName.Navigation; Commands.NewPageCommand = new RelayCommand<PageName>(p => passedNewPage = p); command.Execute(null); return passedNewPage.Equals(expected); }
public void Delete(UIElement element, Layer layer) { f_command = new DeleteCommand(element, layer); f_undoCommands.Push(f_command); f_redoCommands.Clear(); f_command.Execute(); }
public void InsertGeFile(string filename, GraphicContent graphicContent) { f_command = new InsertGeFileCommand(filename, graphicContent); f_undoCommands.Push(f_command); f_redoCommands.Clear(); f_command.Execute(); }
/// <summary> /// The main execution method to decouple actions. Track /// commands in this method if you need to Undo or Redo actions. /// </summary> public void Execute(ICommand command) { command.Execute(); UndoneCommands.Clear(); RedoneCommands.Clear(); Commands.Push(command); }
/// <summary> /// Creates a menu item and adds it to an application bar. /// </summary> /// <param name="appBar"></param> /// <param name="command"></param> /// <param name="text"></param> /// <returns></returns> public static ApplicationBarMenuItem CreateAndAddMenuItem(this IApplicationBar appBar, ICommand command, string text) { ApplicationBarMenuItem mi = new ApplicationBarMenuItem(text); // First-time values. mi.IsEnabled = command.CanExecute(mi); // Adds click handler to execute the command upon click. mi.Click += (o, e) => { if (command.CanExecute(mi)) { command.Execute(mi); } }; // Adds CanExecute changed handler. command.CanExecuteChanged += (o, e) => { mi.IsEnabled = command.CanExecute(mi); }; // Adds the button. appBar.MenuItems.Add(mi); return mi; }
public ICommand ExecuteCommand(ICommand command) { Stack<ICommand> commandStack = GetCommandStack(); command.Execute(); SubscriptionService.SubscriptionService.NotifyAll(command.ToString()); commandStack.Push(command); return command; }
public static void Execute(ICommand command, object parameter, IInputElement target) { var routedCmd = command as RoutedCommand; if (routedCmd != null && routedCmd.CanExecute(parameter, target)) routedCmd.Execute(parameter, target); else if (command != null && command.CanExecute(parameter)) command.Execute(parameter); }
private void ExecuteCommand(ICommand command) { var commandArgs = args.Skip(1).ToArray(); var context = new CommandContext(config, commandArgs); command.Execute(context); WriteContentToFileExecutedByLauncherBatchFile(context.GetContentForFileExecutedByLauncherBatchFile()); }
public static void ExecuteLater(ICommand command) { Thread worker = new Thread(() => { command.Execute(); }); worker.Start(); }
public static void SetReturnCommand(this UITextField textView, ICommand command) { textView.ShouldReturn += _ => { textView.ResignFirstResponder(); command.Execute(null); return true; }; }
public CommandTableViewSource(UITableView tableView, string cellIdentifier, string bindingText, ICommand command) : base(tableView, UITableViewCellStyle.Default, new NSString(cellIdentifier), bindingText, UITableViewCellAccessory.DisclosureIndicator) { SelectionChanged += (sender, e) => { command.Execute(e.AddedItems[0]); tableView.DeselectRow(tableView.IndexPathForSelectedRow, true); }; }
public static void ExecuteCommand( ICommand command, GestureArgs parameter = null) { if (command != null && command.CanExecute (parameter)) { command.Execute (parameter); } }
public void AddReminder(DateTime alarmTime, ICommand command) { TimeSpan deltaTime = alarmTime - DateTime.Now; //Timer reminderTimer = new Timer(delegate { Console.WriteLine(alarmTime); }, null, // deltaTime, new TimeSpan(-1)); Timer reminderTimer = new Timer(delegate { command.Execute(); }, null, deltaTime, new TimeSpan(-1)); }
/// <summary> /// Executes commands of type <see cref="Minesweeper.Game.ICommand"/>. /// </summary> /// <param name="cmd">The command to execute.</param> /// <returns>Returns true if more commands can be executed.</returns> public bool ExecuteCommand(ICommand cmd) { if (cmd == null) { throw new ArgumentNullException(); } return cmd.Execute(); }
public void Run() { var objBindable = new DataObject(); var myBinding = new Binding("Amount", objBindable, "Amount", true, DataSourceUpdateMode.OnPropertyChanged); var objWithBinding = new DataObjectWithBindable(); objWithBinding.PropertyChanged += (sender, args) => { Console.WriteLine(args.PropertyName); }; objWithBinding.DataBindings.Add(myBinding); objBindable.Amount = 30 + 10; objBindable.Message = "test"; objWithBinding.Amount = 55; objBindable.Amount = 54; HiButtonCommand = new RelayCommand( ShowMessage, param => { var t = (DataObject)param; return t.Amount < 10; }); HiButtonCommand.CanExecuteChanged += HiButtonCommandOnCanExecuteChanged; objBindable.Amount = 9; if (HiButtonCommand.CanExecute(objBindable)) { HiButtonCommand.Execute(objBindable); } objBindable.Amount = 11; if (HiButtonCommand.CanExecute(objBindable)) { HiButtonCommand.Execute(objBindable); } }
/// <summary> /// Attempts to executes a command command. /// </summary> /// <param name="cmd">The command to be executed.</param> /// <param name="parameter">The command parameter.</param> /// <returns>True if the command was executed; otherwise false.</returns> private static bool ExecuteCommand(ICommand cmd, object parameter) { if (cmd != null && cmd.CanExecute(parameter)) { cmd.Execute(parameter); return true; } return false; }
protected virtual void ExecuteRefreshCommand(ICommand command) { if (command == null) return; if (!command.CanExecute(null)) return; command.Execute(null); }
/// <summary> /// Executes the supplied command asynchronously. /// </summary> /// <param name="command">The command to execute.</param> public static void Excute(ICommand command) { Task.Factory .StartNew(() => { Log.Debug(string.Format("Executing '{0}'.", command.GetType())); command.Execute(); }, TaskCreationOptions.LongRunning) .ContinueWith(task => Log.Fatal(string.Format("'{0}', failed.", command.GetType()), task.Exception), TaskContinuationOptions.OnlyOnFaulted); }
public void ShowSettings() { if (openedPanel == null) { openedPanel = settings(); ICommand?origCommand = openedPanel.CloseCommand; openedPanel.CloseCommand = new DelegateCommand(() => { origCommand?.Execute(null); openedPanel = null; }); } documentManager.OpenDocument(openedPanel); }
/// <summary> /// A utility method that will pipe an Observable to an ICommand (i.e. /// it will first call its CanExecute with the provided value, then if /// the command can be executed, Execute() will be called). /// </summary> /// <typeparam name="T">The type.</typeparam> /// <param name="item">The source observable to pipe into the command.</param> /// <param name="command">The command to be executed.</param> /// <returns>An object that when disposes, disconnects the Observable /// from the command.</returns> public static IDisposable InvokeCommand <T>(this IObservable <T> item, ICommand?command) { var canExecuteChanged = Observable.FromEvent <EventHandler, Unit>( eventHandler => { void Handler(object?sender, EventArgs e) => eventHandler(Unit.Default); return(Handler); }, h => command !.CanExecuteChanged += h, h => command !.CanExecuteChanged -= h) .StartWith(Unit.Default); return(WithLatestFromFixed(item, canExecuteChanged, (value, _) => new InvokeCommandInfo <ICommand?, T>(command, command !.CanExecute(value), value)) .Where(ii => ii.CanExecute) .Do(ii => command?.Execute(ii.Value)) .Subscribe()); }
void SetUpPicker() { _picker = new UIPickerView(); var width = UIScreen.MainScreen.Bounds.Width; _titleLabel = new UILabel(); _titleLabel.TextAlignment = UITextAlignment.Center; var toolbar = new UIToolbar(new CGRect(0, 0, (float)width, 44)) { BarStyle = UIBarStyle.Default, Translucent = true }; var cancelButton = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (o, e) => { DummyField.ResignFirstResponder(); Select(_model.PreSelectedItem); }); var labelButton = new UIBarButtonItem(_titleLabel); var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace); var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) => { _model.OnUpdatePickerFormModel(); DummyField.ResignFirstResponder(); _command?.Execute(_model.SelectedItem); }); toolbar.SetItems(new[] { cancelButton, spacer, labelButton, spacer, doneButton }, false); DummyField.InputView = _picker; DummyField.InputAccessoryView = toolbar; _model = new NumberPickerSource(); _picker.Model = _model; _model.UpdatePickerFromModel += Model_UpdatePickerFromModel; }
// ドラッグ完了処理 private void Completed() { if (_isCaptured) { _inputElement.ReleaseMouseCapture(); } if (_isDrag) { _isDrag = false; if (_isMoved & _completedNodeMove != null) { // ドラッグ開始前座標 var initial = _originalPoints.ToDictionary(x => x.Key.DataContext as INodeDataContext, x => x.Value); // ドラッグ完了後座標 var completed = _selectedNodes.ToDictionary(x => x.DataContext as INodeDataContext, x => new Point(x.X, x.Y)); //! 完了コマンドを発行する(undo / redo したい場合等に利用する) _completedNodeMove?.Execute(new CompletedMoveNodeEventArgs(initial, completed)); } } }
public string Read(string args) { string[] inputTokens = args.Split(' ', StringSplitOptions.RemoveEmptyEntries); string commandType = inputTokens[0].ToLower(); string[] commandArguments = inputTokens .Skip(1) // ако подадат повече аргументи го правим масив .ToArray(); string result = string.Empty; // ICommand command = default; var type = Assembly .GetCallingAssembly() .GetTypes() .FirstOrDefault(x => x.Name.ToLower() == $"{commandType}Command" .ToLower()); ICommand instance = (ICommand)Activator.CreateInstance(type); //if (commandType == "HelloCommand") //{ // command = new HelloCommand(); //} //else if (commandType == "ExitCommand") //{ // command = new ExitCommand(); //} result = instance?.Execute(commandArguments); // ? - проверява дали е null, ако е продължава!! return(result); }
public void SetTemperature(int temp) { _temp?.Execute(temp); }
private void HandleEvent(object sender, EventArgs args) { _currentCommand?.Execute(null); }
public override void OnVerificationFailed(FirebaseException p0) { onFailed?.Execute(p0.Message); }
internal static void AddNotification(string text, StatusType kind, string tag, ICommand command = null, object commandParameter = null) { AddNotification(text, kind, tag, () => { command?.Execute(commandParameter); }); }
void FixedUpdate() { leftPlayerCommand?.Execute(leftPlayerActor); rightPlayerCommand?.Execute(rightPlayerActor); }
private void OnToggled(object sender, EventArgs e) { _toggleCommand?.Execute(((UISwitch)sender).On); }
protected virtual void TriggerCommand(object parameter) { ICommand command = GetCommand(this); command?.Execute(parameter); }
protected override void Select() { _command?.Execute(); }
/// <summary> /// Calls command's Execute method /// </summary> public void Run() { command?.Execute(); }
protected virtual void TriggerCommand() { ICommand command = GetCommand(this); command?.Execute(GetCommandParameter(this)); }
private void HideImageMenu(object sender, EventArgs e) { _hideImageMenuCommand?.Execute(_index); }
public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { _itemClick?.Execute(GetItemByIndex(indexPath)); }
private void MButton_Clicked(object sender, EventArgs e) { Command?.Execute(null); }
public void Rollback(MarsRover rover, IPlanet planet) { _rollbackCommand?.Execute(rover, planet); }
public static AddedView AddedProduct(ProductModel product = null, ICommand sumbit = null) { var tbName = new TextBox() { Margin = new Thickness(10, 0, 10, 10) }; var lblNameE = new Label() { Content = "Необходимо заполнить Наименование товара", Foreground = Brushes.Red, Visibility = Visibility.Collapsed }; var tbDescription = new TextBox() { Margin = new Thickness(10, 0, 10, 10) }; var tbCode = new TextBox() { Margin = new Thickness(10, 0, 10, 10) }; var tbArticle = new TextBox() { Margin = new Thickness(10, 0, 10, 10) }; var tbMinCount = new TextBox() { Margin = new Thickness(10, 0, 10, 10) }; var lblMinCountE = new Label() { Content = "Должно быть числом", Foreground = Brushes.Red, Visibility = Visibility.Collapsed }; var a = new AddedView { Controls = new List <Control> { new Label() { Content = "Наименование", Margin = new Thickness(10, 0, 10, 0) }, tbName, lblNameE, new Label() { Content = "Описание", Margin = new Thickness(10, 0, 10, 0) }, tbDescription, new Label() { Content = "Код", Margin = new Thickness(10, 0, 10, 0) }, tbCode, new Label() { Content = "Артикул", Margin = new Thickness(10, 0, 10, 0) }, tbArticle, new Label() { Content = "Минимальный остаток", Margin = new Thickness(10, 0, 10, 0) }, tbMinCount } }; if (product == null) { tbMinCount.Text = "0"; } else { tbName.Text = product.ProductName; tbDescription.Text = product.Description; tbCode.Text = product.Code; tbArticle.Text = product.Article; tbMinCount.Text = product.MinCount.ToString(); } a.Submit = new SimpleCommand(() => { if (string.IsNullOrEmpty(tbName.Text.Trim())) { lblNameE.Visibility = Visibility.Visible; return; } int res; if (!int.TryParse(tbMinCount.Text.Trim(), out res)) { lblMinCountE.Visibility = Visibility.Visible; return; } Services.Products.Save(new ProductModel() { ProductName = tbName.Text, Description = tbDescription.Text, Code = tbCode.Text, Article = tbArticle.Text, MinCount = int.Parse(tbMinCount.Text), Count = 0 }); sumbit?.Execute(null); a.Close(); }); a.Init(); mainWindow.ShowAddedWindow(a); return(a); }
private void EllipseAdorner_MouseDown(object sender, MouseButtonEventArgs e) { command?.Execute(this); }
public void Draw(string command) { char ch = command.ElementAt(0); String[] cmd; try { ICoordinate coordinate = null; char cmdChoice = char.ToUpper(ch); char commandParameter = char.MinValue; switch (char.ToUpper(ch)) { case 'C': cmd = command.Split(' '); int width = int.Parse(cmd[1]); int height = int.Parse(cmd[2]); if (width < (Console.WindowWidth - 10) && height < (Console.WindowHeight - 5)) { canvas = new Canvas(width, height); commandParameter = char.ToUpper(ch); } else { Console.WriteLine("Canvas is larger than console window. Please try again!!"); } break; case 'L': cmd = command.Split(' '); coordinate = new Coordinates(int.Parse(cmd[1]), int.Parse(cmd[2]), int.Parse(cmd[3]), int.Parse(cmd[4])); commandParameter = char.ToUpper(ch); cmdChoice = 'D'; break; case 'R': cmd = command.Split(' '); coordinate = new Coordinates(int.Parse(cmd[1]), int.Parse(cmd[2]), int.Parse(cmd[3]), int.Parse(cmd[4])); commandParameter = char.ToUpper(ch); cmdChoice = 'D'; break; case 'B': cmd = command.Split(' '); coordinate = new Coordinates(int.Parse(cmd[1]), int.Parse(cmd[2]), int.MinValue, int.MinValue); commandParameter = 'C'; ColorCodes code; Enum.TryParse(cmd[3].ElementAt(0).ToString().ToUpper(), out code); ColourfulConsole.CurrentColorCode = code; break; default: Console.WriteLine("Invalid Command.."); break; } if (canvas != null) { Invoker commandInvoker = new Invoker(); ICommand canvasCommand = commandInvoker.GetCommand(cmdChoice); if (canvasCommand != null) { canvasCommand.Canvas = canvas; canvasCommand.CommandParameter = commandParameter; canvasCommand.Coordinates = coordinate; var output = canvasCommand?.Execute(); ColourfulConsole.Write(output, 'C'); } else { Console.WriteLine("\nInvalid command. Try again!!\n"); } } } catch (IndexOutOfRangeException e) { Console.WriteLine("\nEntered coordinates are not in limit of canvas. Try again with correct coordinates!!\n"); } catch (CanvasException e) { Console.WriteLine(e.Message); } catch (Exception e) { if (canvas == null) { Console.WriteLine("Canvas is not created. Please create Canvas first"); } else { Console.WriteLine("\nError Occurred : " + e.Message + "\nPlease try again"); } } }
private void TapAction() { _tapCommand?.Execute(_tapParameter); }
public void Undo() { _undoneOperation?.Execute(); }
private static void Window_Closed(object sender, EventArgs e) { ICommand closed = GetClosed(sender as Window); closed?.Execute(null); }
private void Execute() => _command?.Execute(null);
/// <summary> /// Executes command on given board. /// </summary> /// <param name="b">Board</param> /// <param name="command">Command</param> /// <returns></returns> public Board ExecuteCommand(Board b, ICommand command) { command?.Execute(b); return(b); }
void OnClick(object sender, EventArgs e) { _command?.Execute(_commandParameter ?? Element); }
public static AddedView AddedProvider(ProviderModel provider = null, ICommand sumbit = null) { var tbName = new TextBox() { Margin = new Thickness(10, 0, 10, 10) }; var lblNameE = new Label() { Content = "Необходимо заполнить Имя поставщика", Foreground = Brushes.Red, Visibility = Visibility.Collapsed }; var tbAddress = new TextBox() { Margin = new Thickness(10, 0, 10, 10) }; var tbEmail = new TextBox() { Margin = new Thickness(10, 0, 10, 10) }; var tbPhone = new TextBox() { Margin = new Thickness(10, 0, 10, 10) }; var tbNote = new TextBox() { Margin = new Thickness(10, 0, 10, 10) }; var a = new AddedView { Controls = new List <Control> { new Label() { Content = "Имя", Margin = new Thickness(10, 0, 10, 0) }, tbName, lblNameE, new Label() { Content = "Адрес", Margin = new Thickness(10, 0, 10, 0) }, tbAddress, new Label() { Content = "E-mail", Margin = new Thickness(10, 0, 10, 0) }, tbEmail, new Label() { Content = "Телефон", Margin = new Thickness(10, 0, 10, 0) }, tbPhone, new Label() { Content = "Примечание", Margin = new Thickness(10, 0, 10, 0) }, tbNote } }; if (provider != null) { tbName.Text = provider.Name; tbAddress.Text = provider.Address; tbEmail.Text = provider.Email; tbPhone.Text = provider.Phone; tbNote.Text = provider.Note; } a.Submit = new SimpleCommand(() => { if (string.IsNullOrEmpty(tbName.Text.Trim())) { lblNameE.Visibility = Visibility.Visible; return; } Services.Providers.Save(new ProviderModel() { Name = tbName.Text, Address = tbAddress.Text, Email = tbEmail.Text, Phone = tbPhone.Text, Note = tbNote.Text }); sumbit?.Execute(null); a.Close(); }); a.Init(); mainWindow.ShowAddedWindow(a); return(a); }
public void Execute(TrackingModule trackingModule) { trackingModule.Position.Orientation = RotationMappings[trackingModule.Position.Orientation]; _nextCommandInChain?.Execute(trackingModule); }