Пример #1
0
        private void PostUpsertHandler(ClientUpsertCommand c)
        {
            ClientState cs = c.ClientStateData;

            _ActorState = cs;
            AutoSaveSnashot(false);
            _logger.Info($"Updated/Inserted {cs.DocumentType} for id:{_ActorState.Id}");
            ClientUpsertedEvent message = new ClientUpsertedEvent(_ActorState.Clone(), c.User, c.ConnectionId);

            Sender.Tell(message, Self);
            NotifyCommandEventSubscribers(message);
        }
Пример #2
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 <ClientInsertCommand>(c => InsertNewClientCommand(c));
            Command <ClientUpsertCommand>(c => UpsertClientCommand(c));
            Command <ClientUpdateCommand>(c => UpdateClientCommand(c));
            Command <ClientDeleteCommand>(c => DeleteClientCommand(c));
            Command <ClientUnDeleteCommand>(c => UnDeleteClientCommand(c));

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

            // Requests
            Command <ClientGetStateRequest>(r => {
                Sender.Tell(new ClientGetStateResponse(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 Received unhandled 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.");
        }
Пример #3
0
 private bool InsertNewClientCommand(ClientInsertCommand c)
 {
     if (c.ClientStateData.Name == null || c.ClientStateData.Name == "")
     {
         Sender.Tell(new ClientFailedInsertEvent("UserName field cannot be blank(or null).", c.ClientStateData, c.User, c.ConnectionId));
         _logger.Error($"While insert PersistenceId: {PersistenceId} client name is missing.");
     }
     if (c.ClientStateData.Id == null || c.ClientStateData.Id == "")
     {
         _ActorState = new ClientState(PersistenceId, c.ClientStateData);
         AutoSaveSnashot(true);
         _logger.Info($"Inserted {_ActorState.DocumentType} for id:{_ActorState.Id}");
         ClientInsertedEvent message = new ClientInsertedEvent(_ActorState.Clone(), c.User, c.ConnectionId);
         Sender.Tell(message, Self);
         NotifyCommandEventSubscribers(message);
     }
     return(true);
 }