Example #1
0
        /// <summary>
        /// The command processing state sets this actor ready to receive any command from other actors.
        /// </summary>
        private void CommandProcessing()
        {
            _logger.Info($"{PersistenceId} Getting Ready.");

            // Commands
            Command <UserInsertCommand>(c => {
                _ActorState = new UserState(PersistenceId, c.UserStateData);

                AutoSaveSnapshot(true);

                _logger.Debug($"User's :{c.User} insert command recorded for User id:{_ActorState.Id}.");

                NotifyCommandEventSubscribers(new UserInsertRecordedEvent(Sender, c, c.User, c.ConnectionId));
            });

            Command <UserUpsertCommand>(c => { Persist <UserUpsertCommand>(c, PostUpsertHandler); });

            Command <UserUpdateCommand>(c => { Persist <UserUpdateCommand>(c, PostUpdateHandler); });

            Command <UserDeleteCommand>(c => { Persist <UserDeleteCommand>(c, PostDeleteHandler); });

            Command <UserUnDeleteCommand>(c => { Persist <UserUnDeleteCommand>(c, PostUnDeleteHandler); });

            //Persistence layer messages
            Command <SaveSnapshotSuccess>(c => HandleSuccessfulSnapshotSave(c));
            Command <SaveSnapshotFailure>(c => HandleUnSuccessfulSnapshotSave(c));

            // Requests
            Command <UserGetStateRequest>(r => {
                Sender.Tell(new UserGetStateResponse(Sender, _ActorState.Clone(), r));
            });
            Command <SubscribeForCommandEvents>(r => HandleCommandEventsSubscriptionRequest(r));
            Command <UnSubscribeForCommandEvents>(r => HandleCommandEventsUnSubscribeRequest(r));

            // Configuration
            Command <SetSnapshotTriggerCount>(c => { Persist <SetSnapshotTriggerCount>(c, SetSnapshotTriggerConfigurationValue); });
            Command <SetInactivityFlushSec>(c => { Persist <SetInactivityFlushSec>(c, SetInactivityFlushSecConfigurationValue); });

            // General String messages
            Command <string>(s => HandleStringCommand(s));

            // This catch all will log if there are any weird unhandled messages.
            Command <object>(message =>
            {
                _logger.Debug($"In \"Command\" state ignoring message from:{Sender.Path.ToStringWithAddress()} Unhandled Message:{message.GetType().Name}");
            });

            // Pull all the messages that where not handled during recovery.
            Stash.UnstashAll();

            _logger.Info($"{PersistenceId} Ready.");
        }