/// <summary>
 /// The add state machine.
 /// </summary>
 /// <param name="record">
 /// The record. 
 /// </param>
 private void AddOrUpdateStateMachine(ActivityStateRecord record)
 {
     var history = this.maxHistory;
     this.currentStateMachine = this.stateMachines.AddOrUpdate(
         GetKey(record),
         s =>
         new StateMachineInfo(history)
             {
                 Name = record.Activity.Name,
                 InstanceState = record.GetInstanceState(),
                 InstanceId = record.InstanceId
             },
         (s, info) =>
             {
                 info.InstanceState = record.GetInstanceState();
                 return info;
             });
 }
        /// <summary>
        /// Updates the state info based on the record
        /// </summary>
        /// <param name="record">
        /// The activity state record 
        /// </param>
        internal void UpdateState(ActivityStateRecord record)
        {
            this.InstanceState = record.GetInstanceState();
            switch (this.InstanceState)
            {
                case ActivityInstanceState.Executing:
                    break;
                case ActivityInstanceState.Closed:
                    this.CurrentState = null;
                    this.possibleTransitions = null;

                    break;
                case ActivityInstanceState.Canceled:
                    this.CurrentState = null;
                    this.possibleTransitions = null;
                    break;
                case ActivityInstanceState.Faulted:
                    this.CurrentState = null;
                    this.possibleTransitions = null;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }