Example #1
0
        private static bool ConvertDirectoryInfoToTreeNode(out BDirectoryTreeNode _CreatedNode, BDirectoryTreeNode _Parent, DirectoryInfo _DirectoryInfo, Action <string> _ErrorMessageAction = null)
        {
            _CreatedNode = null;
            try
            {
                _CreatedNode = new BDirectoryTreeNode(_DirectoryInfo.Name, _Parent, new List <BDirectoryTreeNode>(), EBDirectoryTreeNodeType.Directory);
                foreach (FileInfo _ChildFile in _DirectoryInfo.GetFiles())
                {
                    _CreatedNode.GetChildren().Add(new BDirectoryTreeNode(_ChildFile.Name, _CreatedNode, null, EBDirectoryTreeNodeType.File));
                }

                foreach (DirectoryInfo _ChildDirectory in _DirectoryInfo.GetDirectories())
                {
                    if (!ConvertDirectoryInfoToTreeNode(out BDirectoryTreeNode ChildDirectoryNode, _CreatedNode, _ChildDirectory))
                    {
                        _CreatedNode = null;
                        return(false);
                    }
                    _CreatedNode.GetChildren().Add(ChildDirectoryNode);
                }
            }
            catch (Exception e)
            {
                _CreatedNode = null;
                _ErrorMessageAction?.Invoke("BCommonUtilities->ConvertDirectoryInfoToTreeNode has failed with " + e.Message + ", trace: " + e.StackTrace);
                return(false);
            }
            return(true);
        }
Example #2
0
 public BDirectoryTreeNode(string _Name, BDirectoryTreeNode _Parent, List <BDirectoryTreeNode> _Children, EBDirectoryTreeNodeType _NodeType)
 {
     NodeType = _NodeType;
     Name     = _Name;
     Parent   = _Parent;
     Children = _Children;
 }
Example #3
0
 public static bool GetDirectoryTreeStructure(out BDirectoryTreeNode _ParentNode, string _DirectoryPath, Action <string> _ErrorMessageAction = null)
 {
     _ParentNode = null;
     try
     {
         if (!ConvertDirectoryInfoToTreeNode(out _ParentNode, null, new DirectoryInfo(_DirectoryPath)))
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         _ParentNode = null;
         _ErrorMessageAction?.Invoke("BCommonUtilities->GetDirectoryTreeStructure has failed with " + e.Message + ", trace: " + e.StackTrace);
         return(false);
     }
     return(_ParentNode != null);
 }