/// <exclude />
        public RelationshipGraph(EntityToken sourceEntityToken, RelationshipGraphSearchOption searchOption, bool lazyEvaluation, bool excludeReoccuringNodes)
        {
            _excludeReoccuringNodes = excludeReoccuringNodes;

            Verify.ArgumentNotNull(sourceEntityToken, "sourceEntityToken");

            _searchOption = searchOption;

            RelationshipGraphNode node = new RelationshipGraphNode(sourceEntityToken, 0, RelationshipGraphNodeType.Entity);

            _levels.Add(0, new List <RelationshipGraphNode> {
                node
            });

            string userName = UserValidationFacade.IsLoggedIn() ? UserSettings.Username : null;

            ExpandNextLevel(userName);

            if (lazyEvaluation == false)
            {
                while (_moreLevelsToExpend)
                {
                    ExpandNextLevel(userName);
                }
            }
        }
        /// <exclude />
        public static void ClearCache(EntityToken entityToken)
        {
            if (!Enabled)
            {
                return;
            }

            string userName = UserValidationFacade.IsLoggedIn() ? ResolveUsername() : null;

            ClearCache(entityToken, userName);
        }
        /// <exclude />
        public static bool GetCachedHookingParents(EntityToken entityToken, out IEnumerable <EntityToken> parentEntityTokens)
        {
            if (!Enabled)
            {
                parentEntityTokens = null;
                return(false);
            }

            string userName = UserValidationFacade.IsLoggedIn() ? ResolveUsername() : null;

            return(GetCachedHookingParents(entityToken, out parentEntityTokens, userName));
        }
        internal RelationshipGraphLevel GetLevel(int level)
        {
            string userName = UserValidationFacade.IsLoggedIn() ? UserSettings.Username : null;

            while (_levels.Count - 1 < level && _moreLevelsToExpend)
            {
                ExpandNextLevel(userName);
            }

            if (_levels.Count - 1 < level)
            {
                return(null);
            }

            return(new RelationshipGraphLevel(level, _levels[level]));
        }
        /// <exclude />
        public static void AddNativeCache(EntityToken entityToken, IEnumerable <EntityToken> parentEntityTokens)
        {
            if (!Enabled || !UserValidationFacade.IsLoggedIn())
            {
                return;
            }

            CacheEntry cacheEntry = new CacheEntry(entityToken)
            {
                ParentEntityTokens = parentEntityTokens.EvaluateOrNull(),
                Timestamp          = DateTime.Now
            };

            CacheKey cacheKey = new CacheKey {
                Username = ResolveUsername(), EntityToken = entityToken, Locale = Data.LocalizationScopeManager.CurrentLocalizationScope
            };

            _nativeCache.TryAdd(cacheKey, cacheEntry);

            if (_nativeCache.Count > MaxSize)
            {
                _nativeCache = new ConcurrentDictionary <CacheKey, CacheEntry>();
            }
        }
        /// <summary>
        /// This method will return all allowed permission for the current logged in user given the <paramref name="entityToken"/>.
        /// </summary>
        /// <param name="entityToken">EntityToken to get permissions for.</param>
        /// <returns>Allowed permission types</returns>
        public static IEnumerable <PermissionType> GetPermissionsForCurrentUser(EntityToken entityToken)
        {
            UserToken userToken = UserValidationFacade.GetUserToken();

            return(GetPermissions(userToken, entityToken));
        }