/// <summary> /// Get a factor tree node for specified locale by the spcified factor id. /// </summary> /// <param name="locale">Locale.</param> /// <param name="factorId">The specified factor id.</param> /// <param name="getOnlyPublicFactors">Get only public factor tree node or not from cache.</param> /// <returns>A factor tree node related to the specified factor id for specified locale.</returns> protected virtual IFactorTreeNode GetFactorTreeNode(ILocale locale, int factorId, Boolean getOnlyPublicFactors) { String factorTreeType = getOnlyPublicFactors ? FactorTreesPermissionType.PublicFactorTrees.ToString() : FactorTreesPermissionType.AllFactorTrees.ToString(); IFactorTreeNode factorTreeNode = null; if (FactorTreeNodes.ContainsKey(locale.ISOCode + "#" + factorTreeType)) { factorTreeNode = ((Dictionary <int, IFactorTreeNode>)(FactorTreeNodes[locale.ISOCode + "#" + factorTreeType]))[factorId]; } return(factorTreeNode); }
/// <summary> /// Add a factor tree node to the parents /// of this factor tree node. /// </summary> /// <param name='factorTreeNode'>Factor tree node to add.</param> public void AddParent(IFactorTreeNode factorTreeNode) { Parents.Add(factorTreeNode); }
/// <summary> /// Get a factor tree node by the specified factor id. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="factorId">The specified factor id.</param> /// <returns>A factor tree node related to the specified factor id.</returns> public override IFactorTreeNode GetFactorTree(IUserContext userContext, int factorId) { IFactorTreeNode factorTreeNode = null; FactorTreeNodeList factorTrees = null; Dictionary <int, IFactorTreeNode> factorTreeNodes = new Dictionary <int, IFactorTreeNode>(); IFactorTreeSearchCriteria searchCriteria; searchCriteria = new FactorTreeSearchCriteria(); searchCriteria.FactorIds = new List <Int32>(); searchCriteria.FactorIds.Add(factorId); Boolean getOnlyPublicFactors = !IsUserAuthorizedToReadNonPublicFactors(userContext); // Get cached factor trees factorTrees = GetFactorTrees(userContext.Locale, getOnlyPublicFactors); factorTreeNode = GetFactorTreeNode(userContext.Locale, factorId, getOnlyPublicFactors); if (factorTrees.IsNull()) { // Get factor trees based on user role and rights (get public factors or all factors) factorTrees = base.GetFactorTrees(userContext); // Store factor trees in cache SetFactorTrees(factorTrees, userContext.Locale, getOnlyPublicFactors); foreach (IFactorTreeNode node in factorTrees) { if (!factorTreeNodes.ContainsKey(node.Id)) { factorTreeNodes.Add(node.Id, node); } AddFactorTreeChildren(factorTreeNodes, node.Children); } // Store factor tree nodes in cache SetFactorTreeNodes(factorTreeNodes, userContext.Locale, getOnlyPublicFactors); } if (factorTrees.IsNotNull()) { foreach (var factorTree in factorTrees) { if (factorTree.Id == factorId) { factorTreeNode = factorTree; break; } } } if (factorTreeNode.IsNull() && factorTreeNodes.IsNotNull()) { foreach (var factorTree in factorTreeNodes) { if (factorTree.Key == factorId) { factorTreeNode = factorTree.Value; break; } } } return(factorTreeNode); }
/// <summary> /// Add a factor tree node to the children /// of this factor tree node. /// </summary> /// <param name='factorTreeNode'>Factor tree node to add.</param> public void AddChild(IFactorTreeNode factorTreeNode) { factorTreeNode.AddParent(this); Children.Add(factorTreeNode); }