Beispiel #1
0
        public void LoadList(SorryCardGamePlayerItem tempPlayer, CommandContainer command)
        {
            _thisPlayer = tempPlayer;
            StackPanel thisStack = new StackPanel();

            thisStack.Orientation = Orientation.Horizontal;
            _clickCommand         = tempPlayer.GetPlainCommand(command, nameof(SorryCardGamePlayerItem.SorryPlayerAsync)); //not just player anymore.
            _thisList             = new CustomBasicList <CardGraphicsWPF>();
            for (int x = 1; x <= 4; x++)
            {
                var thisCard = new CardGraphicsWPF();
                _thisList.Add(thisCard);
                thisCard.SendSize("", new SorryCardGameCardInformation());
                thisCard.DataContext = null;
                thisStack.Children.Add(thisCard);
            }
            Text        = _thisPlayer.NickName;
            DataContext = _thisPlayer;
            var thisRect = ThisFrame.GetControlArea();

            thisStack.Margin = new Thickness(thisRect.Left + 3, thisRect.Top + 10, 3, 3);
            var thisGrid = new Grid();

            thisGrid.Children.Add(ThisDraw);
            thisGrid.Children.Add(thisStack);
            Content = thisGrid;
            _clickCommand !.CanExecuteChanged += ClickCommandChange;
            MouseUp += BoardWPF_MouseUp;
            _thisPlayer.PropertyChanged += ThisPlayerPropertyChange;
            RefreshList();
        }
        Entry CreateEntry(int?maxLength = 2,
                          bool shouldDismissKeyboardAutomatically = false,
                          ICommand?command = null,
                          EventHandler <MaxLengthReachedEventArgs>?eventHandler = null)
        {
            var behavior = new MaxLengthReachedBehavior
            {
                ShouldDismissKeyboardAutomatically = shouldDismissKeyboardAutomatically,
                Command = command
            };

            if (eventHandler != null)
            {
                behavior.MaxLengthReached += eventHandler;
            }

            var entry = new Entry
            {
                MaxLength = maxLength ?? int.MaxValue,
                Behaviors =
                {
                    behavior
                }
            };

            // We simulate Focus/Unfocus behavior ourselves
            // because unit tests doesn't have "platform-specific" part
            // where IsFocused is controlled in the real app
            entry.FocusChangeRequested += (s, e) => entry.SetValue(VisualElement.IsFocusedPropertyKey, e.Focus);

            return(entry);
        }
Beispiel #3
0
        public void LoadList(SorryCardGamePlayerItem tempPlayer, CommandContainer command)
        {
            _thisPlayer = tempPlayer;
            StackLayout thisStack = new StackLayout();

            thisStack.Orientation      = StackOrientation.Horizontal;
            _clickCommand              = tempPlayer.GetPlainCommand(command, nameof(SorryCardGamePlayerItem.SorryPlayerAsync)); //not just player anymore.
            thisStack.InputTransparent = true;
            _thisList = new CustomBasicList <CardGraphicsXF>();
            for (int x = 1; x <= 4; x++)
            {
                var thisCard = new CardGraphicsXF();
                _thisList.Add(thisCard);
                thisCard.SendSize("", new SorryCardGameCardInformation());
                thisCard.BindingContext   = null;
                thisCard.InputTransparent = true;
                thisStack.Children.Add(thisCard);
            }
            Text           = _thisPlayer.NickName;
            BindingContext = _thisPlayer;
            var thisRect = ThisFrame.GetControlArea();

            thisStack.Margin = new Thickness(thisRect.Left + 3, thisRect.Top + 10, 3, 3);
            var thisGrid = new Grid();

            ThisDraw.EnableTouchEvents = true;
            ThisDraw.Touch            += ThisDraw_Touch;
            thisGrid.Children.Add(ThisDraw);
            thisGrid.Children.Add(thisStack);
            Content = thisGrid;
            _clickCommand !.CanExecuteChanged += ClickCommandChange;
            _thisPlayer.PropertyChanged       += ThisPlayerPropertyChange;
            RefreshList();
        }
Beispiel #4
0
    /// <summary>
    /// Makes this Builder a TestCommand-Builder.
    /// </summary>
    /// <returns><see cref="TestCommandBuilder"/>.</returns>
    public TestCommandBuilder InTestMode()
    {
        var command = new TestCommand();

        Command = command;
        return(new TestCommandBuilder(ref command));
    }
