Exemplo n.º 1
0
        private static IEnumerable <Operation> GetLargestPossibleOperation()
        {
            var destinations = new[]
            {
                //new WirelessNetworkAddress("AAAAAA"),
                //new WirelessNetworkAddress("BBBBBB"),
                new WirelessNetworkAddress("CCCCCC")
            };

            var operation = new VisualizeOperation(destinations)
            {
                CurrentCompetitorNumber = 999,
                NextCompetitorNumber    = 999,
                StartTimer          = true,
                PrimaryTimerValue   = TimeSpan.FromSeconds(999).Add(TimeSpan.FromMilliseconds(987)),
                SecondaryTimerValue = TimeSpan.FromSeconds(999).Add(TimeSpan.FromMilliseconds(987)),
                FaultCount          = 99,
                RefusalCount        = 99,
                Eliminated          = true,
                PreviousPlacement   = 999
            };

            byte[] buffer = PacketWriter.Write(operation, true);
            Console.WriteLine($"*** Maximum operation length in bytes: {buffer.Length}\n");
            yield break;
        }
Exemplo n.º 2
0
 private void DispatchStartTimer(VisualizeOperation operation)
 {
     if (operation.StartTimer)
     {
         actor.StartPrimaryTimer();
     }
 }
Exemplo n.º 3
0
 private void DispatchEliminated(VisualizeOperation operation)
 {
     if (operation.Eliminated != null)
     {
         actor.SetElimination(operation.Eliminated.Value);
     }
 }
Exemplo n.º 4
0
 private void DispatchNextCompetitorNumber(VisualizeOperation operation)
 {
     if (operation.NextCompetitorNumber != null)
     {
         int?number = operation.NextCompetitorNumber == CirceHiddenCompetitorNumber ? null : operation.NextCompetitorNumber;
         actor.SetOrClearNextCompetitorNumber(number);
     }
 }
Exemplo n.º 5
0
 private void DispatchPlacement(VisualizeOperation operation)
 {
     if (operation.PreviousPlacement != null)
     {
         int?placement = operation.PreviousPlacement == CirceHiddenPlacement ? null : operation.PreviousPlacement;
         actor.SetOrClearPreviousCompetitorPlacement(placement);
     }
 }
Exemplo n.º 6
0
 private void DispatchRefusals(VisualizeOperation operation)
 {
     if (operation.RefusalCount != null)
     {
         int?count = operation.RefusalCount == CirceHiddenFaultsRefusals ? null : operation.RefusalCount;
         actor.SetOrClearRefusalCount(count);
     }
 }
Exemplo n.º 7
0
 private void DispatchSecondaryTimerValue(VisualizeOperation operation)
 {
     if (operation.SecondaryTimerValue != null)
     {
         TimeSpan?time = operation.SecondaryTimerValue == CirceHiddenTime ? null : operation.SecondaryTimerValue;
         actor.SetOrClearSecondaryTime(time);
     }
 }
Exemplo n.º 8
0
            void IOperationAcceptor.Accept(VisualizeOperation operation)
            {
                Guard.NotNull(operation, nameof(operation));

                foreach (IWirelessDevice targetDevice in GetDevicesWithAddresses(operation.DestinationAddresses))
                {
                    IWirelessDevice snapshot = targetDevice;
                    snapshot.Accept(operation);
                }
            }
Exemplo n.º 9
0
        public void Dispatch(VisualizeOperation operation)
        {
            Guard.NotNull(operation, nameof(operation));

            invokeContext.EnsureOnMainThread(() =>
            {
                // Important: Dispatch Elimination Change before handling time changes.
                DispatchEliminated(operation);
                DispatchCurrentCompetitorNumber(operation);
                DispatchNextCompetitorNumber(operation);

                // Important: Dispatch Secondary Timer Value before Primary Timer Value (can occur when competitor has previous results before start of run)
                DispatchSecondaryTimerValue(operation);

                // Important: Dispatch Primary Timer Value before Start Timer (they should never occur both, but just in case).
                DispatchPrimaryTimerValue(operation);
                DispatchStartTimer(operation);

                DispatchFaults(operation);
                DispatchRefusals(operation);
                DispatchPlacement(operation);
            });
        }
 public void Accept(VisualizeOperation operation)
 {
 }
Exemplo n.º 11
0
 void IWirelessDevice.Accept(VisualizeOperation operation)
 {
     // Not applicable for a mediator.
 }
        public void When_reading_visualize_operation_it_must_be_correct()
        {
            // Arrange
            byte[] buffer =
            {
                2,
                ByteFor('0'),
                ByteFor('7'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('2'),
                ByteFor('8'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('2'),
                ByteFor('3'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('2'),
                ByteFor('9'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('2'),
                ByteFor('5'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('0'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('1'),
                ByteFor(':'),
                ByteFor('2'),
                ByteFor('5'),
                ByteFor('9'),
                ByteFor('4'),
                ByteFor('3'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('2'),
                ByteFor(':'),
                ByteFor('5'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('3'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('0'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('4'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('5'),
                ByteFor(':'),
                ByteFor('2'),
                ByteFor('3'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('1'),
                ByteFor('4'),
                ByteFor(':'),
                ByteFor('A'),
                ByteFor('B'),
                ByteFor('C'),
                ByteFor('D'),
                ByteFor('E'),
                ByteFor('F'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('1'),
                ByteFor('4'),
                ByteFor(':'),
                ByteFor('A'),
                ByteFor('A'),
                ByteFor('B'),
                ByteFor('B'),
                ByteFor('C'),
                ByteFor('C'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('8'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('6'),
                ByteFor('1'),
                ByteFor('2'),
                ByteFor('3'),
                ByteFor('\t'),
                3
            };

            var reader = new PacketReader();

            // Act
            Operation operation = reader.Read(buffer);

            // Assert
            var expected = new VisualizeOperation(new[]
            {
                new WirelessNetworkAddress("ABCDEF"),
                new WirelessNetworkAddress("AABBCC")
            })
            {
                CurrentCompetitorNumber = 123,
                NextCompetitorNumber    = 125,
                StartTimer          = true,
                PrimaryTimerValue   = 25.Seconds().And(943.Milliseconds()),
                SecondaryTimerValue = 16.Seconds().And(123.Milliseconds()),
                FaultCount          = 5,
                RefusalCount        = 10,
                Eliminated          = true,
                PreviousPlacement   = 23
            };

            operation.Should().BeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
        public void When_writing_visualize_operation_it_must_be_correct()
        {
            // Arrange
            var operation = new VisualizeOperation(new[]
            {
                new WirelessNetworkAddress("ABCDEF"),
                new WirelessNetworkAddress("AABBCC")
            })
            {
                CurrentCompetitorNumber = 123,
                NextCompetitorNumber    = 125,
                StartTimer          = true,
                PrimaryTimerValue   = 25.Seconds().And(943.Milliseconds()),
                SecondaryTimerValue = 16.Seconds().And(123.Milliseconds()),
                FaultCount          = 5,
                RefusalCount        = 10,
                Eliminated          = true,
                PreviousPlacement   = 23
            };

            // Act
            byte[] buffer = PacketWriter.Write(operation, false);

            // Assert
            buffer.Should().BeEquivalentTo(new byte[]
            {
                2,
                ByteFor('0'),
                ByteFor('7'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('4'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('2'),
                ByteFor('8'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('2'),
                ByteFor('3'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('2'),
                ByteFor('9'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('2'),
                ByteFor('5'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('0'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('1'),
                ByteFor(':'),
                ByteFor('2'),
                ByteFor('5'),
                ByteFor('9'),
                ByteFor('4'),
                ByteFor('3'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('8'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('6'),
                ByteFor('1'),
                ByteFor('2'),
                ByteFor('3'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('2'),
                ByteFor(':'),
                ByteFor('5'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('3'),
                ByteFor(':'),
                ByteFor('1'),
                ByteFor('0'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('3'),
                ByteFor('5'),
                ByteFor(':'),
                ByteFor('2'),
                ByteFor('3'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('1'),
                ByteFor('4'),
                ByteFor(':'),
                ByteFor('A'),
                ByteFor('B'),
                ByteFor('C'),
                ByteFor('D'),
                ByteFor('E'),
                ByteFor('F'),
                ByteFor('\t'),
                ByteFor('0'),
                ByteFor('1'),
                ByteFor('4'),
                ByteFor(':'),
                ByteFor('A'),
                ByteFor('A'),
                ByteFor('B'),
                ByteFor('B'),
                ByteFor('C'),
                ByteFor('C'),
                ByteFor('\t'),
                3
            });
        }