/// <summary> /// Формирование дочерних объектов сразу по нескольким узлам /// </summary> /// <param name="tempList">Список объектов, по которым прогружаем дочерние</param> /// <param name="descriptor">Описатель дерева</param> public void LoadDynamicChildren(IEnumerable <FreeHierarchyTreeItem> tempList) { #if DEBUG var sw = new System.Diagnostics.Stopwatch(); sw.Start(); #endif var comparer = new FreeHierarchyTreeItemComparer(); //Это стандартные деревья foreach (var item in tempList) { if (item.IncludeObjectChildren) { if (Tree_ID <= 0) { item.IsFreeHierLoadedInitializet = true; } var brunch = item.AddStandartChildren(false, true, false, false); if (brunch != null) { item.Children.AddRange(brunch.OrderBy(b => b, comparer)); } } item.IsLocalChildrenInitializet = true; if (Tree_ID <= 0) { item.IsChildrenInitializet = true; } } #if DEBUG sw.Stop(); Console.WriteLine("LoadDynamicChildren: стандартные деревья {0} млс", sw.ElapsedMilliseconds); sw.Restart(); #endif if (Tree_ID <= 0) { return; } //Пока работает кроме ФИАС var parendIds = tempList .Where(tl => !tl.IsFreeHierLoadedInitializet) .Select(tl => tl.FreeHierItem_ID) .ToList(); var branches = FreeHierarchyService.GetBranches(Manager.User.User_ID, Tree_ID.GetValueOrDefault(), parendIds, false); if (branches == null) { return; } var itemsForPrepare = new List <TFreeHierarchyTreeItem>(); foreach (var branch in branches) { if (branch.Value == null) { continue; } itemsForPrepare.AddRange(branch.Value); } #if DEBUG sw.Stop(); Console.WriteLine("LoadDynamicChildren: GetBranches {0} млс", sw.ElapsedMilliseconds); sw.Restart(); #endif FreeHierarchyTreePreparer.PrepareGlobalDictionaries(itemsForPrepare); foreach (var item in tempList) { if (item.IsFreeHierLoadedInitializet) { continue; } List <TFreeHierarchyTreeItem> children; if (branches.TryGetValue(item.FreeHierItem_ID, out children) && children != null) { var brunch = FreeHierarchyTreePreparer.BuildBranch(item, children, this, false, null, false); if (brunch != null) { item.Children.AddRange(brunch.OrderBy(b => b, comparer)); } } item.IsChildrenInitializet = true; } #if DEBUG sw.Stop(); Console.WriteLine("LoadDynamicChildren: PrepareGlobalDictionaries and BuildBranch {0} млс", sw.ElapsedMilliseconds); #endif }
public static IDictionary <int, FreeHierarchyTreeItem> GetTree(FreeHierarchyTreeDescriptor descriptor, out bool isFirstLoaded, bool isHideTi = false, HashSet <long> selectedNodes = null, bool isFullReload = false, HashSet <int> singreRootFreeHierItemIds = null) { isFirstLoaded = false; //Признак администратора bool isUserAdmin = Manager.User.IsAdmin; #if DEBUG var sw = new System.Diagnostics.Stopwatch(); sw.Start(); #endif #region это стандартные деревья их не загружаем switch (descriptor.Tree_ID) { //case TreeTypeStandartPS: case TreeTypeStandartTIFormula: case TreeTypeStandartDistributingArrangementAndBusSystem: //if (isFullReload) //{ // descriptor.UpdateIncludedObjectChildrenAsync(Manager.User.User_ID); //} return(GenerateStandartTreePS(descriptor, isHideTi)); case TreeTypeStandartSections: case TreeTypeStandartSectionsNSI: return(GenerateStandartTreeSections(descriptor)); case TreeTypeStandartBySupplyPS: return(GenerateStandartTreeBySupplyPS(descriptor, isHideTi)); case TreeTypeStandartGroupTP: return(JuridicalPersonTree.GenerateJuridicalPersonTree(descriptor, true, false)); case TreeTypeStandartJuridicalPerson: return(JuridicalPersonTree.GenerateJuridicalPersonTree(descriptor, false, true)); case TreeTypeStandart_Dict_OPCUAServers: return(GenerateStandartTree_Dict_OPCUAServers(descriptor)); case TreeTypeStandart_Dict_FIAS: return(GenerateStandartTree_FIAS(false, descriptor)); case TreeTypeStandart_Dict_FIASToHierarchy: return(GenerateStandartTree_FIAS(true, descriptor)); case TreeExplXmlExportConfigs: return(GenerateExplXmlExportConfigsTree(descriptor)); case TreeExplXmlBalance63: return(GenerateBalance63Tree(descriptor)); case TreeOldTelescope: return(GenerateOldTelescopeTree(descriptor)); } #endregion var result = new ConcurrentDictionary <int, FreeHierarchyTreeItem>(); List <TFreeHierarchyTreeItem> tempList = null; try { int?parenId = null; if (singreRootFreeHierItemIds != null) { parenId = singreRootFreeHierItemIds.FirstOrDefault(); } tempList = FreeHierarchyTreeDictionary.GetBranch(Manager.User.User_ID, descriptor.Tree_ID.GetValueOrDefault(), parenId, isFullReload, onError: Manager.UI.ShowMessage); } catch (Exception ex) { Manager.UI.ShowMessage(ex.Message); } #if DEBUG sw.Stop(); Console.WriteLine("Запрос дерева в БД {0} млс", sw.ElapsedMilliseconds); sw.Restart(); #endif if (tempList == null) { return(result); } FreeHierarchyTreePreparer.PrepareGlobalDictionaries(tempList); if (descriptor != null) { descriptor.Tree = result; } foreach (var newItem in FreeHierarchyTreePreparer.BuildBranch(null, tempList, descriptor, isHideTi, selectedNodes)) { result.TryAdd(newItem.FreeHierItem_ID, newItem); } //if ((uspdList!=null&&(uspdList.Count>0))) //{ // ProcessUspdInTree(result,uspdList, isFilteredBySmallTi, isHideTi); //} #if DEBUG sw.Stop(); Console.WriteLine("Построение дерева {0} млс", sw.ElapsedMilliseconds); #endif return(result); }