Exemple #1
0
        /// <summary>
        ///     It doesn't cache user profiles
        /// </summary>
        /// <param name="uow"></param>
        /// <param name="userDto"></param>
        protected void CacheUserDto(IdentityUow uow, UserDto userDto)
        {
            if (userDto == null)
            {
                return;
            }

            uow.Cache.SetCachedItemAsync(CacheKeyHelper.GetCacheKey <UserDto>(userDto.Key), userDto);
            uow.Cache.SetCachedItemAsync(CacheKeyHelper.GetCacheKey <UserDto>(userDto.Username), userDto);
            uow.Cache.SetCachedItemAsync(CacheKeyHelper.GetCacheKey <UserDto>(userDto.Email), userDto);

            uow.Cache.SetCachedItemAsync(
                CacheKeyHelper.GetCacheKey <UserDto>(userDto.Mobile.LocalNumberWithAreaCode), userDto);

            uow.Cache.SetCachedItemAsync(
                CacheKeyHelper.GetCacheKey <UserDto>(userDto.Mobile.LocalNumberWithAreaCodeInDigits), userDto);

            var userUpdatedEvent = new UserUpdatedEvent {
                UpdatedUser = userDto
            };
            var userProfile = GetUserProfile(userDto.Key, _userProfileConfig.UserProfileOriginator);

            if (!string.IsNullOrWhiteSpace(userProfile?.Body))
            {
                var basicMemberInfo = Serializer.Deserialize <BasicMemberInfo>(userProfile.Body);
                userUpdatedEvent.Roles = basicMemberInfo.Roles;
            }

            DispatchEvent(userUpdatedEvent);
        }
Exemple #2
0
        public void Process(UserUpdatedEvent @event)
        {
            var user = _users.GetById(@event.Id);

            if (user == null)
            {
                user = new User()
                {
                    Id            = @event.Id,
                    Name          = @event.Name,
                    PhoneNumber   = @event.PhoneNumber,
                    Email         = @event.Email,
                    Geo           = @event.Geo,
                    RecipientType = @event.UserType
                };
            }
            else
            {
                user.Id            = @event.Id;
                user.Name          = @event.Name;
                user.PhoneNumber   = @event.PhoneNumber;
                user.Email         = @event.Email;
                user.Geo           = @event.Geo;
                user.RecipientType = @event.UserType;
            }
            _users.Save(user);
        }
Exemple #3
0
        public void Handle(UserUpdatedEvent @event)
        {
            var account = AccountInfos.FirstOrDefault(x => x.Id == @event.UserId);

            if (account != null)
            {
            }
        }
Exemple #4
0
 private void Apply(UserUpdatedEvent @event)
 {
     FirstName  = @event.FirstName;
     LastName   = @event.LastName;
     Email      = @event.Email;
     Position   = @event.Position;
     Department = @event.Department;
     IsAdmin    = @event.IsAdmin;
 }
