예제 #1
0
        public bool HaveCustomChildElements(EntityToken parentEntityToken, Dictionary <string, string> piggybag)
        {
            TreeSharedRootsFacade.Initialize(Context.ProviderName);

            foreach (Tree tree in TreeFacade.GetTreesByEntityToken(parentEntityToken))
            {
                if (tree.RootTreeNode.ChildNodes.Any())
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        /// <exclude />
        public static ActionNode Deserialize(Dictionary <string, string> serializedValueCollection, bool removeEntiresFromCollection = false)
        {
            string treeId       = StringConversionServices.DeserializeValueString(serializedValueCollection[TreeIdSerializedKeyName]);
            int    actionNodeId = StringConversionServices.DeserializeValueInt(serializedValueCollection[ActionNodeIdSerializedKeyName]);

            if (removeEntiresFromCollection)
            {
                serializedValueCollection.Remove(TreeIdSerializedKeyName);
                serializedValueCollection.Remove(ActionNodeIdSerializedKeyName);
            }

            Tree tree = TreeFacade.GetTree(treeId);

            return(tree?.GetActionNode(actionNodeId));
        }
        public Dictionary <EntityToken, IEnumerable <EntityToken> > GetParents(IEnumerable <EntityToken> entityTokens)
        {
            Dictionary <EntityToken, IEnumerable <EntityToken> > result = new Dictionary <EntityToken, IEnumerable <EntityToken> >();

            foreach (EntityToken entityToken in entityTokens)
            {
                TreeNodeDynamicContext dynamicContext = new TreeNodeDynamicContext(TreeNodeDynamicContextDirection.Up)
                {
                    CurrentEntityToken = entityToken
                };


                if (entityToken is TreeSimpleElementEntityToken ||
                    entityToken is TreeFunctionElementGeneratorEntityToken)
                {
                    var parentEntityTokenSource = entityToken as IEntityTokenContainingParentEntityToken;

                    try
                    {
                        result.Add(entityToken, new[] { parentEntityTokenSource.GetParentEntityToken() });
                    }
                    catch (Exception ex)
                    {
                        string treeId;

                        if (entityToken is TreeSimpleElementEntityToken)
                        {
                            treeId = (entityToken as TreeSimpleElementEntityToken).TreeNodeId;
                        }
                        else if (entityToken is TreeFunctionElementGeneratorEntityToken)
                        {
                            treeId = (entityToken as TreeFunctionElementGeneratorEntityToken).TreeNodeId;
                        }
                        else
                        {
                            throw new InvalidOperationException("This code should not be reachable.");
                        }

                        Log.LogError("TreeFacade", "The tree '{0}' failed to return parent entity tokens and are ignored", treeId);
                        Log.LogError("TreeFacade", ex);
                    }
                }
                else if (entityToken is TreeDataFieldGroupingElementEntityToken)
                {
                    TreeDataFieldGroupingElementEntityToken treeDataFieldGroupingElementEntityToken = entityToken as TreeDataFieldGroupingElementEntityToken;
                    string treeId = entityToken.Source;

                    try
                    {
                        Tree tree = TreeFacade.GetTree(treeId);

                        string   treeNodeId = treeDataFieldGroupingElementEntityToken.TreeNodeId;
                        TreeNode treeNode   = tree.GetTreeNode(treeNodeId);

                        dynamicContext.FieldGroupingValues    = treeDataFieldGroupingElementEntityToken.GroupingValues;
                        dynamicContext.FieldFolderRangeValues = treeDataFieldGroupingElementEntityToken.FolderRangeValues;
                        dynamicContext.CurrentTreeNode        = treeNode;

                        result.Add(entityToken, treeNode.ParentNode.GetEntityTokens(entityToken, dynamicContext));
                    }
                    catch (Exception ex)
                    {
                        Log.LogError("TreeFacade", $"The tree '{treeId}' failed to return parent entity tokens and are ignored");
                        Log.LogError("TreeFacade", ex);
                    }
                }
                else if (entityToken is DataEntityToken)
                {
                    DataEntityToken dataEntityToken = entityToken as DataEntityToken;

                    Type interfaceType = dataEntityToken.InterfaceType;

                    foreach (Tree tree in TreeFacade.AllTrees)
                    {
                        List <TreeNode> treeNodes;
                        if (!tree.BuildProcessContext.DataInteraceToTreeNodes.TryGetValue(interfaceType, out treeNodes))
                        {
                            continue;
                        }

                        IEnumerable <EntityToken> concatList = null;

                        foreach (TreeNode treeNode in treeNodes)
                        {
                            try
                            {
                                dynamicContext.CurrentTreeNode = treeNode;

                                concatList = concatList.ConcatOrDefault(treeNode.ParentNode.GetEntityTokens(entityToken, dynamicContext));
                            }
                            catch (Exception ex)
                            {
                                Log.LogError("TreeFacade", $"The tree '{treeNode.Tree.TreeId}' failed to return parent entity tokens and are ignored");
                                Log.LogError("TreeFacade", ex);
                            }
                        }

                        if (concatList != null)
                        {
                            // Filtering the current element to avoid loops while resolving security
                            concatList = concatList.Where(e => !entityToken.Equals(e));

                            IEnumerable <EntityToken> existingList;
                            if (result.TryGetValue(entityToken, out existingList))
                            {
                                result[entityToken] = existingList.Concat(concatList);
                            }
                            else
                            {
                                result.Add(entityToken, concatList);
                            }
                        }
                    }
                }
                else if (entityToken is TreePerspectiveEntityToken)
                {
                    result.Add(entityToken, new[] { TreeSharedRootsFacade.SharedRootFolders[entityToken.Id].AttachmentPoint.AttachingPoint.EntityToken });
                }
            }

            return(result);
        }
예제 #4
0
        public IEnumerable <ElementAttachingProviderResult> GetAlternateElementLists(EntityToken parentEntityToken, Dictionary <string, string> piggybag)
        {
            TreeSharedRootsFacade.Initialize(Context.ProviderName);

            IEnumerable <Tree> trees = TreeFacade.GetTreesByEntityToken(parentEntityToken);

            foreach (Tree tree in trees)
            {
                foreach (IAttachmentPoint attachmentPoint in tree.GetAttachmentPoints(parentEntityToken))
                {
                    TreeNodeDynamicContext dynamicContext = new TreeNodeDynamicContext(TreeNodeDynamicContextDirection.Down)
                    {
                        ElementProviderName = this.Context.ProviderName,
                        Piggybag            = piggybag,
                        CurrentEntityToken  = parentEntityToken,
                        CurrentTreeNode     = tree.RootTreeNode,
                        IsRoot = true
                    };

                    ElementAttachingProviderResult result = null;
                    try
                    {
                        result = new ElementAttachingProviderResult()
                        {
                            Elements         = tree.RootTreeNode.GetElements(parentEntityToken, dynamicContext).Evaluate(),
                            Position         = attachmentPoint.Position,
                            PositionPriority = 0
                        };
                    }
                    catch (Exception ex)
                    {
                        LoggingService.LogError("TreeFacade", string.Format("Getting elements from the three '{0}' failed", tree.TreeId));
                        LoggingService.LogError("TreeFacade", ex);

                        Element errorElement = ShowErrorElementHelper.CreateErrorElement(
                            StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "KeyFacade.ErrorTreeNode.Label"),
                            tree.TreeId,
                            ex.Message);

                        result = new ElementAttachingProviderResult()
                        {
                            Elements = new List <Element>()
                            {
                                errorElement
                            },
                            Position         = attachmentPoint.Position,
                            PositionPriority = 0
                        };
                    }

                    yield return(result);
                }
            }

            foreach (CustomTreePerspectiveInfo info in TreeSharedRootsFacade.SharedRootFolders.Values)
            {
                if (info.AttachmentPoint.IsAttachmentPoint(parentEntityToken))
                {
                    Element element = new Element(new ElementHandle(info.Element.ElementHandle.ProviderName, info.Element.ElementHandle.EntityToken))
                    {
                        VisualData = info.Element.VisualData
                    };

                    int counter = 0;
                    foreach (Tree tree in info.Trees)
                    {
                        string key = StringConstants.PiggybagSharedTreeId + (counter++);
                        element.ElementHandle.Piggyback[key] = tree.TreeId;
                    }

                    ElementAttachingProviderResult result = new ElementAttachingProviderResult
                    {
                        Elements         = new [] { info.Element },
                        Position         = info.AttachmentPoint.Position,
                        PositionPriority = 10000
                    };

                    yield return(result);
                }
            }
        }
예제 #5
0
        public IEnumerable <Element> GetChildren(EntityToken parentEntityToken, Dictionary <string, string> piggybag)
        {
            TreeSharedRootsFacade.Initialize(Context.ProviderName);

            List <Tree> trees;

            if (parentEntityToken is TreePerspectiveEntityToken)
            {
                if (TreeSharedRootsFacade.SharedRootFolders.ContainsKey(parentEntityToken.Id))
                {
                    trees = TreeSharedRootsFacade.SharedRootFolders[parentEntityToken.Id].Trees;
                }
                else
                {
                    trees = new List <Tree>();
                }
            }
            else
            {
                if (piggybag.ContainsKey(StringConstants.PiggybagTreeId))
                {
                    string treeId = piggybag.Where(f => f.Key == StringConstants.PiggybagTreeId).SingleOrDefault().Value;
                    Tree   tree   = TreeFacade.GetTree(treeId);
                    if (tree == null)
                    {
                        return new Element[] { }
                    }
                    ;
                    trees = new List <Tree> {
                        tree
                    };
                }
                else
                {
                    trees = new List <Tree>();

                    int counter = 0;
                    while (true)
                    {
                        string key = StringConstants.PiggybagSharedTreeId + (counter++);

                        if (!piggybag.ContainsKey(key))
                        {
                            break;
                        }

                        string treeId = piggybag[key];
                        Tree   tree   = TreeFacade.GetTree(treeId);
                        if (tree != null)
                        {
                            trees.Add(tree);
                        }
                    }
                }
            }

            IEnumerable <Element> result = new List <Element>();

            foreach (Tree tree in trees)
            {
                TreeNodeDynamicContext dynamicContext = new TreeNodeDynamicContext(TreeNodeDynamicContextDirection.Down)
                {
                    ElementProviderName = this.Context.ProviderName,
                    Piggybag            = piggybag,
                    CurrentEntityToken  = parentEntityToken
                };

                try
                {
                    if (parentEntityToken is TreePerspectiveEntityToken)
                    {
                        TreeNode treeNode = tree.RootTreeNode;

                        dynamicContext.CurrentTreeNode = treeNode;

                        IEnumerable <Element> elements = treeNode.ChildNodes.GetElements(parentEntityToken, dynamicContext);
                        result = result.ConcatOrDefault(elements);
                    }
                    else if (parentEntityToken is TreeSimpleElementEntityToken)
                    {
                        TreeNode treeNode = tree.GetTreeNode(parentEntityToken.Id);
                        if (treeNode == null)
                        {
                            throw new InvalidOperationException("Tree is out of sync");
                        }

                        dynamicContext.CurrentTreeNode = treeNode;

                        IEnumerable <Element> elements = treeNode.ChildNodes.GetElements(parentEntityToken, dynamicContext);
                        result = result.ConcatOrDefault(elements);
                    }
                    else if (parentEntityToken is TreeFunctionElementGeneratorEntityToken)
                    {
                        TreeNode treeNode = tree.GetTreeNode(parentEntityToken.Id);
                        if (treeNode == null)
                        {
                            throw new InvalidOperationException("Tree is out of sync");
                        }

                        dynamicContext.CurrentTreeNode = treeNode;

                        IEnumerable <Element> elements = treeNode.ChildNodes.GetElements(parentEntityToken, dynamicContext);
                        result = result.ConcatOrDefault(elements);
                    }
                    else if (parentEntityToken is TreeDataFieldGroupingElementEntityToken)
                    {
                        TreeDataFieldGroupingElementEntityToken castedParentEntityToken = parentEntityToken as TreeDataFieldGroupingElementEntityToken;
                        TreeNode treeNode = tree.GetTreeNode(parentEntityToken.Id);
                        if (treeNode == null)
                        {
                            throw new InvalidOperationException("Tree is out of sync");
                        }

                        dynamicContext.CurrentTreeNode        = treeNode;
                        dynamicContext.FieldGroupingValues    = castedParentEntityToken.GroupingValues;
                        dynamicContext.FieldFolderRangeValues = castedParentEntityToken.FolderRangeValues;

                        IEnumerable <Element> elements = treeNode.ChildNodes.GetElements(parentEntityToken, dynamicContext);
                        result = result.ConcatOrDefault(elements);
                    }
                    else if (parentEntityToken is DataEntityToken)
                    {
                        DataEntityToken dataEntityToken = parentEntityToken as DataEntityToken;

                        Type interfaceType = dataEntityToken.InterfaceType;

                        List <TreeNode> treeNodes;
                        if (tree.BuildProcessContext.DataInteraceToTreeNodes.TryGetValue(interfaceType, out treeNodes) == false)
                        {
                            throw new InvalidOperationException();
                        }

                        string parentNodeId = piggybag.GetParentIdFromPiggybag();

                        TreeNode treeNode = treeNodes.Where(f => f.ParentNode.Id == parentNodeId).SingleOrDefault();
                        if (treeNode == null)
                        {
                            throw new InvalidOperationException("Tree is out of sync");
                        }

                        dynamicContext.CurrentTreeNode = treeNode;

                        IEnumerable <Element> elements = treeNode.ChildNodes.GetElements(parentEntityToken, dynamicContext);
                        result = result.ConcatOrDefault(elements);
                    }
                    else
                    {
                        throw new NotImplementedException("Unhandled entityt token type");
                    }


                    result = result.Evaluate();
                }
                catch (Exception ex)
                {
                    LoggingService.LogError("TreeFacade", string.Format("Getting elements from the three '{0}' failed", tree.TreeId));
                    LoggingService.LogError("TreeFacade", ex);

                    Element errorElement = ShowErrorElementHelper.CreateErrorElement(
                        StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "KeyFacade.ErrorTreeNode.Label"),
                        tree.TreeId,
                        ex.Message);

                    return(new Element[] { errorElement });
                }
            }

            return(result);
        }
    }
        public IEnumerable <ElementAction> GetActions(EntityToken entityToken)
        {
            if (TreeFacade.HasPossibleAttachmentPoints(entityToken))
            {
                yield return(new ElementAction(new ActionHandle(new WorkflowActionToken(WorkflowFacade.GetWorkflowType("Composite.C1Console.Trees.Workflows.AddApplicationWorkflow"), AddPermissionTypes)
                {
                    DoIgnoreEntityTokenLocking = true
                }))
                {
                    VisualData = new ActionVisualizedData
                    {
                        Label = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "AddApplicationWorkflow.AddApplication.Label"),
                        ToolTip = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "AddApplicationWorkflow.AddApplication.ToolTip"),
                        Icon = AddApplicationIcon,
                        Disabled = false,
                        ActionLocation = new ActionLocation
                        {
                            ActionType = ActionType.Other,
                            IsInFolder = false,
                            IsInToolbar = false,
                            ActionGroup = ApplicationsActionGroup
                        }
                    }
                });


                yield return(new ElementAction(new ActionHandle(new WorkflowActionToken(WorkflowFacade.GetWorkflowType("Composite.C1Console.Trees.Workflows.RemoveApplicationWorkflow"), RemovePermissionTypes)
                {
                    DoIgnoreEntityTokenLocking = true
                }))
                {
                    VisualData = new ActionVisualizedData
                    {
                        Label = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "RemoveApplicationWorkflow.RemoveApplication.Label"),
                        ToolTip = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "RemoveApplicationWorkflow.RemoveApplication.ToolTip"),
                        Icon = RemoveApplicationIcon,
                        Disabled = false,
                        ActionLocation = new ActionLocation
                        {
                            ActionType = ActionType.Other,
                            IsInFolder = false,
                            IsInToolbar = false,
                            ActionGroup = ApplicationsActionGroup
                        }
                    }
                });
            }


            List <ElementAction> elementActions = new List <ElementAction>();

            foreach (Tree tree in TreeFacade.GetTreesByEntityToken(entityToken))
            {
                TreeNodeDynamicContext dynamicContext = new TreeNodeDynamicContext(TreeNodeDynamicContextDirection.Down)
                {
                    CurrentTreeNode    = tree.RootTreeNode,
                    CurrentEntityToken = entityToken,
                    Piggybag           = new Dictionary <string, string>()
                };

                foreach (ActionNode actionNode in tree.RootTreeNode.ActionNodes)
                {
                    actionNode.AddAction(f => elementActions.Add(f), entityToken, dynamicContext);
                }
            }


            foreach (ElementAction elementAction in elementActions)
            {
                yield return(elementAction);
            }
        }