Ejemplo n.º 1
0
        /// <summary>
        /// Populate the possible <see cref="PossibleFiniteState"/> rows
        /// </summary>
        protected override void PopulatePossibleState()
        {
            this.PossibleState.Clear();

            var defaultStateIid = (this.Thing.DefaultState == null) ? Guid.Empty : this.Thing.DefaultState.Iid;

            foreach (PossibleFiniteState thing in this.Thing.PossibleState.Where(t => t.ChangeKind != ChangeKind.Delete))
            {
                var row = new PossibleFiniteStateRowViewModel(thing, this.Session, this);
                this.PossibleState.Add(row);
                row.Index     = this.Thing.PossibleState.IndexOf(thing);
                row.IsDefault = thing.Iid == defaultStateIid;
            }

            this.SelectedDefaultState = this.PossibleState.Select(s => s.Thing).SingleOrDefault(x => x.Iid == defaultStateIid);
        }
        /// <summary>
        /// Populate the <see cref="PossibleFiniteState"/> row list
        /// </summary>
        private void PopulateFiniteState()
        {
            var currentPossibleStates = this.ContainedRows.Select(x => (PossibleFiniteState)x.Thing).ToList();
            var updatedPossibleStates = this.Thing.PossibleState.ToList();

            var newPossibleStates = updatedPossibleStates.Except(currentPossibleStates).ToList();
            var oldPossibleStates = currentPossibleStates.Except(updatedPossibleStates).ToList();

            foreach (var statelist in newPossibleStates)
            {
                var row = new PossibleFiniteStateRowViewModel(statelist, this.Session, this);
                row.Index = this.Thing.PossibleState.IndexOf(statelist);
                this.ContainedRows.Add(row);
            }

            foreach (var statelist in oldPossibleStates)
            {
                var row = this.ContainedRows.SingleOrDefault(x => x.Thing == statelist);
                if (row != null)
                {
                    this.ContainedRows.RemoveAndDispose(row);
                }
            }

            var rowsToUpdate = this.ContainedRows.Where(x => this.Thing.PossibleState.Contains(x.Thing)).ToList();

            foreach (var row in rowsToUpdate.OfType <PossibleFiniteStateRowViewModel>())
            {
                row.IsDefault = row.Thing.IsDefault;
            }

            // Reorder the list if necessary
            if (!this.Thing.PossibleState.SequenceEqual(this.ContainedRows.Select(x => x.Thing)))
            {
                this.ContainedRows.Sort((c1, c2) => this.Thing.PossibleState.FindIndex(c => c.Iid == c1.Thing.Iid) - this.Thing.PossibleState.FindIndex(c => c.Iid == c2.Thing.Iid));
            }
        }