Example #1
0
        public static void StartApplication(ActorSystem actorSystem, string shardProxyRoleName)
        {
            Cluster.Get(actorSystem).RegisterOnMemberUp(() =>
            {
                //Instantiate an aggregate proxy reference to the worker node that hosts the
                //aggregates. This is the reference to proxy client commands to
                var aggregateProxy = StartUserAccountClusterProxy(actorSystem, shardProxyRoleName);

                Console.WriteLine("Press Enter To Create A Random User Account, or Q to quit.");

                var key  = Console.ReadLine();
                var quit = key?.ToUpper() == "Q";

                while (!quit)
                {
                    //Generate random, new UserAccount
                    var aggregateId              = UserAccountId.New;
                    var randomUserAccountName    = Guid.NewGuid().ToString();
                    var createUserAccountCommand = new CreateUserAccountCommand(aggregateId, randomUserAccountName);

                    //Send the command
                    aggregateProxy.Tell(createUserAccountCommand);

                    Console.WriteLine($"CreateUsrAccountCommand: Id={createUserAccountCommand.AggregateId}; Name={createUserAccountCommand.Name} Sent.");

                    Console.WriteLine("Press Enter To Create Another Random User Account, or Q to quit.");
                    key  = Console.ReadLine();
                    quit = key?.ToUpper() == "Q";
                }

                //Shut down the local actor system
                actorSystem.Terminate().Wait();
            });
        }
Example #2
0
        public async Task <IActionResult> Register([FromBody] CreateUserAccountCommand command)
        {
            var result = await this._mediator.Send(command);

            this._presenter.Populate(result);

            return(this._presenter.Result);
        }
Example #3
0
        public async Task <IActionResult> Create(RegisterRequest request)
        {
            var command = new CreateUserAccountCommand
            {
                Email           = request.Email.ToLower().Trim(),
                Password        = request.Password.Trim(),
                ConfirmPassword = request.ConfirmPassword.Trim()
            };
            await _mediator.Send(command);

            return(Created(ApiRoutes.Account.Create, ""));
        }
Example #4
0
        static void Main(string[] args)
        {
            var system = ActorSystem.Create("useraccount-example");

            var aggregateManager = system.ActorOf(Props.Create(() => new UserAccountAggregateManager()));

            var aggregateId = UserAccountId.New;
            var command     = new CreateUserAccountCommand(aggregateId, "foo user");

            aggregateManager.Tell(command);

            while (true)
            {
            }
        }
Example #5
0
        public void Create(CreateUserAccountCommand cmd, IUserNameValidator userNameValidator, PasswordPolicy passwordPolicy)
        {
            Condition.Requires(cmd, "cmd").IsNotNull();
            Condition.Requires(userNameValidator, "userNameValidator").IsNotNull();
            Condition.Requires(passwordPolicy, "passwordPolicy").IsNotNull();

            if (!userNameValidator.IsValidUserName(cmd.UserName))
            {
                throw new InvalidUserNameException(cmd.UserName);
            }

            Publish(new UserAccountCreatedEvent(cmd.Id, cmd.UserName, cmd.EMail));

            if (cmd.Password != null)
            {
                SetPassword(cmd.Password, passwordPolicy);
            }
        }
