public void When(HappeningCreated e) => PublishToClients(e);
public Task Upload(string environment) { Console.Out.WriteLine("Uploading satkuxii data to " + environment); var env = new EnvironmentClient(environment); Console.Out.WriteLine("Using connection string " + env.Options.ConnectionString); var jsonData = GetEmbeddedResource("satkuxii.json"); var data = JsonConvert.DeserializeObject <SatkuData>(jsonData); Console.Out.WriteLine("Deserialized, checkpoint count " + data.Checkpoints.Count); var stream = new EventStream(env.Options); stream.AppendEvents( "HappeningsInventory-" + HappeningMessageHandler.RootAggregateId, new List <IEvent> { new HappeningInventoryItemCreated( data.Happening, data.IsDefault, data.Checkpoints.First().Timestamp.AddSeconds(-10)) }).Wait(); var happeningCreated = new HappeningCreated(data.Happening) { Timestamp = data.Checkpoints.First() .Timestamp.AddSeconds(-9) }; stream.AppendEvents( "Happening-" + data.Happening, new List <IEvent> { happeningCreated }).Wait(); var checkpointListEvents = new List <IEvent>(); int order = 1; foreach (var c in data.Checkpoints) { // To keep data simpler to edit by hand, set some properties automatically c.HappeningId = data.Happening; c.Order = order; order++; var validatedEvent = new CheckpointValidated( data.Happening, c.Id, c.Order, c.CheckpointType, c.Name, c.Latitude, c.Longitude, c.DistanceFromPrevious, c.DistanceFromStart) { // Use timestamp little after the happening Timestamp = c.Timestamp.AddSeconds(-1) }; checkpointListEvents.Add(validatedEvent); stream.AppendEvents("Checkpoint-" + c.Id, new List <IEvent> { c }).Wait(); } return(stream.AppendEvents("CheckpointList-" + data.Happening, checkpointListEvents)); }
public void When(HappeningCreated e) { QueryModelRepository.Dashboard.Happenings.Add(e.HappeningId, new HappeningDashboard()); }
public Task When(HappeningCreated e) => // Must create new, empty list of checkpoints for the new happening this.checkpointTypesRepository.CreateAndExecute(e.Id, checkpoint => checkpoint.Create(e.Id));
public IEnumerable <NamedEventStream> LegacyDataAsEvents() { var happeningInventoryStream = new NamedEventStream("HappeningsInventory-" + HappeningMessageHandler.RootAggregateId); var happeningStreams = new List <NamedEventStream>(); var checkpointStreams = new List <NamedEventStream>(); var checkpoints = this.parser.Checkpoints; var happeningsCreated = new Dictionary <string, DateTime>(); foreach (var h in this.parser.Happenings) { happeningsCreated.Add(h.Id, h.CreatedAt); happeningInventoryStream.Events.Add(new HappeningInventoryItemCreated(h.Id, h.Default, h.CreatedAt.ToUtcOffset())); var happeningStream = new NamedEventStream(CreateHappeningStreamId(h.Id)); happeningStreams.Add(happeningStream); var happeningCreated = new HappeningCreated(h.Id) { Timestamp = h.CreatedAt.ToUtcOffset() }; happeningStream.Events.Add(happeningCreated); var checkpointListStream = new NamedEventStream("CheckpointList-" + h.Id); checkpointStreams.Add(checkpointListStream); var h1 = h; foreach (var c in checkpoints.Where(m => m.HappeningId == h1.Id)) { var validatedEvent = new CheckpointValidated( h.Id, c.Id.ToString(), c.Order, c.CheckpointType, c.Name, c.Location.Latitude, c.Location.Longitude, c.DistanceFromPreviousCheckpoint, c.DistanceFromStart) { // Use timestamp little after the happening Timestamp = h.CreatedAt.AddSeconds(1).ToUtcOffset() }; checkpointListStream.Events.Add(validatedEvent); var checkpointStream = new NamedEventStream(CreateCheckpointStreamId(c.Id)); checkpointStreams.Add(checkpointStream); var createdEvent = new CheckpointCreated( h.Id, c.Id.ToString(), c.CheckpointType, c.Order, c.Name, c.Location.Latitude, c.Location.Longitude, c.DistanceFromPreviousCheckpoint, c.DistanceFromStart) { // Use a timestamp that is little after validated event Timestamp = validatedEvent.Timestamp.AddSeconds(1) }; checkpointStream.Events.Add(createdEvent); } } yield return(happeningInventoryStream); int anonymousWalkers = 1; var attendees = this.parser.Attendees.ToList(); var personIdMap = new Dictionary <Guid, string>(); foreach (var p in this.parser.People) { var personStream = new NamedEventStream("Person-" + p.Id); string displayName = p.Name; if (!p.MayShowNameToPublic) { displayName = string.Format( CultureInfo.CurrentCulture, "Anonyymi kävelijä {0:n0}", anonymousWalkers); anonymousWalkers++; } var namesplit = p.Name.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var lastname = namesplit[0]; var firstname = string.Join(" ", namesplit.Skip(1)); personIdMap.Add(p.Id, p.NewEventBasedId); var personCreatedEvent = new PersonCreated( p.NewEventBasedId, null, lastname, firstname, displayName, new ContactInformation(p.Phone, p.Email, p.TwitterName), null) { // Create all legacy persons immediately after first happening was created, // as otherwise they would not been available on AttendeeScanIn etc. events. Timestamp = happeningsCreated.Values.Min().AddSeconds(1).ToUtcOffset() }; personStream.Events.Add(personCreatedEvent); // Get attendance info for this person personStream.Events.AddRange( attendees.Where(m => m.PersonId == p.Id) .Select(a => { var linkEvent = new PersonLinkedToHappening( a.Id.ToString(), p.NewEventBasedId, a.HappeningId, null) { // Link immediately after happening has been created Timestamp = happeningsCreated[a.HappeningId].AddSeconds(2).ToUtcOffset() }; return(linkEvent); })); yield return(personStream); } var startedEmittedTo = new HashSet <string>(); foreach (var parsedReading in this.parser.Readings) { var reading = parsedReading.Entity; var readingCheckpoint = checkpoints.First(m => m.Id == reading.CheckpointId); var scanInfo = new ScanInfo( readingCheckpoint.HappeningId, reading.CheckpointId.ToString(), personIdMap[attendees.First(m => m.Id == parsedReading.AttendeeId).PersonId], "fooid", reading.Timestamp.ToUtcOffset(), reading.Timestamp.ToUtcOffset(), reading.SavedBy); var readingEvent = reading.ReadingType == ReadingType.In ? (AttendeeScanBase) new AttendeeScanIn(scanInfo) : new AttendeeScanOut(scanInfo); readingEvent.Id = reading.Id.ToString(); readingEvent.ScanId = readingEvent.Id; // Find the correct checkpoint stream to append this reading event var cpStream = checkpointStreams.First(m => m.Name.Equals(CreateCheckpointStreamId(reading.CheckpointId))); cpStream.Events.Add(readingEvent); if (readingCheckpoint.CheckpointType == CheckpointType.Start && startedEmittedTo.Add(readingCheckpoint.HappeningId)) { // Emit happening started event var happeningStartedEvent = new HappeningStarted(readingCheckpoint.HappeningId) { Timestamp = readingEvent.Timestamp.AddSeconds(1) }; cpStream.Events.Add(happeningStartedEvent); } if (readingCheckpoint.CheckpointType == CheckpointType.Finish) { // Emit attendee completed event var completedEvent = new AttendeeCompleted( readingEvent.HappeningId, readingEvent.PersonId) { Timestamp = readingEvent.Timestamp }; cpStream.Events.Add(completedEvent); } } foreach (var parsedQuitter in this.parser.Quitters) { var quit = parsedQuitter.Entity; var scanInfo = new ScanInfo( checkpoints.First(m => m.Id == quit.CheckpointId).HappeningId, quit.CheckpointId.ToString(), personIdMap[attendees.First(m => m.Id == parsedQuitter.AttendeeId).PersonId], quit.Id.ToString(), quit.Timestamp.ToUtcOffset(), quit.Timestamp.ToUtcOffset(), quit.SavedBy); var quitEvent = new AttendeeQuit( scanInfo, quit.WalkedSinceLastCheckpoint, quit.Description) { // Use the same ID as original data Id = quit.Id.ToString() }; // Find the correct stream to append this quit event var s = happeningStreams.First(m => m.Name.Equals(CreateHappeningStreamId(scanInfo.HappeningId))); s.Events.Add(quitEvent); } // Individual happening streams foreach (var s in happeningStreams) { yield return(s); } foreach (var s in checkpointStreams) { yield return(s); } }
public void When(HappeningCreated e) { this.HappeningId = e.HappeningId; }
public void When(HappeningCreated e) { QueryModelRepository.Csv.Add(e.HappeningId, new CsvDataFile());; }