コード例 #1
0
ファイル: GroupSettings.cs プロジェクト: CrushYar/UnityDisk
        public GroupSettingsContainer LoadGroupTree()
        {
            string strValue = _settings.GetValueAsString(_parameterName);

            if (String.IsNullOrEmpty(strValue))
            {
                _container = new GroupSettingsContainer()
                {
                    Items = new List <GroupSettingsItem>(), Name = "Room", IsActive = false
                };
                return(_container);
            }
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(GroupSettingsContainer), new[] {
                typeof(GroupSettingsItem),
                typeof(GroupSettingsGroup)
            });
            var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(strValue));

            using (var reader = new StreamReader(memoryStream, Encoding.UTF8))
            {
                _container = (GroupSettingsContainer)xmlSerializer.Deserialize(reader);
            }

            return(_container);
        }
コード例 #2
0
ファイル: GroupSettings.cs プロジェクト: CrushYar/UnityDisk
        public void Add(IList <string> path, GroupSettingsItem item)
        {
            string fullCurrentPath = String.Empty;
            GroupSettingsContainer itemDirectory = FindItemDirectory(path);

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

            itemDirectory.Items.Add(item);

            SaveGroupTree();
        }
コード例 #3
0
ファイル: GroupSettings.cs プロジェクト: CrushYar/UnityDisk
        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();
        }
コード例 #4
0
ファイル: GroupSettings.cs プロジェクト: CrushYar/UnityDisk
        /// <summary>
        /// Сканирует контейнер на наличие элемента
        /// </summary>
        /// <param name="container">Контейнер для анализа</param>
        /// <param name="name">Имя элемента</param>
        /// <param name="type">Тип элемента</param>
        /// <returns>Возвращает true - при наличии элемента с указанным именем и типом</returns>
        private bool NameScan(GroupSettingsContainer 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);
        }
コード例 #5
0
ファイル: GroupSettings.cs プロジェクト: CrushYar/UnityDisk
        public void SetActive(IList <string> path, string name, bool value)
        {
            string fullCurrentPath = String.Empty;
            GroupSettingsContainer itemDirectory = FindItemDirectory(path);

            GroupSettingsContainer itemForSetActive = itemDirectory.Items.FirstOrDefault(it => it.Name == name && it.Type == GroupTreeTypeEnum.Container) as GroupSettingsContainer;

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

            bool oldValue = itemForSetActive.IsActive;

            itemForSetActive.IsActive = value;

            SaveGroupTree();
        }
コード例 #6
0
ファイル: GroupSettings.cs プロジェクト: CrushYar/UnityDisk
        private GroupSettingsContainer FindItemDirectory(IList <string> path)
        {
            string fullCurrentPath = String.Empty;
            GroupSettingsContainer walkerToBottom = _container;

            foreach (var containernNme in path)
            {
                fullCurrentPath += "/" + containernNme;
                walkerToBottom   =
                    walkerToBottom.Items.First(it =>
                                               it.Name == containernNme && it.Type == GroupTreeTypeEnum.Container) as GroupSettingsContainer;
                if (walkerToBottom == null)
                {
                    throw new InvalidDataException(String.Concat("Don't found the container: '{0}'",
                                                                 fullCurrentPath));
                }
            }

            return(walkerToBottom);
        }
コード例 #7
0
ファイル: GroupSettings.cs プロジェクト: CrushYar/UnityDisk
        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();
        }
コード例 #8
0
ファイル: GroupSettings.cs プロジェクト: CrushYar/UnityDisk
        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();
        }
コード例 #9
0
ファイル: GroupSettings.cs プロジェクト: CrushYar/UnityDisk
 public GroupSettings(ISettings settings, string parameterName, GroupSettingsContainer container)
 {
     _settings      = settings;
     _parameterName = parameterName;
     _container     = container;
 }