Beispiel #5
0
    /// <summary>
    /// Makes this Builder an UpdateCommand-Builder.
    /// </summary>
    /// <returns><see cref="UpdateCommandBuilder"/>.</returns>
    public UpdateCommandBuilder InUpdateMode()
    {
        var command = new UpdateCommand();

        Command = command;
        return(new UpdateCommandBuilder(ref command));
    }
Beispiel #6
0
    /// <summary>
    /// Makes this Builder an InformationCommand-Builder.
    /// </summary>
    /// <returns><see cref="InformationCommandBuilder"/>.</returns>
    public InformationCommandBuilder InInformationMode()
    {
        var command = new InformationCommand();

        Command = command;
        return(new InformationCommandBuilder(ref command));
    }
Beispiel #7
0
    /// <summary>
    /// Makes this Builder an ExtractCommand-Builder.
    /// </summary>
    /// <returns><see cref="ExtractCommandBuilder"/>.</returns>
    public ExtractCommandBuilder InExtractMode()
    {
        var command = new ExtractCommand();

        Command = command;
        return(new ExtractCommandBuilder(ref command));
    }
Beispiel #8
0
    /// <summary>
    /// Makes this Builder a DeleteCommand-Builder.
    /// </summary>
    /// <returns><see cref="DeleteCommandBuilder"/>.</returns>
    public DeleteCommandBuilder InDeleteMode()
    {
        var command = new DeleteCommand();

        Command = command;
        return(new DeleteCommandBuilder(ref command));
    }
Beispiel #9
0
    /// <summary>
    /// Makes this Builder an AddCommand-Builder.
    /// </summary>
    /// <returns><see cref="AddCommandBuilder"/>.</returns>
    public AddCommandBuilder InAddMode()
    {
        var command = new AddCommand();

        Command = command;
        return(new AddCommandBuilder(ref command));
    }
Beispiel #10
0
    /// <summary>
    /// Makes this Builder a RenameCommand-Builder.
    /// </summary>
    /// <returns><see cref="RenameCommandBuilder"/>.</returns>
    public RenameCommandBuilder InRenameMode()
    {
        var command = new RenameCommand();

        Command = command;
        return(new RenameCommandBuilder(ref command));
    }
