Exemplo n.º 1
0
        /// <summary>
        /// Enumerate the allowed object types and, for each, the list of objects for that type
        /// </summary>
        /// <param name="app">Access application</param>
        /// <exception cref="ArgumentNullException"> if <paramref name="app"/> is null</exception>
        private void FillObjectTree(AccessIO.AccessApp app)
        {
            //TODO: Do the work in background
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }

            const string key = "db";

            Images                = new TreeImages(AccessApp.ContainersFactory(fileName));
            tree.ImageList        = Images.ImageList;
            tree.ImageKey         = key;
            tree.SelectedImageKey = key;

            tree.Nodes.Clear();
            TreeNode root = tree.Nodes.Add(Path.GetFileName(app.FileName));

            root.ToolTipText = app.FileName;
            foreach (ContainerNames container in app.AllowedContainers)
            {
                TreeNode subItem = root.Nodes.Add(container.DisplayPluralName);
                subItem.ImageKey         = container.DefaultExtension.ToString();
                subItem.SelectedImageKey = container.DefaultExtension.ToString();
                foreach (IObjecOptions item in app.LoadObjectNames(container.InvariantName))
                {
                    TreeNode node = new TreeNode(item.Name);
                    node.Tag              = item;
                    node.ImageKey         = app.AllowedContainers.Find(item.ObjectType).FileExtension.ToString();
                    node.SelectedImageKey = node.ImageKey;
                    subItem.Nodes.Add(node);
                }
            }
        }
Exemplo n.º 2
0
        private void FillTree(string rootPath)
        {
            if (String.IsNullOrEmpty(rootPath))
            {
                return;
            }

            if (!Directory.Exists(rootPath))
            {
                throw new ArgumentException(Properties.Resources.RootPathNotValid);
            }

            tree.Nodes.Clear();

            TreeNode rootNode = new TreeNode(BuildRootNodeText(rootPath));

            tree.Nodes.Add(rootNode);

            //Get the list of containers depending on the 'database properties' file
            //If do not exists that file, containers will be null and we don't know what folders structure should to expect
            Containers containers = AccessApp.ContainersFactory(rootNode.Text);

            if (containers == null)
            {
                rootNode.Nodes.Add(Properties.Resources.EmptyFileStructure);
                tree.CheckBoxes = false;
                return;
            }
            else
            {
                tree.CheckBoxes = true;
            }

            const string key = "folder";

            Images                = new TreeImages(containers);
            tree.ImageList        = Images.ImageList;
            tree.ImageKey         = key;
            tree.SelectedImageKey = key;

            DirectoryInfo rootDirectory             = new DirectoryInfo(rootPath);
            IEnumerable <DirectoryInfo> directories = rootDirectory.EnumerateDirectories();

            foreach (ContainerNames names in containers)
            {
                TreeNode node = rootNode.Nodes.Add(names.InvariantName, names.InvariantName);
                node.ImageKey         = names.DefaultExtension.ToString();
                node.SelectedImageKey = node.ImageKey;

                DirectoryInfo di = directories.FirstOrDefault <DirectoryInfo>(d => d.Name == names.InvariantName);
                if (di != null)
                {
                    FillContainerFiles(di, node, names.ObjectTypes);
                }
            }
        }