Example #6
0
        public static void Main(string[] args)
        {
            //Get configuration file using Akkatecture's defaults as fallback
            var path       = Environment.CurrentDirectory;
            var configPath = Path.Combine(path, "client.conf");
            var config     = ConfigurationFactory.ParseString(File.ReadAllText(configPath))
                             .WithFallback(AkkatectureClusteringDefaultSettings.DefaultConfig());

            //Create actor system
            var clustername        = config.GetString("akka.cluster.name");
            var shardProxyRoleName = config.GetString("akka.cluster.singleton-proxy.role");
            var actorSystem        = ActorSystem.Create(clustername, config);

            //Instantiate an aggregate proxy reference to the worker node that hosts the
            //aggregates. This is the reference to proxy client commands to
            var aggregateProxy = StartUserAccountClusterProxy(actorSystem, shardProxyRoleName);

            Console.WriteLine("Press Enter To Create A Random User Account, or Q to quit.");

            var key  = Console.ReadLine();
            var quit = key?.ToUpper() == "Q";

            while (!quit)
            {
                //Generate random, new UserAccount
                var aggregateId              = UserAccountId.New;
                var randomUserAccountName    = Guid.NewGuid().ToString();
                var createUserAccountCommand = new CreateUserAccountCommand(aggregateId, randomUserAccountName);

                //Send the command
                aggregateProxy.Tell(createUserAccountCommand);

                Console.WriteLine($"CreateUsrAccountCommand: Id={createUserAccountCommand.AggregateId}; Name={createUserAccountCommand.Name} Sent.");

                Console.WriteLine("Press Enter To Create Another Random User Account, or Q to quit.");
                key  = Console.ReadLine();
                quit = key?.ToUpper() == "Q";
            }

            //Shut down the local actor system
            actorSystem.Terminate().Wait();
            Console.WriteLine("Akkatecture.Examples.ClusterClient Exiting.");
        }
Example #7
0
        public void CanCreateAndReloadUserAccount()
        {
            // Arrange
            CreateUserAccountCommand cmd = new CreateUserAccountCommand(new UserAccountId(Guid.NewGuid()), "Johny", new EMail("*****@*****.**"), "123456");

            // Act
            UserAccountApplicationService.Handle(cmd);
            var user = Repository.Get(cmd.Id);

            // Assert
            Assert.IsNotNull(user);
            Assert.IsNotNull(user.Aggregate);
            Assert.AreEqual(cmd.Id, user.Aggregate.State.Id);
            Assert.AreEqual(cmd.UserName, user.Aggregate.State.UserName);
            Assert.AreEqual(cmd.EMail, user.Aggregate.State.EMail);
            Assert.IsNotNull(user.Aggregate.State.PasswordSalt);
            Assert.IsNotNull(user.Aggregate.State.PasswordHash);
            Assert.AreEqual(Configuration.Settings.PasswordHashAlgorithm, user.Aggregate.State.PasswordHashAlgorithm);
        }
Example #8
0
        public static void Main(string[] args)
        {
            //Create actor system
            var system = ActorSystem.Create("useraccount-example");


            //Build create user account aggregate command
            var aggregateId = UserAccountId.New;
            var createUserAccountCommand = new CreateUserAccountCommand(aggregateId, "foo bar");

            //Send command, this is equivalent to command.publish() in other cqrs frameworks
            //system.PublishCommandAsync(createUserAccountCommand);

            var changeNameCommand = new UserAccountChangeNameCommand(aggregateId, "foo bar baz");

            //system.PublishCommandAsync(changeNameCommand);

            //block end of program
            Console.ReadLine();
        }
Example #9
0
        public static void Main(string[] args)
        {
            //Create actor system
            var system = ActorSystem.Create("useraccount-example");

            //Create supervising aggregate manager for UserAccount aggregate root actors
            var aggregateManager = system.ActorOf(Props.Create(() => new UserAccountAggregateManager()));

            //Build create user account aggregate command
            var aggregateId = UserAccountId.New;
            var createUserAccountCommand = new CreateUserAccountCommand(aggregateId, "foo bar");

            //Send command, this is equivalent to command.publish() in other cqrs frameworks
            aggregateManager.Tell(createUserAccountCommand);

            var changeNameCommand = new UserAccountChangeNameCommand(aggregateId, "foo bar baz");

            aggregateManager.Tell(changeNameCommand);

            //block end of program
            Console.ReadLine();
        }
Example #10
0
 public bool Execute(CreateUserAccountCommand command)
 {
     Create(command.Name);
     return(true);
 }
Example #11
0
 public void Handle(CreateUserAccountCommand cmd)
 {
     Update(cmd, user => user.Create(cmd, UserNameValidator, Configuration.Settings.GetPasswordPolicy()));
 }
Example #12
0
 public IExecutionResult Execute(CreateUserAccountCommand command)
 {
     Create(command.Name);
     return(ExecutionResult.Success());
 }