public async Task MigrateAsync(IStreamMigrationArgs e)
        {
            var events       = e.GetExistingEvents();
            var accessRadius = new Dictionary <int, float>();

            while (await events.MoveNextAsync())
            {
                switch (events.Current)
                {
                case ExhibitCreated created: accessRadius[created.Id] = created.Properties.AccessRadius; break;

                case ExhibitDeleted deleted: accessRadius.Remove(deleted.Id); break;

                case ExhibitUpdated updated:
                    // ReSharper disable once CompareOfFloatsByEqualityOperator
                    if (updated.Properties.AccessRadius == 0)
                    {
                        updated.Properties.AccessRadius = accessRadius[updated.Id];
                    }
                    break;
                }

                e.AppendEvent(events.Current);
            }
        }
예제 #2
0
        public async Task MigrateAsync(IStreamMigrationArgs e)
        {
            var events = e.GetExistingEvents();
            var pages  = new HashSet <int>(); // IDs of all currently existing pages

            while (await events.MoveNextAsync())
            {
                switch (events.Current)
                {
                case ExhibitCreated ev:
                    ev.Properties.Pages = ev.Properties.Pages?.Where(pages.Contains).ToList();
                    break;

                case ExhibitUpdated ev:
                    ev.Properties.Pages = ev.Properties.Pages?.Where(pages.Contains).ToList();
                    break;

                case ExhibitPageCreated3 ev:
                    pages.Add(ev.Id);
                    break;

                case ExhibitPageDeleted2 ev:
                    pages.Remove(ev.Id);
                    break;
                }

                e.AppendEvent(events.Current);
            }
        }
예제 #3
0
        public async Task MigrateAsync(IStreamMigrationArgs e)
        {
            var adminId = "auth0|5968ed8cdd1b3733ca94865d";
            var events  = e.GetExistingEvents();


            while (await events.MoveNextAsync())
            {
                switch (events.Current)
                {
                case UserActivityBaseEvent ev:
                    ev.UserId = ev.UserId ?? adminId;
                    e.AppendEvent(ev);
                    break;

                default:
                    // All other events are copied without modifications
                    e.AppendEvent(events.Current);
                    break;
                }
            }
        }
예제 #4
0
        public async Task MigrateAsync(IStreamMigrationArgs e)
        {
            var events        = e.GetExistingEvents();
            var lastTimestamp = DateTimeOffset.MinValue;

            while (await events.MoveNextAsync())
            {
                switch (events.Current)
                {
                case IDeleteEvent ev:
                    // In v3, IDeleteEvents did not store a timestamp.
                    // For v4, we have to choose a "realistic" timestamp
                    // => just use the timestamp of the last CRUD event
                    ev.Timestamp = lastTimestamp;
                    e.AppendEvent(ev);
                    break;

                case ICrudEvent ev:
                    lastTimestamp = ev.Timestamp;
                    e.AppendEvent(ev);
                    break;

                case ReferenceAdded _:
                    // Ignore, do not add ReferenceAdded/Removed events to the v4 stream
                    break;

                case ReferenceRemoved _:
                    // Ignore, do not add ReferenceAdded/Removed events to the v4 stream
                    break;

                default:
                    // All other events are copied without modifications
                    e.AppendEvent(events.Current);
                    break;
                }
            }
        }
예제 #5
0
        public async Task MigrateAsync(IStreamMigrationArgs e)
        {
            var events = e.GetExistingEvents();

            while (await events.MoveNextAsync())
            {
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (events.Current is ExhibitCreated exhibitCreated && exhibitCreated.Properties.AccessRadius == 0)
                {
                    // If AccessRadius is still 0, we assume that this exhibit was created in an earlier version
                    // of DataStore => thus, we now assign it a default radius of 10 meters
                    exhibitCreated.Properties.AccessRadius = .01f;
                }

                e.AppendEvent(events.Current);
            }
        }
예제 #6
0
        public async Task MigrateAsync(IStreamMigrationArgs e)
        {
            var events           = e.GetExistingEvents();
            var appetizerPageIds = new HashSet <int>();

            while (await events.MoveNextAsync())
            {
                switch (events.Current)
                {
                case ExhibitPageCreated3 ev:
                    if (ev.Properties.Type == AppetizerPageType)
                    {
                        // remember ID, do not append this event to new stream
                        appetizerPageIds.Add(ev.Id);
                    }
                    else
                    {
                        // pages of other types are kept, but first filter out referenced appetizer pages
                        ev.Properties.AdditionalInformationPages =
                            ev.Properties.AdditionalInformationPages?.Except(appetizerPageIds).ToList();
                        e.AppendEvent(ev);
                    }
                    break;

                case ExhibitPageUpdated3 ev:
                    // do not append update-event for appetizer pages
                    // (note: page type can't be changed in update-events)
                    if (!appetizerPageIds.Contains(ev.Id))
                    {
                        // filter out referenced appetizer pages
                        ev.Properties.AdditionalInformationPages =
                            ev.Properties.AdditionalInformationPages?.Except(appetizerPageIds).ToList();
                        e.AppendEvent(ev);
                    }
                    break;

                case ExhibitPageDeleted2 ev:
                    // do not append delete-event for appetizer pages
                    if (!appetizerPageIds.Remove(ev.Id))
                    {
                        e.AppendEvent(ev);
                    }
                    break;

                case ExhibitCreated ev:
                    // filter out referenced appetizer pages
                    ev.Properties.Pages = ev.Properties.Pages?.Except(appetizerPageIds).ToList();
                    e.AppendEvent(ev);
                    break;

                case ExhibitUpdated ev:
                    // filter out referenced appetizer pages
                    ev.Properties.Pages = ev.Properties.Pages?.Except(appetizerPageIds).ToList();
                    e.AppendEvent(ev);
                    break;

                default:
                    // all other events are copied without modification
                    e.AppendEvent(events.Current);
                    break;
                }
            }
        }
        public async Task MigrateAsync(IStreamMigrationArgs e)
        {
            var events   = e.GetExistingEvents();
            var pages    = new Dictionary <int, List <int> >(); // stores the page IDs for each exhibit
            var exhibits = new Dictionary <int, int>();         // stores the exhibit ID for each page

            while (await events.MoveNextAsync())
            {
                switch (events.Current)
                {
                case ReferenceAdded ev when ev.SourceType == ResourceType.ExhibitPage && ev.TargetType == ResourceType.Exhibit:
                case ReferenceRemoved ev2 when ev2.SourceType == ResourceType.ExhibitPage && ev2.TargetType == ResourceType.Exhibit:
                    // pages no longer reference the containing exhibit => ignore such references
                    break;

                case ExhibitUpdated ev:
                    // "PUT /Exhibit/{id}" now allows to reorder pages using the new 'pages'-field
                    // => emit new ExhibitUpdated-events with correctly populated 'pages' array
                    var pageIds = pages.TryGetValue(ev.Id, out var ids) ? ids : new List <int>();
                    e.AppendEvent(new ExhibitUpdated
                    {
                        Id         = ev.Id,
                        Timestamp  = ev.Timestamp,
                        Properties = new ExhibitArgs
                        {
                            Pages       = pageIds,
                            Description = ev.Properties.Description,
                            Image       = ev.Properties.Image,
                            Latitude    = ev.Properties.Latitude,
                            Longitude   = ev.Properties.Longitude,
                            Name        = ev.Properties.Name,
                            Status      = ev.Properties.Status,
                            Tags        = ev.Properties.Tags
                        }
                    });
                    break;

                case ExhibitPageCreated2 ev:
                    // for each page, remember the exhibit containing it (we need it in case ExhibitPageDeleted)
                    exhibits[ev.Id] = ev.ExhibitId;

                    // ...and add the page ID to the exhibit's pages array
                    if (pages.TryGetValue(ev.ExhibitId, out var list))
                    {
                        list.Add(ev.Id);
                    }
                    else
                    {
                        pages[ev.ExhibitId] = new List <int> {
                            ev.Id
                        }
                    };

                    e.AppendEvent(ev);
                    break;

                case ExhibitPageDeleted ev:
                    // In v0, ExhibitPageDeleted did not store the exhibit ID.
                    // So we have to find that one out here and emit a new ExhibitPageDeleted event.
                    var exhibitId = exhibits[ev.Id];
                    pages[exhibitId].Remove(ev.Id);

                    e.AppendEvent(new ExhibitPageDeleted
                    {
                        Id        = ev.Id,
                        ExhibitId = exhibitId
                    });
                    break;

                default:
                    // all other events remain the same
                    e.AppendEvent(events.Current);
                    break;
                }
            }
        }
