private void ConfigureMachine()
        {
            machine = new StateMachine <TicketSimulationStateType, TicketSimulationTriggerType>(
                () => this.state,
                s => this.state = s
                );

            // this state machine code is modified from https://github.com/dotnet-state-machine/stateless/tree/dev/example/BugTrackerExample
            // under the Apache 2.0 license: https://github.com/dotnet-state-machine/stateless/blob/dev/LICENSE
            machine.OnTransitionedAsync(LogTransitionAsync <TicketSimulationStateType, TicketSimulationTriggerType>);

            machine.Configure(TicketSimulationStateType.None)
            .Permit(TicketSimulationTriggerType.Create, TicketSimulationStateType.Created)
            ;

            machine.Configure(TicketSimulationStateType.Created)
            .Permit(TicketSimulationTriggerType.Initialize, TicketSimulationStateType.Initialized)
            .OnEntryAsync(async() => await OnCreated())
            ;

            initializedTrigger = machine.SetTriggerParameters <Guid, SimulationType>(TicketSimulationTriggerType.Initialize);
            machine.Configure(TicketSimulationStateType.Initialized)
            .Permit(TicketSimulationTriggerType.Void, TicketSimulationStateType.Voided)
            .Permit(TicketSimulationTriggerType.Render, TicketSimulationStateType.Rendered)
            .Permit(TicketSimulationTriggerType.Recieve, TicketSimulationStateType.Recieved)
            .OnEntryFromAsync(initializedTrigger, (checkoutSessionRefId, simulationType) => OnInitialized(checkoutSessionRefId, simulationType))
            ;

            machine.Configure(TicketSimulationStateType.Voided)
            .SubstateOf(TicketSimulationStateType.Initialized)
            .Permit(TicketSimulationTriggerType.Kill, TicketSimulationStateType.DeadManWalking)
            .OnEntryAsync(async() => await OnVoided())
            //.OnExitAsync(() => OnDeadManWalking())
            ;
        }
        private async Task OnInitialized(Guid checkoutSessionRefId, SimulationType simulationType)
        {
            this.stateFlags = this.stateFlags | TicketSimulationStateType.Initialized;

            // map the values
            this._TicketStatus.CheckoutSessionRefId = checkoutSessionRefId;
            //this._TicketStatus.SimulationType = simulationType;

            await AddOrUpdateEntityStateAsync();

            ActorEventSource.Current.ActorMessage(this, $"Actor [{this.GetActorReference().ActorId.GetGuidId()}] initialized.");
        }
        private async Task OnVoided()
        {
            if (!this.stateFlags.HasFlag(TicketSimulationStateType.Voided))
            {
                this.stateFlags = this.stateFlags | TicketSimulationStateType.Voided;

                Debug.Assert(state == machine.State);

                this._TicketStatus.VoidedOn = DateTimeOffset.UtcNow;

                await AddOrUpdateEntityStateAsync();
            }
        }
        private async Task OnCreated()
        {
            if (!this.stateFlags.HasFlag(TicketSimulationStateType.Created))
            {
                // Only way to clean up the Actor Instance so do it first
                await RegisterKillMeReminder();

                this.stateFlags = this.stateFlags | TicketSimulationStateType.Created;

                Debug.Assert(state == machine.State);

                this._TicketStatus = new TicketStatus()
                {
                    TicketRefId = this.GetActorReference().ActorId.GetGuidId()
                };

                await AddOrUpdateEntityStateAsync();

                await StateManager.SaveStateAsync();
            }
        }