示例#1
0
 public static void ApplyProvenance(
     this PostalInformationSyndicationItem item,
     ProvenanceData provenance)
 {
     item.Application  = provenance.Application;
     item.Modification = provenance.Modification;
     item.Operator     = provenance.Operator;
     item.Organisation = provenance.Organisation;
     item.Reason       = provenance.Reason;
 }
示例#2
0
        public PostalInformationSyndicationProjections()
        {
            When <Envelope <PostalInformationWasRegistered> >(async(context, message, ct) =>
            {
                var newPostalInformationSyndicationItem = new PostalInformationSyndicationItem
                {
                    Position                 = message.Position,
                    PostalCode               = message.Message.PostalCode,
                    RecordCreatedAt          = message.Message.Provenance.Timestamp,
                    LastChangedOn            = message.Message.Provenance.Timestamp,
                    ChangeType               = message.EventName,
                    SyndicationItemCreatedAt = DateTimeOffset.UtcNow
                };

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

                await context
                .PostalInformationSyndication
                .AddAsync(newPostalInformationSyndicationItem, ct);
            });

            When <Envelope <PostalInformationWasRealized> >(async(context, message, ct) =>
            {
                await context.CreateNewPostalInformationSyndicationItem(
                    message.Message.PostalCode,
                    message,
                    x => x.Status = PostalInformationStatus.Current,
                    ct);
            });

            When <Envelope <PostalInformationWasRetired> >(async(context, message, ct) =>
            {
                await context.CreateNewPostalInformationSyndicationItem(
                    message.Message.PostalCode,
                    message,
                    x => x.Status = PostalInformationStatus.Retired,
                    ct);
            });

            When <Envelope <PostalInformationPostalNameWasAdded> >(async(context, message, ct) =>
            {
                await context.CreateNewPostalInformationSyndicationItem(
                    message.Message.PostalCode,
                    message,
                    x => x.AddPostalName(new PostalName(message.Message.Name, message.Message.Language)),
                    ct);
            });

            When <Envelope <PostalInformationPostalNameWasRemoved> >(async(context, message, ct) =>
            {
                await context.CreateNewPostalInformationSyndicationItem(
                    message.Message.PostalCode,
                    message,
                    x =>
                {
                    var name = x.PostalNames.First(y => y.Name == message.Message.Name);
                    x.RemovePostalName(name);
                },
                    ct);
            });

            When <Envelope <MunicipalityWasAttached> >(async(context, message, ct) =>
            {
                await context.CreateNewPostalInformationSyndicationItem(
                    message.Message.PostalCode,
                    message,
                    x => x.MunicipalityNisCode = message.Message.NisCode,
                    ct);
            });

            When <Envelope <PostalInformationWasImportedFromCrab> >(async(context, message, ct) => DoNothing());
            When <Envelope <PostalInformationWasImportedFromBPost> >(async(context, message, ct) => DoNothing());
        }
示例#3
0
 public static void SetEventData <T>(this PostalInformationSyndicationItem syndicationItem, T message)
 => syndicationItem.EventDataAsXml = message.ToXml(message.GetType().Name).ToString(SaveOptions.DisableFormatting);