Ejemplo n.º 1
0
        public StreetNameSyndicationProjections()
        {
            #region Legacy Events

            When <Envelope <StreetNameWasRegistered> >(async(context, message, ct) =>
            {
                var streetNameSyndicationItem = new StreetNameSyndicationItem
                {
                    Position                 = message.Position,
                    StreetNameId             = message.Message.StreetNameId,
                    NisCode                  = message.Message.NisCode,
                    RecordCreatedAt          = message.Message.Provenance.Timestamp,
                    LastChangedOn            = message.Message.Provenance.Timestamp,
                    ChangeType               = message.EventName,
                    SyndicationItemCreatedAt = DateTimeOffset.UtcNow
                };

                streetNameSyndicationItem.ApplyProvenance(message.Message.Provenance);
                streetNameSyndicationItem.SetEventData(message.Message, message.EventName);

                await context
                .StreetNameSyndication
                .AddAsync(streetNameSyndicationItem, ct);
            });

            When <Envelope <StreetNamePersistentLocalIdWasAssigned> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.PersistentLocalId = message.Message.PersistentLocalId,
                    ct);
            });

            When <Envelope <StreetNameWasNamed> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateNameByLanguage(x, message.Message.Name, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameNameWasCleared> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateNameByLanguage(x, null, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameNameWasCorrected> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateNameByLanguage(x, message.Message.Name, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameNameWasCorrectedToCleared> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateNameByLanguage(x, null, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameHomonymAdditionWasDefined> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateHomonymAdditionByLanguage(x, message.Message.HomonymAddition, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameHomonymAdditionWasCleared> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateHomonymAdditionByLanguage(x, null, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameHomonymAdditionWasCorrected> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateHomonymAdditionByLanguage(x, message.Message.HomonymAddition, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameHomonymAdditionWasCorrectedToCleared> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateHomonymAdditionByLanguage(x, null, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameBecameCurrent> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Current,
                    ct);
            });

            When <Envelope <StreetNameWasCorrectedToCurrent> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Current,
                    ct);
            });

            When <Envelope <StreetNameWasProposed> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Proposed,
                    ct);
            });

            When <Envelope <StreetNameWasCorrectedToProposed> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Proposed,
                    ct);
            });

            When <Envelope <StreetNameWasRetired> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Retired,
                    ct);
            });

            When <Envelope <StreetNameWasCorrectedToRetired> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Retired,
                    ct);
            });

            When <Envelope <StreetNameStatusWasRemoved> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = null,
                    ct);
            });

            When <Envelope <StreetNameStatusWasCorrectedToRemoved> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = null,
                    ct);
            });

            When <Envelope <StreetNameBecameComplete> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.IsComplete = true,
                    ct);
            });

            When <Envelope <StreetNameBecameIncomplete> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.IsComplete = false,
                    ct);
            });

            When <Envelope <StreetNameWasRemoved> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => { },
                    ct);
            });

            When <Envelope <StreetNamePrimaryLanguageWasCleared> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNamePrimaryLanguageWasCorrected> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNamePrimaryLanguageWasCorrectedToCleared> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNamePrimaryLanguageWasDefined> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNameSecondaryLanguageWasCleared> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNameSecondaryLanguageWasCorrected> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNameSecondaryLanguageWasCorrectedToCleared> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNameSecondaryLanguageWasDefined> >(async(context, message, ct) => DoNothing());

            When <Envelope <StreetNameWasImportedFromCrab> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNameStatusWasImportedFromCrab> >(async(context, message, ct) => DoNothing());

            #endregion

            When <Envelope <StreetNameWasProposedV2> >(async(context, message, ct) =>
            {
                var streetNameSyndicationItem = new StreetNameSyndicationItem
                {
                    Position                 = message.Position,
                    PersistentLocalId        = message.Message.PersistentLocalId,
                    MunicipalityId           = message.Message.MunicipalityId,
                    NisCode                  = message.Message.NisCode,
                    RecordCreatedAt          = message.Message.Provenance.Timestamp,
                    LastChangedOn            = message.Message.Provenance.Timestamp,
                    ChangeType               = message.EventName,
                    SyndicationItemCreatedAt = DateTimeOffset.UtcNow
                };
                UpdateNameByLanguage(streetNameSyndicationItem, message.Message.StreetNameNames);
                streetNameSyndicationItem.ApplyProvenance(message.Message.Provenance);
                streetNameSyndicationItem.SetEventData(message.Message, message.EventName);

                await context
                .StreetNameSyndication
                .AddAsync(streetNameSyndicationItem, ct);
            });

            When <Envelope <MunicipalityNisCodeWasChanged> >(async(context, message, ct) =>
            {
                var streetNames = context
                                  .StreetNameSyndication
                                  .Local
                                  .Where(s => s.MunicipalityId == message.Message.MunicipalityId)
                                  .Union(context.StreetNameSyndication.Where(s => s.MunicipalityId == message.Message.MunicipalityId));

                foreach (var streetNameSyndicationItem in streetNames)
                {
                    streetNameSyndicationItem.NisCode = message.Message.NisCode;
                    streetNameSyndicationItem.ApplyProvenance(message.Message.Provenance);
                    streetNameSyndicationItem.SetEventData(message.Message, message.EventName);
                }
            });
        }
        public StreetNameSyndicationProjections()
        {
            When <Envelope <StreetNameWasRegistered> >(async(context, message, ct) =>
            {
                var streetNameSyndicationItem = new StreetNameSyndicationItem
                {
                    Position        = message.Position,
                    StreetNameId    = message.Message.StreetNameId,
                    NisCode         = message.Message.NisCode,
                    RecordCreatedAt = message.Message.Provenance.Timestamp,
                    LastChangedOn   = message.Message.Provenance.Timestamp,
                    ChangeType      = message.EventName
                };

                streetNameSyndicationItem.ApplyProvenance(message.Message.Provenance);
                streetNameSyndicationItem.SetEventData(message.Message, message.EventName);

                await context
                .StreetNameSyndication
                .AddAsync(streetNameSyndicationItem, ct);
            });

            When <Envelope <StreetNamePersistentLocalIdWasAssigned> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.PersistentLocalId = message.Message.PersistentLocalId,
                    ct);
            });

            When <Envelope <StreetNameWasNamed> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateNameByLanguage(x, message.Message.Name, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameNameWasCleared> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateNameByLanguage(x, null, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameNameWasCorrected> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateNameByLanguage(x, message.Message.Name, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameNameWasCorrectedToCleared> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateNameByLanguage(x, null, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameHomonymAdditionWasDefined> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateHomonymAdditionByLanguage(x, message.Message.HomonymAddition, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameHomonymAdditionWasCleared> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateHomonymAdditionByLanguage(x, null, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameHomonymAdditionWasCorrected> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateHomonymAdditionByLanguage(x, message.Message.HomonymAddition, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameHomonymAdditionWasCorrectedToCleared> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => UpdateHomonymAdditionByLanguage(x, null, message.Message.Language),
                    ct);
            });

            When <Envelope <StreetNameBecameCurrent> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Current,
                    ct);
            });

            When <Envelope <StreetNameWasCorrectedToCurrent> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Current,
                    ct);
            });

            When <Envelope <StreetNameWasProposed> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Proposed,
                    ct);
            });

            When <Envelope <StreetNameWasCorrectedToProposed> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Proposed,
                    ct);
            });

            When <Envelope <StreetNameWasRetired> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Retired,
                    ct);
            });

            When <Envelope <StreetNameWasCorrectedToRetired> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = StreetNameStatus.Retired,
                    ct);
            });

            When <Envelope <StreetNameStatusWasRemoved> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = null,
                    ct);
            });

            When <Envelope <StreetNameStatusWasCorrectedToRemoved> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.Status = null,
                    ct);
            });

            When <Envelope <StreetNameBecameComplete> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.IsComplete = true,
                    ct);
            });

            When <Envelope <StreetNameBecameIncomplete> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => x.IsComplete = false,
                    ct);
            });

            When <Envelope <StreetNameWasRemoved> >(async(context, message, ct) =>
            {
                await context.CreateNewStreetNameSyndicationItem(
                    message.Message.StreetNameId,
                    message,
                    x => { },
                    ct);
            });

            When <Envelope <StreetNamePrimaryLanguageWasCleared> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNamePrimaryLanguageWasCorrected> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNamePrimaryLanguageWasCorrectedToCleared> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNamePrimaryLanguageWasDefined> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNameSecondaryLanguageWasCleared> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNameSecondaryLanguageWasCorrected> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNameSecondaryLanguageWasCorrectedToCleared> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNameSecondaryLanguageWasDefined> >(async(context, message, ct) => DoNothing());

            When <Envelope <StreetNameWasImportedFromCrab> >(async(context, message, ct) => DoNothing());
            When <Envelope <StreetNameStatusWasImportedFromCrab> >(async(context, message, ct) => DoNothing());
        }