Exemple #1
0
        public void Handle(DomainModelCreatedEvent <Group> domainEvent)
        {
            Check.RequireNotNull(domainEvent, "domainEvent");

            var user = _documentSession.Load <User>(domainEvent.DomainModel.User.Id);

            if (domainEvent.Sender is Project)
            {
                var project = domainEvent.DomainModel as Project;
                var groups  = _documentSession.Load <dynamic>(project.AncestorGroups.Select(x => x.Id));

                dynamic activity = MakeActivity(
                    domainEvent,
                    "groupadded",
                    domainEvent.DomainModel.CreatedDateTime,
                    string.Format("{0} created the {1} {2}", user.GetName(), project.Name, "project"),
                    groups);

                activity.GroupAdded = new
                {
                    User  = user,
                    Group = project
                };

                _documentSession.Store(activity);
                _backChannelService.SendActivityToGroupChannel(activity);
            }

            if (domainEvent.Sender is Organisation)
            {
                var organisation = domainEvent.DomainModel as Team;
                var groups       = _documentSession.Load <dynamic>(organisation.AncestorGroups.Select(x => x.Id));

                dynamic activity = MakeActivity(
                    domainEvent,
                    "groupadded",
                    domainEvent.DomainModel.CreatedDateTime,
                    string.Format("{0} created the {1} {2}", user.GetName(), organisation.Name, "organisation"),
                    groups);

                activity.GroupAdded = new
                {
                    User  = user,
                    Group = organisation
                };

                _documentSession.Store(activity);
                _documentSession.SaveChanges();
                _backChannelService.SendActivityToGroupChannel(activity);
            }
        }
Exemple #2
0
        public void Handle(DomainModelCreatedEvent <Comment> domainEvent)
        {
            if (domainEvent.Sender is Observation)
            {
                var observation = domainEvent.Sender as Observation;

                dynamic activity = MakeActivity(
                    domainEvent,
                    "observationcommentadded",
                    domainEvent.DomainModel.CreatedOn,
                    string.Format("{0} added a comment to observation {1}",
                                  domainEvent.User.GetName(),
                                  ((Observation)observation).Title),
                    ((Observation)observation).Groups.Select(x => x.Group),
                    observation.Id);

                activity.ObservationCommentAdded = new
                {
                    Comment = domainEvent.DomainModel
                };

                _documentSession.Store(activity);
                _backChannelService.SendActivityToGroupChannel(activity);
            }

            if (domainEvent.Sender is Post)
            {
                var post  = domainEvent.Sender as Post;
                var group = _documentSession.Load <dynamic>(((Post)post).Group.Id);

                dynamic activity = MakeActivity(
                    domainEvent,
                    "postcommentadded",
                    domainEvent.DomainModel.CreatedOn,
                    string.Format("{0} added a comment to news item {1}",
                                  domainEvent.User.GetName(),
                                  ((Post)post).Subject),
                    new [] { group },
                    post.Id);

                activity.PostCommentAdded = new
                {
                    Comment = domainEvent.DomainModel
                };

                _documentSession.Store(activity);
                _backChannelService.SendActivityToGroupChannel(activity);
            }
        }
        private void Execute(IDomainEvent domainEvent, Sighting sighting, IEnumerable <Project> projects)
        {
            dynamic activity = MakeActivity(
                domainEvent,
                "sightingadded",
                sighting.CreatedOn,
                string.Format("{0} added a sighting", domainEvent.User.GetName()),
                sighting.Groups.Select(x => x.Group),
                sighting.Id);

            if (sighting is Observation)
            {
                activity.ObservationAdded = new
                {
                    Observation = _sightingViewFactory.Make(sighting, domainEvent.User, projects, null)
                };
            }
            else
            {
                activity.RecordAdded = new
                {
                    Record = _sightingViewFactory.Make(sighting, domainEvent.User, projects, null)
                };
            }

            _documentSession.Store(activity);
            _documentSession.SaveChanges();
            _backChannelService.SendActivityToGroupChannel(activity);
        }
        public void Handle(DomainModelCreatedEvent <SightingNote> domainEvent)
        {
            Check.RequireNotNull(domainEvent, "domainEvent");

            var sighting = domainEvent.Sender as Sighting;

            dynamic activity = MakeActivity(
                domainEvent,
                "sightingnoteadded",
                domainEvent.DomainModel.CreatedOn,
                string.Format("{0} described a sighting", domainEvent.User.GetName()),
                sighting.Groups.Select(x => x.Group),
                sighting.Id,
                domainEvent.DomainModel.Id.ToString());

            var projects = _documentSession.Load <Project>(sighting.Groups.Where(x => x.Group.GroupType == "project").Select(x => x.Group.Id));

            activity.SightingNoteAdded = new
            {
                Sighting     = _sightingViewFactory.Make(sighting, domainEvent.User, projects, domainEvent.User),
                SightingNote = _sightingNoteViewFactory.Make(sighting, domainEvent.DomainModel, domainEvent.User, domainEvent.User)
            };

            _documentSession.Store(activity);
            _documentSession.SaveChanges();
            _backChannelService.SendActivityToGroupChannel(activity);
        }
        public void Handle(DomainModelCreatedEvent <Post> domainEvent)
        {
            var group = _documentSession.Load <dynamic>(domainEvent.DomainModel.Group.Id);

            dynamic activity = MakeActivity(
                domainEvent,
                "postadded",
                domainEvent.DomainModel.CreatedOn,
                string.Format("{0} added a news item", domainEvent.User.GetName(), ((Group)group).Name, ((Group)group).GroupType),
                new List <dynamic>()
            {
                group
            },
                domainEvent.DomainModel.Id);

            activity.PostAdded = new
            {
                Post = domainEvent.DomainModel
            };

            _documentSession.Store(activity);
            _documentSession.SaveChanges();
            _backChannelService.SendActivityToGroupChannel(activity);
        }