private static IEnumerable <Element> GetChildren(ElementHandle elementHandle, SearchToken searchToken, bool performSecurityCheck, bool useForeign)
        {
            if (elementHandle == null)
            {
                throw new ArgumentNullException("elementHandle");
            }

            IPerformanceCounterToken performanceToken = PerformanceCounterFacade.BeginElementCreation();

            IEnumerable <Element> children;

            if (ElementProviderRegistry.ElementProviderNames.Contains(elementHandle.ProviderName))
            {
                if ((useForeign == false) || (ElementProviderPluginFacade.IsLocaleAwareElementProvider(elementHandle.ProviderName) == false))
                {
                    children = ElementProviderPluginFacade.GetChildren(elementHandle.ProviderName, elementHandle.EntityToken, searchToken).Evaluate();
                }
                else
                {
                    children = ElementProviderPluginFacade.GetForeignChildren(elementHandle.ProviderName, elementHandle.EntityToken, searchToken).Evaluate();
                }
            }
            else if (ElementAttachingProviderRegistry.ElementAttachingProviderNames.Contains(elementHandle.ProviderName))
            {
                children = ElementAttachingProviderPluginFacade.GetChildren(elementHandle.ProviderName, elementHandle.EntityToken, elementHandle.Piggyback).Evaluate();
            }
            else
            {
                throw new InvalidOperationException(string.Format("No element provider named '{0}' found", elementHandle.ProviderName));
            }

            foreach (Element element in children)
            {
                if (element.VisualData.HasChildren == false)
                {
                    element.VisualData.HasChildren = ElementAttachingProviderFacade.HaveCustomChildElements(element.ElementHandle.EntityToken, element.ElementHandle.Piggyback);
                }
            }

            children = ElementAttachingProviderFacade.AttachElements(elementHandle.EntityToken, elementHandle.Piggyback, children).Evaluate();

            int totalElementCount = children.Count();

            ElementActionProviderFacade.AddActions(children, elementHandle.ProviderName);

            if (performSecurityCheck)
            {
                children = children.FilterActions().Evaluate();
            }

            PerformanceCounterFacade.EndElementCreation(performanceToken, children.Count(), totalElementCount);

            return(children);
        }
Example #2
0
        private static IEnumerable <Element> GetChildren(ElementHandle elementHandle, SearchToken searchToken, bool performSecurityCheck, bool useForeign)
        {
            Verify.ArgumentNotNull(elementHandle, nameof(elementHandle));

            var performanceToken = PerformanceCounterFacade.BeginElementCreation();

            var children = GetChildrenFromProvider(elementHandle, searchToken, useForeign).Evaluate();

            var originalChildren = children;

            children = ElementAttachingProviderFacade.AttachElements(elementHandle.EntityToken, elementHandle.Piggyback, children).Evaluate();

            int totalElementCount = children.Count;

            if (performSecurityCheck)
            {
                children = children.FilterElements().Evaluate();
            }

            // Evaluating HasChildren for not attached elements
            foreach (Element element in originalChildren)
            {
                if (children.Contains(element) && !element.VisualData.HasChildren)
                {
                    element.VisualData.HasChildren = ElementAttachingProviderFacade.HaveCustomChildElements(element.ElementHandle.EntityToken, element.ElementHandle.Piggyback);
                }
            }

            ElementActionProviderFacade.AddActions(children, elementHandle.ProviderName);

            if (performSecurityCheck)
            {
                children = children.FilterActions().Evaluate();
            }

            PerformanceCounterFacade.EndElementCreation(performanceToken, children.Count, totalElementCount);

            return(children);
        }