private static NumberEntryMode GetMatchingEntryModeForModifier(RemoteKeyModifier modifier)
 {
     switch (modifier)
     {
         case RemoteKeyModifier.EnterNextCompetitor:
             return NumberEntryMode.EnteringNextCompetitor;
         case RemoteKeyModifier.EnterCurrentCompetitor:
             return NumberEntryMode.EnteringCurrentCompetitor;
         default:
             throw ExceptionFactory.CreateNotSupportedExceptionFor(modifier);
     }
 }
Example #2
0
        public static void ShouldBeModifierKeyUpFor(this EventArgsWithName <RemoteKeyTracker> eventArgsWithName, WirelessNetworkAddress source,
                                                    RemoteKeyModifier modifier)
        {
            Guard.NotNull(eventArgsWithName, nameof(eventArgsWithName));
            Guard.NotNull(source, nameof(source));

            eventArgsWithName.Name.Should().Be("ModifierKeyUp");
            eventArgsWithName.EventArgs.Should().BeOfType <RemoteKeyModifierEventArgs>();

            var remoteKeyModifierEventArgs = (RemoteKeyModifierEventArgs)eventArgsWithName.EventArgs;

            remoteKeyModifierEventArgs.Source.Should().Be(source);
            remoteKeyModifierEventArgs.Modifier.Should().Be(modifier);
        }
        public static void ShouldBeModifierKeyUpFor(
            [NotNull] this EventArgsWithName<RemoteKeyTracker> eventArgsWithName,
            [NotNull] WirelessNetworkAddress source, RemoteKeyModifier modifier)
        {
            Guard.NotNull(eventArgsWithName, nameof(eventArgsWithName));
            Guard.NotNull(source, nameof(source));

            eventArgsWithName.Name.Should().Be("ModifierKeyUp");
            eventArgsWithName.EventArgs.Should().BeOfType<RemoteKeyModifierEventArgs>();

            var remoteKeyModifierEventArgs = (RemoteKeyModifierEventArgs) eventArgsWithName.EventArgs;
            remoteKeyModifierEventArgs.Source.Should().Be(source);
            remoteKeyModifierEventArgs.Modifier.Should().Be(modifier);
        }
        public void HandleModifierKeyDown([NotNull] WirelessNetworkAddress source, RemoteKeyModifier modifier)
        {
            Guard.NotNull(source, nameof(source));

            modifierStatePerDevice.EnsureDown(source, modifier);

            if (numberEntryState.Mode == NumberEntryMode.None)
            {
                NumberEntryMode newEntryMode = GetMatchingEntryModeForModifier(modifier);
                numberEntryState.ChangeMode(newEntryMode);

                bool isCurrentCompetitor = modifier == RemoteKeyModifier.EnterCurrentCompetitor;
                var args = new CompetitorSelectionEventArgs(isCurrentCompetitor);
                NotifyCompetitorSelecting?.Invoke(this, args);
            }
        }
Example #5
0
 public RemoteKeyModifierEventArgs(WirelessNetworkAddress source, RemoteKeyModifier modifier, TimeSpan?sensorTime)
     : base(source, sensorTime)
 {
     Modifier = modifier;
 }
 public RemoteKeyModifierEventArgs([NotNull] WirelessNetworkAddress source, RemoteKeyModifier modifier,
     [CanBeNull] TimeSpan? sensorTime)
     : base(source, sensorTime)
 {
     Modifier = modifier;
 }
            public void EnsureNotDown([NotNull] WirelessNetworkAddress deviceAddress, RemoteKeyModifier modifier)
            {
                if (statePerDevice.ContainsKey(deviceAddress))
                {
                    ModifiersDownForDevice deviceState = statePerDevice[deviceAddress];

                    switch (modifier)
                    {
                        case RemoteKeyModifier.EnterNextCompetitor:
                            deviceState = deviceState.WithoutEnterNextCompetitor();
                            break;
                        case RemoteKeyModifier.EnterCurrentCompetitor:
                            deviceState = deviceState.WithoutEnterCurrentCompetitor();
                            break;
                        default:
                            throw ExceptionFactory.CreateNotSupportedExceptionFor(modifier);
                    }

                    statePerDevice[deviceAddress] = deviceState;
                }
            }
 public bool IsDown([NotNull] WirelessNetworkAddress deviceAddress, RemoteKeyModifier modifier)
 {
     if (statePerDevice.ContainsKey(deviceAddress))
     {
         switch (modifier)
         {
             case RemoteKeyModifier.EnterNextCompetitor:
                 return statePerDevice[deviceAddress].ContainsEnterNextCompetitor;
             case RemoteKeyModifier.EnterCurrentCompetitor:
                 return statePerDevice[deviceAddress].ContainsEnterCurrentCompetitor;
         }
     }
     return false;
 }
        public void HandleModifierKeyUp([NotNull] WirelessNetworkAddress source, RemoteKeyModifier modifier)
        {
            Guard.NotNull(source, nameof(source));

            modifierStatePerDevice.EnsureNotDown(source, modifier);

            NumberEntryMode matchingEntryMode = GetMatchingEntryModeForModifier(modifier);

            if (numberEntryState.Mode == matchingEntryMode)
            {
                int? builtNumber = numberEntryState.Number;

                numberEntryState.ChangeMode(NumberEntryMode.None);

                bool isCurrentCompetitor = modifier == RemoteKeyModifier.EnterCurrentCompetitor;
                if (builtNumber == null || builtNumber == 0)
                {
                    var args = new CompetitorSelectionEventArgs(isCurrentCompetitor);
                    NotifyCompetitorSelectCanceled?.Invoke(this, args);
                }
                else
                {
                    var args = new CompetitorNumberSelectionEventArgs(builtNumber.Value, isCurrentCompetitor);
                    NotifyCompetitorSelected?.Invoke(this, args);
                }
            }
        }