Пример #1
0
        public bool Remove(T item, NestedSetRemoveChildAction childAction)
        {
            // Does the item have child items?
            int correctionRequired = -2;

            if (_values[item].Left + 1 < _values[item].Right)
            {
                // Yes. What do we do?

                if (childAction == NestedSetRemoveChildAction.ThrowException)
                {
                    throw new NotSupportedException("Unable to remove item due to child items.");
                }
                if (childAction == NestedSetRemoveChildAction.ReturnFalse)
                {
                    return(false);
                }

                if (childAction == NestedSetRemoveChildAction.RecursiveDelete)
                {
                    correctionRequired = _values[item].Left - _values[item].Right - 1;

                    for (int i = _values[item].Left + 1; i < _values[item].Right; i++)
                    {
                        _values.Remove(_positionCache[i]);
                    }
                }
                else if (childAction == NestedSetRemoveChildAction.MoveUpGeneration)
                {
                    for (int i = _values[item].Left + 1; i < _values[item].Right; i++)
                    {
                        NestedSetData workingData = _values[_positionCache[i]];
                        workingData.Left  -= 1;
                        workingData.Right -= 1;

                        // Replace the value
                        _values.Remove(_positionCache[i]);
                        _values.Add(_positionCache[i], workingData);
                    }
                }
            }

            for (int i = _values[item].Right + 1; i < _positionCache.Length; i++)
            {
                NestedSetData workingData = _values[_positionCache[i]];
                workingData.Left  += correctionRequired;
                workingData.Right += correctionRequired;

                // Replace the value
                _values.Remove(_positionCache[i]);
                _values.Add(_positionCache[i], workingData);
            }
            Rebuild();

            return(true);
        }
Пример #2
0
 internal Navigator RemoveCategory(Category category, NavigatorTreeSearchMode treeSearchMode = NavigatorTreeSearchMode.PublicFirst, NestedSetRemoveChildAction childAction = NestedSetRemoveChildAction.MoveUpGeneration)
 {
     switch (treeSearchMode)
     {
         case NavigatorTreeSearchMode.PublicOnly:
             {
                 if (!_publicCategories.ContainsKey(category.IdString))
                     throw new NavigatorException("This instance of Navigator does not contain a \"" +
                                                  category.IdString + "\" category. SearchMode: PublicOnly");
                 _publicCategories.Remove(category.IdString, childAction);
                 break;
             }
         case NavigatorTreeSearchMode.GuestOnly:
             {
                 if (!_guestCategories.ContainsKey(category.IdString))
                     throw new NavigatorException("This instance of Navigator does not contain a \"" +
                                                  category.IdString + "\" category. SearchMode: GuestOnly");
                 _guestCategories.Remove(category.IdString, childAction);
                 break;
             }
         case NavigatorTreeSearchMode.PublicFirst:
             {
                 if (!_publicCategories.ContainsKey(category.IdString))
                     if (!_guestCategories.ContainsKey(category.IdString))
                         throw new NavigatorException("This instance of Navigator does not contain a \"" +
                                                      category.IdString + "\" category. SearchMode: PublicFirst");
                     else
                         _guestCategories.Remove(category.IdString, childAction);
                 else
                     _publicCategories.Remove(category.IdString, childAction);
                 break;
             }
         case NavigatorTreeSearchMode.GuestFirst:
             {
                 if (!_guestCategories.ContainsKey(category.IdString))
                     if (!_publicCategories.ContainsKey(category.IdString))
                         throw new NavigatorException("This instance of Navigator does not contain a \"" +
                                                      category.IdString + "\" category. SearchMode: GuestFirst");
                     else
                         _publicCategories.Remove(category.IdString, childAction);
                 else
                     _guestCategories.Remove(category.IdString, childAction);
                 break;
             }
     }
     return this;
 }
Пример #3
0
        internal Navigator RemoveCategory(Category category, NavigatorTreeSearchMode treeSearchMode = NavigatorTreeSearchMode.PublicFirst, NestedSetRemoveChildAction childAction = NestedSetRemoveChildAction.MoveUpGeneration)
        {
            switch (treeSearchMode)
            {
            case NavigatorTreeSearchMode.PublicOnly:
            {
                if (!_publicCategories.ContainsKey(category.IdString))
                {
                    throw new NavigatorException("This instance of Navigator does not contain a \"" +
                                                 category.IdString + "\" category. SearchMode: PublicOnly");
                }
                _publicCategories.Remove(category.IdString, childAction);
                break;
            }

            case NavigatorTreeSearchMode.GuestOnly:
            {
                if (!_guestCategories.ContainsKey(category.IdString))
                {
                    throw new NavigatorException("This instance of Navigator does not contain a \"" +
                                                 category.IdString + "\" category. SearchMode: GuestOnly");
                }
                _guestCategories.Remove(category.IdString, childAction);
                break;
            }

            case NavigatorTreeSearchMode.PublicFirst:
            {
                if (!_publicCategories.ContainsKey(category.IdString))
                {
                    if (!_guestCategories.ContainsKey(category.IdString))
                    {
                        throw new NavigatorException("This instance of Navigator does not contain a \"" +
                                                     category.IdString + "\" category. SearchMode: PublicFirst");
                    }
                    else
                    {
                        _guestCategories.Remove(category.IdString, childAction);
                    }
                }
                else
                {
                    _publicCategories.Remove(category.IdString, childAction);
                }
                break;
            }

            case NavigatorTreeSearchMode.GuestFirst:
            {
                if (!_guestCategories.ContainsKey(category.IdString))
                {
                    if (!_publicCategories.ContainsKey(category.IdString))
                    {
                        throw new NavigatorException("This instance of Navigator does not contain a \"" +
                                                     category.IdString + "\" category. SearchMode: GuestFirst");
                    }
                    else
                    {
                        _publicCategories.Remove(category.IdString, childAction);
                    }
                }
                else
                {
                    _guestCategories.Remove(category.IdString, childAction);
                }
                break;
            }
            }
            return(this);
        }