Beispiel #11
0
    /// <summary>
    /// Makes this Builder a BenchmarkCommand-Builder.
    /// </summary>
    /// <returns><see cref="BenchmarkCommandBuilder"/>.</returns>
    public BenchmarkCommandBuilder InBenchmarkMode()
    {
        var command = new BenchmarkCommand();

        Command = command;
        return(new BenchmarkCommandBuilder(ref command));
    }
        /// <inheritdoc/>
        public IDisposable?BindCommandToObject(ICommand?command, object?target, IObservable <object?> commandParameter)
        {
            if (target is null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            var type       = target.GetType();
            var cmdPi      = type.GetRuntimeProperty("Command");
            var cmdParamPi = type.GetRuntimeProperty("CommandParameter");
            var ret        = new CompositeDisposable();

            var originalCmd      = cmdPi?.GetValue(target, null);
            var originalCmdParam = cmdParamPi?.GetValue(target, null);

            ret.Add(Disposable.Create(() =>
            {
                cmdPi?.SetValue(target, originalCmd, null);
                cmdParamPi?.SetValue(target, originalCmdParam, null);
            }));

            ret.Add(commandParameter.Subscribe(x => cmdParamPi?.SetValue(target, x, null)));
            cmdPi?.SetValue(target, command, null);

            return(ret);
        }
Beispiel #13
0
    /// <summary>
    /// Makes this Builder a HashCommand-Builder.
    /// </summary>
    /// <returns><see cref="HashCommandBuilder"/>.</returns>
    public HashCommandBuilder InHashMode()
    {
        var command = new HashCommand();

        Command = command;
        return(new HashCommandBuilder(ref command));
    }
Beispiel #14
0
        public Entry CreateEntryWithBehavior(int timeThreshold   = defaultTimeThreshold,
                                             int lengthThreshold = defaultLengthThreshold,
                                             bool shouldDismissKeyboardAutomatically = false,
                                             ICommand?command        = null,
                                             object?commandParameter = null)
        {
            var entry = new Entry
            {
                Behaviors =
                {
                    new UserStoppedTypingBehavior
                    {
                        StoppedTypingTimeThreshold         = timeThreshold,
                        MinimumLengthThreshold             = lengthThreshold,
                        ShouldDismissKeyboardAutomatically = shouldDismissKeyboardAutomatically,
                        Command          = command,
                        CommandParameter = commandParameter
                    }
                }
            };

            // We simulate Focus/Unfocus behavior ourselves
            // because unit tests doesn't have "platform-specific" part
            // where IsFocused is controlled in the real app
            entry.FocusChangeRequested += (s, e) => entry.SetValue(VisualElement.IsFocusedPropertyKey, e.Focus);

            return(entry);
        }
Beispiel #15
0
 /// <summary>
 /// Default constructor for an action
 /// </summary>
 /// <param name="header">The item header</param>
 /// <param name="iconKind">The item icon kind</param>
 /// <param name="command">The item command</param>
 /// <param name="minUserLevel">The minimum user level for the action</param>
 public ActionItemViewModel(string?header, GenericIconKind iconKind, ICommand?command, UserLevel minUserLevel = UserLevel.Normal)
 {
     Header       = header;
     IconKind     = iconKind;
     Command      = command;
     MinUserLevel = minUserLevel;
 }
Beispiel #16
0
 /// <summary>
 ///     Sends a BapsNet message containing one command and no arguments through this controller's queue.
 /// </summary>
 /// <param name="command">The command to send (as a no-argument message).</param>
 protected void Send(ICommand?command)
 {
     if (command != null)
     {
         Send(new MessageBuilder(command));
     }
 }
        private async Task <ICommand?> TryExecuteCommandAsync(ICommand?lastCommand, CancellationToken cancellationToken)
        {
            ICommand?commandWithError = null;
            ICommand?newLastCommand   = null;

            var errorOccured = false;

            var command = _commandPool.Pop();

            try
            {
                if (command != null)
                {
                    await SetHasPendingCommandsAsync(true, cancellationToken).ConfigureAwait(false);

                    try
                    {
                        command.Execute();
                    }
                    catch (InvalidOperationException)
                    {
                        commandWithError = command;
                        throw;
                    }

                    await HandleRepeatableAsync(command, cancellationToken).ConfigureAwait(false);

                    newLastCommand = command;
                }
                else
                {
                    await SetHasPendingCommandsAsync(false, cancellationToken).ConfigureAwait(false);

                    if (lastCommand != null)
                    {
                        CommandProcessed?.Invoke(this, EventArgs.Empty);
                        newLastCommand = null;
                    }
                }
            }
            catch (InvalidOperationException exception)
            {
                errorOccured = true;
                DoErrorOccured(commandWithError, exception);

                newLastCommand = null;
            }
            finally
            {
                if (errorOccured)
                {
                    await SetHasPendingCommandsAsync(false, cancellationToken).ConfigureAwait(false);

                    CommandProcessed?.Invoke(this, EventArgs.Empty);
                    newLastCommand = null;
                }
            }

            return(newLastCommand);
        }
        private async Task HandleRepeatableAsync(ICommand?command, CancellationToken cancellationToken)
        {
            if (command is IRepeatableCommand repeatableCommand)
            {
                // It is necesary because CanRepeate and CanExecute can perform early that globe updates its state.
                await WaitGlobeIterationPerformedAsync().ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();

                if (_commandLoopContext.HasNextIteration && repeatableCommand.CanRepeat() &&
                    repeatableCommand.CanExecute().IsSuccess)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    repeatableCommand.IncreaceIteration();
                    _commandPool.Push(repeatableCommand);
                    CommandAutoExecuted?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    await SetHasPendingCommandsAsync(false, cancellationToken).ConfigureAwait(false);

                    CommandProcessed?.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                await SetHasPendingCommandsAsync(false, cancellationToken).ConfigureAwait(false);

                CommandProcessed?.Invoke(this, EventArgs.Empty);
            }
        }
Beispiel #19
0
        private static void Control_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Control  control = (Control)sender;
            ICommand?command = MouseDoubleClick.GetCommand(control);

            command?.TryExecute(MouseDoubleClick.GetCommandParameter(control), MouseDoubleClick.GetCommandTarget(control) ?? control);
        }
