Exemplo n.º 1
0
        private void LoadRoots()
        {
            //Get all expanded nodes
            List <ITreeItem> oldExpanded = new List <ITreeItem>();

            if (ExpandedNodes.Count > 0)
            {
                foreach (ITreeItem item in ExpandedNodes)
                {
                    oldExpanded.Add(item);
                }
                oldExpanded = new List <ITreeItem>(oldExpanded.OrderBy(x => x.Level));
            }

            //Clean tree
            foreach (ITreeItem item in nodeDict.Values)
            {
                UnSubscribeEvents(item);
            }
            nodeDict.Clear();
            ClearTree();

            //Get drives
            ActionResult <IEnumerable <DriveInfo> > diResult = DirectoryCrawler.GetDrivesReady();

            if (diResult.Successful)
            {
                foreach (DriveInfo item in diResult.Result)
                {
                    DriveTreeItemViewModel vm = new DriveTreeItemViewModel(item);
                    AddToTree(vm);
                    nodeDict.Add(vm.Path.ToLower(), vm);
                    vm.Expanded  += OnVmExpanded;
                    vm.Collapsed += OnVmCollapsed;
                    //create children for root nodes
                    CreateSubFolders(vm);
                }
            }
            //else
            //{
            //    logger.Log(LogFactory.CreateWarningMessage(diResult.GetComments()));
            //    return;
            //}

            if (oldExpanded.Count > 0)
            {
                foreach (ITreeItem item in oldExpanded)
                {
                    if (nodeDict.ContainsKey(item.Path.ToLower()))
                    {
                        nodeDict[item.Path.ToLower()].IsExpanded = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private async Task LoadRootsAsync()
        {
            //Get all expanded nodes
            List <ITreeItem> oldExpanded = new List <ITreeItem>();

            if (ExpandedNodes.Count > 0)
            {
                foreach (ITreeItem item in ExpandedNodes)
                {
                    oldExpanded.Add(item);
                }
                oldExpanded = new List <ITreeItem>(oldExpanded.OrderBy(x => x.Level));
            }

            //Clean tree
            foreach (ITreeItem item in nodeDict.Values)
            {
                UnSubscribeEvents(item);
            }
            nodeDict.Clear();
            ClearTree();

            //Get drives
            IEnumerable <DriveInfo> diResult = await LocalDriveCrawler.GetReadyDrivesAsync();

            foreach (DriveInfo item in diResult)
            {
                DriveTreeItemViewModel vm = new DriveTreeItemViewModel(item);
                AddToTree(vm);
                nodeDict.Add(vm.Path.ToLower(), vm);
                vm.Expanded  += OnVmExpanded;
                vm.Collapsed += OnVmCollapsed;
                //create children for root nodes
                CreateSubFolders(vm);
            }


            if (oldExpanded.Count > 0)
            {
                foreach (ITreeItem item in oldExpanded)
                {
                    if (nodeDict.ContainsKey(item.Path.ToLower()))
                    {
                        nodeDict[item.Path.ToLower()].IsExpanded = true;
                    }
                }
            }
        }