Exemple #5
0
        public async Task HandleAsync(UserUpdatedEvent domainEvent)
        {
            var user = await _userRepository.GetByIdAsync(domainEvent.AggregateId);

            user.EmailAddress = domainEvent.EmailAddress;
            user.Status       = domainEvent.UserStatus.ToString();

            await _userRepository.UpdateAsync(user);
        }
        private void HandleUserUpdatedEvent(UserUpdatedEvent e)
        {
            UserState    cs = e.ResultUserState;
            UserListItem newUserListItem = UserListItem.GenerateUserListItemFromUserState(cs);

            UserListUpdateCommand newCLUC = new UserListUpdateCommand(newUserListItem, e.User, e.ConnectionId);

            _logger.Info($"Updating User list Id:{cs.Id} UserName:{cs.UserName}.");
            Persist <UserListUpdateCommand>(newCLUC, postUserListItemUpdateHandler);
        }
        private async Task SendUserUpdatedEventAsync(Guid userId, string nickName, string avatar, UserType?userType)
        {
            UserUpdatedEvent @event = new UserUpdatedEvent {
                UserId = userId, NickName = nickName, Avatar = avatar, UserType = (int?)userType
            };

            _messageSession = (IMessageSession)_serviceProvider.GetService(typeof(IMessageSession));
            await _messageSession.Publish(@event);

            _logger.LogInformation("----- Published UserUpdatedEvent: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
        }
Exemple #8
0
        public IExecutionResult Create(UpdateUserCommand command)
        {
            var @event = new UserUpdatedEvent(
                command.Id,
                command.FirstName
                );

            Emit(@event);

            return(ExecutionResult.Success());
        }
Exemple #9
0
 private string Descriptify <T>(UserUpdatedEvent e) where T : UserUpdatedEvent
 {
     return(JsonConvert.SerializeObject(new
     {
         e.FirstName,
         e.LastName,
         e.Email,
         e.Department,
         e.Position,
         e.IsAdmin,
     }));
 }
        public async Task UserUpdatedEventHandler_Consume_Updates_Name()
        {
            AuthenticationContext.OpenInMemoryConnection();

            try
            {
                var userUpdatedEvent = new UserUpdatedEvent
                {
                    UserKey      = Guid.NewGuid(),
                    FirstName    = "Ellen",
                    LastName     = "Doe",
                    EmailAddress = "*****@*****.**"
                };

                var user = new User
                {
                    UserKey = userUpdatedEvent.UserKey,
                    Name    = "John Doe"
                };

                var credential = new Credential
                {
                    CredentialType = CredentialType.Email,
                    User           = user,
                    Identifier     = "*****@*****.**"
                };

                using (var context = AuthenticationContext.GetInMemoryContext())
                {
                    context.Users.Add(user);
                    context.Credentials.Add(credential);

                    context.SaveChanges();
                }

                using (var context = AuthenticationContext.GetInMemoryContext())
                {
                    var handler = new UserUpdatedEventHandler(context);
                    await handler.ConsumeAsync(userUpdatedEvent);
                }

                using (var context = AuthenticationContext.GetInMemoryContext())
                {
                    Assert.AreEqual("Ellen Doe", context.Users.Single().Name);
                    Assert.AreEqual("*****@*****.**", context.Credentials.Single().Identifier);
                }
            }
            finally
            {
                AuthenticationContext.CloseInMemoryConnection();
            }
        }
Exemple #11
0
        public async Task UserUpdatedEventHandler_Consume_Updates_Name()
        {
            CharityActionContext.OpenInMemoryConnection();

            try
            {
                var userUpdatedEvent = new UserUpdatedEvent
                {
                    UserKey      = Guid.NewGuid(),
                    FirstName    = "Ellen",
                    LastName     = "Doe",
                    EmailAddress = "*****@*****.**",
                    ProfileImage = "new image"
                };

                var charity = new Charity
                {
                    CharityKey = Guid.NewGuid()
                };

                var charityAction = new CharityAction
                {
                    OrganiserUserKey  = userUpdatedEvent.UserKey,
                    OrganiserUserName = "******",
                    OrganiserImage    = "old image",
                    Charity           = charity
                };

                using (var context = CharityActionContext.GetInMemoryContext())
                {
                    context.CharityActions.Add(charityAction);
                    context.SaveChanges();
                }

                using (var context = CharityActionContext.GetInMemoryContext())
                {
                    var handler = new UserUpdatedEventHandler(context);
                    await handler.ConsumeAsync(userUpdatedEvent);
                }

                using (var context = CharityActionContext.GetInMemoryContext())
                {
                    Assert.AreEqual("Ellen Doe", context.CharityActions.Single().OrganiserUserName);
                    Assert.AreEqual("new image", context.CharityActions.Single().OrganiserImage);
                }
            }
            finally
            {
                CharityActionContext.CloseInMemoryConnection();
            }
        }
        public async Task UserUpdatedEventHandler_Handle_Returns_Success()
        {
            DonationsContext.OpenInMemoryConnection();

            try
            {
                var user = new User {
                    UserKey      = Guid.NewGuid(),
                    ProfileImage = "PrettyImage",
                    UserName     = "******"
                };

                var Event = new UserUpdatedEvent()
                {
                    UserKey      = user.UserKey,
                    AddressLine1 = "AddressLine1",
                    AddressLine2 = "AddressLine2",
                    ProfileImage = "UglyImage",
                    BirthDate    = DateTime.UtcNow,
                    City         = "TestCity",
                    Country      = "TestCountry",
                    EmailAddress = "*****@*****.**",
                    FirstName    = "FirstTest",
                    LastName     = "LastTest",
                    PhoneNumber  = "0600000000"
                };

                using (var context = DonationsContext.GetInMemoryContext())
                {
                    context.Users.Add(user);
                    await context.SaveChangesAsync();

                    var handler = new UserUpdatedEventHandler(context);
                    await handler.ConsumeAsync(Event);
                }

                using (var context = DonationsContext.GetInMemoryContext())
                {
                    Assert.AreEqual(1, context.Users.Count());
                    Assert.AreEqual(Event.FirstName + " " + Event.LastName, context.Users.Single().UserName);
                    Assert.AreEqual(Event.ProfileImage, context.Users.Single().ProfileImage);
                    Assert.AreEqual(Event.UserKey, context.Users.Single().UserKey);
                }
            }
            finally
            {
                DonationsContext.CloseInMemoryConnection();
            }
        }
Exemple #13
0
        public async Task <ApplicationUser> EditUserAsync(EditUserRequest request, [CurrentUserGlobalState] CurrentUser currentUser)
        {
            ApplicationUser user = await _context.Users.SingleAsync(applicationUser => applicationUser.Id == currentUser.UserId.ToString());

            user.Name        = request.Name;
            user.PhoneNumber = request.PhoneNumber;
            _context.Update(user);

            var evt = new UserUpdatedEvent(user.Id, user.Name, user.PhoneNumber);
            await _eventService.SaveEventAndDbContextChangesAsync(evt);

            await _eventService.PublishEventAsync(evt);

            return(user);
        }
Exemple #14
0
        public Task ExecuteAsync(HookType type, IDomainEntityContext <User> context, CancellationToken cancellationToken)
        {
            switch (context.EditMode)
            {
            case EditMode.Create:
                context.AddEventAsync(UserCreatedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken);
                break;

            case EditMode.Update:
                context.AddEventAsync(UserUpdatedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken);
                break;

            case EditMode.Delete:
                context.AddEventAsync(UserDeletedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken);
                break;
            }
            return(Task.CompletedTask);
        }
Exemple #15
0
        public async Task UserUpdatedEventHandler_Consume_Event_Has_No_UserKey()
        {
            StoryContext.OpenInMemoryConnection();

            try
            {
                var userUpdatedEvent = new UserUpdatedEvent
                {
                    UserKey      = Guid.Empty,
                    FirstName    = "Ellen",
                    LastName     = "Doe",
                    ProfileImage = "new image"
                };

                var charityAction = new User
                {
                    UserKey      = Guid.NewGuid(),
                    Name         = "John Doe",
                    ProfileImage = "old image"
                };

                using (var context = StoryContext.GetInMemoryContext())
                {
                    context.Users.Add(charityAction);
                    context.SaveChanges();
                }

                using (var context = StoryContext.GetInMemoryContext())
                {
                    var handler = new UserUpdatedEventHandler(context);
                    await handler.ConsumeAsync(userUpdatedEvent);
                }

                using (var context = StoryContext.GetInMemoryContext())
                {
                    Assert.AreEqual("John Doe", context.Users.Single().Name);
                    Assert.AreEqual("old image", context.Users.Single().ProfileImage);
                }
            }
            finally
            {
                StoryContext.CloseInMemoryConnection();
            }
        }
Exemple #16
0
        public async Task UserUpdatedEventHandler_Consume_Event_Has_No_UserKey()
        {
            CharityContext.OpenInMemoryConnection();

            try
            {
                var userUpdatedEvent = new UserUpdatedEvent
                {
                    UserKey   = Guid.Empty,
                    FirstName = "Ellen",
                    LastName  = "Doe"
                };

                var charity = new Charity
                {
                    OwnerUserKey  = Guid.NewGuid(),
                    OwnerUserName = "******"
                };

                using (var context = CharityContext.GetInMemoryContext())
                {
                    context.Charities.Add(charity);
                    context.SaveChanges();
                }

                using (var context = CharityContext.GetInMemoryContext())
                {
                    var handler = new UserUpdatedEventHandler(context);
                    await handler.ConsumeAsync(userUpdatedEvent);
                }

                using (var context = CharityContext.GetInMemoryContext())
                {
                    Assert.AreEqual("John Doe", context.Charities.Single().OwnerUserName);
                }
            }
            finally
            {
                CharityContext.CloseInMemoryConnection();
            }
        }
Exemple #17
0
        public bool TranslateAkkaUpdateEventToExternalMessage(CommandEventMessage internalCommandEvent)
        {
            UserUpdatedEvent e = internalCommandEvent as UserUpdatedEvent;

            HTTPExternalInterface.HandleEDStateMessage(
                new HTTPDestinedCommandStateEvent(
                    MicroServices.ProcessingStatus.Processed,
                    e.Message,
                    new HTTPSourcedCommand(
                        e.CommandType.ToString(),
                        e.Area.ToString(),
                        null,
                        e.ResultUserState,
                        e.User,
                        e.ConnectionId,
                        e.Id
                        )
                    ),
                false //User only?
                );
            return(true);
        }
        public Task Handle(UserUpdatedEvent message, CancellationToken cancellationToken)
        {
            // Send some greetings e-mail

            return(Task.CompletedTask);
        }
Exemple #19
0
 public void Apply(UserUpdatedEvent domainEvent)
 {
     this.FirstName = domainEvent.FirstName;
 }
 public Task Handle(UserUpdatedEvent notification, CancellationToken cancellationToken)
 {
     return(Task.CompletedTask);
 }
Exemple #21
0
 private void UpdateFrom(UserUpdatedEvent @event)
 {
     Id     = @event.UserId;
     _name  = @event.Name;
     _email = @event.Email;
 }
 public void Handle(UserUpdatedEvent message)
 {
 }
Exemple #23
0
        public Task Handle(UserUpdatedEvent message, CancellationToken cancellationToken)
        {
            // Faça o pós adição, atualizar cache ou algo parecido??

            return(Task.CompletedTask);
        }
Exemple #24
0
 public async Task HandleAsync(UserUpdatedEvent args)
 {
     await SendNotificationAsync <Guid?, User, UserDto>(args, args.User, args.User.FullName);
 }