Exemplo n.º 1
0
        /// <inheritdoc />
        public ChangeSet GetChangeSet(ChangePath path, bool commit = false)
        {
            if (!HasChanges)
            {
                return(null);
            }

            path = path.WithTarget(ChangeTarget.Collection);

            var changes = new ChangeSet();

            foreach (var item in Items.Where(i => i.HasChanges))
            {
                changes.Merge(
                    item.GetChangeSet(path.AppendIndex(item.Index), commit));
            }

            foreach (var removed in Removed)
            {
                changes.Merge(
                    removed.GetChangeSet(path.AppendIndex(removed.Index), commit));
            }

            if (commit)
            {
                Removed.Clear();
            }

            return(changes);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="ChangeSet"/> using the specified path and values.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="values">The values.</param>
        /// <returns></returns>
        public static ChangeSet Create(ChangePath path, params ChangeValue[] values)
        {
            var changeSet = new ChangeSet();

            changeSet.Append(path, values);
            return(changeSet);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Determines whether or not the <see cref="ChangePath"/> starts with
        /// the provided <paramref name="changePath"/>.
        /// </summary>
        /// <param name="changePath">The <see cref="ChangePath"/> to check that is starts with.</param>
        /// <returns></returns>
        public bool StartsWith(ChangePath changePath)
        {
            using (var enumerator1 = changePath.Parts.GetEnumerator())
                using (var enumerator2 = Parts.GetEnumerator())
                {
                    while (enumerator1.MoveNext())
                    {
                        // If we can't move any further with the current path,
                        // then the path we are checking is longer and cannot
                        // possible be a match.
                        if (!enumerator2.MoveNext())
                        {
                            return(false);
                        }

                        // If a part doesn't match, then it doesn't start the path we are checking.
                        if (!Equals(enumerator1.Current, enumerator2.Current))
                        {
                            return(false);
                        }
                    }

                    // We matched all of the parts of the path we were checking,
                    // so it does start with the path.
                    return(true);
                }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Appends the path and values to the <see cref="ChangeSet"/>.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="values">The values.</param>
        public void Append(ChangePath path, params ChangeValue[] values)
        {
            if (!ContainsKey(path))
            {
                this[path] = new List <ChangeValue>();
            }

            this[path].AddRange(values);
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public ChangeSet GetChangeSet(ChangePath path, bool commit = false)
        {
            if (!HasChanges)
            {
                return(null);
            }

            var changes = new ChangeSet();

            foreach (var change in Changes)
            {
                changes.Merge(change.Value.GetChangeSet(path.AppendProperty(change.Key), commit));
            }

            return(changes);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Commits the changes.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="path">The path the change set represents.</param>
 /// <returns>A <see cref="ChangeSet"/> containing the committed changes.</returns>
 public static ChangeSet CommitChanges(this ITracksChanges target, ChangePath path)
 {
     return(target.GetChangeSet(path, commit: true));
 }