예제 #8
0
        public async Task MigrateAsync(IStreamMigrationArgs e)
        {
            var events   = e.GetExistingEvents();
            var exhibits = new Dictionary <int, ExhibitArgs>();

            while (await events.MoveNextAsync())
            {
                switch (events.Current)
                {
                case ExhibitPageCreated2 pageCreated:
                    // In v1, 'ExhibitPageCreated'-events were for creating a page and adding it to an exhibit.
                    // For v2, this needs to be split into multiple events.
                    e.AppendEvent(new ExhibitPageCreated3
                    {
                        Id         = pageCreated.Id,
                        Properties = pageCreated.Properties,
                        Timestamp  = pageCreated.Timestamp
                    });

                    var exhibit = exhibits[pageCreated.ExhibitId];
                    if (exhibit.Pages == null)
                    {
                        exhibit.Pages = new List <int>();
                    }
                    exhibit.Pages.Add(pageCreated.Id);

                    e.AppendEvent(new ExhibitUpdated
                    {
                        Id         = pageCreated.ExhibitId,
                        Timestamp  = pageCreated.Timestamp,
                        Properties = new ExhibitArgs
                        {
                            Name        = exhibit.Name,
                            Description = exhibit.Description,
                            Image       = exhibit.Image,
                            Latitude    = exhibit.Latitude,
                            Longitude   = exhibit.Longitude,
                            Status      = exhibit.Status,
                            Tags        = exhibit.Tags,
                            Pages       = exhibit.Pages
                        }
                    });
                    break;

                case ExhibitPageUpdated2 ev:
                    e.AppendEvent(new ExhibitPageUpdated3
                    {
                        Id         = ev.Id,
                        Properties = ev.Properties,
                        Timestamp  = ev.Timestamp
                    });
                    break;

                case ExhibitPageDeleted ev:
                    e.AppendEvent(new ExhibitPageDeleted2 {
                        Id = ev.Id
                    });
                    break;

                case ExhibitCreated ev:
                    // In v1, 'ExhibitCreated' did not allow specifying pages, so 'Pages' is null
                    // => change that to empty list!
                    ev.Properties.Pages = new List <int>();
                    exhibits[ev.Id]     = ev.Properties;
                    e.AppendEvent(ev);
                    break;

                case ExhibitUpdated ev:
                    exhibits[ev.Id] = ev.Properties;
                    e.AppendEvent(ev);
                    break;

                case ExhibitDeleted ev:
                    exhibits.Remove(ev.Id);
                    e.AppendEvent(ev);
                    break;

                default:
                    // all other events remain the same
                    e.AppendEvent(events.Current);
                    break;
                }
            }

            // In v1, exhibits did not reference their pages.
            // In v2 they do, so we have to add the missing references.
            // (Regarding additional information pages, nothing needs to be changed.)
            foreach (var exhibit in exhibits)
            {
                foreach (var page in exhibit.Value.Pages)
                {
                    e.AppendEvent(new ReferenceAdded(ResourceType.Exhibit, exhibit.Key, ResourceType.ExhibitPage, page));
                }
            }
        }