コード例 #1
0
ファイル: CheckpointState.cs プロジェクト: kerkesix/satku
 public void When(AttendeeScanOutPreceedsScanIn e)
 {
 }
コード例 #2
0
 public void When(AttendeeScanOutPreceedsScanIn e) => PublishToContributorClients(e);
コード例 #3
0
ファイル: Checkpoint.cs プロジェクト: kerkesix/satku
        public void AddScan(ScanInfo scanInfo)
        {
            if (this.State.CheckpointType == CheckpointType.Start && this.State.ReadingsOut.Count == 0)
            {
                // This is the first scan, emit information that happening has started
                this.Apply(new FirstAttendeeForHappeningScanned(scanInfo.HappeningId));
            }

            const int DoubleReadingThresholdSeconds = 5;
            Func <CheckpointScan, bool> match       = reading => reading.PersonId.Equals(scanInfo.PersonId);
            AttendeeScanBase            scan;

            var inReading = this.State.ReadingsIn.FirstOrDefault(match);

            if (inReading != null)
            {
                if (this.State.ReadingsOut.Any(match))
                {
                    // Both in and out readings already exists, do nothing
                    scan = new AttendeeDoubleScan(scanInfo)
                    {
                        Message = "Sekä sisään- että uloslukema on jo tallennettu."
                    };
                }
                else
                {
                    // Check, that this is not a double reading
                    var difference = scanInfo.Timestamp.Subtract(inReading.TimeStamp);

                    if (difference < TimeSpan.FromSeconds(DoubleReadingThresholdSeconds))
                    {
                        scan = new AttendeeDoubleScan(scanInfo)
                        {
                            DifferenceSinceLastRead = difference.TotalSeconds,
                            Message =
                                string.Format(
                                    CultureInfo.CurrentCulture,
                                    "Luku tapahtui alle {0} s kuluessa edellisestä.",
                                    DoubleReadingThresholdSeconds)
                        };
                    }
                    else
                    {
                        // Check that this out reading is not before in reading
                        if (inReading.TimeStamp > scanInfo.ScanTimestamp)
                        {
                            scan = new AttendeeScanOutPreceedsScanIn(scanInfo);
                        }
                        else
                        {
                            scan = new AttendeeScanOut(scanInfo);
                        }
                    }
                }
            }
            else
            {
                if (this.State.CheckpointType == CheckpointType.Passthrough)
                {
                    scan = new AttendeePassthroughScan(scanInfo);
                }
                else
                {
                    // This is the first reading for this person on this checkpoint
                    scan = this.State.CheckpointType == CheckpointType.Start
                        ? (AttendeeScanBase) new AttendeeScanOut(scanInfo)
                        : new AttendeeScanIn(scanInfo);
                }
            }

            // Ensure, that event goes to the same checkpoint (should be correct already)
            scan.CheckpointId = this.State.Id;

            this.Apply(scan);

            if (this.State.CheckpointType == CheckpointType.Start && scan is AttendeeScanOut)
            {
                this.Apply(new AttendeeScannedAtStartCheckpoint(scanInfo.HappeningId, scanInfo.PersonId));
            }

            if (this.State.CheckpointType == CheckpointType.Finish && scan is AttendeeScanIn)
            {
                this.Apply(new AttendeeScannedAtFinishCheckpoint(scanInfo.HappeningId, scanInfo.PersonId));
            }
        }