Example #1
0
        private Task UpdateSequenceAsync(ActionChangeList change, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (change == null)
            {
                throw new ArgumentNullException(nameof(change));
            }

            // Initialize sequence if needed
            var newSequence = !this.Actions.Any();

            // Update sequence
            switch (change.ChangeType)
            {
            case ActionChangeType.InsertActions:
                // Insert at the beginning, being careful to not change the reference to this.Actions instance,
                // since it is tied to the state.
                var newActions = new List <ActionState>(change.Actions);
                newActions.AddRange(this.Actions);
                this.Actions.Clear();
                this.Actions.AddRange(newActions);
                break;

            case ActionChangeType.AppendActions:
            case ActionChangeType.ReplaceSequence:
                this.Actions.AddRange(change.Actions);
                break;
            }

            return(Task.CompletedTask);
        }
        /// <summary>
        /// Queues up a set of changes that will be applied when ApplyChanges is called.
        /// </summary>
        /// <param name="changes">Plan changes to queue up.</param>
        public void QueueChanges(ActionChangeList changes)
        {
            // Pull change lists from turn context
            var queue = this.Changes ?? new List <ActionChangeList>();

            queue.Add(changes);

            // Save back changes to turn context
            Changes = queue;
        }