Ejemplo n.º 1
0
        public void RaceSummary_ReadAndWrite_ShouldBeSymmetric()
        {
            Beacon martijnBeacon = new Beacon(new byte[] { 0, 0, 0, 0, 0, 1 }, 2);

            martijnBeacon.Rssi          = 3;
            martijnBeacon.MeasuredPower = 4;

            Beacon bertBeacon = new Beacon(new byte[] { 0, 0, 0, 0, 0, 5 }, 6);

            bertBeacon.Rssi          = 7;
            bertBeacon.MeasuredPower = 8;

            IdEvent     entered = new IdEvent(new DateTime(2000, 1, 1), new Rider("Martijn", martijnBeacon), "StartId", Direction.Enter);
            TimingEvent timing  = new TimingEvent(new DateTime(2000, 1, 1), new Rider("Bert", bertBeacon), 100, 1);

            TrackerConfig config = new TrackerConfig
            {
                EndMatchTimeout   = 9,
                StartTimingGateId = 10,
                EndTimingGateId   = 11
            };

            RaceSummary subject = new RaceSummary(new List <RaceEvent> {
                entered, timing
            }, config, "StartId", "EndId");

            MemoryStream stream = new MemoryStream();

            subject.WriteSummary(stream);

            stream.Seek(0, SeekOrigin.Begin);

            RaceSummary parsed = RaceSummary.ReadSummary(stream);

            foreach ((Rider r1, Rider r2) in subject.Riders.Zip(parsed.Riders))
            {
                Assert.IsTrue(CompareRiders(r1, r2));
            }

            CollectionAssert.AreEqual(subject.Events.Select(e => e.EventId).ToList(), parsed.Events.Select(e => e.EventId).ToList());
            CollectionAssert.AreEqual(subject.Events.Select(e => e.GetType()).ToList(), parsed.Events.Select(e => e.GetType()).ToList());

            foreach ((RaceEvent e1, RaceEvent e2) in subject.Events.Zip(parsed.Events))
            {
                Assert.IsTrue(CompareRiders(e1.Rider, e2.Rider));
            }

            Assert.AreEqual("StartId", parsed.StartId);
            Assert.AreEqual("EndId", parsed.EndId);

            Assert.AreEqual(config.StartTimingGateId, parsed.Config.StartTimingGateId);
            Assert.AreEqual(config.EndTimingGateId, parsed.Config.EndTimingGateId);
            Assert.AreEqual(config.EndMatchTimeout, parsed.Config.EndMatchTimeout);
        }
Ejemplo n.º 2
0
        public StatusCodeResult Simulate([FromBody] JObject summary)
        {
            byte[]      text = Encoding.UTF8.GetBytes(summary.ToString());
            RaceSummary parsed;

            using (MemoryStream stream = new MemoryStream(text))
            {
                parsed = RaceSummary.ReadSummary(stream);
            }
            manager.Start(parsed);
            return(new StatusCodeResult(200));
        }
Ejemplo n.º 3
0
        protected override int OnExecute(CommandLineApplication app)
        {
            RaceManager manager = new RaceManager();
            RaceSummary summary;

            using (Stream reader = new FileStream(SummaryFile, FileMode.Open))
            {
                summary = RaceSummary.ReadSummary(reader);
            }


            manager.Start(summary);

            manager.CombinedTasks.Wait();

            return(0);
        }