Beispiel #1
0
        private Controller ImportControllerWithChildren(
            string rootControllerPath,
            IReadOnlyCollection <IControllerTag> controllerTags,
            IList <string> userDefinedInterfaces, int depth)
        {
            CheckCurrentDepth(rootControllerPath, depth);

            IControllerTag rootControllerTag;

            if (string.IsNullOrEmpty(rootControllerPath))
            {
                rootControllerTag = controllerTags.FirstOrDefault(ct => ct.GetParentControllerId() == NoControllerId);
            }
            else
            {
                rootControllerTag =
                    controllerTags.FirstOrDefault(ct => string.Equals(ct.GetScopedPath(), rootControllerPath, StringComparison.InvariantCultureIgnoreCase));
            }

            // the tag wasn't found, exit recursive call
            if (rootControllerTag == null)
            {
                return(null);
            }

            Controller controller = _createController.Create(_tagController, rootControllerTag, userDefinedInterfaces, _tagListener);
            IEnumerable <IControllerTag> children = controllerTags.Where(ct => ct.GetParentControllerId() == controller.Id);

            foreach (IControllerTag child in children)
            {
                Controller createdControllerChild = ImportControllerWithChildren(child.GetScopedPath(), controllerTags, userDefinedInterfaces, depth - 1);
                controller.AddChild(createdControllerChild);
            }
            return(controller);
        }