Beispiel #20
0
        private async Task DisplayActionSheetAndExecuteAsync()
        {
            if (Options.IsNullOrEmpty())
            {
                return;
            }

            IList <string> optionTexts = Options.Select(o => o.Text).ToList();

            string optionText = await Application.Current.MainPage.DisplayActionSheet(
                ActionSheetTitle,
                ActionSheetCancel,
                null,
                optionTexts.ToArray()).ConfigureAwait(false);

            int index = optionTexts.IndexOf(optionText);

            if (index >= 0 && index <= optionTexts.Count)
            {
                ActionSheetCellOptionItem optionoItem = Options[index];

                SelectedOptionTag  = optionoItem.Tag;
                SelectedOptionText = optionoItem.Text;

                ICommand?command = optionoItem.Command;

                if (command != null && command.CanExecute(optionoItem.CommandParameter))
                {
                    command.Execute(optionoItem.CommandParameter);
                }
            }
        }
 public FindAnywhereResult(ImageUri icon, string title, string description, ISolutionItem?solutionItem = null, ICommand?command = null)
 {
     Icon          = icon;
     Title         = title;
     Description   = description;
     SolutionItem  = solutionItem;
     CustomCommand = command;
 }
Beispiel #22
0
        private bool ShouldDisplayArgumentHelp(ICommand?command)
        {
            if (command is null)
            {
                return(false);
            }

            return(command.Arguments.Any(ShouldShowHelp));
        }
Beispiel #23
0
 private void UpdateCommand(ICommand?newCommand)
 {
     if (newCommand == null)
     {
         return;
     }
     newCommand.CanExecuteChanged += (_, _) => Update();
     Update();
 }
Beispiel #24
0
    /// <summary>
    /// Default constructor for an action
    /// </summary>
    /// <param name="header">The item header</param>
    /// <param name="iconSource">The icon source</param>
    /// <param name="command">The item command</param>
    /// <param name="minUserLevel">The minimum user level for the action</param>
    public ActionItemViewModel(string?header, ImageSource?iconSource, ICommand?command, UserLevel minUserLevel = UserLevel.Normal)
    {
        iconSource?.Freeze();

        Header       = header;
        IconSource   = iconSource;
        Command      = command;
        MinUserLevel = minUserLevel;
    }
 public DatabaseCellViewModel(DatabaseRowViewModel parent,
                              DatabaseEntity parentEntity,
                              ICommand command,
                              string actionLabel) : base(parentEntity)
 {
     Parent        = parent;
     ActionCommand = command;
     ActionLabel   = actionLabel;
     inConstructor = false;
 }
 private void DoErrorOccured(ICommand?commandWithError, InvalidOperationException exception)
 {
     if (commandWithError != null)
     {
         ErrorOccured?.Invoke(this, new CommandErrorOccuredEventArgs(commandWithError, exception));
     }
     else
     {
         ErrorOccured?.Invoke(this, new ErrorOccuredEventArgs(exception));
     }
 }
Beispiel #27
0
 private void CommandChange(ICommand?oldValue, ICommand?newValue)
 {
     if (oldValue != null)
     {
         oldValue.CanExecuteChanged -= Update;
     }
     if (newValue != null)
     {
         newValue.CanExecuteChanged += Update;
         Update(null, null);
     }
 }
        /// <inheritdoc/>
        public IDisposable?BindCommandToObject <TEventArgs>(ICommand?command, object?target, IObservable <object?> commandParameter, string eventName)
#if MONO
            where TEventArgs : EventArgs
#endif
        {
            // NB: We should fall back to the generic Event-based handler if
            // an event target is specified
#pragma warning disable IDE0022 // Use expression body for methods
            return(null);

#pragma warning restore IDE0022 // Use expression body for methods
        }
Beispiel #29
0
            public void Push(ICommand command)
            {
                _semaphore.Wait();

                try
                {
                    _storedCommand = command;
                }
                finally
                {
                    _semaphore.Release();
                }
            }
Beispiel #30
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _Picker?.Dispose();
                _Picker = null;
                _Dialog?.Dispose();
                _Dialog  = null;
                _Command = null;
            }

            base.Dispose(disposing);
        }