public void DeleteChildCategory(IMasterFormsCategory category)
        {
            // Check
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            if (!_childCategories.Contains(category))
            {
                throw new ArgumentException("Category not child of this category", "category");
            }

            DiskMasterFormsCategoryExample diskCategory = category as DiskMasterFormsCategoryExample;

            if (diskCategory == null)
            {
                throw new Exception("Invalid category type");                   // cast above failed
            }
            // Call clear to delete all children of this category
            category.Clear();

            // Remove it from the list
            _childCategories.Remove(category);
        }
Esempio n. 2
0
        private void DiskMasterFormRepositoryInternal(RasterCodecs rasterCodecsInstance, string rootPath)
        {
            string path = System.IO.Path.GetFullPath(rootPath);

            // Check if we need to create the root directory
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            _rasterCodecsInstance = rasterCodecsInstance;
            _path = path;
            // Create the root category
            _rootCategory = new DiskMasterFormsCategoryExample(this, "root", _path, null);
            Refresh();
        }
        public IMasterFormsCategory AddChildCategory(string name)
        {
            string dir = System.IO.Path.Combine(_path, name);

            // Check if already exists
            if (Directory.Exists(dir))
            {
                throw new ArgumentException(string.Format("A category with the name '{0}' already exists", name), "name");
            }

            // Create the directory
            Directory.CreateDirectory(dir);

            // Add it to the child categories
            DiskMasterFormsCategoryExample cat = new DiskMasterFormsCategoryExample(_repository, name, dir, this);

            _childCategories.AddCategory(cat);
            return(cat);
        }
        internal void Refresh()
        {
            // Clear the collections
            _childCategories.Clear();
            _masterForms.Clear();

            // Read all the master forms in here
            string[] files = Directory.GetFiles(_path, "*.bin");
            foreach (string file in files)
            {
                string name = System.IO.Path.GetFileNameWithoutExtension(file);
                DiskMasterFormExample masterForm = new DiskMasterFormExample(_repository, name, System.IO.Path.Combine(_path, name), this);
                _masterForms.AddMasterForm(masterForm);
            }

            // Read all the directories
            string[] dirs = Directory.GetDirectories(_path);
            foreach (string dir in dirs)
            {
                DiskMasterFormsCategoryExample category = new DiskMasterFormsCategoryExample(_repository, System.IO.Path.GetFileNameWithoutExtension(dir), dir, this);
                _childCategories.AddCategory(category);
                category.Refresh();
            }
        }