Example #1
0
        public void Copy(IList <string> path, string name, GroupTreeTypeEnum type, IList <string> otherPath)
        {
            string     fullCurrentPath   = String.Empty;
            IContainer itemDirectoryFrom = FindItemDirectory(path);
            IContainer itemDirectoryTo   = FindItemDirectory(otherPath);

            IGroupTreeItem itemForCopy =
                itemDirectoryFrom.Items.FirstOrDefault(it => it.Name == name && it.Type == type);

            if (itemForCopy == null)
            {
                throw new DirectoryNotFoundException();
            }

            if (NameScan(itemDirectoryTo, itemForCopy.Name, itemForCopy.Type))
            {
                throw new ArgumentException("Element has already been");
            }

            IGroupTreeItem newItem = itemForCopy.Clone();

            newItem.Parent = itemDirectoryTo;
            itemDirectoryTo.Items.Add(newItem);

            _settings.Copy(path, name, type, otherPath);

            SpaceSize oldSize = new SpaceSize(_groupTree.Size);

            _groupTree.LoadSizeInfo();
            SpaceSize newSize = new SpaceSize(_groupTree.Size);

            OnChangedStructureEvent(newItem, otherPath, RegistryActionEnum.Added);
            OnChangedSizeEvent(oldSize, newSize, GroupTreeSizeChangedEnum.ItemCopied);
        }
Example #2
0
        public void Delete(IList <string> path, string name, GroupTreeTypeEnum type)
        {
            string fullCurrentPath = String.Empty;
            GroupSettingsContainer itemDirectory = FindItemDirectory(path);

            GroupSettingsItem itemForDelete = itemDirectory.Items.FirstOrDefault(it => it.Name == name && it.Type == type);

            if (itemForDelete == null)
            {
                throw new DirectoryNotFoundException();
            }

            itemDirectory.Items.Remove(itemForDelete);

            SaveGroupTree();
        }
Example #3
0
        /// <summary>
        /// Сканирует контейнер на наличие элемента
        /// </summary>
        /// <param name="container">Контейнер для анализа</param>
        /// <param name="name">Имя элемента</param>
        /// <param name="type">Тип элемента</param>
        /// <returns>Возвращает true - при наличии элемента с указанным именем и типом</returns>
        private bool NameScan(IContainer container, string name, GroupTreeTypeEnum type)
        {
            int hashName = name.GetHashCode();

            foreach (var item in container.Items)
            {
                if (item.Type != type)
                {
                    continue;
                }
                if (item.Name.GetHashCode() == hashName)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #4
0
        public void Rename(IList <string> path, string oldName, GroupTreeTypeEnum type, string newName)
        {
            string fullCurrentPath = String.Empty;
            GroupSettingsContainer itemDirectory = FindItemDirectory(path);

            GroupSettingsItem itemForRename = itemDirectory.Items.FirstOrDefault(it => it.Name == oldName && it.Type == type);

            if (itemForRename == null)
            {
                throw new DirectoryNotFoundException();
            }

            if (NameScan(itemDirectory, newName, type))
            {
                throw new ArgumentException("Element has already been");
            }

            itemForRename.Name = newName;

            SaveGroupTree();
        }
Example #5
0
        public void Copy(IList <string> path, string name, GroupTreeTypeEnum type, IList <string> otherPath)
        {
            string fullCurrentPath = String.Empty;
            GroupSettingsContainer itemDirectoryFrom = FindItemDirectory(path);
            GroupSettingsContainer itemDirectoryTo   = FindItemDirectory(otherPath);

            GroupSettingsItem itemForCopy = itemDirectoryFrom.Items.FirstOrDefault(it => it.Name == name && it.Type == type);

            if (itemForCopy == null)
            {
                throw new DirectoryNotFoundException();
            }

            if (NameScan(itemDirectoryTo, itemForCopy.Name, itemForCopy.Type))
            {
                throw new ArgumentException("Element has already been");
            }

            itemDirectoryTo.Items.Add(itemForCopy);

            SaveGroupTree();
        }
Example #6
0
        public void Delete(IList <string> path, string name, GroupTreeTypeEnum type)
        {
            string     fullCurrentPath = String.Empty;
            IContainer itemDirectory   = FindItemDirectory(path);

            IGroupTreeItem itemForDelete = itemDirectory.Items.FirstOrDefault(it => it.Name == name && it.Type == type);

            if (itemForDelete == null)
            {
                throw new DirectoryNotFoundException();
            }

            itemDirectory.Items.Remove(itemForDelete);
            _settings.Delete(path, name, type);

            SpaceSize oldSize = new SpaceSize(_groupTree.Size);

            _groupTree.LoadSizeInfo();
            SpaceSize newSize = new SpaceSize(_groupTree.Size);

            OnChangedStructureEvent(itemForDelete, path, RegistryActionEnum.Removed);
            OnChangedSizeEvent(oldSize, newSize, GroupTreeSizeChangedEnum.ItemDeleted);
        }