예제 #1
0
        /// <summary>
        ///     Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"></see>.
        /// </summary>
        /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param>
        internal void Add(DataPage item)
        {
            item.Parent = this;
            DateTime.Now.GetTimestamp();
            item.Children = new DataPageCollection(Parent, ChangeSetHelper, DatabaseHelper);

            _internalList.Add(item);

            var exists = _internalNameList.TryGetValue(item.SchemaName, out var subList);

            if (!exists)
            {
                subList = new List <string>();
                _internalNameList.Add(item.SchemaName, subList);
            }

            subList?.Add(item.Name);

            Dirty = true;
            ChangeSetHelper.AddChange(ChangeSet.Insert(item));
        }
예제 #2
0
        /// <summary>
        ///     Deletes the first occurrence of a specific object from the
        ///     <see cref="T:System.Collections.Generic.ICollection`1"></see>.
        /// </summary>
        /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param>
        /// <returns>
        ///     true if <paramref name="item">item</paramref> was successfully removed from the
        ///     <see cref="T:System.Collections.Generic.ICollection`1"></see>; otherwise, false. This method also returns false if
        ///     <paramref name="item">item</paramref> is not found in the original
        ///     <see cref="T:System.Collections.Generic.ICollection`1"></see>.
        /// </returns>
        internal bool Delete(DataPage item)
        {
            var itemRemoveResult = _internalList.Remove(item);

            _internalNameList.TryGetValue(item.SchemaName, out var nameListFiltered);

            var nameListRemoveResult = nameListFiltered?.Remove(item.Name);

            if (itemRemoveResult && nameListRemoveResult.HasValue && nameListRemoveResult.Value)
            {
                Dirty = true;
                ChangeSetHelper.AddChange(ChangeSet.Delete(item));
            }

            if (nameListFiltered?.Count == 0)
            {
                _internalNameList.Remove(item.SchemaName);
            }

            return(itemRemoveResult && nameListRemoveResult.HasValue && nameListRemoveResult.Value);
        }